2016-11-14 17:14:59 +01:00
|
|
|
var unread_ui = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
var last_private_message_count = 0;
|
|
|
|
var last_mention_count = 0;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.animate_private_message_changes = function (li, new_private_message_count) {
|
|
|
|
if (new_private_message_count > last_private_message_count) {
|
|
|
|
do_new_messages_animation(li);
|
|
|
|
}
|
|
|
|
last_private_message_count = new_private_message_count;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.animate_mention_changes = function (li, new_mention_count) {
|
|
|
|
if (new_mention_count > last_mention_count) {
|
|
|
|
do_new_messages_animation(li);
|
|
|
|
}
|
|
|
|
last_mention_count = new_mention_count;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.set_count_toggle_button = function (elem, count) {
|
|
|
|
if (count === 0) {
|
|
|
|
if (elem.is(':animated')) {
|
|
|
|
return elem.stop(true, true).hide();
|
|
|
|
}
|
|
|
|
return elem.hide(500);
|
|
|
|
} else if ((count > 0) && (count < 1000)) {
|
|
|
|
elem.show(500);
|
|
|
|
return elem.text(count);
|
|
|
|
}
|
2016-12-02 21:34:35 +01:00
|
|
|
elem.show(500);
|
|
|
|
return elem.text("1k+");
|
2016-11-14 17:14:59 +01:00
|
|
|
};
|
|
|
|
|
2017-02-11 09:55:18 +01:00
|
|
|
exports.update_unread_counts = function () {
|
|
|
|
if (unread.suppress_unread_counts) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pure computation:
|
|
|
|
var res = unread.get_counts();
|
|
|
|
|
|
|
|
// Side effects from here down:
|
|
|
|
// This updates some DOM elements directly, so try to
|
|
|
|
// avoid excessive calls to this.
|
|
|
|
activity.update_dom_with_unread_counts(res);
|
2017-08-12 17:26:12 +02:00
|
|
|
top_left_corner.update_dom_with_unread_counts(res);
|
2017-02-11 09:55:18 +01:00
|
|
|
stream_list.update_dom_with_unread_counts(res);
|
|
|
|
pm_list.update_dom_with_unread_counts(res);
|
|
|
|
notifications.update_title_count(res.home_unread_messages);
|
|
|
|
notifications.update_pm_count(res.private_message_count);
|
2017-08-12 17:26:12 +02:00
|
|
|
|
|
|
|
exports.set_count_toggle_button($("#streamlist-toggle-unreadcount"),
|
2018-05-06 21:43:17 +02:00
|
|
|
res.home_unread_messages);
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2017-02-11 09:55:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.enable = function enable() {
|
|
|
|
unread.suppress_unread_counts = false;
|
|
|
|
exports.update_unread_counts();
|
|
|
|
};
|
|
|
|
|
2017-02-11 08:59:19 +01:00
|
|
|
function consider_bankruptcy() {
|
|
|
|
// Until we've handled possibly declaring bankruptcy, don't show
|
|
|
|
// unread counts since they only consider messages that are loaded
|
|
|
|
// client side and may be different from the numbers reported by
|
|
|
|
// the server.
|
|
|
|
|
|
|
|
if (!page_params.furthest_read_time) {
|
|
|
|
// We've never read a message.
|
2017-02-11 09:55:18 +01:00
|
|
|
exports.enable();
|
2017-02-11 08:59:19 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var now = new XDate(true).getTime() / 1000;
|
2017-08-09 01:28:58 +02:00
|
|
|
if ((page_params.unread_msgs.count > 500) &&
|
2018-03-22 22:18:23 +01:00
|
|
|
(now - page_params.furthest_read_time > 60 * 60 * 24 * 2)) { // 2 days.
|
|
|
|
var rendered_modal = templates.render('bankruptcy_modal', {
|
|
|
|
unread_count: page_params.unread_msgs.count});
|
|
|
|
$('#bankruptcy-unread-count').html(rendered_modal);
|
2017-02-11 08:59:19 +01:00
|
|
|
$('#bankruptcy').modal('show');
|
|
|
|
} else {
|
2017-02-11 09:55:18 +01:00
|
|
|
exports.enable();
|
2017-02-11 08:59:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-30 18:07:49 +02:00
|
|
|
exports.initialize = function () {
|
2017-03-23 04:48:37 +01:00
|
|
|
// No matter how the bankruptcy modal is closed, show unread counts after.
|
|
|
|
$("#bankruptcy").on("hide", function () {
|
2017-03-23 04:46:31 +01:00
|
|
|
unread_ui.enable();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#yes-bankrupt').click(function () {
|
|
|
|
pointer.fast_forward_pointer();
|
|
|
|
$("#yes-bankrupt").hide();
|
|
|
|
$("#no-bankrupt").hide();
|
|
|
|
$(this).after($("<div>").addClass("alert alert-info settings_committed")
|
2018-05-06 21:43:17 +02:00
|
|
|
.text(i18n.t("Bringing you to your latest messages…")));
|
2017-03-23 04:46:31 +01:00
|
|
|
});
|
|
|
|
|
2017-02-11 08:59:19 +01:00
|
|
|
consider_bankruptcy();
|
2017-06-23 21:55:56 +02:00
|
|
|
};
|
2016-11-14 17:14:59 +01:00
|
|
|
|
|
|
|
return exports;
|
|
|
|
}());
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = unread_ui;
|
|
|
|
}
|