Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

message_store: Hide topic links to channels the user lost access to.

Evy Kassirerac0e555dafb6
diff --git a/web/src/message_store.ts b/web/src/message_store.ts
index 52a4668a961..cb9f2658b42 100644
--- a/web/src/message_store.ts
+++ b/web/src/message_store.ts
@@ -565,6 +565,12 @@ export function topic_links_from_narrow(stream_id: number, topic: string): Topic
message_id: message.id,
};
}
+ // Hide links to channels the user has lost access to, e.g.
+ // after being unsubscribed from a private channel, since the
+ // link maps aren't updated when that happens.
+ if (!stream_data.get_sub_by_id(target.stream_id)) {
+ continue;
+ }
// Hide links from this topic to the same topic, since those feel
// unnecessary to reference.
if (target.stream_id === stream_id && util.lower_same(target.topic, topic)) {
diff --git a/web/tests/message_store.test.cjs b/web/tests/message_store.test.cjs
index 1a3dd0884da..70472d05588 100644
--- a/web/tests/message_store.test.cjs
+++ b/web/tests/message_store.test.cjs
@@ -1654,6 +1654,35 @@ test("message links follow the linked message's current location", () => {
assert.deepEqual(message_store.topic_links_from_narrow(sales.stream_id, "Pricing"), []);
});
+test("links to a channel the user lost access to are hidden", () => {
+ message_store.clear_topic_links_for_testing();
+ const design = {name: "design", subscribed: true, stream_id: 10};
+ stream_data.add_sub_for_tests(design);
+ const sales = {name: "sales", subscribed: true, stream_id: 12};
+ stream_data.add_sub_for_tests(sales);
+
+ const linking_message = {
+ id: 651,
+ sender_id: bob.user_id,
+ type: "stream",
+ stream_id: sales.stream_id,
+ topic: "Pricing",
+ content: `<a href="/#narrow/channel/10-design/topic/Logo">link</a>`,
+ };
+ message_store.update_message_cache({type: "server_message", message: linking_message});
+ assert.deepEqual(message_store.topic_links_from_narrow(sales.stream_id, "Pricing"), [
+ {stream_id: design.stream_id, topic: "Logo", message_id: undefined},
+ ]);
+
+ // Losing access to a channel removes it from stream_data, but
+ // links to its topics from other channels' messages stay in the
+ // link maps.
+ stream_data.delete_sub(design.stream_id);
+ assert.deepEqual(message_store.topic_links_from_narrow(sales.stream_id, "Pricing"), []);
+
+ stream_data.add_sub_for_tests(design);
+});
+
test("reify_message_id handles a message that links to itself", () => {
message_store.clear_topic_links_for_testing();
const design = {name: "design", subscribed: true, stream_id: 10};