Skip to content

Commit d1895b7

Browse files
chrisbobbesm-sayedi
authored andcommitted
autocomplete: Exclude muted users from user-mention autocomplete
Co-authored-by: Sayed Mahmood Sayedi <[email protected]>
1 parent f23302b commit d1895b7

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/model/autocomplete.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'compose.dart';
1212
import 'emoji.dart';
1313
import 'narrow.dart';
1414
import 'store.dart';
15+
import 'user.dart';
1516

1617
extension ComposeContentAutocomplete on ComposeContentController {
1718
AutocompleteIntent<ComposeAutocompleteQuery>? autocompleteIntent() {
@@ -648,7 +649,7 @@ class MentionAutocompleteView extends AutocompleteView<MentionAutocompleteQuery,
648649
}
649650

650651
MentionAutocompleteResult? _testUser(MentionAutocompleteQuery query, User user) {
651-
if (query.testUser(user, store.autocompleteViewManager.autocompleteDataCache)) {
652+
if (query.testUser(user, store.autocompleteViewManager.autocompleteDataCache, store)) {
652653
return UserMentionAutocompleteResult(userId: user.userId);
653654
}
654655
return null;
@@ -753,9 +754,10 @@ class MentionAutocompleteQuery extends ComposeAutocompleteQuery {
753754
|| wildcardOption.localizedCanonicalString(localizations).contains(_lowercase);
754755
}
755756

756-
bool testUser(User user, AutocompleteDataCache cache) {
757+
bool testUser(User user, AutocompleteDataCache cache, UserStore store) {
757758
// TODO(#236) test email too, not just name
758759
if (!user.isActive) return false;
760+
if (store.isUserMuted(user.userId)) return false;
759761

760762
return _testName(user, cache);
761763
}

test/model/autocomplete_test.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,19 +404,33 @@ void main() {
404404
});
405405

406406
group('MentionAutocompleteQuery.testUser', () {
407+
late PerAccountStore store;
408+
407409
void doCheck(String rawQuery, User user, bool expected) {
408410
final result = MentionAutocompleteQuery(rawQuery)
409-
.testUser(user, AutocompleteDataCache());
411+
.testUser(user, AutocompleteDataCache(), store);
410412
expected ? check(result).isTrue() : check(result).isFalse();
411413
}
412414

413415
test('user is always excluded when not active regardless of other criteria', () {
416+
store = eg.store();
417+
414418
doCheck('Full Name', eg.user(fullName: 'Full Name', isActive: false), false);
415419
// When active then other criteria will be checked
416420
doCheck('Full Name', eg.user(fullName: 'Full Name', isActive: true), true);
417421
});
418422

423+
test('user is always excluded when muted, regardless of other criteria', () async {
424+
store = eg.store();
425+
await store.setMutedUsers([1]);
426+
doCheck('Full Name', eg.user(userId: 1, fullName: 'Full Name'), false);
427+
// When not muted, then other criteria will be checked
428+
doCheck('Full Name', eg.user(userId: 2, fullName: 'Full Name'), true);
429+
});
430+
419431
test('user is included if fullname words match the query', () {
432+
store = eg.store();
433+
420434
doCheck('', eg.user(fullName: 'Full Name'), true);
421435
doCheck('', eg.user(fullName: ''), true); // Unlikely case, but should not crash
422436
doCheck('Full Name', eg.user(fullName: 'Full Name'), true);

0 commit comments

Comments
 (0)