unread: Show unread count for only 1:1 human PMs for right sidebar icon.

Uptil now, the right sidebar user list unread count included bot and group
PMs which sometimes resulted in the confusing state of the user list icon
indicating unread messages but on expanding the user list, no username
had a counter beside it, since the list only has individual human users.

Now this right sidebar unread count too excludes bots and groups, so the
unread count and the user list are consistent, without any ghost counts.
This commit is contained in:
N-Shar-ma 2023-01-17 00:16:26 +05:30 committed by Tim Abbott
parent 8efa3965fd
commit 0e55b2aed9
2 changed files with 15 additions and 1 deletions

View File

@ -154,14 +154,22 @@ class UnreadPMCounter {
get_counts() {
const pm_dict = new Map(); // Hash by user_ids_string -> count
let total_count = 0;
let right_sidebar_count = 0;
for (const [user_ids_string, id_set] of this.bucketer) {
const count = id_set.size;
pm_dict.set(user_ids_string, count);
const user_ids = people.user_ids_string_to_ids_array(user_ids_string);
const is_with_one_human =
user_ids.length === 1 && !people.get_by_user_id(user_ids[0]).is_bot;
if (is_with_one_human) {
right_sidebar_count += count;
}
total_count += count;
}
return {
total_count,
pm_dict,
right_sidebar_count,
};
}
@ -704,6 +712,7 @@ export function get_counts() {
const pm_res = unread_pm_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.home_unread_messages += pm_res.total_count;
return res;

View File

@ -84,7 +84,12 @@ export function update_unread_counts() {
// Set the unread counts that we show in the buttons that
// toggle open the sidebar menus when we have a thin window.
set_count_toggle_button($("#streamlist-toggle-unreadcount"), res.home_unread_messages);
set_count_toggle_button($("#userlist-toggle-unreadcount"), res.private_message_count);
// Bots and group PMs do not appear in the right sidebar user list, so
// we show unread count for only non bot 1:1 private messages there.
set_count_toggle_button(
$("#userlist-toggle-unreadcount"),
res.right_sidebar_private_message_count,
);
}
export function should_display_bankruptcy_banner() {