2017-08-12 17:26:12 +02:00
|
|
|
exports.update_count_in_dom = function (unread_count_elem, count) {
|
2019-11-02 00:06:25 +01: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();
|
|
|
|
value_span.text('');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
count_span.show();
|
|
|
|
value_span.text(count);
|
|
|
|
};
|
|
|
|
|
2019-01-30 18:24:56 +01:00
|
|
|
exports.update_starred_count = function (count) {
|
2019-11-02 00:06:25 +01: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
|
2019-11-02 00:06:25 +01: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);
|
|
|
|
|
|
|
|
unread_ui.animate_mention_changes(mentioned_li,
|
|
|
|
counts.mentioned_message_count);
|
|
|
|
};
|
|
|
|
|
|
|
|
function deselect_top_left_corner_items() {
|
2019-01-30 18:24:56 +01:00
|
|
|
function remove(elem) {
|
|
|
|
elem.removeClass('active-filter active-sub-filter');
|
2017-08-12 17:26:12 +02:00
|
|
|
}
|
|
|
|
|
2019-01-30 18:24:56 +01:00
|
|
|
remove($('.top_left_all_messages'));
|
|
|
|
remove($('.top_left_private_messages'));
|
|
|
|
remove($('.top_left_starred_messages'));
|
|
|
|
remove($('.top_left_mentions'));
|
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"
|
|
|
|
ops = filter.operands('in');
|
|
|
|
if (ops.length >= 1) {
|
|
|
|
filter_name = ops[0];
|
|
|
|
if (filter_name === 'home') {
|
2019-01-30 18:24:56 +01:00
|
|
|
filter_li = $('.top_left_all_messages');
|
2017-08-12 17:26:12 +02:00
|
|
|
filter_li.addClass('active-filter');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ops = filter.operands('is');
|
|
|
|
if (ops.length >= 1) {
|
|
|
|
filter_name = ops[0];
|
2019-01-30 18:24:56 +01: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');
|
2017-08-12 17:26:12 +02:00
|
|
|
filter_li.addClass('active-filter');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-21 00:04:46 +02:00
|
|
|
if (exports.should_expand_pm_list(filter)) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const op_pm = filter.operands('pm-with');
|
2017-08-12 17:26:12 +02:00
|
|
|
pm_list.expand(op_pm);
|
|
|
|
} else {
|
|
|
|
pm_list.close();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-21 00:04:46 +02:00
|
|
|
exports.should_expand_pm_list = function (filter) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const op_is = filter.operands('is');
|
2018-10-21 00:04:46 +02:00
|
|
|
|
|
|
|
if (op_is.length >= 1 && _.contains(op_is, "private")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const op_pm = filter.operands('pm-with');
|
2018-10-21 00:04:46 +02:00
|
|
|
|
|
|
|
if (op_pm.length !== 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const emails_strings = op_pm[0];
|
|
|
|
const emails = emails_strings.split(',');
|
2018-10-21 00:04:46 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const has_valid_emails = people.is_valid_bulk_emails_for_compose(emails);
|
2018-10-21 00:04:46 +02:00
|
|
|
|
|
|
|
return has_valid_emails;
|
|
|
|
};
|
|
|
|
|
2017-08-12 17:26:12 +02:00
|
|
|
exports.handle_narrow_deactivated = function () {
|
|
|
|
deselect_top_left_corner_items();
|
|
|
|
pm_list.close();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const filter_li = $('.top_left_all_messages');
|
2017-08-12 17:26:12 +02:00
|
|
|
filter_li.addClass('active-filter');
|
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.top_left_corner = exports;
|