Skip to content

Commit 9471546

Browse files
committed
chris squash: Make _mutedUsers private; adjust some names/docs
Making the Set private was Greg's suggestion in review: #1530 (comment) It required changing some tests to use `isUserMuted` instead, and removing some helper methods on PerAccountStoreTestExtension that weren't used anyway. We can add it back later if needed, or do something else.
1 parent c7a5cbc commit 9471546

File tree

5 files changed

+21
-43
lines changed

5 files changed

+21
-43
lines changed

lib/model/store.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -646,11 +646,8 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
646646
Iterable<User> get allUsers => _users.allUsers;
647647

648648
@override
649-
Set<int> get mutedUsers => _users.mutedUsers;
650-
651-
@override
652-
bool isUserMuted(int id, {Set<int>? mutedUsers}) =>
653-
_users.isUserMuted(id, mutedUsers: mutedUsers);
649+
bool isUserMuted(int userId, {Set<int>? mutedUsers}) =>
650+
_users.isUserMuted(userId, mutedUsers: mutedUsers);
654651

655652
final UserStoreImpl _users;
656653

lib/model/user.dart

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import 'package:flutter/foundation.dart';
2-
31
import '../api/model/events.dart';
42
import '../api/model/initial_snapshot.dart';
53
import '../api/model/model.dart';
@@ -69,15 +67,11 @@ mixin UserStore on PerAccountStoreBase {
6967
?? message.senderFullName;
7068
}
7169

72-
/// Ids of all the users muted by [selfUser].
73-
@visibleForTesting
74-
Set<int> get mutedUsers;
75-
76-
/// Whether the user with the given [id] is muted by [selfUser].
70+
/// Whether the user with [userId] is muted by the self-user.
7771
///
78-
/// By default, looks for the user id in [UserStore.mutedUsers] unless
79-
/// [mutedUsers] is non-null, in which case looks in the latter.
80-
bool isUserMuted(int id, {Set<int>? mutedUsers});
72+
/// Looks for [userId] in a private [Set],
73+
/// or in [mutedUsers] instead if that's non-null.
74+
bool isUserMuted(int userId, {Set<int>? mutedUsers});
8175
}
8276

8377
/// The implementation of [UserStore] that does the work.
@@ -94,7 +88,7 @@ class UserStoreImpl extends PerAccountStoreBase with UserStore {
9488
.followedBy(initialSnapshot.realmNonActiveUsers)
9589
.followedBy(initialSnapshot.crossRealmBots)
9690
.map((user) => MapEntry(user.userId, user))),
97-
mutedUsers = _toUserIds(initialSnapshot.mutedUsers);
91+
_mutedUsers = _toUserIds(initialSnapshot.mutedUsers);
9892

9993
final Map<int, User> _users;
10094

@@ -104,12 +98,11 @@ class UserStoreImpl extends PerAccountStoreBase with UserStore {
10498
@override
10599
Iterable<User> get allUsers => _users.values;
106100

107-
@override
108-
final Set<int> mutedUsers;
101+
final Set<int> _mutedUsers;
109102

110103
@override
111-
bool isUserMuted(int id, {Set<int>? mutedUsers}) {
112-
return (mutedUsers ?? this.mutedUsers).contains(id);
104+
bool isUserMuted(int userId, {Set<int>? mutedUsers}) {
105+
return (mutedUsers ?? _mutedUsers).contains(userId);
113106
}
114107

115108
static Set<int> _toUserIds(List<MutedUserItem> mutedUserItems) {
@@ -156,7 +149,7 @@ class UserStoreImpl extends PerAccountStoreBase with UserStore {
156149
}
157150

158151
void handleMutedUsersEvent(MutedUsersEvent event) {
159-
mutedUsers.clear();
160-
mutedUsers.addAll(_toUserIds(event.mutedUsers));
152+
_mutedUsers.clear();
153+
_mutedUsers.addAll(_toUserIds(event.mutedUsers));
161154
}
162155
}

test/model/store_checks.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ extension PerAccountStoreChecks on Subject<PerAccountStore> {
5757
Subject<int> get selfUserId => has((x) => x.selfUserId, 'selfUserId');
5858
Subject<UserSettings?> get userSettings => has((x) => x.userSettings, 'userSettings');
5959
Subject<Map<int, SavedSnippet>> get savedSnippets => has((x) => x.savedSnippets, 'savedSnippets');
60-
Subject<Set<int>> get mutedUsers => has((x) => x.mutedUsers, 'mutedUsers');
6160
Subject<Map<int, ZulipStream>> get streams => has((x) => x.streams, 'streams');
6261
Subject<Map<String, ZulipStream>> get streamsByName => has((x) => x.streamsByName, 'streamsByName');
6362
Subject<Map<int, Subscription>> get subscriptions => has((x) => x.subscriptions, 'subscriptions');

test/model/test_store.dart

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:collection/collection.dart';
21
import 'package:zulip/api/model/events.dart';
32
import 'package:zulip/api/model/initial_snapshot.dart';
43
import 'package:zulip/api/model/model.dart';
@@ -268,21 +267,6 @@ extension PerAccountStoreTestExtension on PerAccountStore {
268267
}
269268
}
270269

271-
Future<void> muteUser(int id) async {
272-
await handleEvent(eg.mutedUsersEvent([...mutedUsers, id]));
273-
}
274-
275-
Future<void> muteUsers(List<int> ids) async {
276-
for (final id in ids) {
277-
await muteUser(id);
278-
}
279-
}
280-
281-
Future<void> unmuteUser(int id) async {
282-
await handleEvent(eg.mutedUsersEvent(
283-
mutedUsers.whereNot((userId) => userId == id).toList()));
284-
}
285-
286270
Future<void> addStream(ZulipStream stream) async {
287271
await addStreams([stream]);
288272
}

test/model/user_test.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import 'package:zulip/api/model/model.dart';
55

66
import '../api/model/model_checks.dart';
77
import '../example_data.dart' as eg;
8-
import 'store_checks.dart';
98
import 'test_store.dart';
109

1110
void main() {
@@ -89,12 +88,18 @@ void main() {
8988
final store = eg.store(initialSnapshot: eg.initialSnapshot(
9089
realmUsers: [user1, user2, user3],
9190
mutedUsers: [MutedUserItem(id: 2), MutedUserItem(id: 1)]));
92-
check(store).mutedUsers.deepEquals({2, 1});
91+
check(store.isUserMuted(1)).isTrue();
92+
check(store.isUserMuted(2)).isTrue();
93+
check(store.isUserMuted(3)).isFalse();
9394

9495
await store.handleEvent(eg.mutedUsersEvent([2, 1, 3]));
95-
check(store).mutedUsers.deepEquals({2, 1, 3});
96+
check(store.isUserMuted(1)).isTrue();
97+
check(store.isUserMuted(2)).isTrue();
98+
check(store.isUserMuted(3)).isTrue();
9699

97100
await store.handleEvent(eg.mutedUsersEvent([2, 3]));
98-
check(store).mutedUsers.deepEquals({2, 3});
101+
check(store.isUserMuted(1)).isFalse();
102+
check(store.isUserMuted(2)).isTrue();
103+
check(store.isUserMuted(3)).isTrue();
99104
});
100105
}

0 commit comments

Comments
 (0)