Skip to content

Commit 03cb3d3

Browse files
chrisbobbegnprice
authored andcommitted
autocomplete [nfc]: Construct user result in query.testUser
1 parent fded259 commit 03cb3d3

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

lib/model/autocomplete.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -650,10 +650,7 @@ class MentionAutocompleteView extends AutocompleteView<MentionAutocompleteQuery,
650650
}
651651

652652
MentionAutocompleteResult? _testUser(MentionAutocompleteQuery query, User user) {
653-
if (query.testUser(user, store.autocompleteViewManager.autocompleteDataCache, store)) {
654-
return UserMentionAutocompleteResult(userId: user.userId);
655-
}
656-
return null;
653+
return query.testUser(user, store.autocompleteViewManager.autocompleteDataCache, store);
657654
}
658655

659656
@override
@@ -755,12 +752,14 @@ class MentionAutocompleteQuery extends ComposeAutocompleteQuery {
755752
|| wildcardOption.localizedCanonicalString(localizations).contains(_lowercase);
756753
}
757754

758-
bool testUser(User user, AutocompleteDataCache cache, UserStore store) {
759-
if (!user.isActive) return false;
760-
if (store.isUserMuted(user.userId)) return false;
755+
MentionAutocompleteResult? testUser(User user, AutocompleteDataCache cache, UserStore store) {
756+
if (!user.isActive) return null;
757+
if (store.isUserMuted(user.userId)) return null;
761758

762759
// TODO(#236) test email too, not just name
763-
return _testName(user, cache);
760+
if (!_testName(user, cache)) return null;
761+
762+
return UserMentionAutocompleteResult(userId: user.userId);
764763
}
765764

766765
bool _testName(User user, AutocompleteDataCache cache) {

test/model/autocomplete_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,9 @@ void main() {
409409
void doCheck(String rawQuery, User user, bool expected) {
410410
final result = MentionAutocompleteQuery(rawQuery)
411411
.testUser(user, AutocompleteDataCache(), store);
412-
expected ? check(result).isTrue() : check(result).isFalse();
412+
expected
413+
? check(result).isA<UserMentionAutocompleteResult>()
414+
: check(result).isNull();
413415
}
414416

415417
test('user is always excluded when not active regardless of other criteria', () {

0 commit comments

Comments
 (0)