File tree Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -204,10 +204,21 @@ class MentionAutocompleteView extends ChangeNotifier {
204
204
final aLatestMessageId = recentDms.latestMessagesByRecipient[userA.userId];
205
205
final bLatestMessageId = recentDms.latestMessagesByRecipient[userB.userId];
206
206
207
- return switch ((aLatestMessageId, bLatestMessageId)) {
208
- (int a, int b) => - a.compareTo (b),
209
- (int (), _) => - 1 ,
210
- (_, int ()) => 1 ,
207
+ return - compareRecentMessageIds (aLatestMessageId, bLatestMessageId);
208
+ }
209
+
210
+ /// Compares [a] to [b] , with null less than all integers.
211
+ ///
212
+ /// The values should represent the most recent message ID in each of two
213
+ /// sets of messages, with null meaning the set is empty.
214
+ ///
215
+ /// Return values are as with [Comparable.compareTo] .
216
+ @visibleForTesting
217
+ static int compareRecentMessageIds (int ? a, int ? b) {
218
+ return switch ((a, b)) {
219
+ (int a, int b) => a.compareTo (b),
220
+ (int (), _) => 1 ,
221
+ (_, int ()) => - 1 ,
211
222
_ => 0 ,
212
223
};
213
224
}
Original file line number Diff line number Diff line change @@ -365,6 +365,23 @@ void main() {
365
365
await store.addUsers (users);
366
366
}
367
367
368
+ group ('MentionAutocompleteView.compareRecentMessageIds' , () {
369
+ test ('both a and b are non-null' , () async {
370
+ check (MentionAutocompleteView .compareRecentMessageIds (2 , 5 )).isLessThan (0 );
371
+ check (MentionAutocompleteView .compareRecentMessageIds (5 , 2 )).isGreaterThan (0 );
372
+ check (MentionAutocompleteView .compareRecentMessageIds (5 , 5 )).equals (0 );
373
+ });
374
+
375
+ test ('one of a and b is null' , () async {
376
+ check (MentionAutocompleteView .compareRecentMessageIds (null , 5 )).isLessThan (0 );
377
+ check (MentionAutocompleteView .compareRecentMessageIds (5 , null )).isGreaterThan (0 );
378
+ });
379
+
380
+ test ('both of a and b are null' , () async {
381
+ check (MentionAutocompleteView .compareRecentMessageIds (null , null )).equals (0 );
382
+ });
383
+ });
384
+
368
385
group ('MentionAutocompleteView.compareByDms' , () {
369
386
const idA = 1 ;
370
387
const idB = 2 ;
You can’t perform that action at this time.
0 commit comments