Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/model/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ mixin UserStore on PerAccountStoreBase, RealmStore {
/// Consider using [userDisplayName].
User? getUser(int userId);

/// All known users in the realm.
/// All known users in the realm, including deactivated users.
///
/// Before presenting these users in the UI, consider whether to exclude
/// users who are deactivated (see [User.isActive]) or muted ([isUserMuted]).
///
/// This may have a large number of elements, like tens of thousands.
/// Consider [getUser] or other alternatives to iterating through this.
Expand Down
7 changes: 3 additions & 4 deletions lib/widgets/new_dm_sheet.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import '../api/model/model.dart';
import '../generated/l10n/zulip_localizations.dart';
Expand Down Expand Up @@ -69,9 +68,9 @@ class _NewDmPickerState extends State<NewDmPicker> with PerAccountStoreAwareStat
}

void _initSortedUsers(PerAccountStore store) {
final sansMuted = store.allUsers
.whereNot((user) => store.isUserMuted(user.userId));
sortedUsers = List<User>.from(sansMuted)
final users = store.allUsers
.where((user) => user.isActive && !store.isUserMuted(user.userId));
sortedUsers = List<User>.from(users)
..sort((a, b) => MentionAutocompleteView.compareByDms(a, b, store: store));
_updateFilteredUsers(store);
}
Expand Down
46 changes: 39 additions & 7 deletions test/widgets/new_dm_sheet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,24 +116,19 @@ void main() {
});

group('user filtering', () {
final mutedUser = eg.user(fullName: 'Someone Muted');
final testUsers = [
eg.user(fullName: 'Alice Anderson'),
eg.user(fullName: 'Bob Brown'),
eg.user(fullName: 'Charlie Carter'),
mutedUser,
];

testWidgets('shows all non-muted users initially', (tester) async {
await setupSheet(tester, users: testUsers, mutedUserIds: [mutedUser.userId]);
testWidgets('shows full list initially', (tester) async {
await setupSheet(tester, users: testUsers);
check(findText(includePlaceholders: false, 'Alice Anderson')).findsOne();
check(findText(includePlaceholders: false, 'Bob Brown')).findsOne();
check(findText(includePlaceholders: false, 'Charlie Carter')).findsOne();

check(find.byIcon(ZulipIcons.check_circle_unchecked)).findsExactly(3);
check(find.byIcon(ZulipIcons.check_circle_checked)).findsNothing();
check(findText(includePlaceholders: false, 'Someone Muted')).findsNothing();
check(findText(includePlaceholders: false, 'Muted user')).findsNothing();
});

testWidgets('shows filtered users based on search', (tester) async {
Expand All @@ -145,6 +140,43 @@ void main() {
check(findText(includePlaceholders: false, 'Bob Brown')).findsNothing();
});

testWidgets('deactivated users excluded', (tester) async {
// Omit a deactivated user both before there's a query…
final deactivatedUser = eg.user(fullName: 'Impostor Charlie', isActive: false);
await setupSheet(tester, users: [...testUsers, deactivatedUser]);
check(findText(includePlaceholders: false, 'Impostor Charlie')).findsNothing();
check(findText(includePlaceholders: false, 'Charlie Carter')).findsOne();
check(find.byIcon(ZulipIcons.check_circle_unchecked)).findsExactly(3);

// … and after a query that would match their name.
await tester.enterText(find.byType(TextField), 'Charlie');
await tester.pump();
check(findText(includePlaceholders: false, 'Impostor Charlie')).findsNothing();
check(findText(includePlaceholders: false, 'Charlie Carter')).findsOne();
check(find.byIcon(ZulipIcons.check_circle_unchecked)).findsExactly(1);
});

testWidgets('muted users excluded', (tester) async {
// Omit muted users both before there's a query…
final mutedUser = eg.user(fullName: 'Someone Muted');
await setupSheet(tester,
users: [...testUsers, mutedUser], mutedUserIds: [mutedUser.userId]);
check(findText(includePlaceholders: false, 'Someone Muted')).findsNothing();
check(findText(includePlaceholders: false, 'Muted user')).findsNothing();
check(findText(includePlaceholders: false, 'Alice Anderson')).findsOne();
check(find.byIcon(ZulipIcons.check_circle_unchecked)).findsExactly(3);

// … and after a query. One which matches both the user's actual name and
// the replacement text "Muted user", for good measure.
await tester.enterText(find.byType(TextField), 'e');
await tester.pump();
check(findText(includePlaceholders: false, 'Someone Muted')).findsNothing();
check(findText(includePlaceholders: false, 'Muted user')).findsNothing();
check(findText(includePlaceholders: false, 'Alice Anderson')).findsOne();
check(findText(includePlaceholders: false, 'Charlie Carter')).findsOne();
check(find.byIcon(ZulipIcons.check_circle_unchecked)).findsExactly(2);
});

// TODO test sorting by recent-DMs
// TODO test that scroll position resets on query change

Expand Down