2019-11-02 00:06:25 +01:00
|
|
|
let actively_scrolling = false;
|
2018-03-08 20:18:36 +01:00
|
|
|
|
2020-05-24 15:27:58 +02:00
|
|
|
let loading_older_messages_indicator_showing = false;
|
2020-05-26 16:27:06 +02:00
|
|
|
let loading_newer_messages_indicator_showing = false;
|
2018-03-09 14:27:42 +01:00
|
|
|
exports.show_loading_older = function () {
|
2020-05-24 15:27:58 +02:00
|
|
|
if (!loading_older_messages_indicator_showing) {
|
|
|
|
loading.make_indicator($('#loading_older_messages_indicator'),
|
2018-05-06 21:43:17 +02:00
|
|
|
{abs_positioned: true});
|
2020-05-24 15:27:58 +02:00
|
|
|
loading_older_messages_indicator_showing = true;
|
2018-03-08 20:18:36 +01:00
|
|
|
floating_recipient_bar.hide();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-09 14:27:42 +01:00
|
|
|
exports.hide_loading_older = function () {
|
2020-05-24 15:27:58 +02:00
|
|
|
if (loading_older_messages_indicator_showing) {
|
|
|
|
loading.destroy_indicator($("#loading_older_messages_indicator"));
|
|
|
|
loading_older_messages_indicator_showing = false;
|
2018-03-08 20:18:36 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-05-26 16:27:06 +02:00
|
|
|
exports.show_loading_newer = function () {
|
|
|
|
if (!loading_newer_messages_indicator_showing) {
|
|
|
|
$(".bottom-messages-logo").show();
|
|
|
|
loading.make_indicator($('#loading_newer_messages_indicator'),
|
|
|
|
{abs_positioned: true});
|
|
|
|
loading_newer_messages_indicator_showing = true;
|
|
|
|
floating_recipient_bar.hide();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.hide_loading_newer = function () {
|
|
|
|
if (loading_newer_messages_indicator_showing) {
|
|
|
|
$(".bottom-messages-logo").hide();
|
|
|
|
loading.destroy_indicator($("#loading_newer_messages_indicator"));
|
|
|
|
loading_newer_messages_indicator_showing = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-09 22:12:38 +01:00
|
|
|
exports.hide_indicators = function () {
|
|
|
|
exports.hide_loading_older();
|
2020-05-26 16:27:06 +02:00
|
|
|
exports.hide_loading_newer();
|
2018-03-09 22:12:38 +01:00
|
|
|
};
|
|
|
|
|
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 {
|
2018-08-04 08:39:30 +02:00
|
|
|
pointer.set_suppress_scroll_pointer_update(false);
|
2018-03-08 20:41:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2020-05-26 16:27:06 +02:00
|
|
|
show_loading: exports.show_loading_newer,
|
|
|
|
hide_loading: exports.hide_loading_newer,
|
2018-03-11 20:19:30 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let scroll_timer;
|
2018-03-08 20:18:36 +01:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.message_scroll = exports;
|