Skip to content

Commit e900b2d

Browse files
committed
msglist [nfc]: Introduce haveNewest in model, always true for now
1 parent cece587 commit e900b2d

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

lib/model/message_list.dart

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ mixin _MessageSequence {
9393
///
9494
/// This may or may not represent all the message history that
9595
/// conceptually belongs in this message list.
96-
/// That information is expressed in [fetched] and [haveOldest].
96+
/// That information is expressed in [fetched], [haveOldest], [haveNewest].
9797
///
9898
/// See also [middleMessage], an index which divides this list
9999
/// into a top slice and a bottom slice.
@@ -120,11 +120,19 @@ mixin _MessageSequence {
120120

121121
/// Whether we know we have the oldest messages for this narrow.
122122
///
123-
/// (Currently we always have the newest messages for the narrow,
124-
/// once [fetched] is true, because we start from the newest.)
123+
/// See also [haveNewest].
125124
bool get haveOldest => _haveOldest;
126125
bool _haveOldest = false;
127126

127+
/// Whether we know we have the newest messages for this narrow.
128+
///
129+
/// (Currently this is always true once [fetched] is true,
130+
/// because we start from the newest.)
131+
///
132+
/// See also [haveOldest].
133+
bool get haveNewest => _haveNewest;
134+
bool _haveNewest = false;
135+
128136
/// Whether this message list is currently busy when it comes to
129137
/// fetching more messages.
130138
///
@@ -157,7 +165,7 @@ mixin _MessageSequence {
157165
/// before, between, or after the messages.
158166
///
159167
/// This information is completely derived from [messages] and
160-
/// the flags [haveOldest] and [busyFetchingMore].
168+
/// the flags [haveOldest], [haveNewest], and [busyFetchingMore].
161169
/// It exists as an optimization, to memoize that computation.
162170
///
163171
/// See also [middleItem], an index which divides this list
@@ -314,6 +322,7 @@ mixin _MessageSequence {
314322
messages.clear();
315323
middleMessage = 0;
316324
_haveOldest = false;
325+
_haveNewest = false;
317326
_status = FetchingStatus.unstarted;
318327
_fetchBackoffMachine = null;
319328
contents.clear();
@@ -504,7 +513,7 @@ class MessageListView with ChangeNotifier, _MessageSequence {
504513
Future<void> fetchInitial() async {
505514
// TODO(#80): fetch from anchor firstUnread, instead of newest
506515
// TODO(#82): fetch from a given message ID as anchor
507-
assert(!fetched && !haveOldest && !busyFetchingMore);
516+
assert(!fetched && !haveOldest && !haveNewest && !busyFetchingMore);
508517
assert(messages.isEmpty && contents.isEmpty);
509518
_setStatus(FetchingStatus.fetchInitial, was: FetchingStatus.unstarted);
510519
// TODO schedule all this in another isolate
@@ -531,6 +540,7 @@ class MessageListView with ChangeNotifier, _MessageSequence {
531540
// Now [middleMessage] is the last message (the one just added).
532541
}
533542
_haveOldest = result.foundOldest;
543+
_haveNewest = true; // TODO(#82)
534544
_setStatus(FetchingStatus.idle, was: FetchingStatus.fetchInitial);
535545
}
536546

test/model/message_list_test.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ void main() {
150150
checkNotifiedOnce();
151151
check(model)
152152
..messages.length.equals(kMessageListFetchBatchSize)
153-
..haveOldest.isFalse();
153+
..haveOldest.isFalse()
154+
..haveNewest.isTrue();
154155
checkLastRequest(
155156
narrow: narrow.apiEncode(),
156157
anchor: 'newest',
@@ -180,7 +181,8 @@ void main() {
180181
checkNotifiedOnce();
181182
check(model)
182183
..messages.length.equals(30)
183-
..haveOldest.isTrue();
184+
..haveOldest.isTrue()
185+
..haveNewest.isTrue();
184186
});
185187

186188
test('no messages found', () async {
@@ -194,7 +196,8 @@ void main() {
194196
check(model)
195197
..fetched.isTrue()
196198
..messages.isEmpty()
197-
..haveOldest.isTrue();
199+
..haveOldest.isTrue()
200+
..haveNewest.isTrue();
198201
});
199202

200203
// TODO(#824): move this test
@@ -2139,9 +2142,10 @@ void checkInvariants(MessageListView model) {
21392142
check(model)
21402143
..messages.isEmpty()
21412144
..haveOldest.isFalse()
2145+
..haveNewest.isFalse()
21422146
..busyFetchingMore.isFalse();
21432147
}
2144-
if (model.haveOldest) {
2148+
if (model.haveOldest && model.haveNewest) {
21452149
check(model).busyFetchingMore.isFalse();
21462150
}
21472151

@@ -2275,5 +2279,6 @@ extension MessageListViewChecks on Subject<MessageListView> {
22752279
Subject<int> get middleItem => has((x) => x.middleItem, 'middleItem');
22762280
Subject<bool> get fetched => has((x) => x.fetched, 'fetched');
22772281
Subject<bool> get haveOldest => has((x) => x.haveOldest, 'haveOldest');
2282+
Subject<bool> get haveNewest => has((x) => x.haveNewest, 'haveNewest');
22782283
Subject<bool> get busyFetchingMore => has((x) => x.busyFetchingMore, 'busyFetchingMore');
22792284
}

0 commit comments

Comments
 (0)