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 {
152152 /// This information is completely derived from [messages] and
153153 /// the flags [haveOldest] , [fetchingOlder] and [fetchOlderCoolingDown] .
154154 /// 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.
155158 final QueueList <MessageListItem > items = QueueList ();
156159
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+
157166 int _findMessageWithId (int messageId) {
158167 return binarySearchByKey (messages, messageId,
159168 (message, messageId) => message.id.compareTo (messageId));
Original file line number Diff line number Diff line change @@ -572,10 +572,9 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
572572 // The list has two slivers: a top sliver growing upward,
573573 // and a bottom sliver growing downward.
574574 // Each sliver has some of the items from `model!.items`.
575- const maxBottomItems = 1 ;
576575 final totalItems = model! .items.length;
577- final bottomItems = totalItems <= maxBottomItems ? totalItems : maxBottomItems ;
578- final topItems = totalItems - bottomItems ;
576+ final topItems = model ! .middleItem ;
577+ final bottomItems = totalItems - topItems ;
579578
580579 // The top sliver has its child 0 as the item just before the
581580 // sliver boundary, child 1 as the item before that, and so on.
Original file line number Diff line number Diff line change @@ -2006,6 +2006,10 @@ void checkInvariants(MessageListView model) {
20062006 });
20072007 }
20082008 check (model.items).length.equals (i);
2009+
2010+ check (model).middleItem
2011+ ..isGreaterOrEqual (0 )
2012+ ..isLessOrEqual (model.items.length);
20092013}
20102014
20112015extension MessageListRecipientHeaderItemChecks on Subject <MessageListRecipientHeaderItem > {
@@ -2033,6 +2037,7 @@ extension MessageListViewChecks on Subject<MessageListView> {
20332037 Subject <List <Message >> get messages => has ((x) => x.messages, 'messages' );
20342038 Subject <List <ZulipMessageContent >> get contents => has ((x) => x.contents, 'contents' );
20352039 Subject <List <MessageListItem >> get items => has ((x) => x.items, 'items' );
2040+ Subject <int > get middleItem => has ((x) => x.middleItem, 'middleItem' );
20362041 Subject <bool > get fetched => has ((x) => x.fetched, 'fetched' );
20372042 Subject <bool > get haveOldest => has ((x) => x.haveOldest, 'haveOldest' );
20382043 Subject <bool > get fetchingOlder => has ((x) => x.fetchingOlder, 'fetchingOlder' );
You can’t perform that action at this time.
0 commit comments