Skip to content

Muted users prep #1530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 13, 2025
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
Binary file modified assets/icons/ZulipIcons.ttf
Binary file not shown.
3 changes: 3 additions & 0 deletions assets/icons/eye.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/eye_off.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions assets/icons/person.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
19 changes: 19 additions & 0 deletions lib/api/model/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ sealed class Event {
}
// case 'muted_topics': … // TODO(#422) we ignore this feature on older servers
case 'user_topic': return UserTopicEvent.fromJson(json);
case 'muted_users': return MutedUsersEvent.fromJson(json);
case 'message': return MessageEvent.fromJson(json);
case 'update_message': return UpdateMessageEvent.fromJson(json);
case 'delete_message': return DeleteMessageEvent.fromJson(json);
Expand Down Expand Up @@ -733,6 +734,24 @@ class UserTopicEvent extends Event {
Map<String, dynamic> toJson() => _$UserTopicEventToJson(this);
}

/// A Zulip event of type `muted_users`: https://zulip.com/api/get-events#muted_users
@JsonSerializable(fieldRename: FieldRename.snake)
class MutedUsersEvent extends Event {
@override
@JsonKey(includeToJson: true)
String get type => 'muted_users';

final List<MutedUserItem> mutedUsers;

MutedUsersEvent({required super.id, required this.mutedUsers});

factory MutedUsersEvent.fromJson(Map<String, dynamic> json) =>
_$MutedUsersEventFromJson(json);

@override
Map<String, dynamic> toJson() => _$MutedUsersEventToJson(this);
}

/// A Zulip event of type `message`: https://zulip.com/api/get-events#message
@JsonSerializable(fieldRename: FieldRename.snake)
class MessageEvent extends Event {
Expand Down
15 changes: 15 additions & 0 deletions lib/api/model/events.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/api/model/initial_snapshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class InitialSnapshot {

// final List<…> mutedTopics; // TODO(#422) we ignore this feature on older servers

final List<MutedUserItem> mutedUsers;

final Map<String, RealmEmojiItem> realmEmoji;

final List<RecentDmConversation> recentPrivateConversations;
Expand Down Expand Up @@ -132,6 +134,7 @@ class InitialSnapshot {
required this.serverTypingStartedExpiryPeriodMilliseconds,
required this.serverTypingStoppedWaitPeriodMilliseconds,
required this.serverTypingStartedWaitPeriodMilliseconds,
required this.mutedUsers,
required this.realmEmoji,
required this.recentPrivateConversations,
required this.savedSnippets,
Expand Down
4 changes: 4 additions & 0 deletions lib/api/model/initial_snapshot.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions lib/api/model/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,25 @@ class CustomProfileFieldExternalAccountData {
Map<String, dynamic> toJson() => _$CustomProfileFieldExternalAccountDataToJson(this);
}

/// An item in the [InitialSnapshot.mutedUsers] or [MutedUsersEvent].
///
/// For docs, search for "muted_users:"
/// in <https://zulip.com/api/register-queue>.
@JsonSerializable(fieldRename: FieldRename.snake)
class MutedUserItem {
final int id;

// Mobile doesn't use the timestamp; ignore.
// final int timestamp;
Comment on lines +121 to +122
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, this is good.

In #1530 (comment) I actually only meant to suggest removing the timestamps from the model, not the API binding. Removing them from the API binding is fine too, but definitely should have this comment as Chris's commit message says:

chris squash: leave comment about MutedUserItem.timestamp

So it doesn't look like we just forgot about this field.


const MutedUserItem({required this.id});

factory MutedUserItem.fromJson(Map<String, dynamic> json) =>
_$MutedUserItemFromJson(json);

Map<String, dynamic> toJson() => _$MutedUserItemToJson(this);
}

/// An item in [InitialSnapshot.realmEmoji] or [RealmEmojiUpdateEvent].
///
/// For docs, search for "realm_emoji:"
Expand Down
6 changes: 6 additions & 0 deletions lib/api/model/model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions lib/model/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,10 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
@override
Iterable<User> get allUsers => _users.allUsers;

@override
bool isUserMuted(int userId, {MutedUsersEvent? event}) =>
_users.isUserMuted(userId, event: event);

final UserStoreImpl _users;

final TypingStatus typingStatus;
Expand Down Expand Up @@ -949,6 +953,11 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
assert(debugLog("server event: reaction/${event.op}"));
_messages.handleReactionEvent(event);

case MutedUsersEvent():
assert(debugLog("server event: muted_users"));
_users.handleMutedUsersEvent(event);
notifyListeners();

case UnexpectedEvent():
assert(debugLog("server event: ${jsonEncode(event.toJson())}")); // TODO log better
}
Expand Down
21 changes: 20 additions & 1 deletion lib/model/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ mixin UserStore on PerAccountStoreBase {
return getUser(message.senderId)?.fullName
?? message.senderFullName;
}

/// Whether the user with [userId] is muted by the self-user.
///
/// Looks for [userId] in a private [Set],
/// or in [event.mutedUsers] instead if event is non-null.
bool isUserMuted(int userId, {MutedUsersEvent? event});
}

/// The implementation of [UserStore] that does the work.
Expand All @@ -81,7 +87,8 @@ class UserStoreImpl extends PerAccountStoreBase with UserStore {
initialSnapshot.realmUsers
.followedBy(initialSnapshot.realmNonActiveUsers)
.followedBy(initialSnapshot.crossRealmBots)
.map((user) => MapEntry(user.userId, user)));
.map((user) => MapEntry(user.userId, user))),
_mutedUsers = Set.from(initialSnapshot.mutedUsers.map((item) => item.id));

final Map<int, User> _users;

Expand All @@ -91,6 +98,13 @@ class UserStoreImpl extends PerAccountStoreBase with UserStore {
@override
Iterable<User> get allUsers => _users.values;

final Set<int> _mutedUsers;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chris squash: Make _mutedUsers private; adjust some names/docs

Making the Set private was Greg's suggestion in review:
  https://github.com/zulip/zulip-flutter/pull/1530#discussion_r2110615283

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.

Yeah, looks good.

If we later feel that seeing the whole Set would be really helpful for testing, we can add a getter like

  Iterable<int> debugMutedUsers => _mutedUsers;

and tests can compare using unorderedEquals. The "debug" prefix makes clear that getter isn't something the app should be invoking in normal operation.


@override
bool isUserMuted(int userId, {MutedUsersEvent? event}) {
return (event?.mutedUsers.map((item) => item.id) ?? _mutedUsers).contains(userId);
}

void handleRealmUserEvent(RealmUserEvent event) {
switch (event) {
case RealmUserAddEvent():
Expand Down Expand Up @@ -129,4 +143,9 @@ class UserStoreImpl extends PerAccountStoreBase with UserStore {
}
}
}

void handleMutedUsersEvent(MutedUsersEvent event) {
_mutedUsers.clear();
_mutedUsers.addAll(event.mutedUsers.map((item) => item.id));
}
}
4 changes: 2 additions & 2 deletions lib/widgets/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class _HomePageState extends State<HomePage> {
narrow: const CombinedFeedNarrow()))),
button(_HomePageTab.channels, ZulipIcons.hash_italic),
// TODO(#1094): Users
button(_HomePageTab.directMessages, ZulipIcons.user),
button(_HomePageTab.directMessages, ZulipIcons.two_person),
_NavigationBarButton( icon: ZulipIcons.menu,
selected: false,
onPressed: () => _showMainMenu(context, tabNotifier: _tab)),
Expand Down Expand Up @@ -549,7 +549,7 @@ class _DirectMessagesButton extends _NavigationBarMenuButton {
const _DirectMessagesButton({required super.tabNotifier});

@override
IconData get icon => ZulipIcons.user;
IconData get icon => ZulipIcons.two_person;

@override
String label(ZulipLocalizations zulipLocalizations) {
Expand Down
73 changes: 41 additions & 32 deletions lib/widgets/icons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,95 +72,104 @@ abstract final class ZulipIcons {
/// The Zulip custom icon "edit".
static const IconData edit = IconData(0xf110, fontFamily: "Zulip Icons");

/// The Zulip custom icon "eye".
static const IconData eye = IconData(0xf111, fontFamily: "Zulip Icons");

/// The Zulip custom icon "eye_off".
static const IconData eye_off = IconData(0xf112, fontFamily: "Zulip Icons");

/// The Zulip custom icon "follow".
static const IconData follow = IconData(0xf111, fontFamily: "Zulip Icons");
static const IconData follow = IconData(0xf113, fontFamily: "Zulip Icons");

/// The Zulip custom icon "format_quote".
static const IconData format_quote = IconData(0xf112, fontFamily: "Zulip Icons");
static const IconData format_quote = IconData(0xf114, fontFamily: "Zulip Icons");

/// The Zulip custom icon "globe".
static const IconData globe = IconData(0xf113, fontFamily: "Zulip Icons");
static const IconData globe = IconData(0xf115, fontFamily: "Zulip Icons");

/// The Zulip custom icon "group_dm".
static const IconData group_dm = IconData(0xf114, fontFamily: "Zulip Icons");
static const IconData group_dm = IconData(0xf116, fontFamily: "Zulip Icons");

/// The Zulip custom icon "hash_italic".
static const IconData hash_italic = IconData(0xf115, fontFamily: "Zulip Icons");
static const IconData hash_italic = IconData(0xf117, fontFamily: "Zulip Icons");

/// The Zulip custom icon "hash_sign".
static const IconData hash_sign = IconData(0xf116, fontFamily: "Zulip Icons");
static const IconData hash_sign = IconData(0xf118, fontFamily: "Zulip Icons");

/// The Zulip custom icon "image".
static const IconData image = IconData(0xf117, fontFamily: "Zulip Icons");
static const IconData image = IconData(0xf119, fontFamily: "Zulip Icons");

/// The Zulip custom icon "inbox".
static const IconData inbox = IconData(0xf118, fontFamily: "Zulip Icons");
static const IconData inbox = IconData(0xf11a, fontFamily: "Zulip Icons");

/// The Zulip custom icon "info".
static const IconData info = IconData(0xf119, fontFamily: "Zulip Icons");
static const IconData info = IconData(0xf11b, fontFamily: "Zulip Icons");

/// The Zulip custom icon "inherit".
static const IconData inherit = IconData(0xf11a, fontFamily: "Zulip Icons");
static const IconData inherit = IconData(0xf11c, fontFamily: "Zulip Icons");

/// The Zulip custom icon "language".
static const IconData language = IconData(0xf11b, fontFamily: "Zulip Icons");
static const IconData language = IconData(0xf11d, fontFamily: "Zulip Icons");

/// The Zulip custom icon "lock".
static const IconData lock = IconData(0xf11c, fontFamily: "Zulip Icons");
static const IconData lock = IconData(0xf11e, fontFamily: "Zulip Icons");

/// The Zulip custom icon "menu".
static const IconData menu = IconData(0xf11d, fontFamily: "Zulip Icons");
static const IconData menu = IconData(0xf11f, fontFamily: "Zulip Icons");

/// The Zulip custom icon "message_checked".
static const IconData message_checked = IconData(0xf11e, fontFamily: "Zulip Icons");
static const IconData message_checked = IconData(0xf120, fontFamily: "Zulip Icons");

/// The Zulip custom icon "message_feed".
static const IconData message_feed = IconData(0xf11f, fontFamily: "Zulip Icons");
static const IconData message_feed = IconData(0xf121, fontFamily: "Zulip Icons");

/// The Zulip custom icon "mute".
static const IconData mute = IconData(0xf120, fontFamily: "Zulip Icons");
static const IconData mute = IconData(0xf122, fontFamily: "Zulip Icons");

/// The Zulip custom icon "person".
static const IconData person = IconData(0xf123, fontFamily: "Zulip Icons");

/// The Zulip custom icon "plus".
static const IconData plus = IconData(0xf121, fontFamily: "Zulip Icons");
static const IconData plus = IconData(0xf124, fontFamily: "Zulip Icons");

/// The Zulip custom icon "read_receipts".
static const IconData read_receipts = IconData(0xf122, fontFamily: "Zulip Icons");
static const IconData read_receipts = IconData(0xf125, fontFamily: "Zulip Icons");

/// The Zulip custom icon "send".
static const IconData send = IconData(0xf123, fontFamily: "Zulip Icons");
static const IconData send = IconData(0xf126, fontFamily: "Zulip Icons");

/// The Zulip custom icon "settings".
static const IconData settings = IconData(0xf124, fontFamily: "Zulip Icons");
static const IconData settings = IconData(0xf127, fontFamily: "Zulip Icons");

/// The Zulip custom icon "share".
static const IconData share = IconData(0xf125, fontFamily: "Zulip Icons");
static const IconData share = IconData(0xf128, fontFamily: "Zulip Icons");

/// The Zulip custom icon "share_ios".
static const IconData share_ios = IconData(0xf126, fontFamily: "Zulip Icons");
static const IconData share_ios = IconData(0xf129, fontFamily: "Zulip Icons");

/// The Zulip custom icon "smile".
static const IconData smile = IconData(0xf127, fontFamily: "Zulip Icons");
static const IconData smile = IconData(0xf12a, fontFamily: "Zulip Icons");

/// The Zulip custom icon "star".
static const IconData star = IconData(0xf128, fontFamily: "Zulip Icons");
static const IconData star = IconData(0xf12b, fontFamily: "Zulip Icons");

/// The Zulip custom icon "star_filled".
static const IconData star_filled = IconData(0xf129, fontFamily: "Zulip Icons");
static const IconData star_filled = IconData(0xf12c, fontFamily: "Zulip Icons");

/// The Zulip custom icon "three_person".
static const IconData three_person = IconData(0xf12a, fontFamily: "Zulip Icons");
static const IconData three_person = IconData(0xf12d, fontFamily: "Zulip Icons");

/// The Zulip custom icon "topic".
static const IconData topic = IconData(0xf12b, fontFamily: "Zulip Icons");
static const IconData topic = IconData(0xf12e, fontFamily: "Zulip Icons");

/// The Zulip custom icon "topics".
static const IconData topics = IconData(0xf12c, fontFamily: "Zulip Icons");
static const IconData topics = IconData(0xf12f, fontFamily: "Zulip Icons");

/// The Zulip custom icon "unmute".
static const IconData unmute = IconData(0xf12d, fontFamily: "Zulip Icons");
/// The Zulip custom icon "two_person".
static const IconData two_person = IconData(0xf130, fontFamily: "Zulip Icons");

/// The Zulip custom icon "user".
static const IconData user = IconData(0xf12e, fontFamily: "Zulip Icons");
/// The Zulip custom icon "unmute".
static const IconData unmute = IconData(0xf131, fontFamily: "Zulip Icons");

// END GENERATED ICON DATA
}
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/inbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class _AllDmsHeaderItem extends _HeaderItem {

@override String title(ZulipLocalizations zulipLocalizations) =>
zulipLocalizations.recentDmConversationsSectionHeader;
@override IconData get icon => ZulipIcons.user;
@override IconData get icon => ZulipIcons.two_person;

// TODO(design) check if this is the right variable for these
@override Color collapsedIconColor(context) => DesignVariables.of(context).labelMenuButton;
Expand Down
Loading