2018-03-08 20:18:36 +01:00
|
|
|
var message_scroll = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
var actively_scrolling = false;
|
|
|
|
|
|
|
|
var loading_more_messages_indicator_showing = false;
|
2018-03-09 14:27:42 +01:00
|
|
|
exports.show_loading_older = function () {
|
2018-03-08 20:18:36 +01:00
|
|
|
if (! loading_more_messages_indicator_showing) {
|
|
|
|
loading.make_indicator($('#loading_more_messages_indicator'),
|
2018-05-06 21:43:17 +02:00
|
|
|
{abs_positioned: true});
|
2018-03-08 20:18:36 +01:00
|
|
|
loading_more_messages_indicator_showing = true;
|
|
|
|
floating_recipient_bar.hide();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-09 14:27:42 +01:00
|
|
|
exports.hide_loading_older = function () {
|
2018-03-08 20:18:36 +01:00
|
|
|
if (loading_more_messages_indicator_showing) {
|
|
|
|
loading.destroy_indicator($("#loading_more_messages_indicator"));
|
|
|
|
loading_more_messages_indicator_showing = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-09 22:12:38 +01:00
|
|
|
exports.hide_indicators = function () {
|
|
|
|
exports.hide_loading_older();
|
|
|
|
};
|
|
|
|
|
2018-03-08 20:18:36 +01:00
|
|
|
exports.actively_scrolling = function () {
|
|
|
|
return actively_scrolling;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.scroll_finished = function () {
|
|
|
|
actively_scrolling = false;
|
|
|
|
|
2018-03-08 20:41:43 +01:00
|
|
|
if (!$('#home').hasClass('active')) {
|
|
|
|
return;
|
2018-03-08 20:18:36 +01:00
|
|
|
}
|
2018-03-08 20:41:43 +01:00
|
|
|
|
|
|
|
if (!pointer.suppress_scroll_pointer_update) {
|
|
|
|
message_viewport.keep_pointer_in_view();
|
|
|
|
} else {
|
|
|
|
pointer.suppress_scroll_pointer_update = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
floating_recipient_bar.update();
|
|
|
|
|
2018-03-08 20:47:52 +01:00
|
|
|
if (message_viewport.at_top()) {
|
2018-03-09 02:23:49 +01:00
|
|
|
message_fetch.maybe_load_older_messages({
|
2018-03-08 20:41:43 +01:00
|
|
|
msg_list: current_msg_list,
|
2018-03-09 14:27:42 +01:00
|
|
|
show_loading: exports.show_loading_older,
|
|
|
|
hide_loading: exports.hide_loading_older,
|
2018-03-08 20:41:43 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-03-11 20:19:30 +01:00
|
|
|
if (message_viewport.at_bottom()) {
|
|
|
|
message_fetch.maybe_load_newer_messages({
|
|
|
|
msg_list: current_msg_list,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-03-08 20:41:43 +01:00
|
|
|
// When the window scrolls, it may cause some messages to
|
|
|
|
// enter the screen and become read. Calling
|
|
|
|
// unread_ops.process_visible will update necessary
|
|
|
|
// data structures and DOM elements.
|
|
|
|
setTimeout(unread_ops.process_visible, 0);
|
2018-03-08 20:18:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
var scroll_timer;
|
|
|
|
function scroll_finish() {
|
|
|
|
actively_scrolling = true;
|
|
|
|
clearTimeout(scroll_timer);
|
|
|
|
scroll_timer = setTimeout(exports.scroll_finished, 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.initialize = function () {
|
2018-05-16 20:42:42 +02:00
|
|
|
message_viewport.message_pane.scroll(_.throttle(function () {
|
2018-03-08 20:18:36 +01:00
|
|
|
unread_ops.process_visible();
|
|
|
|
scroll_finish();
|
2018-05-16 20:42:42 +02:00
|
|
|
}, 50));
|
2018-03-08 20:18:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
|
|
|
|
}());
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = message_scroll;
|
|
|
|
}
|