2016-06-10 19:22:24 +02:00
|
|
|
// This file is being eliminated as part of the general purge of
|
|
|
|
// global variables from Zulip (everything is being moved into
|
|
|
|
// modules). Please don't add things here.
|
|
|
|
|
2016-04-20 22:37:26 +02:00
|
|
|
var home_msg_list = new message_list.MessageList('zhome',
|
2014-02-03 22:48:25 +01:00
|
|
|
new Filter([{operator: "in", operand: "home"}]), {muting_enabled: true}
|
2013-07-25 22:08:16 +02:00
|
|
|
);
|
2013-02-22 20:48:31 +01:00
|
|
|
var current_msg_list = home_msg_list;
|
2013-09-06 00:19:15 +02:00
|
|
|
|
2013-03-04 23:44:07 +01:00
|
|
|
var queued_mark_as_read = [];
|
|
|
|
var queued_flag_timer;
|
|
|
|
|
2013-08-08 20:24:25 +02:00
|
|
|
function consider_bankruptcy() {
|
2013-08-19 19:02:52 +02:00
|
|
|
// 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.
|
|
|
|
|
2013-08-08 20:24:25 +02:00
|
|
|
if (!page_params.furthest_read_time) {
|
|
|
|
// We've never read a message.
|
2014-01-31 17:44:21 +01:00
|
|
|
unread.enable();
|
2013-08-08 20:24:25 +02:00
|
|
|
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');
|
2013-08-19 19:02:52 +02:00
|
|
|
} else {
|
2014-01-31 17:44:21 +01:00
|
|
|
unread.enable();
|
2013-08-08 20:24:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-31 23:13:22 +01:00
|
|
|
// 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) {
|
|
|
|
activity.process_loaded_messages(messages);
|
|
|
|
activity.update_huddles();
|
|
|
|
unread.process_loaded_messages(messages);
|
|
|
|
unread.update_unread_counts();
|
2014-03-13 19:03:31 +01:00
|
|
|
resize.resize_page_components();
|
2014-01-31 23:13:22 +01:00
|
|
|
}
|
|
|
|
|
2013-09-06 00:18:29 +02:00
|
|
|
function main() {
|
2013-08-02 23:38:26 +02:00
|
|
|
activity.set_user_statuses(page_params.initial_presences,
|
|
|
|
page_params.initial_servertime);
|
|
|
|
|
2016-04-12 17:38:47 +02:00
|
|
|
pointer.server_furthest_read = page_params.initial_pointer;
|
2013-08-13 22:52:56 +02:00
|
|
|
if (page_params.orig_initial_pointer !== undefined &&
|
2016-04-12 17:38:47 +02:00
|
|
|
page_params.orig_initial_pointer > pointer.server_furthest_read) {
|
|
|
|
pointer.server_furthest_read = page_params.orig_initial_pointer;
|
2013-08-13 22:52:56 +02:00
|
|
|
}
|
2016-04-12 17:38:47 +02:00
|
|
|
pointer.furthest_read = pointer.server_furthest_read;
|
2013-08-02 23:38:26 +02:00
|
|
|
|
2013-08-08 20:24:25 +02:00
|
|
|
// Before trying to load messages: is this user way behind?
|
|
|
|
consider_bankruptcy();
|
|
|
|
|
2013-08-02 23:38:26 +02:00
|
|
|
// We only send pointer updates when the user has been idle for a
|
|
|
|
// short while to avoid hammering the server
|
|
|
|
$(document).idle({idle: 1000,
|
2016-04-12 17:38:47 +02:00
|
|
|
onIdle: pointer.send_pointer_update,
|
2013-08-02 23:38:26 +02:00
|
|
|
keepTracking: true});
|
|
|
|
|
|
|
|
$(document).on('message_selected.zulip', function (event) {
|
2013-12-13 20:20:28 +01:00
|
|
|
// Only advance the pointer when not narrowed
|
2013-12-18 19:06:55 +01:00
|
|
|
if (event.id === -1) {
|
|
|
|
return;
|
|
|
|
}
|
2013-12-19 17:03:08 +01:00
|
|
|
// Additionally, don't advance the pointer server-side
|
|
|
|
// if the selected message is local-only
|
2013-12-13 20:20:28 +01:00
|
|
|
if (event.msg_list === home_msg_list && page_params.narrow_stream === undefined) {
|
2016-04-12 17:38:47 +02:00
|
|
|
if (event.id > pointer.furthest_read &&
|
2013-12-19 17:03:08 +01:00
|
|
|
home_msg_list.get(event.id).local_id === undefined) {
|
2016-04-12 17:38:47 +02:00
|
|
|
pointer.furthest_read = event.id;
|
2013-11-26 19:06:21 +01:00
|
|
|
}
|
2013-08-02 23:38:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (event.mark_read && event.previously_selected !== -1) {
|
|
|
|
// Mark messages between old pointer and new pointer as read
|
|
|
|
var messages;
|
|
|
|
if (event.id < event.previously_selected) {
|
2014-01-31 22:06:07 +01:00
|
|
|
messages = event.msg_list.message_range(event.id, event.previously_selected);
|
2013-08-02 23:38:26 +02:00
|
|
|
} else {
|
2014-01-31 22:06:07 +01:00
|
|
|
messages = event.msg_list.message_range(event.previously_selected, event.id);
|
2013-08-02 23:38:26 +02:00
|
|
|
}
|
2014-01-31 17:44:21 +01:00
|
|
|
unread.mark_messages_as_read(messages, {from: 'pointer'});
|
2013-08-02 23:38:26 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$(function () {
|
|
|
|
main();
|
|
|
|
});
|