unread: Move consider_bankruptcy into unread module.

This commit is contained in:
Tim Abbott
2016-11-05 10:49:34 -07:00
parent be3e9e3a05
commit d76f9b09a3
3 changed files with 30 additions and 27 deletions

View File

@@ -562,6 +562,7 @@ $(function () {
gear_menu.initialize();
hashchange.initialize();
invite.initialize();
unread.initialize();
activity.initialize();
emoji.initialize();
});

View File

@@ -301,6 +301,35 @@ exports.mark_topic_as_read = function mark_topic_as_read(stream, topic, cont) {
success: cont});
};
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.
unread.enable();
return;
}
var now = new XDate(true).getTime() / 1000;
if ((page_params.unread_count > 500) &&
(now - page_params.furthest_read_time > 60 * 60 * 24 * 2)) { // 2 days.
var unread_info = templates.render('bankruptcy_modal',
{"unread_count": page_params.unread_count});
$('#bankruptcy-unread-count').html(unread_info);
$('#bankruptcy').modal('show');
} else {
unread.enable();
}
}
exports.initialize = function initialize() {
consider_bankruptcy();
};
return exports;
}());
if (typeof module !== 'undefined') {

View File

@@ -7,30 +7,6 @@ var home_msg_list = new message_list.MessageList('zhome',
);
var current_msg_list = home_msg_list;
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.
unread.enable();
return;
}
var now = new XDate(true).getTime() / 1000;
if ((page_params.unread_count > 500) &&
(now - page_params.furthest_read_time > 60 * 60 * 24 * 2)) { // 2 days.
var unread_info = templates.render('bankruptcy_modal',
{"unread_count": page_params.unread_count});
$('#bankruptcy-unread-count').html(unread_info);
$('#bankruptcy').modal('show');
} else {
unread.enable();
}
}
// This is annoying to move to unread.js because the natural name
// would be unread.process_loaded_messages, which this calls
function process_loaded_for_unread(messages) {
@@ -52,9 +28,6 @@ function main() {
}
pointer.furthest_read = pointer.server_furthest_read;
// Before trying to load messages: is this user way behind?
consider_bankruptcy();
// We only send pointer updates when the user has been idle for a
// short while to avoid hammering the server
$(document).idle({idle: 1000,