From 3c89fe222ad117847eb60cc60871fb1bfd294573 Mon Sep 17 00:00:00 2001 From: Hardik Dharmani Date: Wed, 13 Sep 2023 00:28:40 +0530 Subject: [PATCH] refactor: Rename `private_message` to `direct_message`. This commit renames all uses of `private_message` in `unread.js` to `direct_message`. Renamed `private_message_count` to `direct_message_count` and `right_sidebar_private_message_count` to `right_sidebar_direct_message_count`. --- web/src/notifications.js | 2 +- web/src/pm_list.js | 2 +- web/src/unread.js | 8 ++++---- web/src/unread_ui.js | 2 +- web/tests/pm_list.test.js | 8 ++++---- web/tests/unread.test.js | 12 ++++++------ 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/web/src/notifications.js b/web/src/notifications.js index 9bf51fc413..cf2471b671 100644 --- a/web/src/notifications.js +++ b/web/src/notifications.js @@ -120,7 +120,7 @@ export function redraw_title() { export function update_unread_counts(counts) { const new_unread_count = unread.calculate_notifiable_count(counts); - const new_pm_count = counts.private_message_count; + const new_pm_count = counts.direct_message_count; if (new_unread_count === unread_count && new_pm_count === pm_count) { return; } diff --git a/web/src/pm_list.js b/web/src/pm_list.js index e980beb761..df6acaf74f 100644 --- a/web/src/pm_list.js +++ b/web/src/pm_list.js @@ -120,7 +120,7 @@ export function update_dom_with_unread_counts(counts) { // could matter. update_private_messages(); // This is just the global unread count. - set_count(counts.private_message_count); + set_count(counts.direct_message_count); } export function highlight_all_private_messages_view() { diff --git a/web/src/unread.js b/web/src/unread.js index d0ac3d5c91..a894e4ac7b 100644 --- a/web/src/unread.js +++ b/web/src/unread.js @@ -780,7 +780,7 @@ export function get_counts() { // Return a data structure with various counts. This function should be // pretty cheap, even if you don't care about all the counts, and you // should strive to keep it free of side effects on globals or DOM. - res.private_message_count = 0; + res.direct_message_count = 0; res.mentioned_message_count = unread_mentions_counter.size; res.direct_message_with_mention_count = direct_message_with_mention_count.size; @@ -795,8 +795,8 @@ export function get_counts() { const pm_res = unread_direct_message_counter.get_counts(); res.pm_count = pm_res.pm_dict; - res.private_message_count = pm_res.total_count; - res.right_sidebar_private_message_count = pm_res.right_sidebar_count; + res.direct_message_count = pm_res.total_count; + res.right_sidebar_direct_message_count = pm_res.right_sidebar_count; res.home_unread_messages += pm_res.total_count; return res; @@ -816,7 +816,7 @@ export function calculate_notifiable_count(res) { // DESKTOP_ICON_COUNT_DISPLAY_NOTIFIABLE new_message_count = res.mentioned_message_count + - res.private_message_count - + res.direct_message_count - // Avoid double-counting direct messages containing mentions res.direct_message_with_mention_count; } else if (no_notifications) { diff --git a/web/src/unread_ui.js b/web/src/unread_ui.js index f32f548638..fa96e351d7 100644 --- a/web/src/unread_ui.js +++ b/web/src/unread_ui.js @@ -94,7 +94,7 @@ export function update_unread_counts(skip_animations = false) { // 1:1 direct messages there. set_count_toggle_button( $("#userlist-toggle-unreadcount"), - res.right_sidebar_private_message_count, + res.right_sidebar_direct_message_count, ); } diff --git a/web/tests/pm_list.test.js b/web/tests/pm_list.test.js index 752225301a..c61e66b2ab 100644 --- a/web/tests/pm_list.test.js +++ b/web/tests/pm_list.test.js @@ -23,18 +23,18 @@ run_test("update_dom_with_unread_counts", () => { $private_li.set_find_results(".unread_count", $total_count); counts = { - private_message_count: 10, + direct_message_count: 10, }; - pm_list.set_count(counts.private_message_count); + pm_list.set_count(counts.direct_message_count); assert.equal($total_count.text(), "10"); assert.equal($total_count.hasClass("hide"), false); counts = { - private_message_count: 0, + direct_message_count: 0, }; - pm_list.set_count(counts.private_message_count); + pm_list.set_count(counts.direct_message_count); assert.equal($total_count.text(), ""); assert.equal($total_count.hasClass("hide"), true); }); diff --git a/web/tests/unread.test.js b/web/tests/unread.test.js index 59f31f7396..eea7fc41d0 100644 --- a/web/tests/unread.test.js +++ b/web/tests/unread.test.js @@ -43,7 +43,7 @@ const social = { stream_data.add_sub(social); function assert_zero_counts(counts) { - assert.equal(counts.private_message_count, 0); + assert.equal(counts.direct_message_count, 0); assert.equal(counts.home_unread_messages, 0); assert.equal(counts.mentioned_message_count, 0); assert.equal(counts.stream_count.size, 0); @@ -387,7 +387,7 @@ test("phantom_messages", () => { test("private_messages", () => { let counts = unread.get_counts(); - assert.equal(counts.private_message_count, 0); + assert.equal(counts.direct_message_count, 0); const message = { id: 15, @@ -399,12 +399,12 @@ test("private_messages", () => { unread.process_loaded_messages([message]); counts = unread.get_counts(); - assert.equal(counts.private_message_count, 1); + assert.equal(counts.direct_message_count, 1); assert.equal(counts.pm_count.get("999"), 1); test_notifiable_count(counts.home_unread_messages, 1); unread.mark_as_read(message.id); counts = unread.get_counts(); - assert.equal(counts.private_message_count, 0); + assert.equal(counts.direct_message_count, 0); assert.equal(counts.pm_count.get("999"), 0); test_notifiable_count(counts.home_unread_messages, 0); }); @@ -462,7 +462,7 @@ test("private_messages", () => { assert.deepEqual(unread.get_msg_ids_for_private(), []); assert.deepEqual(unread.get_all_msg_ids(), []); const counts = unread.get_counts(); - assert.equal(counts.private_message_count, 0); + assert.equal(counts.direct_message_count, 0); test_notifiable_count(counts.home_unread_messages, 0); }); @@ -791,6 +791,6 @@ test("errors", () => { unread.mark_as_read(message.id); const counts = unread.get_counts(); - assert.equal(counts.private_message_count, 0); + assert.equal(counts.direct_message_count, 0); test_notifiable_count(counts.home_unread_messages, 0); });