From 55fd3123797e1f102f25942bc2efc03a59cd67f8 Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Tue, 5 Dec 2023 20:36:43 +0530 Subject: [PATCH] typing_events: Do not show typing notifications for inaccessible users. This commit adds code to not show typing notifications for inaccessible users as the user would not have any information even if we show them as the name shown would be "Unknown user". --- web/src/typing_events.js | 4 +++- web/tests/example8.test.js | 6 +++++- web/tests/typing_events.test.js | 13 ++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/web/src/typing_events.js b/web/src/typing_events.js index a6f0750a2c..7c13139090 100644 --- a/web/src/typing_events.js +++ b/web/src/typing_events.js @@ -58,7 +58,9 @@ function get_users_typing_for_narrow() { export function render_notifications_for_narrow() { const user_ids = get_users_typing_for_narrow(); - const users_typing = user_ids.map((user_id) => people.get_by_user_id(user_id)); + const users_typing = user_ids + .map((user_id) => people.get_user_by_id_assert_valid(user_id)) + .filter((person) => !person.is_inaccessible_user); const num_of_users_typing = users_typing.length; if (num_of_users_typing === 0) { diff --git a/web/tests/example8.test.js b/web/tests/example8.test.js index 2e9d6ae727..3594c63549 100644 --- a/web/tests/example8.test.js +++ b/web/tests/example8.test.js @@ -2,11 +2,15 @@ const {strict: assert} = require("assert"); -const {zrequire} = require("./lib/namespace"); +const {mock_esm, zrequire} = require("./lib/namespace"); const {run_test} = require("./lib/test"); const $ = require("./lib/zjquery"); const {page_params} = require("./lib/zpage_params"); +mock_esm("../src/settings_data", { + user_can_access_all_other_users: () => true, +}); + /* Until now, we had seen various testing techniques, learned how to use helper functions like `mock_esm`, `override` of diff --git a/web/tests/typing_events.test.js b/web/tests/typing_events.test.js index ddb315571d..ce9c4163e8 100644 --- a/web/tests/typing_events.test.js +++ b/web/tests/typing_events.test.js @@ -2,11 +2,13 @@ const {strict: assert} = require("assert"); -const {zrequire} = require("./lib/namespace"); +const {mock_esm, zrequire} = require("./lib/namespace"); const {run_test} = require("./lib/test"); const $ = require("./lib/zjquery"); const {page_params} = require("./lib/zpage_params"); +const settings_data = mock_esm("../src/settings_data"); + const {Filter} = zrequire("filter"); const narrow_state = zrequire("narrow_state"); const people = zrequire("people"); @@ -44,6 +46,7 @@ people.add_active_user(kitty); run_test("render_notifications_for_narrow", ({override, mock_template}) => { override(page_params, "user_id", anna.user_id); + override(settings_data, "user_can_access_all_other_users", () => true); const group = [anna.user_id, vronsky.user_id, levin.user_id, kitty.user_id]; const conversation_key = typing_data.get_direct_message_conversation_key(group); const group_emails = `${anna.email},${vronsky.email},${levin.email},${kitty.email}`; @@ -89,4 +92,12 @@ run_test("render_notifications_for_narrow", ({override, mock_template}) => { typing_data.remove_typist(conversation_key, kitty.user_id); typing_events.render_notifications_for_narrow(); assert.ok(!$typing_notifications.visible()); + + // #typing_notifications should be hidden for inaccessible users. + override(settings_data, "user_can_access_all_other_users", () => false); + const inaccessible_user = people.add_inaccessible_user(20); + typing_data.add_typist(conversation_key, inaccessible_user.user_id); + typing_data.add_typist(conversation_key, 21); + typing_events.render_notifications_for_narrow(); + assert.ok(!$typing_notifications.visible()); });