diff --git a/web/src/user_topics.ts b/web/src/user_topics.ts index 10298b9a0b..5a781ed3ac 100644 --- a/web/src/user_topics.ts +++ b/web/src/user_topics.ts @@ -19,7 +19,7 @@ type ServerUserTopic = z.infer; export type UserTopic = { stream_id: number; - stream: string | undefined; + stream: string; topic: string; date_updated: number; date_updated_str: string; @@ -37,6 +37,7 @@ const user_topic_schema = z.object({ const all_user_topics = new Map< number, FoldDict<{ + stream_name: string; date_updated: number; visibility_policy: number; }> @@ -51,6 +52,7 @@ export const all_visibility_policies = { export function update_user_topics( stream_id: number, + stream_name: string, topic: string, visibility_policy: number, date_updated: number, @@ -64,7 +66,7 @@ export function update_user_topics( all_user_topics.set(stream_id, sub_dict); } const time = get_time_from_date_muted(date_updated); - sub_dict.set(topic, {date_updated: time, visibility_policy}); + sub_dict.set(topic, {date_updated: time, visibility_policy, stream_name}); } } @@ -95,14 +97,14 @@ export function is_topic_unmuted_or_followed(stream_id: number, topic: string): export function get_user_topics_for_visibility_policy(visibility_policy: number): UserTopic[] { const topics: UserTopic[] = []; for (const [stream_id, sub_dict] of all_user_topics) { - const stream = sub_store.maybe_get_stream_name(stream_id); for (const topic of sub_dict.keys()) { if (sub_dict.get(topic)!.visibility_policy === visibility_policy) { - const date_updated = sub_dict.get(topic)!.date_updated; + const topic_dict = sub_dict.get(topic)!; + const date_updated = topic_dict.date_updated; const date_updated_str = timerender.render_now(new Date(date_updated)).time_str; topics.push({ stream_id, - stream, + stream: topic_dict.stream_name, topic, date_updated, date_updated_str, @@ -210,7 +212,7 @@ export function set_user_topic(user_topic: ServerUserTopic): void { return; } - update_user_topics(stream_id, topic, user_topic.visibility_policy, date_updated); + update_user_topics(stream_id, stream_name, topic, user_topic.visibility_policy, date_updated); } export function set_user_topics(user_topics: ServerUserTopic[]): void { diff --git a/web/tests/message_list_data.test.js b/web/tests/message_list_data.test.js index 0f60eacaeb..9a4bfac4eb 100644 --- a/web/tests/message_list_data.test.js +++ b/web/tests/message_list_data.test.js @@ -151,7 +151,12 @@ run_test("muting", () => { {id: 9, type: "private", to_user_ids: "9", sender_id: 11}, ]; - user_topics.update_user_topics(1, "muted", user_topics.all_visibility_policies.MUTED); + user_topics.update_user_topics( + 1, + "random stream name", + "muted", + user_topics.all_visibility_policies.MUTED, + ); muted_users.add_muted_user(10); // `messages_filtered_for_topic_mutes` should skip filtering diff --git a/web/tests/notifications.test.js b/web/tests/notifications.test.js index 39311fb4c4..598ef88cc7 100644 --- a/web/tests/notifications.test.js +++ b/web/tests/notifications.test.js @@ -38,12 +38,14 @@ stream_data.add_sub(muted); user_topics.update_user_topics( general.stream_id, + general.name, "muted topic", user_topics.all_visibility_policies.MUTED, ); user_topics.update_user_topics( general.stream_id, + general.name, "followed topic", user_topics.all_visibility_policies.FOLLOWED, ); diff --git a/web/tests/settings_user_topics.test.js b/web/tests/settings_user_topics.test.js index b8da97bc9a..232ea5909d 100644 --- a/web/tests/settings_user_topics.test.js +++ b/web/tests/settings_user_topics.test.js @@ -23,6 +23,7 @@ stream_data.add_sub(frontend); run_test("settings", ({override, override_rewire}) => { user_topics.update_user_topics( frontend.stream_id, + frontend.name, "js", user_topics.all_visibility_policies.MUTED, 1577836800, diff --git a/web/tests/unread.test.js b/web/tests/unread.test.js index f6214759b1..beabfb4d1d 100644 --- a/web/tests/unread.test.js +++ b/web/tests/unread.test.js @@ -245,6 +245,7 @@ test("muting", () => { user_topics.update_user_topics( social.stream_id, + social.stream_name, "test_muting", user_topics.all_visibility_policies.MUTED, ); @@ -481,11 +482,12 @@ test("mentions", () => { test_notifiable_count(counts.home_unread_messages, 0); const muted_stream_id = 900; + const muted_stream_name = "muted stream for testing unread mentions"; const unmuted_stream_id = 901; sub_store.add_hydrated_sub(muted_stream_id, { muted_stream_id, - name: "muted stream for testing unread mentions", + name: muted_stream_name, subscribed: true, is_muted: true, }); @@ -498,6 +500,7 @@ test("mentions", () => { user_topics.update_user_topics( muted_stream_id, + muted_stream_name, "lunch", user_topics.all_visibility_policies.MUTED, ); @@ -638,7 +641,12 @@ test("mention updates", () => { test("stream_has_any_unread_mentions", () => { const muted_stream_id = 401; - user_topics.update_user_topics(401, "lunch", user_topics.all_visibility_policies.MUTED); + user_topics.update_user_topics( + 401, + "random_stream_name", + "lunch", + user_topics.all_visibility_policies.MUTED, + ); const mention_me_message = { id: 15, diff --git a/web/tests/user_topics.test.js b/web/tests/user_topics.test.js index 4013ea3cee..db40c436f6 100644 --- a/web/tests/user_topics.test.js +++ b/web/tests/user_topics.test.js @@ -55,64 +55,139 @@ test("edge_cases", () => { test("add_and_remove_mutes", () => { assert.ok(!user_topics.is_topic_muted(devel.stream_id, "java")); - user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.MUTED); + user_topics.update_user_topics( + devel.stream_id, + devel.name, + "java", + all_visibility_policies.MUTED, + ); assert.ok(user_topics.is_topic_muted(devel.stream_id, "java")); // test idempotency - user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.MUTED); + user_topics.update_user_topics( + devel.stream_id, + devel.name, + "java", + all_visibility_policies.MUTED, + ); assert.ok(user_topics.is_topic_muted(devel.stream_id, "java")); - user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.INHERIT); + user_topics.update_user_topics( + devel.stream_id, + devel.name, + "java", + all_visibility_policies.INHERIT, + ); assert.ok(!user_topics.is_topic_muted(devel.stream_id, "java")); // test idempotency - user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.INHERIT); + user_topics.update_user_topics( + devel.stream_id, + devel.name, + "java", + all_visibility_policies.INHERIT, + ); assert.ok(!user_topics.is_topic_muted(devel.stream_id, "java")); // test unknown stream is harmless too - user_topics.update_user_topics(unknown.stream_id, "java", all_visibility_policies.INHERIT); + user_topics.update_user_topics( + unknown.stream_id, + unknown.name, + "java", + all_visibility_policies.INHERIT, + ); assert.ok(!user_topics.is_topic_muted(unknown.stream_id, "java")); }); test("add_and_remove_unmutes", () => { assert.ok(!user_topics.is_topic_unmuted(devel.stream_id, "java")); - user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.UNMUTED); + user_topics.update_user_topics( + devel.stream_id, + devel.name, + "java", + all_visibility_policies.UNMUTED, + ); assert.ok(user_topics.is_topic_unmuted(devel.stream_id, "java")); // test idempotency - user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.UNMUTED); + user_topics.update_user_topics( + devel.stream_id, + devel.name, + "java", + all_visibility_policies.UNMUTED, + ); assert.ok(user_topics.is_topic_unmuted(devel.stream_id, "java")); - user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.INHERIT); + user_topics.update_user_topics( + devel.stream_id, + devel.name, + "java", + all_visibility_policies.INHERIT, + ); assert.ok(!user_topics.is_topic_unmuted(devel.stream_id, "java")); // test idempotency - user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.INHERIT); + user_topics.update_user_topics( + devel.stream_id, + devel.name, + "java", + all_visibility_policies.INHERIT, + ); assert.ok(!user_topics.is_topic_unmuted(devel.stream_id, "java")); // test unknown stream is harmless too - user_topics.update_user_topics(unknown.stream_id, "java", all_visibility_policies.INHERIT); + user_topics.update_user_topics( + unknown.stream_id, + unknown.name, + "java", + all_visibility_policies.INHERIT, + ); assert.ok(!user_topics.is_topic_unmuted(unknown.stream_id, "java")); }); test("add_and_remove_follows", () => { assert.ok(!user_topics.is_topic_followed(devel.stream_id, "java")); - user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.FOLLOWED); + user_topics.update_user_topics( + devel.stream_id, + devel.name, + "java", + all_visibility_policies.FOLLOWED, + ); assert.ok(user_topics.is_topic_followed(devel.stream_id, "java")); // test idempotency - user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.FOLLOWED); + user_topics.update_user_topics( + devel.stream_id, + devel.name, + "java", + all_visibility_policies.FOLLOWED, + ); assert.ok(user_topics.is_topic_followed(devel.stream_id, "java")); - user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.INHERIT); + user_topics.update_user_topics( + devel.stream_id, + devel.name, + "java", + all_visibility_policies.INHERIT, + ); assert.ok(!user_topics.is_topic_followed(devel.stream_id, "java")); // test idempotency - user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.INHERIT); + user_topics.update_user_topics( + devel.stream_id, + devel.name, + "java", + all_visibility_policies.INHERIT, + ); assert.ok(!user_topics.is_topic_followed(devel.stream_id, "java")); // test unknown stream is harmless too - user_topics.update_user_topics(unknown.stream_id, "java", all_visibility_policies.INHERIT); + user_topics.update_user_topics( + unknown.stream_id, + unknown.name, + "java", + all_visibility_policies.INHERIT, + ); assert.ok(!user_topics.is_topic_followed(unknown.stream_id, "java")); }); @@ -125,12 +200,14 @@ test("get_mutes", () => { ); user_topics.update_user_topics( office.stream_id, + office.name, "gossip", all_visibility_policies.MUTED, 1577836800, ); user_topics.update_user_topics( devel.stream_id, + devel.name, "java", all_visibility_policies.MUTED, 1577836700, @@ -168,12 +245,14 @@ test("get_unmutes", () => { ); user_topics.update_user_topics( office.stream_id, + office.name, "gossip", all_visibility_policies.UNMUTED, 1577836800, ); user_topics.update_user_topics( devel.stream_id, + devel.name, "java", all_visibility_policies.UNMUTED, 1577836700, @@ -211,12 +290,14 @@ test("get_follows", () => { ); user_topics.update_user_topics( office.stream_id, + office.name, "gossip", all_visibility_policies.FOLLOWED, 1577836800, ); user_topics.update_user_topics( devel.stream_id, + devel.name, "java", all_visibility_policies.FOLLOWED, 1577836700,