2021-02-28 00:43:33 +01:00
|
|
|
import * as topic_list from "./topic_list";
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let last_mention_count = 0;
|
2016-11-14 17:14:59 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-02-28 00:40:18 +01:00
|
|
|
export function animate_mention_changes(li, new_mention_count) {
|
2016-11-14 17:14:59 +01:00
|
|
|
if (new_mention_count > last_mention_count) {
|
|
|
|
do_new_messages_animation(li);
|
|
|
|
}
|
|
|
|
last_mention_count = new_mention_count;
|
2021-02-28 00:40:18 +01:00
|
|
|
}
|
2016-11-14 17:14:59 +01:00
|
|
|
|
2021-02-28 00:40:18 +01:00
|
|
|
export function set_count_toggle_button(elem, count) {
|
2016-11-14 17:14:59 +01:00
|
|
|
if (count === 0) {
|
2020-07-15 01:29:15 +02:00
|
|
|
if (elem.is(":animated")) {
|
2016-11-14 17:14:59 +01:00
|
|
|
return elem.stop(true, true).hide();
|
|
|
|
}
|
|
|
|
return elem.hide(500);
|
2018-06-06 18:50:09 +02:00
|
|
|
} else if (count > 0 && count < 1000) {
|
2016-11-14 17:14:59 +01:00
|
|
|
elem.show(500);
|
|
|
|
return elem.text(count);
|
|
|
|
}
|
2016-12-02 21:34:35 +01:00
|
|
|
elem.show(500);
|
|
|
|
return elem.text("1k+");
|
2021-02-28 00:40:18 +01:00
|
|
|
}
|
2016-11-14 17:14:59 +01:00
|
|
|
|
2021-02-28 00:40:18 +01:00
|
|
|
export function update_unread_counts() {
|
2017-02-11 09:55:18 +01:00
|
|
|
// Pure computation:
|
2019-11-02 00:06:25 +01:00
|
|
|
const res = unread.get_counts();
|
2017-02-11 09:55:18 +01:00
|
|
|
|
|
|
|
// Side effects from here down:
|
|
|
|
// This updates some DOM elements directly, so try to
|
|
|
|
// avoid excessive calls to this.
|
|
|
|
activity.update_dom_with_unread_counts(res);
|
2017-08-12 17:26:12 +02:00
|
|
|
top_left_corner.update_dom_with_unread_counts(res);
|
2017-02-11 09:55:18 +01:00
|
|
|
stream_list.update_dom_with_unread_counts(res);
|
|
|
|
pm_list.update_dom_with_unread_counts(res);
|
2020-01-31 20:15:46 +01:00
|
|
|
topic_list.update();
|
2019-11-02 00:06:25 +01:00
|
|
|
const notifiable_unread_count = unread.calculate_notifiable_count(res);
|
2020-10-21 04:07:35 +02:00
|
|
|
notifications.update_unread_counts(notifiable_unread_count, res.private_message_count);
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2021-02-28 00:40:18 +01:00
|
|
|
set_count_toggle_button($("#streamlist-toggle-unreadcount"), res.home_unread_messages);
|
|
|
|
}
|
2017-02-11 09:55:18 +01:00
|
|
|
|
2021-02-28 00:40:18 +01:00
|
|
|
export function should_display_bankruptcy_banner() {
|
2017-02-11 08:59:19 +01:00
|
|
|
// Until we've handled possibly declaring bankruptcy, don't show
|
|
|
|
// unread counts since they only consider messages that are loaded
|
|
|
|
// client side and may be different from the numbers reported by
|
|
|
|
// the server.
|
|
|
|
|
|
|
|
if (!page_params.furthest_read_time) {
|
|
|
|
// We've never read a message.
|
2020-03-28 19:33:46 +01:00
|
|
|
return false;
|
2017-02-11 08:59:19 +01:00
|
|
|
}
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
const now = Date.now() / 1000;
|
2020-07-15 00:34:28 +02:00
|
|
|
if (
|
|
|
|
page_params.unread_msgs.count > 500 &&
|
|
|
|
now - page_params.furthest_read_time > 60 * 60 * 24 * 2
|
|
|
|
) {
|
|
|
|
// 2 days.
|
2020-03-28 19:33:46 +01:00
|
|
|
return true;
|
2017-02-11 08:59:19 +01:00
|
|
|
}
|
|
|
|
|
2020-03-28 19:33:46 +01:00
|
|
|
return false;
|
2021-02-28 00:40:18 +01:00
|
|
|
}
|
2016-11-14 17:14:59 +01:00
|
|
|
|
2021-02-28 00:40:18 +01:00
|
|
|
export function initialize() {
|
|
|
|
update_unread_counts();
|
|
|
|
}
|