Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
stream_events: Use update_unread_counts API.
Tim Abbott5a8354341808
diff --git a/frontend_tests/node_tests/stream_events.js b/frontend_tests/node_tests/stream_events.jsindex 6fced6d3357..b156dd4a28e 100644--- a/frontend_tests/node_tests/stream_events.js+++ b/frontend_tests/node_tests/stream_events.js@@ -11,21 +11,14 @@ const $ = require("../zjsunit/zjquery");const noop = () => {};const color_data = mock_esm("../../static/js/color_data");-const message_util = mock_esm("../../static/js/message_util");const stream_color = mock_esm("../../static/js/stream_color");const stream_list = mock_esm("../../static/js/stream_list");const stream_muting = mock_esm("../../static/js/stream_muting");const stream_settings_ui = mock_esm("../../static/js/stream_settings_ui", {update_settings_for_subscribed: noop,});+const unread_ui = mock_esm("../../static/js/unread_ui");-mock_esm("../../static/js/all_messages_data", {- all_messages_data: {- all_messages() {- return ["msg"];- },- },-});const message_lists = mock_esm("../../static/js/message_lists", {current: {},});@@ -278,16 +271,14 @@ test("marked_subscribed (normal)", ({override}) => {narrow_to_frontend();- let args;let list_updated = false;const stream_list_stub = make_stub();const message_view_header_stub = make_stub();- const message_util_stub = make_stub();override(stream_list, "add_sidebar_row", stream_list_stub.f);override(stream_list, "update_subscribe_to_more_streams_link", noop);- override(message_util, "do_unread_count_updates", message_util_stub.f);+ override(unread_ui, "update_unread_counts", noop);override(message_view_header,"maybe_rerender_title_area_for_stream",@@ -299,10 +290,7 @@ test("marked_subscribed (normal)", ({override}) => {stream_events.mark_subscribed(sub, [], "blue");- args = message_util_stub.get_args("messages");- assert.deepEqual(args.messages, ["msg"]);-- args = stream_list_stub.get_args("sub");+ const args = stream_list_stub.get_args("sub");assert.equal(args.sub.stream_id, sub.stream_id);assert.equal(message_view_header_stub.num_calls, 1);@@ -313,9 +301,9 @@ test("marked_subscribed (normal)", ({override}) => {});test("marked_subscribed (color)", ({override}) => {- override(message_util, "do_unread_count_updates", noop);override(stream_list, "add_sidebar_row", noop);override(stream_list, "update_subscribe_to_more_streams_link", noop);+ override(unread_ui, "update_unread_counts", noop);const sub = {subscribed: false,@@ -349,9 +337,9 @@ test("marked_subscribed (emails)", ({override}) => {// Test assigning subscriber emails// narrow state is undefined- override(message_util, "do_unread_count_updates", noop);override(stream_list, "add_sidebar_row", noop);override(stream_list, "update_subscribe_to_more_streams_link", noop);+ override(unread_ui, "update_unread_counts", noop);const subs_stub = make_stub();override(stream_settings_ui, "update_settings_for_subscribed", subs_stub.f);@@ -378,6 +366,7 @@ test("mark_unsubscribed (update_settings_for_unsubscribed)", ({override}) => {override(stream_settings_ui, "update_settings_for_unsubscribed", stub.f);override(stream_list, "remove_sidebar_row", noop);override(stream_list, "update_subscribe_to_more_streams_link", noop);+ override(unread_ui, "update_unread_counts", noop);stream_events.mark_unsubscribed(sub);const args = stub.get_args("sub");@@ -400,6 +389,7 @@ test("mark_unsubscribed (render_title_area)", ({override}) => {override(message_lists.current, "update_trailing_bookend", noop);override(stream_list, "remove_sidebar_row", noop);override(stream_list, "update_subscribe_to_more_streams_link", noop);+ override(unread_ui, "update_unread_counts", noop);stream_events.mark_unsubscribed(sub);diff --git a/static/js/stream_events.js b/static/js/stream_events.jsindex 6d0df553908..60817207f12 100644--- a/static/js/stream_events.js+++ b/static/js/stream_events.js@@ -1,10 +1,8 @@import $ from "jquery";-import {all_messages_data} from "./all_messages_data";import * as blueslip from "./blueslip";import * as color_data from "./color_data";import * as message_lists from "./message_lists";-import * as message_util from "./message_util";import * as message_view_header from "./message_view_header";import * as narrow_state from "./narrow_state";import * as overlays from "./overlays";@@ -17,6 +15,7 @@ import * as stream_list from "./stream_list";import * as stream_muting from "./stream_muting";import * as stream_settings_ui from "./stream_settings_ui";import * as sub_store from "./sub_store";+import * as unread_ui from "./unread_ui";// In theory, this function should apply the account-level defaults,// however, they are only called after a manual override, so@@ -140,9 +139,9 @@ export function mark_subscribed(sub, subscribers, color) {message_lists.current.update_trailing_bookend();}- // Update unread counts as the new stream in sidebar might- // need its unread counts re-calculated- message_util.do_unread_count_updates(all_messages_data.all_messages());+ // The new stream in sidebar might need its unread counts+ // re-calculated.+ unread_ui.update_unread_counts();stream_list.add_sidebar_row(sub);stream_list.update_subscribe_to_more_streams_link();@@ -168,6 +167,10 @@ export function mark_unsubscribed(sub) {message_lists.current.update_trailing_bookend();}+ // Unread messages in the now-unsubscribe stream need to be+ // removed from global count totals.+ unread_ui.update_unread_counts();+stream_list.remove_sidebar_row(sub.stream_id);stream_list.update_subscribe_to_more_streams_link();}