From 04c355c248dd48496695d325b2ea38dddc1e4f67 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Bodas Date: Wed, 5 May 2021 09:08:24 +0530 Subject: [PATCH] typing notifications: Exclude muted typists. --- frontend_tests/node_tests/typing_data.js | 16 ++++++++++++++++ static/js/typing_data.js | 6 ++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/frontend_tests/node_tests/typing_data.js b/frontend_tests/node_tests/typing_data.js index d923d94c55..ead644c1e1 100644 --- a/frontend_tests/node_tests/typing_data.js +++ b/frontend_tests/node_tests/typing_data.js @@ -5,11 +5,13 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); +const muting = zrequire("muting"); const typing_data = zrequire("typing_data"); function test(label, f) { run_test(label, (override) => { typing_data.clear_for_testing(); + muting.set_muted_users([]); f(override); }); } @@ -59,6 +61,20 @@ test("basics", () => { assert.deepEqual(typing_data.get_group_typists([20, 40]), [20]); }); +test("muted_typists_excluded", () => { + typing_data.add_typist([5, 10, 15], 5); + typing_data.add_typist([5, 10, 15], 10); + + // Nobody is muted. + assert.deepEqual(typing_data.get_group_typists([5, 10, 15]), [5, 10]); + assert.deepEqual(typing_data.get_all_typists(), [5, 10]); + + // Mute a user, and test that the get_* functions exclude that user. + muting.add_muted_user(10); + assert.deepEqual(typing_data.get_group_typists([5, 10, 15]), [5]); + assert.deepEqual(typing_data.get_all_typists(), [5]); +}); + test("timers", () => { const events = {}; diff --git a/static/js/typing_data.js b/static/js/typing_data.js index 1c39d70588..d909a299dd 100644 --- a/static/js/typing_data.js +++ b/static/js/typing_data.js @@ -1,5 +1,6 @@ import _ from "lodash"; +import * as muting from "./muting"; import * as util from "./util"; // See docs/subsystems/typing-indicators.md for details on typing indicators. @@ -48,14 +49,15 @@ export function remove_typist(group, typist) { export function get_group_typists(group) { const key = get_key(group); - return typist_dct.get(key) || []; + const user_ids = typist_dct.get(key) || []; + return muting.filter_muted_user_ids(user_ids); } export function get_all_typists() { let typists = [].concat(...Array.from(typist_dct.values())); typists = util.sorted_ids(typists); typists = _.sortedUniq(typists); - return typists; + return muting.filter_muted_user_ids(typists); } // The next functions aren't pure data, but it is easy