2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-08-20 21:24:06 +02:00
|
|
|
const people = require("./people");
|
|
|
|
|
2017-08-12 17:26:12 +02:00
|
|
|
exports.update_count_in_dom = function (unread_count_elem, count) {
|
2020-07-15 01:29:15 +02:00
|
|
|
const count_span = unread_count_elem.find(".count");
|
|
|
|
const value_span = count_span.find(".value");
|
2017-08-12 17:26:12 +02:00
|
|
|
|
|
|
|
if (count === 0) {
|
|
|
|
count_span.hide();
|
2020-07-15 01:29:15 +02:00
|
|
|
value_span.text("");
|
2017-08-12 17:26:12 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
count_span.show();
|
|
|
|
value_span.text(count);
|
|
|
|
};
|
|
|
|
|
2019-01-30 18:24:56 +01:00
|
|
|
exports.update_starred_count = function (count) {
|
2020-07-15 01:29:15 +02:00
|
|
|
const starred_li = $(".top_left_starred_messages");
|
2019-01-30 18:24:56 +01:00
|
|
|
exports.update_count_in_dom(starred_li, count);
|
|
|
|
};
|
2017-08-12 17:26:12 +02:00
|
|
|
|
|
|
|
exports.update_dom_with_unread_counts = function (counts) {
|
|
|
|
// 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
|
|
|
|
|
|
|
exports.update_count_in_dom(mentioned_li, counts.mentioned_message_count);
|
|
|
|
exports.update_count_in_dom(home_li, counts.home_unread_messages);
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
unread_ui.animate_mention_changes(mentioned_li, counts.mentioned_message_count);
|
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;
|
|
|
|
}
|
|
|
|
|
2017-08-12 17:26:12 +02:00
|
|
|
exports.handle_narrow_activated = function (filter) {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.handle_narrow_deactivated = function () {
|
|
|
|
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");
|
2017-08-12 17:26:12 +02:00
|
|
|
};
|
|
|
|
|
2020-07-05 12:19:09 +02:00
|
|
|
exports.narrow_to_recent_topics = function () {
|
|
|
|
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);
|
2020-07-05 12:19:09 +02:00
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.top_left_corner = exports;
|