Skip to content

Commit 3655582

Browse files
committed
user [nfc]: Factor out an allUsers iterable
1 parent 40c06f2 commit 3655582

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

lib/model/autocomplete.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ class MentionAutocompleteView extends AutocompleteView<MentionAutocompleteQuery,
449449
required PerAccountStore store,
450450
required Narrow narrow,
451451
}) {
452-
return store.users.values.toList()
452+
return store.allUsers.toList()
453453
..sort(_comparator(store: store, narrow: narrow));
454454
}
455455

lib/model/compose.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ String wrapWithBacktickFence({required String content, String? infoString}) {
132132
/// through all users; avoid it in performance-sensitive codepaths.
133133
String userMention(User user, {bool silent = false, UserStore? users}) {
134134
bool includeUserId = users == null
135-
|| users.users.values.where((u) => u.fullName == user.fullName)
135+
|| users.allUsers.where((u) => u.fullName == user.fullName)
136136
.take(2).length == 2;
137137

138138
return '@${silent ? '_' : ''}**${user.fullName}${includeUserId ? '|${user.userId}' : ''}**';

lib/model/user.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ mixin UserStore {
4646
/// For details, see [users].
4747
User? getUser(int userId) => users[userId];
4848

49+
/// All known users in the realm.
50+
///
51+
/// This may have a large number of elements, like tens of thousands.
52+
/// Consider [getUser] or other alternatives to iterating through this.
53+
///
54+
/// There may be perfectly real users which are not known
55+
/// and so are not found here. For details, see [users].
56+
Iterable<User> get allUsers => users.values;
57+
4958
/// The name to show the given user as in the UI, even for unknown users.
5059
///
5160
/// This is the user's [User.fullName] if the user is known,

test/model/store_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ void main() {
411411
// clobber the recorded registerQueue request so we can't check it.
412412
// checkLastRequest();
413413

414-
check(updateMachine.store.users.values).unorderedMatches(
414+
check(updateMachine.store.allUsers).unorderedMatches(
415415
users.map((expected) => (it) => it.fullName.equals(expected.fullName)));
416416
}));
417417

@@ -468,7 +468,7 @@ void main() {
468468
updateMachine.debugPauseLoop();
469469
check(complete).isTrue();
470470
// checkLastRequest(); TODO UpdateMachine.debugPauseLoop was too late; see comment above
471-
check(updateMachine.store.users.values).unorderedMatches(
471+
check(updateMachine.store.allUsers).unorderedMatches(
472472
users.map((expected) => (it) => it.fullName.equals(expected.fullName)));
473473
}));
474474

0 commit comments

Comments
 (0)