Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

settings: Update SETTINGS/TOPICS panel to include followed topics.

Prakhar Pratyush93a18b999aa9
diff --git a/web/src/settings_config.ts b/web/src/settings_config.ts
index f2ff4e4b186..7a771394cdd 100644
--- a/web/src/settings_config.ts
+++ b/web/src/settings_config.ts
@@ -886,6 +886,10 @@ export const system_user_groups_list = [
];
export const user_topic_visibility_policy_values = {
+ followed: {
+ code: 3,
+ description: $t({defaultMessage: "Followed"}),
+ },
muted: {
code: 1,
description: $t({defaultMessage: "Muted"}),
diff --git a/web/src/settings_user_topics.js b/web/src/settings_user_topics.js
index 521f3517ae0..734bf3cf419 100644
--- a/web/src/settings_user_topics.js
+++ b/web/src/settings_user_topics.js
@@ -3,6 +3,7 @@ import $ from "jquery";
import render_user_topic_ui_row from "../templates/user_topic_ui_row.hbs";
import * as ListWidget from "./list_widget";
+import {page_params} from "./page_params";
import * as scroll_util from "./scroll_util";
import * as settings_config from "./settings_config";
import * as user_topics from "./user_topics";
@@ -31,6 +32,7 @@ export function populate_list() {
user_topic,
user_topic_visibility_policy_values:
settings_config.user_topic_visibility_policy_values,
+ development: page_params.development_environment,
};
return render_user_topic_ui_row(context);
},
diff --git a/web/src/user_topics.js b/web/src/user_topics.js
index 1399bfbaf01..a6173444eb8 100644
--- a/web/src/user_topics.js
+++ b/web/src/user_topics.js
@@ -46,6 +46,10 @@ export function get_topic_visibility_policy(stream_id, topic) {
return all_visibility_policies.INHERIT;
}
+export function is_topic_followed(stream_id, topic) {
+ return get_topic_visibility_policy(stream_id, topic) === all_visibility_policies.FOLLOWED;
+}
+
export function is_topic_unmuted(stream_id, topic) {
return get_topic_visibility_policy(stream_id, topic) === all_visibility_policies.UNMUTED;
}
diff --git a/web/templates/settings/user_topics_settings.hbs b/web/templates/settings/user_topics_settings.hbs
index fb85c6ecd04..b0ace536bb6 100644
--- a/web/templates/settings/user_topics_settings.hbs
+++ b/web/templates/settings/user_topics_settings.hbs
@@ -1,14 +1,27 @@
<div id="user-topic-settings" class="settings-section" data-name="topics">
<p>
- {{#tr}}
- Zulip lets you mute topics and streams to avoid receiving notifications messages you are not interested in.
- Muting a stream effectively mutes all topics in that stream. You can also manually mute a topic in an unmuted stream,
- or unmute a topic in a muted stream. <z-link>Learn more.</z-link>
- {{#*inline "z-link"}}<a href="/help/mute-a-topic" target="_blank" rel="noopener noreferrer">{{> @partial-block}}</a>{{/inline}}
- {{/tr}}
+ {{#if development}}
+ {{#tr}}
+ Zulip lets you configure notifications for each topic. You can also automatically follow or unmute topics
+ you start or participate in.
+ {{/tr}}
+ {{else}}
+ {{#tr}}
+ Zulip lets you mute topics and streams to avoid receiving notifications messages you are not interested in.
+ Muting a stream effectively mutes all topics in that stream. You can also manually mute a topic in an unmuted stream,
+ or unmute a topic in a muted stream. <z-link>Learn more.</z-link>
+ {{#*inline "z-link"}}<a href="/help/mute-a-topic" target="_blank" rel="noopener noreferrer">{{> @partial-block}}</a>{{/inline}}
+ {{/tr}}
+ {{/if}}
</p>
<div class="settings_panel_list_header">
- <h3>{{t "Topic settings"}}</h3>
+ {{#if development}}
+ <h3>{{t "Topic settings"}}
+ {{> ../help_link_widget link="/help/mute-a-topic" }}
+ </h3>
+ {{else}}
+ <h3>{{t "Topic settings"}}</h3>
+ {{/if}}
<input id="user_topics_search" class="search filter_text_input" type="text" placeholder="{{t 'Filter topics' }}" aria-label="{{t 'Filter topics' }}"/>
</div>
<div class="progressive-table-wrapper" data-simplebar>
diff --git a/web/templates/user_topic_ui_row.hbs b/web/templates/user_topic_ui_row.hbs
index ae4e21749df..77ca2552fc5 100644
--- a/web/templates/user_topic_ui_row.hbs
+++ b/web/templates/user_topic_ui_row.hbs
@@ -5,7 +5,9 @@
<td>
<select class="settings_user_topic_visibility_policy prop-element list_select bootstrap-focus-style" data-setting-widget-type="number">
{{#each ../user_topic_visibility_policy_values}}
- <option value='{{this.code}}' {{#if (eq this.code ../visibility_policy)}}selected{{/if}}>{{this.description}}</option>
+ {{#unless (and (eq this.description "Followed") (not ../../development))}}
+ <option value='{{this.code}}' {{#if (eq this.code ../visibility_policy)}}selected{{/if}}>{{this.description}}</option>
+ {{/unless}}
{{/each}}
</select>
</td>
diff --git a/web/tests/user_topics.test.js b/web/tests/user_topics.test.js
index b24cff8f137..6a79ec6d2ca 100644
--- a/web/tests/user_topics.test.js
+++ b/web/tests/user_topics.test.js
@@ -96,6 +96,27 @@ test("add_and_remove_unmutes", () => {
assert.ok(!user_topics.is_topic_unmuted(unknown.stream_id, "java"));
});
+test("add_and_remove_follows", () => {
+ assert.ok(!user_topics.is_topic_followed(devel.stream_id, "java"));
+ user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.FOLLOWED);
+ assert.ok(user_topics.is_topic_followed(devel.stream_id, "java"));
+
+ // test idempotency
+ user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.FOLLOWED);
+ assert.ok(user_topics.is_topic_followed(devel.stream_id, "java"));
+
+ user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.INHERIT);
+ assert.ok(!user_topics.is_topic_followed(devel.stream_id, "java"));
+
+ // test idempotency
+ user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.INHERIT);
+ assert.ok(!user_topics.is_topic_followed(devel.stream_id, "java"));
+
+ // test unknown stream is harmless too
+ user_topics.update_user_topics(unknown.stream_id, "java", all_visibility_policies.INHERIT);
+ assert.ok(!user_topics.is_topic_followed(unknown.stream_id, "java"));
+});
+
test("get_mutes", () => {
assert.deepEqual(
user_topics.get_user_topics_for_visibility_policy(
@@ -182,6 +203,49 @@ test("get_unmutes", () => {
]);
});
+test("get_follows", () => {
+ assert.deepEqual(
+ user_topics.get_user_topics_for_visibility_policy(
+ user_topics.all_visibility_policies.FOLLOWED,
+ ),
+ [],
+ );
+ user_topics.update_user_topics(
+ office.stream_id,
+ "gossip",
+ all_visibility_policies.FOLLOWED,
+ 1577836800,
+ );
+ user_topics.update_user_topics(
+ devel.stream_id,
+ "java",
+ all_visibility_policies.FOLLOWED,
+ 1577836700,
+ );
+ const all_followed_topics = user_topics
+ .get_user_topics_for_visibility_policy(user_topics.all_visibility_policies.FOLLOWED)
+ .sort((a, b) => a.date_updated - b.date_updated);
+
+ assert.deepEqual(all_followed_topics, [
+ {
+ date_updated: 1577836700000,
+ date_updated_str: "Dec 31, 2019",
+ stream: devel.name,
+ stream_id: devel.stream_id,
+ topic: "java",
+ visibility_policy: all_visibility_policies.FOLLOWED,
+ },
+ {
+ date_updated: 1577836800000,
+ date_updated_str: "Jan 1, 2020",
+ stream: office.name,
+ stream_id: office.stream_id,
+ topic: "gossip",
+ visibility_policy: all_visibility_policies.FOLLOWED,
+ },
+ ]);
+});
+
test("set_user_topics", () => {
blueslip.expect("warn", "Unknown stream ID in set_user_topic: 999");
@@ -189,6 +253,7 @@ test("set_user_topics", () => {
assert.ok(!user_topics.is_topic_muted(social.stream_id, "breakfast"));
assert.ok(!user_topics.is_topic_muted(design.stream_id, "typography"));
assert.ok(!user_topics.is_topic_unmuted(office.stream_id, "lunch"));
+ assert.ok(!user_topics.is_topic_followed(devel.stream_id, "dinner"));
page_params.user_topics = [
{
@@ -215,6 +280,12 @@ test("set_user_topics", () => {
last_updated: "1577836800",
visibility_policy: all_visibility_policies.UNMUTED,
},
+ {
+ stream_id: devel.stream_id,
+ topic_name: "dinner",
+ last_updated: "1577836800",
+ visibility_policy: all_visibility_policies.FOLLOWED,
+ },
];
user_topics.initialize();
@@ -259,6 +330,22 @@ test("set_user_topics", () => {
],
);
+ assert.deepEqual(
+ user_topics
+ .get_user_topics_for_visibility_policy(user_topics.all_visibility_policies.FOLLOWED)
+ .sort(),
+ [
+ {
+ date_updated: 1577836800000,
+ date_updated_str: "Jan 1, 2020",
+ stream: devel.name,
+ stream_id: devel.stream_id,
+ topic: "dinner",
+ visibility_policy: all_visibility_policies.FOLLOWED,
+ },
+ ],
+ );
+
user_topics.set_user_topic({
stream_id: design.stream_id,
topic_name: "typography",
@@ -274,6 +361,14 @@ test("set_user_topics", () => {
visibility_policy: all_visibility_policies.INHERIT,
});
assert.ok(!user_topics.is_topic_unmuted(devel.stream_id, "lunch"));
+
+ user_topics.set_user_topic({
+ stream_id: devel.stream_id,
+ topic_name: "dinner",
+ last_updated: "1577836800",
+ visibility_policy: all_visibility_policies.INHERIT,
+ });
+ assert.ok(!user_topics.is_topic_followed(devel.stream_id, "dinner"));
});
test("case_insensitivity", () => {