@@ -94,7 +94,7 @@ mixin _MessageSequence {
94
94
///
95
95
/// This may or may not represent all the message history that
96
96
/// conceptually belongs in this message list.
97
- /// That information is expressed in [fetched] and [haveOldest] .
97
+ /// That information is expressed in [fetched] , [haveOldest] , [haveNewest ] .
98
98
///
99
99
/// See also [middleMessage] , an index which divides this list
100
100
/// into a top slice and a bottom slice.
@@ -121,11 +121,19 @@ mixin _MessageSequence {
121
121
122
122
/// Whether we know we have the oldest messages for this narrow.
123
123
///
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] .
126
125
bool get haveOldest => _haveOldest;
127
126
bool _haveOldest = false ;
128
127
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
+
129
137
/// Whether this message list is currently busy when it comes to
130
138
/// fetching more messages.
131
139
///
@@ -158,7 +166,7 @@ mixin _MessageSequence {
158
166
/// before, between, or after the messages.
159
167
///
160
168
/// This information is completely derived from [messages] and
161
- /// the flags [haveOldest] and [busyFetchingMore] .
169
+ /// the flags [haveOldest] , [haveNewest] , and [busyFetchingMore] .
162
170
/// It exists as an optimization, to memoize that computation.
163
171
///
164
172
/// See also [middleItem] , an index which divides this list
@@ -315,6 +323,7 @@ mixin _MessageSequence {
315
323
messages.clear ();
316
324
middleMessage = 0 ;
317
325
_haveOldest = false ;
326
+ _haveNewest = false ;
318
327
_status = FetchingStatus .unstarted;
319
328
_fetchBackoffMachine = null ;
320
329
contents.clear ();
@@ -534,7 +543,7 @@ class MessageListView with ChangeNotifier, _MessageSequence {
534
543
Future <void > fetchInitial () async {
535
544
// TODO(#80): fetch from anchor firstUnread, instead of newest
536
545
// TODO(#82): fetch from a given message ID as anchor
537
- assert (! fetched && ! haveOldest && ! busyFetchingMore);
546
+ assert (! fetched && ! haveOldest && ! haveNewest && ! busyFetchingMore);
538
547
assert (messages.isEmpty && contents.isEmpty);
539
548
_setStatus (FetchingStatus .fetchInitial, was: FetchingStatus .unstarted);
540
549
// TODO schedule all this in another isolate
@@ -561,6 +570,7 @@ class MessageListView with ChangeNotifier, _MessageSequence {
561
570
// Now [middleMessage] is the last message (the one just added).
562
571
}
563
572
_haveOldest = result.foundOldest;
573
+ _haveNewest = true ; // TODO(#82)
564
574
_setStatus (FetchingStatus .idle, was: FetchingStatus .fetchInitial);
565
575
}
566
576
@@ -715,8 +725,16 @@ class MessageListView with ChangeNotifier, _MessageSequence {
715
725
if (! narrow.containsMessage (message) || ! _messageVisible (message)) {
716
726
return ;
717
727
}
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.
720
738
return ;
721
739
}
722
740
// TODO insert in middle instead, when appropriate
0 commit comments