2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2021-02-28 00:44:57 +01:00
|
|
|
import * as pm_list from "./pm_list";
|
2021-02-28 00:57:20 +01:00
|
|
|
import * as resize from "./resize";
|
2021-04-09 09:18:43 +02:00
|
|
|
import * as ui_util from "./ui_util";
|
2021-04-09 09:20:15 +02:00
|
|
|
import * as unread_ui from "./unread_ui";
|
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
|
|
|
|
2021-02-28 00:44:57 +01:00
|
|
|
export function update_dom_with_unread_counts(counts) {
|
2017-08-12 17:26:12 +02:00
|
|
|
// Note that "Private messages" counts are handled in pm_list.js.
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
unread_ui.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
|
|
|
|
2020-07-05 12:19:09 +02:00
|
|
|
function deselect_top_left_corner_items() {
|
2020-07-15 01:29:15 +02:00
|
|
|
remove($(".top_left_all_messages"));
|
|
|
|
remove($(".top_left_private_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_private_messages"));
|
|
|
|
remove($(".top_left_starred_messages"));
|
|
|
|
remove($(".top_left_mentions"));
|
|
|
|
$(".top_left_recent_topics").addClass("active-filter");
|
|
|
|
pm_list.close();
|
2020-11-30 11:07:54 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
resize.resize_stream_filters_container();
|
|
|
|
}, 0);
|
2021-02-28 00:44:57 +01:00
|
|
|
}
|