@@ -358,10 +358,12 @@ void main() {
358
358
Future <void > prepare ({
359
359
List <User > users = const [],
360
360
List <RecentDmConversation > dmConversations = const [],
361
+ List <Message > messages = const [],
361
362
}) async {
362
363
store = eg.store (initialSnapshot: eg.initialSnapshot (
363
364
recentPrivateConversations: dmConversations));
364
365
await store.addUsers (users);
366
+ await store.addMessages (messages);
365
367
}
366
368
367
369
group ('MentionAutocompleteView.compareNullable' , () {
@@ -378,6 +380,71 @@ void main() {
378
380
379
381
test ('both of [a] and [b] are null' , () async {
380
382
check (MentionAutocompleteView .compareNullable (null , null )).equals (0 );
383
+ check (MentionAutocompleteView .compareNullable (null , null )).equals (0 );
384
+ });
385
+ });
386
+
387
+ group ('MentionAutocompleteView.compareByRecency' , () {
388
+ final userA = eg.otherUser;
389
+ final userB = eg.thirdUser;
390
+ final stream = eg.stream ();
391
+ const topic1 = 'topic1' ;
392
+ const topic2 = 'topic2' ;
393
+
394
+ Message message (User sender, String topic) {
395
+ return eg.streamMessage (
396
+ sender: sender,
397
+ stream: stream,
398
+ topic: topic,
399
+ );
400
+ }
401
+
402
+ /// Determines the priority between [userA] and [userB] based on their activity.
403
+ ///
404
+ /// The activity is first looked for in [topic] then in [stream] .
405
+ ///
406
+ /// Returns a negative number if [userA] has more recent activity,
407
+ /// returns a positive number if [userB] has more recent activity, and
408
+ /// returns `0` if the activity is the same or there is no activity at all.
409
+ int compareAB ({required String ? topic}) {
410
+ return MentionAutocompleteView .compareByRecency (
411
+ userA,
412
+ userB,
413
+ streamId: stream.streamId,
414
+ topic: topic,
415
+ store: store,
416
+ );
417
+ }
418
+
419
+ test ('prioritizes the user with more recent activity in the topic' , () async {
420
+ await prepare (messages: [
421
+ message (userA, topic1),
422
+ message (userB, topic1),
423
+ ]);
424
+ check (compareAB (topic: topic1)).isGreaterThan (0 );
425
+ });
426
+
427
+ test ('prioritizes the user with more recent activity in the stream '
428
+ 'if there is no activity in the topic from both users' , () async {
429
+ await prepare (messages: [
430
+ message (userA, topic1),
431
+ message (userB, topic1),
432
+ ]);
433
+ check (compareAB (topic: topic2)).isGreaterThan (0 );
434
+ });
435
+
436
+ test ('prioritizes the user with more recent activity in the stream '
437
+ 'if there is no topic provided' , () async {
438
+ await prepare (messages: [
439
+ message (userA, topic1),
440
+ message (userB, topic2),
441
+ ]);
442
+ check (compareAB (topic: null )).isGreaterThan (0 );
443
+ });
444
+
445
+ test ('prioritizes none of the users if there is no activity in the stream from both users' , () async {
446
+ await prepare (messages: []);
447
+ check (compareAB (topic: null )).equals (0 );
381
448
});
382
449
});
383
450
@@ -435,8 +502,11 @@ void main() {
435
502
});
436
503
437
504
group ('autocomplete suggests relevant users in the intended order' , () {
438
- // The order should be:
439
- // 1. Users most recent in the DM conversations
505
+ // 1. Users most recent in the current topic/stream
506
+ // 2. Users most recent in the DM conversations
507
+
508
+ final stream = eg.stream ();
509
+ const topic = 'topic' ;
440
510
441
511
Future <void > checkResultsIn (Narrow narrow, {required List <int > expected}) async {
442
512
final users = [
@@ -453,7 +523,22 @@ void main() {
453
523
RecentDmConversation (userIds: [0 , 1 ], maxMessageId: 100 ),
454
524
];
455
525
456
- await prepare (users: users, dmConversations: dmConversations);
526
+ final messages = [
527
+ eg.streamMessage (
528
+ sender: users[0 ],
529
+ stream: stream,
530
+ topic: topic,
531
+ ),
532
+ eg.streamMessage (
533
+ sender: users[4 ],
534
+ stream: stream,
535
+ ),
536
+ ];
537
+
538
+ await prepare (
539
+ users: users,
540
+ dmConversations: dmConversations,
541
+ messages: messages);
457
542
final view = MentionAutocompleteView .init (store: store, narrow: narrow);
458
543
459
544
bool done = false ;
@@ -467,11 +552,11 @@ void main() {
467
552
}
468
553
469
554
test ('StreamNarrow' , () async {
470
- await checkResultsIn (const StreamNarrow (1 ), expected: [3 , 0 , 1 , 2 , 4 ]);
555
+ await checkResultsIn (StreamNarrow (stream.streamId ), expected: [4 , 0 , 3 , 1 , 2 ]);
471
556
});
472
557
473
558
test ('TopicNarrow' , () async {
474
- await checkResultsIn (const TopicNarrow (1 , ' topic' ), expected: [3 , 0 , 1 , 2 , 4 ]);
559
+ await checkResultsIn (TopicNarrow (stream.streamId, topic), expected: [0 , 4 , 3 , 1 , 2 ]);
475
560
});
476
561
477
562
test ('DmNarrow' , () async {
0 commit comments