mirror of https://github.com/zulip/zulip.git
message_viewport: Extract function to check if it is visible.
We also add a check to see if `message_feed_container` is visible, since it is possible that recent topics could be visible which was not a possibility when this logic was written.
This commit is contained in:
parent
a5b4bd9ddc
commit
0db7fe389e
|
@ -54,7 +54,6 @@ const message_list = mock_esm("../../static/js/message_list");
|
|||
const message_lists = mock_esm("../../static/js/message_lists");
|
||||
const message_viewport = mock_esm("../../static/js/message_viewport");
|
||||
const notifications = mock_esm("../../static/js/notifications");
|
||||
const overlays = mock_esm("../../static/js/overlays");
|
||||
const unread_ui = mock_esm("../../static/js/unread_ui");
|
||||
|
||||
message_lists.current = {};
|
||||
|
@ -90,14 +89,17 @@ run_test("unread_ops", (override) => {
|
|||
},
|
||||
];
|
||||
|
||||
// We don't want recent topics to process message for this test.
|
||||
override(recent_topics, "is_visible", () => false);
|
||||
// Show message_viewport as not visible so that messages will be stored as unread.
|
||||
override(message_viewport, "is_visible_and_focused", () => false);
|
||||
|
||||
// Make our test message appear to be unread, so that
|
||||
// we then need to subsequently process them as read.
|
||||
unread.process_loaded_messages(test_messages);
|
||||
|
||||
// Make our window appear visible.
|
||||
override(notifications, "is_window_focused", () => true);
|
||||
// Make our message_viewport appear visible.
|
||||
override(message_viewport, "is_visible_and_focused", () => true);
|
||||
|
||||
// Make our "test" message appear visible.
|
||||
override(message_viewport, "bottom_message_visible", () => true);
|
||||
|
@ -119,9 +121,6 @@ run_test("unread_ops", (override) => {
|
|||
channel_post_opts = opts;
|
||||
});
|
||||
|
||||
// Let the real code skip over details related to active overlays.
|
||||
override(overlays, "is_active", () => false);
|
||||
|
||||
let can_mark_messages_read;
|
||||
|
||||
// Set up an override to point to the above var, so we can
|
||||
|
|
|
@ -4,6 +4,8 @@ import * as blueslip from "./blueslip";
|
|||
import {media_breakpoints_num} from "./css_variables";
|
||||
import * as message_lists from "./message_lists";
|
||||
import * as message_scroll from "./message_scroll";
|
||||
import * as notifications from "./notifications";
|
||||
import * as overlays from "./overlays";
|
||||
import * as rows from "./rows";
|
||||
import * as util from "./util";
|
||||
|
||||
|
@ -473,3 +475,14 @@ export function initialize() {
|
|||
stop_auto_scrolling();
|
||||
});
|
||||
}
|
||||
|
||||
export function is_visible_and_focused() {
|
||||
if (
|
||||
overlays.is_active() ||
|
||||
!notifications.is_window_focused() ||
|
||||
!$("#message_feed_container").is(":visible")
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import * as message_lists from "./message_lists";
|
|||
import * as message_store from "./message_store";
|
||||
import * as message_viewport from "./message_viewport";
|
||||
import * as notifications from "./notifications";
|
||||
import * as overlays from "./overlays";
|
||||
import * as recent_topics from "./recent_topics";
|
||||
import * as reload from "./reload";
|
||||
import * as unread from "./unread";
|
||||
|
@ -104,11 +103,8 @@ export function notify_server_message_read(message, options) {
|
|||
// If we ever materially change the algorithm for this function, we
|
||||
// may need to update notifications.received_messages as well.
|
||||
export function process_visible() {
|
||||
if (overlays.is_active() || !notifications.is_window_focused()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
message_viewport.is_visible_and_focused() &&
|
||||
message_viewport.bottom_message_visible() &&
|
||||
message_lists.current.can_mark_messages_read()
|
||||
) {
|
||||
|
|
Loading…
Reference in New Issue