@@ -94,7 +94,7 @@ mixin _MessageSequence {
9494 ///
9595 /// This may or may not represent all the message history that
9696 /// conceptually belongs in this message list.
97- /// That information is expressed in [fetched] and [haveOldest] .
97+ /// That information is expressed in [fetched] , [haveOldest] , [haveNewest ] .
9898 ///
9999 /// See also [middleMessage] , an index which divides this list
100100 /// into a top slice and a bottom slice.
@@ -121,11 +121,19 @@ mixin _MessageSequence {
121121
122122 /// Whether we know we have the oldest messages for this narrow.
123123 ///
124- /// (Currently we always have the newest messages for the narrow,
125- /// once [fetched] is true, because we start from the newest.)
124+ /// See also [haveNewest] .
126125 bool get haveOldest => _haveOldest;
127126 bool _haveOldest = false ;
128127
128+ /// Whether we know we have the newest messages for this narrow.
129+ ///
130+ /// (Currently this is always true once [fetched] is true,
131+ /// because we start from the newest.)
132+ ///
133+ /// See also [haveOldest] .
134+ bool get haveNewest => _haveNewest;
135+ bool _haveNewest = false ;
136+
129137 /// Whether this message list is currently busy when it comes to
130138 /// fetching more messages.
131139 ///
@@ -158,7 +166,7 @@ mixin _MessageSequence {
158166 /// before, between, or after the messages.
159167 ///
160168 /// This information is completely derived from [messages] and
161- /// the flags [haveOldest] and [busyFetchingMore] .
169+ /// the flags [haveOldest] , [haveNewest] , and [busyFetchingMore] .
162170 /// It exists as an optimization, to memoize that computation.
163171 ///
164172 /// See also [middleItem] , an index which divides this list
@@ -315,6 +323,7 @@ mixin _MessageSequence {
315323 messages.clear ();
316324 middleMessage = 0 ;
317325 _haveOldest = false ;
326+ _haveNewest = false ;
318327 _status = FetchingStatus .unstarted;
319328 _fetchBackoffMachine = null ;
320329 contents.clear ();
@@ -534,7 +543,7 @@ class MessageListView with ChangeNotifier, _MessageSequence {
534543 Future <void > fetchInitial () async {
535544 // TODO(#80): fetch from anchor firstUnread, instead of newest
536545 // TODO(#82): fetch from a given message ID as anchor
537- assert (! fetched && ! haveOldest && ! busyFetchingMore);
546+ assert (! fetched && ! haveOldest && ! haveNewest && ! busyFetchingMore);
538547 assert (messages.isEmpty && contents.isEmpty);
539548 _setStatus (FetchingStatus .fetchInitial, was: FetchingStatus .unstarted);
540549 // TODO schedule all this in another isolate
@@ -561,6 +570,7 @@ class MessageListView with ChangeNotifier, _MessageSequence {
561570 // Now [middleMessage] is the last message (the one just added).
562571 }
563572 _haveOldest = result.foundOldest;
573+ _haveNewest = true ; // TODO(#82)
564574 _setStatus (FetchingStatus .idle, was: FetchingStatus .fetchInitial);
565575 }
566576
@@ -715,8 +725,16 @@ class MessageListView with ChangeNotifier, _MessageSequence {
715725 if (! narrow.containsMessage (message) || ! _messageVisible (message)) {
716726 return ;
717727 }
718- if (! fetched) {
719- // TODO mitigate this fetch/event race: save message to add to list later
728+ if (! haveNewest) {
729+ // This message list's [messages] doesn't yet reach the new end
730+ // of the narrow's message history. (Either [fetchInitial] hasn't yet
731+ // completed, or if it has then it was in the middle of history and no
732+ // subsequent fetch has reached the end.)
733+ // So this still-newer message doesn't belong.
734+ // Leave it to be found by a subsequent fetch when appropriate.
735+ // TODO mitigate this fetch/event race: save message to add to list later,
736+ // in case the fetch that reaches the end is already ongoing and
737+ // didn't include this message.
720738 return ;
721739 }
722740 // TODO insert in middle instead, when appropriate
0 commit comments