Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
message_viewport: Extract function to check if it is visible.
Aman Agrawal0db7fe389e3b
diff --git a/frontend_tests/node_tests/example7.js b/frontend_tests/node_tests/example7.jsindex 4c510660f48..0f26b1bfed9 100644--- a/frontend_tests/node_tests/example7.js+++ b/frontend_tests/node_tests/example7.js@@ -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 candiff --git a/static/js/message_viewport.js b/static/js/message_viewport.jsindex 8707c208cf2..c2b539b9539 100644--- a/static/js/message_viewport.js+++ b/static/js/message_viewport.js@@ -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;+}diff --git a/static/js/unread_ops.js b/static/js/unread_ops.jsindex e973849f3d2..67a09de3319 100644--- a/static/js/unread_ops.js+++ b/static/js/unread_ops.js@@ -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()) {