Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

left_sidebar: Highlight DM header on new unreads.

Karl Stolleyb30161b636f8
diff --git a/web/src/pm_list.ts b/web/src/pm_list.ts
index 60805c96ba5..1666a806f6c 100644
--- a/web/src/pm_list.ts
+++ b/web/src/pm_list.ts
@@ -28,6 +28,7 @@ const ls_key = "left_sidebar_direct_messages_collapsed_state";
const ls_schema = z._default(z.boolean(), false);
const ls = localstorage();
let private_messages_collapsed = false;
+let last_direct_message_count: number | undefined;
// The direct messages section can be zoomed in to view more messages.
// This keeps track of if we're zoomed in or not.
@@ -168,15 +169,36 @@ export function expand(): void {
update_private_messages();
}
-export function update_dom_with_unread_counts(counts: FullUnreadCountsData): void {
+export function update_dom_with_unread_counts(
+ counts: FullUnreadCountsData,
+ skip_animations = false,
+): void {
// In theory, we could support passing the counts object through
// to pm_list_data, rather than fetching it directly there. But
// it's not an important optimization, because it's unlikely a
// user would have 10,000s of unread direct messages where it
// could matter.
update_private_messages();
+
// This is just the global unread count.
- set_count(counts.direct_message_count);
+ const new_direct_message_count = counts.direct_message_count;
+ set_count(new_direct_message_count);
+
+ if (last_direct_message_count === undefined) {
+ // We don't want to animate the DM header
+ // when Zulip first loads, but we must update
+ // the last DM count to correctly animate
+ // the arrival of new unread DMs.
+ last_direct_message_count = new_direct_message_count;
+ return;
+ }
+
+ if (new_direct_message_count > last_direct_message_count && !skip_animations) {
+ const $dm_header = $("#direct-messages-section-header");
+ ui_util.do_new_unread_animation($dm_header);
+ }
+
+ last_direct_message_count = new_direct_message_count;
}
export function highlight_all_private_messages_view(): void {
diff --git a/web/src/ui_init.js b/web/src/ui_init.js
index 7615bf7f822..c17962acc0c 100644
--- a/web/src/ui_init.js
+++ b/web/src/ui_init.js
@@ -398,8 +398,8 @@ function initialize_unread_ui() {
unread_ui.register_update_unread_counts_hook((counts) =>
stream_list.update_dom_with_unread_counts(counts),
);
- unread_ui.register_update_unread_counts_hook((counts) =>
- pm_list.update_dom_with_unread_counts(counts),
+ unread_ui.register_update_unread_counts_hook((counts, skip_animations) =>
+ pm_list.update_dom_with_unread_counts(counts, skip_animations),
);
unread_ui.register_update_unread_counts_hook(() => topic_list.update());
unread_ui.register_update_unread_counts_hook((counts) =>
diff --git a/web/src/unread_ops.ts b/web/src/unread_ops.ts
index ca34eff39c8..7eaaa03ab4f 100644
--- a/web/src/unread_ops.ts
+++ b/web/src/unread_ops.ts
@@ -788,7 +788,7 @@ export function process_unread_messages_event({
unread_ui.notify_messages_remain_unread();
}
- unread_ui.update_unread_counts();
+ unread_ui.update_unread_counts(true);
}
// Takes a list of messages and marks them as read.
diff --git a/web/styles/left_sidebar.css b/web/styles/left_sidebar.css
index 8362c2a39bc..eee62fe97fb 100644
--- a/web/styles/left_sidebar.css
+++ b/web/styles/left_sidebar.css
@@ -1026,7 +1026,8 @@ li.active-sub-filter {
}
}
-.top_left_mentions {
+.top_left_mentions,
+#direct-messages-section-header {
/* To highlight the background when a new unread arrives,
we set the background on the .new-unread class. */
&.new-unread {