Skip to content

Commit d8ebe5e

Browse files
committed
message [nfc]: Pull out some helpers for reconcileMessages; add TODO(zulip#1798)
1 parent 41f5f20 commit d8ebe5e

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

lib/model/message.dart

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,20 @@ class MessageStoreImpl extends HasChannelStore with MessageStore, _OutboxMessage
400400

401401
void reconcileMessages(List<Message> messages) {
402402
assert(!_disposed);
403-
// What to do when some of the just-fetched messages are already known?
403+
for (int i = 0; i < messages.length; i++) {
404+
final message = messages[i];
405+
messages[i] = this.messages.update(message.id,
406+
ifAbsent: () => _reconcileUnrecognizedMessage(message),
407+
(current) => _reconcileRecognizedMessage(current, message));
408+
}
409+
}
410+
411+
Message _reconcileUnrecognizedMessage(Message incoming) {
412+
return _stripMatchFields(incoming);
413+
}
414+
415+
Message _reconcileRecognizedMessage(Message current, Message incoming) {
416+
// This just-fetched message is one we already know about.
404417
// This is common and normal: in particular it happens when one message list
405418
// overlaps another, e.g. a stream and a topic within it.
406419
//
@@ -415,12 +428,8 @@ class MessageStoreImpl extends HasChannelStore with MessageStore, _OutboxMessage
415428
// we won't hear those events again; the only way to wind up with an
416429
// updated message is to use the version we have, that already reflects
417430
// those events' changes. So we always stick with the version we have.
418-
for (int i = 0; i < messages.length; i++) {
419-
final message = messages[i];
420-
messages[i] = this.messages.putIfAbsent(message.id, () {
421-
return _stripMatchFields(message);
422-
});
423-
}
431+
// TODO(#1798) consider unsubscribed channels
432+
return current;
424433
}
425434

426435
Message _stripMatchFields(Message message) {

0 commit comments

Comments
 (0)