js: Break cyclic dependency between top_left_corner and unread_ui.

This commit breaks the cyclic dependency between "top_left_corner.js"
and "unread_ui.js".

It achieves this by shifting the "animate_mention_changes" function
from "unread_ui.js" to "top_left_corner.js".
This commit is contained in:
sbansal1999 2023-04-07 23:36:13 +05:30 committed by Tim Abbott
parent 338436dfbd
commit e1a2789de2
2 changed files with 23 additions and 23 deletions

View File

@ -2,7 +2,8 @@ import $ from "jquery";
import * as resize from "./resize";
import * as ui_util from "./ui_util";
import * as unread_ui from "./unread_ui";
let last_mention_count = 0;
export function update_starred_count(count) {
const $starred_li = $(".top_left_starred_messages");
@ -19,7 +20,7 @@ export function update_dom_with_unread_counts(counts) {
ui_util.update_unread_count_in_dom($mentioned_li, counts.mentioned_message_count);
ui_util.update_unread_count_in_dom($home_li, counts.home_unread_messages);
unread_ui.animate_mention_changes($mentioned_li, counts.mentioned_message_count);
animate_mention_changes($mentioned_li, counts.mentioned_message_count);
}
function remove($elem) {
@ -78,3 +79,23 @@ export function narrow_to_recent_topics() {
resize.resize_stream_filters_container();
}, 0);
}
export function animate_mention_changes($li, new_mention_count) {
if (new_mention_count > last_mention_count) {
do_new_messages_animation($li);
}
last_mention_count = new_mention_count;
}
function do_new_messages_animation($li) {
$li.addClass("new_messages");
function mid_animation() {
$li.removeClass("new_messages");
$li.addClass("new_messages_fadeout");
}
function end_animation() {
$li.removeClass("new_messages_fadeout");
}
setTimeout(mid_animation, 3000);
setTimeout(end_animation, 6000);
}

View File

@ -13,7 +13,6 @@ import * as topic_list from "./topic_list";
import * as unread from "./unread";
import {notify_server_messages_read} from "./unread_ops";
let last_mention_count = 0;
let user_closed_mark_as_read_turned_off_banner = false;
export function hide_mark_as_read_turned_off_banner() {
// Use visibility instead of hide() to prevent messages on the screen from
@ -32,26 +31,6 @@ export function notify_messages_remain_unread() {
}
}
function do_new_messages_animation($li) {
$li.addClass("new_messages");
function mid_animation() {
$li.removeClass("new_messages");
$li.addClass("new_messages_fadeout");
}
function end_animation() {
$li.removeClass("new_messages_fadeout");
}
setTimeout(mid_animation, 3000);
setTimeout(end_animation, 6000);
}
export function animate_mention_changes($li, new_mention_count) {
if (new_mention_count > last_mention_count) {
do_new_messages_animation($li);
}
last_mention_count = new_mention_count;
}
export function set_count_toggle_button($elem, count) {
if (count === 0) {
if ($elem.is(":animated")) {