@@ -408,7 +408,20 @@ class MessageStoreImpl extends HasChannelStore with MessageStore, _OutboxMessage
408408
409409 void reconcileMessages (List <Message > messages) {
410410 assert (! _disposed);
411- // What to do when some of the just-fetched messages are already known?
411+ for (int i = 0 ; i < messages.length; i++ ) {
412+ final message = messages[i];
413+ messages[i] = this .messages.update (message.id,
414+ ifAbsent: () => _reconcileUnrecognizedMessage (message),
415+ (current) => _reconcileRecognizedMessage (current, message));
416+ }
417+ }
418+
419+ Message _reconcileUnrecognizedMessage (Message incoming) {
420+ return _stripMatchFields (incoming);
421+ }
422+
423+ Message _reconcileRecognizedMessage (Message current, Message incoming) {
424+ // This just-fetched message is one we already know about.
412425 // This is common and normal: in particular it happens when one message list
413426 // overlaps another, e.g. a stream and a topic within it.
414427 //
@@ -423,12 +436,8 @@ class MessageStoreImpl extends HasChannelStore with MessageStore, _OutboxMessage
423436 // we won't hear those events again; the only way to wind up with an
424437 // updated message is to use the version we have, that already reflects
425438 // those events' changes. So we always stick with the version we have.
426- for (int i = 0 ; i < messages.length; i++ ) {
427- final message = messages[i];
428- messages[i] = this .messages.putIfAbsent (message.id, () {
429- return _stripMatchFields (message);
430- });
431- }
439+ // TODO(#1798) consider unsubscribed channels
440+ return current;
432441 }
433442
434443 Message _stripMatchFields (Message message) {
0 commit comments