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 @@ -572,10 +572,9 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
572
572
// The list has two slivers: a top sliver growing upward,
573
573
// and a bottom sliver growing downward.
574
574
// Each sliver has some of the items from `model!.items`.
575
- const maxBottomItems = 1 ;
576
575
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 ;
579
578
580
579
// The top sliver has its child 0 as the item just before the
581
580
// 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) {
2006
2006
});
2007
2007
}
2008
2008
check (model.items).length.equals (i);
2009
+
2010
+ check (model).middleItem
2011
+ ..isGreaterOrEqual (0 )
2012
+ ..isLessOrEqual (model.items.length);
2009
2013
}
2010
2014
2011
2015
extension MessageListRecipientHeaderItemChecks on Subject <MessageListRecipientHeaderItem > {
@@ -2033,6 +2037,7 @@ extension MessageListViewChecks on Subject<MessageListView> {
2033
2037
Subject <List <Message >> get messages => has ((x) => x.messages, 'messages' );
2034
2038
Subject <List <ZulipMessageContent >> get contents => has ((x) => x.contents, 'contents' );
2035
2039
Subject <List <MessageListItem >> get items => has ((x) => x.items, 'items' );
2040
+ Subject <int > get middleItem => has ((x) => x.middleItem, 'middleItem' );
2036
2041
Subject <bool > get fetched => has ((x) => x.fetched, 'fetched' );
2037
2042
Subject <bool > get haveOldest => has ((x) => x.haveOldest, 'haveOldest' );
2038
2043
Subject <bool > get fetchingOlder => has ((x) => x.fetchingOlder, 'fetchingOlder' );
You can’t perform that action at this time.
0 commit comments