2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2021-02-28 00:57:20 +01:00
|
|
|
import * as resize from "./resize";
|
2023-05-02 21:08:15 +02:00
|
|
|
import * as scheduled_messages from "./scheduled_messages";
|
2021-04-09 09:18:43 +02:00
|
|
|
import * as ui_util from "./ui_util";
|
2023-04-07 20:06:13 +02:00
|
|
|
|
|
|
|
let last_mention_count = 0;
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2021-02-28 00:44:57 +01:00
|
|
|
export function update_starred_count(count) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $starred_li = $(".top_left_starred_messages");
|
|
|
|
ui_util.update_unread_count_in_dom($starred_li, count);
|
2021-02-28 00:44:57 +01:00
|
|
|
}
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2023-05-02 21:08:15 +02:00
|
|
|
export function update_scheduled_messages_row() {
|
|
|
|
const $scheduled_li = $(".top_left_scheduled_messages");
|
|
|
|
const count = scheduled_messages.get_count();
|
2023-05-02 19:25:44 +02:00
|
|
|
if (count > 0) {
|
|
|
|
$scheduled_li.show();
|
|
|
|
} else {
|
|
|
|
$scheduled_li.hide();
|
|
|
|
}
|
2023-05-02 21:08:15 +02:00
|
|
|
ui_util.update_unread_count_in_dom($scheduled_li, count);
|
|
|
|
}
|
|
|
|
|
2023-05-03 19:32:40 +02:00
|
|
|
export function update_dom_with_unread_counts(counts, skip_animations) {
|
2023-06-16 13:23:39 +02:00
|
|
|
// Note that direct message counts are handled in pm_list.js.
|
2017-08-12 17:26:12 +02:00
|
|
|
|
|
|
|
// mentioned/home have simple integer counts
|
2022-01-25 11:36:19 +01:00
|
|
|
const $mentioned_li = $(".top_left_mentions");
|
|
|
|
const $home_li = $(".top_left_all_messages");
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
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);
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2023-05-03 19:32:40 +02:00
|
|
|
if (!skip_animations) {
|
|
|
|
animate_mention_changes($mentioned_li, counts.mentioned_message_count);
|
|
|
|
}
|
2021-02-28 00:44:57 +01:00
|
|
|
}
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
function remove($elem) {
|
|
|
|
$elem.removeClass("active-filter active-sub-filter");
|
2020-07-05 12:19:09 +02:00
|
|
|
}
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2022-09-13 13:15:57 +02:00
|
|
|
export function deselect_top_left_corner_items() {
|
2020-07-15 01:29:15 +02:00
|
|
|
remove($(".top_left_all_messages"));
|
|
|
|
remove($(".top_left_starred_messages"));
|
|
|
|
remove($(".top_left_mentions"));
|
2020-07-05 12:19:09 +02:00
|
|
|
remove($(".top_left_recent_topics"));
|
2017-08-12 17:26:12 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 00:44:57 +01:00
|
|
|
export function handle_narrow_activated(filter) {
|
2017-08-12 17:26:12 +02:00
|
|
|
deselect_top_left_corner_items();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let ops;
|
|
|
|
let filter_name;
|
2022-01-25 11:36:19 +01:00
|
|
|
let $filter_li;
|
2017-08-12 17:26:12 +02:00
|
|
|
|
|
|
|
// TODO: handle confused filters like "in:all stream:foo"
|
2020-07-15 01:29:15 +02:00
|
|
|
ops = filter.operands("in");
|
2017-08-12 17:26:12 +02:00
|
|
|
if (ops.length >= 1) {
|
|
|
|
filter_name = ops[0];
|
2020-07-15 01:29:15 +02:00
|
|
|
if (filter_name === "home") {
|
2022-01-25 11:36:19 +01:00
|
|
|
$filter_li = $(".top_left_all_messages");
|
|
|
|
$filter_li.addClass("active-filter");
|
2017-08-12 17:26:12 +02:00
|
|
|
}
|
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
ops = filter.operands("is");
|
2017-08-12 17:26:12 +02:00
|
|
|
if (ops.length >= 1) {
|
|
|
|
filter_name = ops[0];
|
2020-07-15 01:29:15 +02:00
|
|
|
if (filter_name === "starred") {
|
2022-01-25 11:36:19 +01:00
|
|
|
$filter_li = $(".top_left_starred_messages");
|
|
|
|
$filter_li.addClass("active-filter");
|
2020-07-15 01:29:15 +02:00
|
|
|
} else if (filter_name === "mentioned") {
|
2022-01-25 11:36:19 +01:00
|
|
|
$filter_li = $(".top_left_mentions");
|
|
|
|
$filter_li.addClass("active-filter");
|
2017-08-12 17:26:12 +02:00
|
|
|
}
|
|
|
|
}
|
2021-02-28 00:44:57 +01:00
|
|
|
}
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2021-02-28 00:44:57 +01:00
|
|
|
export function handle_narrow_deactivated() {
|
2017-08-12 17:26:12 +02:00
|
|
|
deselect_top_left_corner_items();
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $filter_li = $(".top_left_all_messages");
|
|
|
|
$filter_li.addClass("active-filter");
|
2021-02-28 00:44:57 +01:00
|
|
|
}
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2021-02-28 00:44:57 +01:00
|
|
|
export function narrow_to_recent_topics() {
|
2020-07-05 12:19:09 +02:00
|
|
|
remove($(".top_left_all_messages"));
|
|
|
|
remove($(".top_left_starred_messages"));
|
|
|
|
remove($(".top_left_mentions"));
|
|
|
|
$(".top_left_recent_topics").addClass("active-filter");
|
2020-11-30 11:07:54 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
resize.resize_stream_filters_container();
|
|
|
|
}, 0);
|
2021-02-28 00:44:57 +01:00
|
|
|
}
|
2023-04-07 20:06:13 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2023-05-02 21:08:15 +02:00
|
|
|
|
|
|
|
export function initialize() {
|
|
|
|
update_scheduled_messages_row();
|
|
|
|
}
|