mirror of https://github.com/zulip/zulip.git
Only suggest declaring bankruptcy once.
Use information from the server to figure out if we should prompt for bankruptcy, rather than trying repeatedly inside load_more. (imported from commit ccb8cb1ce482b8bf3d343e7324fef7981880282d)
This commit is contained in:
parent
1a0cc2b421
commit
29a64b6c59
|
@ -1205,6 +1205,22 @@ function fast_forward_pointer() {
|
|||
});
|
||||
}
|
||||
|
||||
function consider_bankruptcy() {
|
||||
if (!page_params.furthest_read_time) {
|
||||
// We've never read a message.
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
_.each(page_params.people_list, function (person) {
|
||||
people_dict.set(person.email, person);
|
||||
|
@ -1224,6 +1240,9 @@ function main() {
|
|||
furthest_read = page_params.initial_pointer;
|
||||
server_furthest_read = page_params.initial_pointer;
|
||||
|
||||
// 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,
|
||||
|
@ -1262,22 +1281,6 @@ function main() {
|
|||
|
||||
// get the initial message list
|
||||
function load_more(messages) {
|
||||
|
||||
// Before trying to load anything: is this user way behind?
|
||||
var last_read_message = home_msg_list.get(home_msg_list.closest_id(page_params.initial_pointer));
|
||||
if (last_read_message !== undefined) {
|
||||
var now = new XDate().getTime() / 1000;
|
||||
var num_unread = unread.get_counts().home_unread_messages;
|
||||
|
||||
if ((num_unread > 500) &&
|
||||
(now - last_read_message.timestamp > 60 * 60 * 24 * 2)) { // 2 days.
|
||||
var unread_info = templates.render('bankruptcy_modal',
|
||||
{"unread_count": num_unread});
|
||||
$('#bankruptcy-unread-count').html(unread_info);
|
||||
$('#bankruptcy').modal('show');
|
||||
}
|
||||
}
|
||||
|
||||
// If we received the initially selected message, select it on the client side,
|
||||
// but not if the user has already selected another one during load.
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue