@@ -11,6 +11,7 @@ import '../api/model/model_checks.dart';
11
11
import '../example_data.dart' as eg;
12
12
import '../stdlib_checks.dart' ;
13
13
import 'message_list_test.dart' ;
14
+ import 'store_checks.dart' ;
14
15
import 'test_store.dart' ;
15
16
16
17
void main () {
@@ -160,6 +161,88 @@ void main() {
160
161
});
161
162
});
162
163
164
+ group ('handleUpdateMessageEvent' , () {
165
+ test ('update a message' , () async {
166
+ final originalMessage = eg.streamMessage (
167
+ content: "<p>Hello, world</p>" );
168
+ final updateEvent = eg.updateMessageEditEvent (originalMessage,
169
+ flags: [MessageFlag .starred],
170
+ renderedContent: "<p>Hello, edited</p>" ,
171
+ editTimestamp: 99999 ,
172
+ isMeMessage: true ,
173
+ );
174
+ await prepare ();
175
+ await prepareMessages ([originalMessage]);
176
+
177
+ final message = store.messages.values.single;
178
+ check (message)
179
+ ..content.not ((it) => it.equals (updateEvent.renderedContent! ))
180
+ ..lastEditTimestamp.isNull ()
181
+ ..flags.not ((it) => it.deepEquals (updateEvent.flags))
182
+ ..isMeMessage.not ((it) => it.equals (updateEvent.isMeMessage! ));
183
+
184
+ await store.handleEvent (updateEvent);
185
+ checkNotifiedOnce ();
186
+ check (store).messages.values.single
187
+ ..identicalTo (message)
188
+ ..content.equals (updateEvent.renderedContent! )
189
+ ..lastEditTimestamp.equals (updateEvent.editTimestamp)
190
+ ..flags.equals (updateEvent.flags)
191
+ ..isMeMessage.equals (updateEvent.isMeMessage! );
192
+ });
193
+
194
+ test ('ignore when message unknown' , () async {
195
+ final originalMessage = eg.streamMessage (
196
+ content: "<p>Hello, world</p>" );
197
+ final updateEvent = eg.updateMessageEditEvent (originalMessage,
198
+ messageId: originalMessage.id + 1 ,
199
+ renderedContent: "<p>Hello, edited</p>" ,
200
+ );
201
+ await prepare ();
202
+ await prepareMessages ([originalMessage]);
203
+
204
+ await store.handleEvent (updateEvent);
205
+ checkNotNotified ();
206
+ check (store).messages.values.single
207
+ ..content.equals (originalMessage.content)
208
+ ..content.not ((it) => it.equals (updateEvent.renderedContent! ));
209
+ });
210
+
211
+ // TODO(server-5): Cut legacy case for rendering-only message update
212
+ Future <void > checkRenderingOnly ({required bool legacy}) async {
213
+ final originalMessage = eg.streamMessage (
214
+ lastEditTimestamp: 78492 ,
215
+ content: "<p>Hello, world</p>" );
216
+ final updateEvent = eg.updateMessageEditEvent (originalMessage,
217
+ renderedContent: "<p>Hello, world</p> <div>Some link preview</div>" ,
218
+ editTimestamp: 99999 ,
219
+ renderingOnly: legacy ? null : true ,
220
+ userId: null ,
221
+ );
222
+ await prepare ();
223
+ await prepareMessages ([originalMessage]);
224
+ final message = store.messages.values.single;
225
+
226
+ await store.handleEvent (updateEvent);
227
+ checkNotifiedOnce ();
228
+ check (store).messages.values.single
229
+ ..identicalTo (message)
230
+ // Content is updated...
231
+ ..content.equals (updateEvent.renderedContent! )
232
+ // ... edit timestamp is not.
233
+ ..lastEditTimestamp.equals (originalMessage.lastEditTimestamp)
234
+ ..lastEditTimestamp.not ((it) => it.equals (updateEvent.editTimestamp));
235
+ }
236
+
237
+ test ('rendering-only update does not change timestamp' , () async {
238
+ await checkRenderingOnly (legacy: false );
239
+ });
240
+
241
+ test ('rendering-only update does not change timestamp (for old server versions)' , () async {
242
+ await checkRenderingOnly (legacy: true );
243
+ });
244
+ });
245
+
163
246
group ('handleReactionEvent' , () {
164
247
test ('add reaction' , () async {
165
248
final originalMessage = eg.streamMessage (reactions: []);
0 commit comments