2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2021-02-28 00:44:57 +01:00
|
|
|
import * as people from "./people";
|
|
|
|
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) {
|
2020-07-15 01:29:15 +02:00
|
|
|
const starred_li = $(".top_left_starred_messages");
|
2021-04-09 09:18:43 +02:00
|
|
|
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
|
2020-07-15 01:29:15 +02:00
|
|
|
const mentioned_li = $(".top_left_mentions");
|
|
|
|
const home_li = $(".top_left_all_messages");
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2021-04-09 09:18:43 +02: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
|
|
|
|
2020-07-15 00:34:28 +02: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
|
|
|
|
2020-07-05 12:19:09 +02:00
|
|
|
function remove(elem) {
|
|
|
|
elem.removeClass("active-filter active-sub-filter");
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2020-02-02 12:17:28 +01:00
|
|
|
function should_expand_pm_list(filter) {
|
2020-07-15 01:29:15 +02:00
|
|
|
const op_is = filter.operands("is");
|
2020-02-02 12:17:28 +01:00
|
|
|
|
|
|
|
if (op_is.length >= 1 && op_is.includes("private")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const op_pm = filter.operands("pm-with");
|
2020-02-02 12:17:28 +01:00
|
|
|
|
|
|
|
if (op_pm.length !== 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const emails_strings = op_pm[0];
|
2020-07-15 01:29:15 +02:00
|
|
|
const emails = emails_strings.split(",");
|
2020-02-02 12:17:28 +01:00
|
|
|
|
|
|
|
const has_valid_emails = people.is_valid_bulk_emails_for_compose(emails);
|
|
|
|
|
|
|
|
return has_valid_emails;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
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") {
|
|
|
|
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") {
|
|
|
|
filter_li = $(".top_left_starred_messages");
|
|
|
|
filter_li.addClass("active-filter");
|
|
|
|
} else if (filter_name === "mentioned") {
|
|
|
|
filter_li = $(".top_left_mentions");
|
|
|
|
filter_li.addClass("active-filter");
|
2017-08-12 17:26:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-02 12:17:28 +01:00
|
|
|
if (should_expand_pm_list(filter)) {
|
2020-01-06 15:00:11 +01:00
|
|
|
pm_list.expand();
|
2017-08-12 17:26:12 +02:00
|
|
|
} else {
|
|
|
|
pm_list.close();
|
|
|
|
}
|
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();
|
|
|
|
pm_list.close();
|
|
|
|
|
2020-07-15 01:29:15 +02: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
|
|
|
}
|