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`.
This commit is contained in:
Hardik Dharmani 2023-09-13 00:28:40 +05:30 committed by Tim Abbott
parent b8d84abc47
commit 3c89fe222a
6 changed files with 17 additions and 17 deletions

View File

@ -120,7 +120,7 @@ export function redraw_title() {
export function update_unread_counts(counts) { export function update_unread_counts(counts) {
const new_unread_count = unread.calculate_notifiable_count(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) { if (new_unread_count === unread_count && new_pm_count === pm_count) {
return; return;
} }

View File

@ -120,7 +120,7 @@ export function update_dom_with_unread_counts(counts) {
// could matter. // could matter.
update_private_messages(); update_private_messages();
// This is just the global unread count. // 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() { export function highlight_all_private_messages_view() {

View File

@ -780,7 +780,7 @@ export function get_counts() {
// Return a data structure with various counts. This function should be // 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 // 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. // 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.mentioned_message_count = unread_mentions_counter.size;
res.direct_message_with_mention_count = direct_message_with_mention_count.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(); const pm_res = unread_direct_message_counter.get_counts();
res.pm_count = pm_res.pm_dict; res.pm_count = pm_res.pm_dict;
res.private_message_count = pm_res.total_count; res.direct_message_count = pm_res.total_count;
res.right_sidebar_private_message_count = pm_res.right_sidebar_count; res.right_sidebar_direct_message_count = pm_res.right_sidebar_count;
res.home_unread_messages += pm_res.total_count; res.home_unread_messages += pm_res.total_count;
return res; return res;
@ -816,7 +816,7 @@ export function calculate_notifiable_count(res) {
// DESKTOP_ICON_COUNT_DISPLAY_NOTIFIABLE // DESKTOP_ICON_COUNT_DISPLAY_NOTIFIABLE
new_message_count = new_message_count =
res.mentioned_message_count + res.mentioned_message_count +
res.private_message_count - res.direct_message_count -
// Avoid double-counting direct messages containing mentions // Avoid double-counting direct messages containing mentions
res.direct_message_with_mention_count; res.direct_message_with_mention_count;
} else if (no_notifications) { } else if (no_notifications) {

View File

@ -94,7 +94,7 @@ export function update_unread_counts(skip_animations = false) {
// 1:1 direct messages there. // 1:1 direct messages there.
set_count_toggle_button( set_count_toggle_button(
$("#userlist-toggle-unreadcount"), $("#userlist-toggle-unreadcount"),
res.right_sidebar_private_message_count, res.right_sidebar_direct_message_count,
); );
} }

View File

@ -23,18 +23,18 @@ run_test("update_dom_with_unread_counts", () => {
$private_li.set_find_results(".unread_count", $total_count); $private_li.set_find_results(".unread_count", $total_count);
counts = { 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.text(), "10");
assert.equal($total_count.hasClass("hide"), false); assert.equal($total_count.hasClass("hide"), false);
counts = { 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.text(), "");
assert.equal($total_count.hasClass("hide"), true); assert.equal($total_count.hasClass("hide"), true);
}); });

View File

@ -43,7 +43,7 @@ const social = {
stream_data.add_sub(social); stream_data.add_sub(social);
function assert_zero_counts(counts) { 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.home_unread_messages, 0);
assert.equal(counts.mentioned_message_count, 0); assert.equal(counts.mentioned_message_count, 0);
assert.equal(counts.stream_count.size, 0); assert.equal(counts.stream_count.size, 0);
@ -387,7 +387,7 @@ test("phantom_messages", () => {
test("private_messages", () => { test("private_messages", () => {
let counts = unread.get_counts(); let counts = unread.get_counts();
assert.equal(counts.private_message_count, 0); assert.equal(counts.direct_message_count, 0);
const message = { const message = {
id: 15, id: 15,
@ -399,12 +399,12 @@ test("private_messages", () => {
unread.process_loaded_messages([message]); unread.process_loaded_messages([message]);
counts = unread.get_counts(); 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); assert.equal(counts.pm_count.get("999"), 1);
test_notifiable_count(counts.home_unread_messages, 1); test_notifiable_count(counts.home_unread_messages, 1);
unread.mark_as_read(message.id); unread.mark_as_read(message.id);
counts = unread.get_counts(); 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); assert.equal(counts.pm_count.get("999"), 0);
test_notifiable_count(counts.home_unread_messages, 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_msg_ids_for_private(), []);
assert.deepEqual(unread.get_all_msg_ids(), []); assert.deepEqual(unread.get_all_msg_ids(), []);
const counts = unread.get_counts(); 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); test_notifiable_count(counts.home_unread_messages, 0);
}); });
@ -791,6 +791,6 @@ test("errors", () => {
unread.mark_as_read(message.id); unread.mark_as_read(message.id);
const counts = unread.get_counts(); 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); test_notifiable_count(counts.home_unread_messages, 0);
}); });