Skip to content

Commit

Permalink
follow-topic: Add follow/unfollow options to topic action sheet
Browse files Browse the repository at this point in the history
Fixes: zulip#5771
  • Loading branch information
gnprice committed Nov 17, 2023
1 parent 66c8985 commit 4410bde
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/action-sheets/__tests__/action-sheet-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,21 @@ describe('constructTopicActionButtons', () => {
expect(titles({ ...eg.plusBackgroundData, mute })).toContain('Mute topic');
});

test('show followTopic on muted topic', () => {
const mute = makeMuteState([[eg.stream, topic]]);
expect(titles({ ...eg.plusBackgroundData, mute })).toContain('Follow topic');
});

test('show followTopic', () => {
const mute = makeMuteState([]);
expect(titles({ ...eg.plusBackgroundData, mute })).toContain('Follow topic');
});

test('show unfollowTopic', () => {
const mute = makeMuteState([[eg.stream, topic, UserTopicVisibilityPolicy.Followed]]);
expect(titles({ ...eg.plusBackgroundData, mute })).toContain('Unfollow topic');
});

test('show resolveTopic', () => {
expect(titles({ ...eg.plusBackgroundData })).toContain('Resolve topic');
});
Expand Down
48 changes: 46 additions & 2 deletions src/action-sheets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,24 @@ const muteTopic = {
},
};

const followTopic = {
title: 'Follow topic',
errorMessage: 'Failed to follow topic',
action: async ({ auth, streamId, topic, zulipFeatureLevel }) => {
invariant(zulipFeatureLevel >= 219, 'Should only attempt to follow topic on FL 219+');
await api.updateUserTopic(auth, streamId, topic, UserTopicVisibilityPolicy.Followed);
},
};

const unfollowTopic = {
title: 'Unfollow topic',
errorMessage: 'Failed to unfollow topic',
action: async ({ auth, streamId, topic, zulipFeatureLevel }) => {
invariant(zulipFeatureLevel >= 219, 'Should only attempt to unfollow topic on FL 219+');
await api.updateUserTopic(auth, streamId, topic, UserTopicVisibilityPolicy.None);
},
};

const copyLinkToTopic = {
title: 'Copy link to topic',
errorMessage: 'Failed to copy topic link',
Expand Down Expand Up @@ -651,6 +669,11 @@ export const constructTopicActionButtons = (args: {|
const sub = subscriptions.get(streamId);
const streamMuted = !!sub && !sub.in_home_view;

// TODO(server-7.0): Simplify this condition away.
const supportsUnmutingTopics = zulipFeatureLevel >= 170;
// TODO(server-8.0): Simplify this condition away.
const supportsFollowingTopics = zulipFeatureLevel >= 219;

const buttons = [];
const unreadCount = getUnreadCountForTopic(unread, streamId, topic);
if (unreadCount > 0) {
Expand All @@ -661,25 +684,46 @@ export const constructTopicActionButtons = (args: {|
switch (getTopicVisibilityPolicy(mute, streamId, topic)) {
case UserTopicVisibilityPolicy.Muted:
buttons.push(unmuteTopic);
if (supportsFollowingTopics) {
buttons.push(followTopic);
}
break;
case UserTopicVisibilityPolicy.None:
case UserTopicVisibilityPolicy.Unmuted:
buttons.push(muteTopic);
if (supportsFollowingTopics) {
buttons.push(followTopic);
}
break;
case UserTopicVisibilityPolicy.Followed:
buttons.push(muteTopic);
if (supportsFollowingTopics) {
buttons.push(unfollowTopic);
}
break;
}
} else if (sub && streamMuted) {
// Muted stream.
// TODO(server-7.0): Simplify this condition away.
if (zulipFeatureLevel >= 170) {
if (supportsUnmutingTopics) {
switch (getTopicVisibilityPolicy(mute, streamId, topic)) {
case UserTopicVisibilityPolicy.None:
case UserTopicVisibilityPolicy.Muted:
buttons.push(unmuteTopicInMutedStream);
if (supportsFollowingTopics) {
buttons.push(followTopic);
}
break;
case UserTopicVisibilityPolicy.Unmuted:
buttons.push(muteTopic);
if (supportsFollowingTopics) {
buttons.push(followTopic);
}
break;
case UserTopicVisibilityPolicy.Followed:
buttons.push(muteTopic);
if (supportsFollowingTopics) {
buttons.push(unfollowTopic);
}
break;
}
}
Expand Down
4 changes: 4 additions & 0 deletions static/translations/messages_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@
"Delete topic": "Delete topic",
"Deleting a topic will immediately remove it and its messages for everyone. Other users may find this confusing, especially if they had received an email or push notification related to the deleted messages.\n\nAre you sure you want to permanently delete “{topic}”?": "Deleting a topic will immediately remove it and its messages for everyone. Other users may find this confusing, especially if they had received an email or push notification related to the deleted messages.\n\nAre you sure you want to permanently delete “{topic}”?",
"Unmute topic": "Unmute topic",
"Follow topic": "Follow topic",
"Failed to follow topic": "Failed to follow topic",
"Unfollow topic": "Unfollow topic",
"Failed to unfollow topic": "Failed to unfollow topic",
"Mute stream": "Mute stream",
"Unmute stream": "Unmute stream",
"No Internet connection": "No Internet connection",
Expand Down

0 comments on commit 4410bde

Please sign in to comment.