Skip to content

Commit f3f4df2

Browse files
committed
new-dm: Exclude muted users
This completes the planned work for muting muted users (hooray!). Fixes: #296
1 parent fea048b commit f3f4df2

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/widgets/new_dm_sheet.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:collection/collection.dart';
12
import 'package:flutter/material.dart';
23
import '../api/model/model.dart';
34
import '../generated/l10n/zulip_localizations.dart';
@@ -68,7 +69,9 @@ class _NewDmPickerState extends State<NewDmPicker> with PerAccountStoreAwareStat
6869
}
6970

7071
void _initSortedUsers(PerAccountStore store) {
71-
sortedUsers = List<User>.from(store.allUsers)
72+
final sansMuted = store.allUsers
73+
.whereNot((User user) => store.isUserMuted(user.userId));
74+
sortedUsers = List<User>.from(sansMuted)
7275
..sort((a, b) => MentionAutocompleteView.compareByDms(a, b, store: store));
7376
_updateFilteredUsers(store);
7477
}

test/widgets/new_dm_sheet_test.dart

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import 'test_app.dart';
2121

2222
Future<void> setupSheet(WidgetTester tester, {
2323
required List<User> users,
24+
List<int>? mutedUserIds,
2425
}) async {
2526
addTearDown(testBinding.reset);
2627

@@ -31,6 +32,9 @@ Future<void> setupSheet(WidgetTester tester, {
3132
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
3233
final store = await testBinding.globalStore.perAccount(eg.selfAccount.id);
3334
await store.addUsers(users);
35+
if (mutedUserIds != null) {
36+
await store.setMutedUsers(mutedUserIds);
37+
}
3438

3539
await tester.pumpWidget(TestZulipApp(
3640
navigatorObservers: [testNavObserver],
@@ -106,17 +110,24 @@ void main() {
106110
});
107111

108112
group('user filtering', () {
113+
final mutedUser = eg.user(fullName: 'Someone Muted');
109114
final testUsers = [
110115
eg.user(fullName: 'Alice Anderson'),
111116
eg.user(fullName: 'Bob Brown'),
112117
eg.user(fullName: 'Charlie Carter'),
118+
mutedUser,
113119
];
114120

115-
testWidgets('shows all users initially', (tester) async {
116-
await setupSheet(tester, users: testUsers);
121+
testWidgets('shows all non-muted users initially', (tester) async {
122+
await setupSheet(tester, users: testUsers, mutedUserIds: [mutedUser.userId]);
117123
check(find.text('Alice Anderson')).findsOne();
118124
check(find.text('Bob Brown')).findsOne();
119125
check(find.text('Charlie Carter')).findsOne();
126+
127+
check(find.byIcon(ZulipIcons.check_circle_unchecked)).findsExactly(3);
128+
check(find.byIcon(ZulipIcons.check_circle_checked)).findsNothing();
129+
check(find.text('Someone Muted')).findsNothing();
130+
check(find.text('Muted user')).findsNothing();
120131
});
121132

122133
testWidgets('shows filtered users based on search', (tester) async {

0 commit comments

Comments
 (0)