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".
This commit is contained in:
Sahil Batra 2023-12-05 20:36:43 +05:30 committed by Tim Abbott
parent cd94837d6b
commit 55fd312379
3 changed files with 20 additions and 3 deletions

View File

@ -58,7 +58,9 @@ function get_users_typing_for_narrow() {
export function render_notifications_for_narrow() { export function render_notifications_for_narrow() {
const user_ids = get_users_typing_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; const num_of_users_typing = users_typing.length;
if (num_of_users_typing === 0) { if (num_of_users_typing === 0) {

View File

@ -2,11 +2,15 @@
const {strict: assert} = require("assert"); const {strict: assert} = require("assert");
const {zrequire} = require("./lib/namespace"); const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test"); const {run_test} = require("./lib/test");
const $ = require("./lib/zjquery"); const $ = require("./lib/zjquery");
const {page_params} = require("./lib/zpage_params"); 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 Until now, we had seen various testing techniques, learned
how to use helper functions like `mock_esm`, `override` of how to use helper functions like `mock_esm`, `override` of

View File

@ -2,11 +2,13 @@
const {strict: assert} = require("assert"); const {strict: assert} = require("assert");
const {zrequire} = require("./lib/namespace"); const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test"); const {run_test} = require("./lib/test");
const $ = require("./lib/zjquery"); const $ = require("./lib/zjquery");
const {page_params} = require("./lib/zpage_params"); const {page_params} = require("./lib/zpage_params");
const settings_data = mock_esm("../src/settings_data");
const {Filter} = zrequire("filter"); const {Filter} = zrequire("filter");
const narrow_state = zrequire("narrow_state"); const narrow_state = zrequire("narrow_state");
const people = zrequire("people"); const people = zrequire("people");
@ -44,6 +46,7 @@ people.add_active_user(kitty);
run_test("render_notifications_for_narrow", ({override, mock_template}) => { run_test("render_notifications_for_narrow", ({override, mock_template}) => {
override(page_params, "user_id", anna.user_id); 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 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 conversation_key = typing_data.get_direct_message_conversation_key(group);
const group_emails = `${anna.email},${vronsky.email},${levin.email},${kitty.email}`; 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_data.remove_typist(conversation_key, kitty.user_id);
typing_events.render_notifications_for_narrow(); typing_events.render_notifications_for_narrow();
assert.ok(!$typing_notifications.visible()); 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());
}); });