File tree Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -152,8 +152,17 @@ mixin _MessageSequence {
152
152
/// This information is completely derived from [messages] and
153
153
/// the flags [haveOldest] , [fetchingOlder] and [fetchOlderCoolingDown] .
154
154
/// It exists as an optimization, to memoize that computation.
155
+ ///
156
+ /// See also [middleItem] , an index which divides this list
157
+ /// into a top slice and a bottom slice.
155
158
final QueueList <MessageListItem > items = QueueList ();
156
159
160
+ /// An index into [items] dividing it into a top slice and a bottom slice.
161
+ ///
162
+ /// The indices 0 to before [middleItem] are the top slice of [items] ,
163
+ /// and the indices from [middleItem] to the end are the bottom slice.
164
+ int get middleItem => items.isEmpty ? 0 : items.length - 1 ;
165
+
157
166
int _findMessageWithId (int messageId) {
158
167
return binarySearchByKey (messages, messageId,
159
168
(message, messageId) => message.id.compareTo (messageId));
Original file line number Diff line number Diff line change @@ -574,10 +574,9 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
574
574
// The list has two slivers: a top sliver growing upward,
575
575
// and a bottom sliver growing downward.
576
576
// Each sliver has some of the items from `model!.items`.
577
- const maxBottomItems = 1 ;
578
577
final totalItems = model! .items.length;
579
- final bottomItems = totalItems <= maxBottomItems ? totalItems : maxBottomItems ;
580
- final topItems = totalItems - bottomItems ;
578
+ final topItems = model ! .middleItem ;
579
+ final bottomItems = totalItems - topItems ;
581
580
582
581
// The top sliver has its child 0 as the item just before the
583
582
// sliver boundary, child 1 as the item before that, and so on.
Original file line number Diff line number Diff line change @@ -2002,6 +2002,10 @@ void checkInvariants(MessageListView model) {
2002
2002
});
2003
2003
}
2004
2004
check (model.items).length.equals (i);
2005
+
2006
+ check (model).middleItem
2007
+ ..isGreaterOrEqual (0 )
2008
+ ..isLessOrEqual (model.items.length);
2005
2009
}
2006
2010
2007
2011
extension MessageListRecipientHeaderItemChecks on Subject <MessageListRecipientHeaderItem > {
@@ -2029,6 +2033,7 @@ extension MessageListViewChecks on Subject<MessageListView> {
2029
2033
Subject <List <Message >> get messages => has ((x) => x.messages, 'messages' );
2030
2034
Subject <List <ZulipMessageContent >> get contents => has ((x) => x.contents, 'contents' );
2031
2035
Subject <List <MessageListItem >> get items => has ((x) => x.items, 'items' );
2036
+ Subject <int > get middleItem => has ((x) => x.middleItem, 'middleItem' );
2032
2037
Subject <bool > get fetched => has ((x) => x.fetched, 'fetched' );
2033
2038
Subject <bool > get haveOldest => has ((x) => x.haveOldest, 'haveOldest' );
2034
2039
Subject <bool > get fetchingOlder => has ((x) => x.fetchingOlder, 'fetchingOlder' );
You can’t perform that action at this time.
0 commit comments