Skip to content

Commit ed301e7

Browse files
committed
mute: Use api.updateUserTopic where available
Fixes: zulip#5726
1 parent ce78593 commit ed301e7

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

src/action-sheets/index.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type {
2121
Stream,
2222
LocalizableText,
2323
} from '../types';
24+
import { UserTopicVisibilityPolicy } from '../api/modelTypes';
2425
import type { UnreadState } from '../unread/unreadModelTypes';
2526
import {
2627
apiNarrowOfNarrow,
@@ -280,22 +281,32 @@ const markAsUnreadFromMessage = {
280281
const unmuteTopic = {
281282
title: 'Unmute topic',
282283
errorMessage: 'Failed to unmute topic',
283-
action: async ({ auth, streamId, topic, streams }) => {
284-
const stream = streams.get(streamId);
285-
invariant(stream !== undefined, 'Stream with provided streamId must exist.');
286-
// This still uses a stream name (#3918) because the API method does; see there.
287-
await api.setTopicMute(auth, stream.name, topic, false);
284+
action: async ({ auth, streamId, topic, streams, zulipFeatureLevel }) => {
285+
if (zulipFeatureLevel >= 170) {
286+
await api.updateUserTopic(auth, streamId, topic, UserTopicVisibilityPolicy.None);
287+
} else {
288+
// TODO(server-7.0): Cut this fallback to setTopicMute.
289+
const stream = streams.get(streamId);
290+
invariant(stream !== undefined, 'Stream with provided streamId must exist.');
291+
// This still uses a stream name (#3918) because the API method does; see there.
292+
await api.setTopicMute(auth, stream.name, topic, false);
293+
}
288294
},
289295
};
290296

291297
const muteTopic = {
292298
title: 'Mute topic',
293299
errorMessage: 'Failed to mute topic',
294-
action: async ({ auth, streamId, topic, streams }) => {
295-
const stream = streams.get(streamId);
296-
invariant(stream !== undefined, 'Stream with provided streamId must exist.');
297-
// This still uses a stream name (#3918) because the API method does; see there.
298-
await api.setTopicMute(auth, stream.name, topic, true);
300+
action: async ({ auth, streamId, topic, streams, zulipFeatureLevel }) => {
301+
if (zulipFeatureLevel >= 170) {
302+
await api.updateUserTopic(auth, streamId, topic, UserTopicVisibilityPolicy.Muted);
303+
} else {
304+
// TODO(server-7.0): Cut this fallback to setTopicMute.
305+
const stream = streams.get(streamId);
306+
invariant(stream !== undefined, 'Stream with provided streamId must exist.');
307+
// This still uses a stream name (#3918) because the API method does; see there.
308+
await api.setTopicMute(auth, stream.name, topic, true);
309+
}
299310
},
300311
};
301312

0 commit comments

Comments
 (0)