Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
mute user: Hide from top left corner PM list.
Abhijeet Prasad Bodas15e3420ee420
diff --git a/frontend_tests/node_tests/pm_conversations.js b/frontend_tests/node_tests/pm_conversations.jsindex c65b2cf27cc..621d1b38524 100644--- a/frontend_tests/node_tests/pm_conversations.js+++ b/frontend_tests/node_tests/pm_conversations.js@@ -5,6 +5,7 @@ const {strict: assert} = require("assert");const {zrequire} = require("../zjsunit/namespace");const {run_test} = require("../zjsunit/test");+const muting = zrequire("muting");const people = zrequire("people");const pmc = zrequire("pm_conversations");@@ -21,6 +22,7 @@ const params = {function test(label, f) {run_test(label, (override) => {pmc.clear_for_testing();+ muting.set_muted_topics([]);people.initialize_current_user(15);f(override);});@@ -68,3 +70,31 @@ test("insert_recent_private_message", () => {]);assert.deepEqual(pmc.recent.get_strings(), ["1", "1,2,3", "15", "3", "1,2"]);});++test("muted_users", () => {+ pmc.recent.initialize(params);++ // Base data+ assert.deepEqual(pmc.recent.get(), [+ {user_ids_string: "1", max_message_id: 100},+ {user_ids_string: "3", max_message_id: 99},+ {user_ids_string: "1,2", max_message_id: 98},+ {user_ids_string: "1,2,3", max_message_id: 97},+ {user_ids_string: "15", max_message_id: 96},+ ]);+ assert.deepEqual(pmc.recent.get_strings(), ["1", "3", "1,2", "1,2,3", "15"]);++ // Mute some users.+ muting.add_muted_user(1);+ muting.add_muted_user(2);++ // We should now get back only those messages which are either-+ // 1:1 PMs in which the other user hasn't been muted.+ // Huddles where there's at least one non-muted participant.+ assert.deepEqual(pmc.recent.get(), [+ {user_ids_string: "3", max_message_id: 99},+ {user_ids_string: "1,2,3", max_message_id: 97},+ {user_ids_string: "15", max_message_id: 96},+ ]);+ assert.deepEqual(pmc.recent.get_strings(), ["3", "1,2,3", "15"]);+});diff --git a/static/js/muting_ui.js b/static/js/muting_ui.jsindex 05b98a61d86..f6d6ab3c935 100644--- a/static/js/muting_ui.js+++ b/static/js/muting_ui.js@@ -13,6 +13,7 @@ import * as message_lists from "./message_lists";import * as muting from "./muting";import * as overlays from "./overlays";import * as people from "./people";+import * as pm_list from "./pm_list";import * as popovers from "./popovers";import * as recent_topics from "./recent_topics";import * as settings_muted_topics from "./settings_muted_topics";@@ -150,6 +151,7 @@ export function rerender_for_muted_user() {}activity.redraw();+ pm_list.update_private_messages();}export function handle_user_updates(muted_user_ids) {diff --git a/static/js/pm_conversations.js b/static/js/pm_conversations.jsindex c2e43c19923..7b2033d9f60 100644--- a/static/js/pm_conversations.js+++ b/static/js/pm_conversations.js@@ -1,4 +1,5 @@import {FoldDict} from "./fold_dict";+import * as muting from "./muting";import * as people from "./people";const partners = new Set();@@ -11,6 +12,18 @@ export function is_partner(user_id) {return partners.has(user_id);}+function filter_muted_pms(conversation) {+ // We hide muted users from the top left corner, as well as those huddles+ // in which all participants are muted.+ const recipients = conversation.user_ids_string.split(",").map((id) => Number.parseInt(id, 10));++ if (recipients.every((id) => muting.is_user_muted(id))) {+ return false;+ }++ return true;+}+class RecentPrivateMessages {// This data structure keeps track of the sets of users you've had// recent conversations with, sorted by time (implemented via@@ -59,13 +72,15 @@ class RecentPrivateMessages {get() {// returns array of structs with user_ids_string and// message_id- return this.recent_private_messages;+ return this.recent_private_messages.filter((pm) => filter_muted_pms(pm));}get_strings() {// returns array of structs with user_ids_string and// message_id- return this.recent_private_messages.map((conversation) => conversation.user_ids_string);+ return this.recent_private_messages+ .filter((pm) => filter_muted_pms(pm))+ .map((conversation) => conversation.user_ids_string);}initialize(params) {