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.

user muting: Add helpers to filter out muted users.

Abhijeet Prasad Bodas47764ded7609
diff --git a/frontend_tests/node_tests/muting.js b/frontend_tests/node_tests/muting.js
index f6c177da279..dbd09c7cba0 100644
--- a/frontend_tests/node_tests/muting.js
+++ b/frontend_tests/node_tests/muting.js
@@ -92,6 +92,30 @@ test("add_and_remove_mutes", () => {
assert(!muting.is_user_muted(1));
});
+test("get_unmuted_users", () => {
+ const hamlet = {
+ user_id: 1,
+ full_name: "King Hamlet",
+ };
+ const cordelia = {
+ user_id: 2,
+ full_name: "Cordelia, Lear's Daughter",
+ };
+ const othello = {
+ user_id: 3,
+ full_name: "Othello, Moor of Venice",
+ };
+
+ muting.add_muted_user(hamlet.user_id);
+ muting.add_muted_user(cordelia.user_id);
+
+ assert.deepEqual(
+ muting.filter_muted_user_ids([hamlet.user_id, cordelia.user_id, othello.user_id]),
+ [othello.user_id],
+ );
+ assert.deepEqual(muting.filter_muted_users([hamlet, cordelia, othello]), [othello]);
+});
+
test("get_mutes", () => {
assert.deepEqual(muting.get_muted_topics(), []);
muting.add_muted_topic(office.stream_id, "gossip", 1577836800);
diff --git a/static/js/muting.js b/static/js/muting.js
index 291a6beb55b..eeaf4a9e653 100644
--- a/static/js/muting.js
+++ b/static/js/muting.js
@@ -98,6 +98,18 @@ export function is_user_muted(user_id) {
return muted_users.has(user_id);
}
+export function filter_muted_user_ids(user_ids) {
+ // Returns a copy of the user ID list, after removing muted user IDs.
+ const base_user_ids = [...user_ids];
+ return base_user_ids.filter((user_id) => !is_user_muted(user_id));
+}
+
+export function filter_muted_users(persons) {
+ // Returns a copy of the people list, after removing muted users.
+ const base_users = [...persons];
+ return base_users.filter((person) => !is_user_muted(person.user_id));
+}
+
export function get_muted_users() {
const users = [];
for (const [id, date_muted] of muted_users) {