Skip to content

Commit dadf9de

Browse files
committed
user [nfc]: Factor out an allUsers iterable
1 parent 268a462 commit dadf9de

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
@@ -433,7 +433,7 @@ void main() {
433433
// clobber the recorded registerQueue request so we can't check it.
434434
// checkLastRequest();
435435

436-
check(updateMachine.store.users.values).unorderedMatches(
436+
check(updateMachine.store.allUsers).unorderedMatches(
437437
users.map((expected) => (it) => it.fullName.equals(expected.fullName)));
438438
}));
439439

@@ -490,7 +490,7 @@ void main() {
490490
updateMachine.debugPauseLoop();
491491
check(complete).isTrue();
492492
// checkLastRequest(); TODO UpdateMachine.debugPauseLoop was too late; see comment above
493-
check(updateMachine.store.users.values).unorderedMatches(
493+
check(updateMachine.store.allUsers).unorderedMatches(
494494
users.map((expected) => (it) => it.fullName.equals(expected.fullName)));
495495
}));
496496

0 commit comments

Comments
 (0)