2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-07-25 02:02:35 +02:00
|
|
|
const _ = require("lodash");
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let actively_scrolling = false;
|
2018-03-08 20:18:36 +01:00
|
|
|
|
2020-06-18 08:29:08 +02:00
|
|
|
// Tracks whether the next scroll that will complete is initiated by
|
|
|
|
// code, not the user, and thus should avoid moving the selected
|
|
|
|
// message.
|
|
|
|
let update_selection_on_next_scroll = true;
|
|
|
|
exports.suppress_selection_update_on_next_scroll = function () {
|
|
|
|
update_selection_on_next_scroll = false;
|
|
|
|
};
|
|
|
|
|
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) {
|
2020-07-15 00:34:28 +02:00
|
|
|
loading.make_indicator($("#loading_older_messages_indicator"), {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();
|
2020-07-15 00:34:28 +02:00
|
|
|
loading.make_indicator($("#loading_newer_messages_indicator"), {abs_positioned: true});
|
2020-05-26 16:27:06 +02:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2020-06-14 12:33:12 +02:00
|
|
|
exports.show_history_limit_notice = function () {
|
|
|
|
$(".top-messages-logo").hide();
|
|
|
|
$(".history-limited-box").show();
|
2020-06-18 21:34:48 +02:00
|
|
|
narrow.hide_empty_narrow_message();
|
2020-06-14 12:33:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.hide_history_limit_notice = function () {
|
|
|
|
$(".top-messages-logo").show();
|
|
|
|
$(".history-limited-box").hide();
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.hide_end_of_results_notice = function () {
|
|
|
|
$(".all-messages-search-caution").hide();
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.show_end_of_results_notice = function () {
|
|
|
|
$(".all-messages-search-caution").show();
|
|
|
|
// Set the link to point to this search with streams:public added.
|
|
|
|
// It's a bit hacky to use the href, but
|
|
|
|
// !filter.includes_full_stream_history() implies streams:public
|
|
|
|
// wasn't already present.
|
2020-06-20 05:48:18 +02:00
|
|
|
const update_hash = hash_util.search_public_streams_notice_url();
|
|
|
|
$(".all-messages-search-caution a.search-shared-history").attr("href", update_hash);
|
2020-06-14 12:33:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.update_top_of_narrow_notices = function (msg_list) {
|
|
|
|
// Assumes that the current state is all notices hidden (i.e. this
|
|
|
|
// will not hide a notice that should not be there)
|
|
|
|
if (msg_list !== current_msg_list) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
if (msg_list.data.fetch_status.has_found_oldest() && current_msg_list !== home_msg_list) {
|
2020-06-14 12:33:12 +02:00
|
|
|
const filter = narrow_state.filter();
|
|
|
|
// Potentially display the notice that lets users know
|
|
|
|
// that not all messages were searched. One could
|
|
|
|
// imagine including `filter.is_search()` in these
|
|
|
|
// conditions, but there's a very legitimate use case
|
|
|
|
// for moderation of searching for all messages sent
|
|
|
|
// by a potential spammer user.
|
2020-07-15 00:34:28 +02:00
|
|
|
if (
|
|
|
|
!filter.contains_only_private_messages() &&
|
2020-06-14 12:33:12 +02:00
|
|
|
!filter.includes_full_stream_history() &&
|
2020-07-15 00:34:28 +02:00
|
|
|
!filter.is_personal_filter()
|
|
|
|
) {
|
2020-06-14 12:33:12 +02:00
|
|
|
exports.show_end_of_results_notice();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg_list.data.fetch_status.history_limited()) {
|
|
|
|
exports.show_history_limit_notice();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.hide_top_of_narrow_notices = function () {
|
|
|
|
exports.hide_end_of_results_notice();
|
|
|
|
exports.hide_history_limit_notice();
|
|
|
|
};
|
|
|
|
|
2018-03-08 20:18:36 +01:00
|
|
|
exports.actively_scrolling = function () {
|
|
|
|
return actively_scrolling;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.scroll_finished = function () {
|
|
|
|
actively_scrolling = false;
|
|
|
|
|
2020-07-04 16:25:41 +02:00
|
|
|
if (!$("#message_feed_container").hasClass("active")) {
|
2018-03-08 20:41:43 +01:00
|
|
|
return;
|
2018-03-08 20:18:36 +01:00
|
|
|
}
|
2018-03-08 20:41:43 +01:00
|
|
|
|
2020-06-18 08:29:08 +02:00
|
|
|
if (update_selection_on_next_scroll) {
|
2018-03-08 20:41:43 +01:00
|
|
|
message_viewport.keep_pointer_in_view();
|
|
|
|
} else {
|
2020-06-18 08:29:08 +02:00
|
|
|
update_selection_on_next_scroll = true;
|
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-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
|
|
|
};
|
|
|
|
|
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 () {
|
2020-07-20 21:26:58 +02:00
|
|
|
message_viewport.message_pane.on(
|
|
|
|
"scroll",
|
2020-07-15 00:34:28 +02:00
|
|
|
_.throttle(() => {
|
|
|
|
unread_ops.process_visible();
|
|
|
|
scroll_finish();
|
|
|
|
}, 50),
|
|
|
|
);
|
2020-06-18 08:37:25 +02:00
|
|
|
|
|
|
|
// Scroll handler that marks messages as read when you scroll past them.
|
2020-07-15 01:29:15 +02:00
|
|
|
$(document).on("message_selected.zulip", (event) => {
|
2020-06-18 08:37:25 +02:00
|
|
|
if (event.id === -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-13 18:29:24 +02:00
|
|
|
if (event.mark_read && event.previously_selected_id !== -1) {
|
2020-06-18 08:37:25 +02:00
|
|
|
// Mark messages between old pointer and new pointer as read
|
|
|
|
let messages;
|
2020-09-13 18:29:24 +02:00
|
|
|
if (event.id < event.previously_selected_id) {
|
|
|
|
messages = event.msg_list.message_range(event.id, event.previously_selected_id);
|
2020-06-18 08:37:25 +02:00
|
|
|
} else {
|
2020-09-13 18:29:24 +02:00
|
|
|
messages = event.msg_list.message_range(event.previously_selected_id, event.id);
|
2020-06-18 08:37:25 +02:00
|
|
|
}
|
|
|
|
if (event.msg_list.can_mark_messages_read()) {
|
2020-07-15 01:29:15 +02:00
|
|
|
unread_ops.notify_server_messages_read(messages, {from: "pointer"});
|
2020-06-18 08:37:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2018-03-08 20:18:36 +01:00
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.message_scroll = exports;
|