Skip to content

Commit

Permalink
mute: Offer UI to unmute topic in muted stream
Browse files Browse the repository at this point in the history
Fixes: zulip#5691
  • Loading branch information
gnprice committed Apr 26, 2023
1 parent 0095054 commit b4a41be
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/action-sheets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,15 @@ const markAsUnreadFromMessage = {
},
};

const unmuteTopicInMutedStream = {
title: 'Unmute topic',
errorMessage: 'Failed to unmute topic',
action: async ({ auth, streamId, topic, streams, zulipFeatureLevel }) => {
invariant(zulipFeatureLevel >= 170, 'Should only attempt to unmute in muted stream on FL 170+');
await api.updateUserTopic(auth, streamId, topic, UserTopicVisibilityPolicy.Unmuted);
},
};

const unmuteTopic = {
title: 'Unmute topic',
errorMessage: 'Failed to unmute topic',
Expand Down Expand Up @@ -631,13 +640,14 @@ export const constructTopicActionButtons = (args: {|
ownUserRole: Role,
subscriptions: Map<number, Subscription>,
unread: UnreadState,
zulipFeatureLevel: number,
...
}>,
streamId: number,
topic: string,
|}): Button<TopicArgs>[] => {
const { backgroundData, streamId, topic } = args;
const { mute, ownUserRole, subscriptions, unread } = backgroundData;
const { mute, ownUserRole, subscriptions, unread, zulipFeatureLevel } = backgroundData;
const sub = subscriptions.get(streamId);
const streamMuted = !!sub && !sub.in_home_view;

Expand All @@ -658,7 +668,19 @@ export const constructTopicActionButtons = (args: {|
break;
}
} else if (sub && streamMuted) {
// TODO(#5691): offer new "unmute topic" concept, when server supports it
// Muted stream.
// TODO(server-7.0): Simplify this condition away.
if (zulipFeatureLevel >= 170) {
switch (getTopicVisibilityPolicy(mute, streamId, topic)) {
case UserTopicVisibilityPolicy.None:
case UserTopicVisibilityPolicy.Muted:
buttons.push(unmuteTopicInMutedStream);
break;
case UserTopicVisibilityPolicy.Unmuted:
buttons.push(muteTopic);
break;
}
}
} else {
// Not subscribed to stream at all; no muting.
}
Expand Down

0 comments on commit b4a41be

Please sign in to comment.