Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
message_store: Drop links to unstored messages when they are deleted.
Evy Kassirer66e41c3219df
diff --git a/web/src/message_store.ts b/web/src/message_store.tsindex bc523a76e43..8f78393e475 100644--- a/web/src/message_store.ts+++ b/web/src/message_store.ts@@ -1087,6 +1087,11 @@ export function remove(message_ids: number[]): void {const message = get(message_id);if (message?.type === "stream") {remove_message_from_topic_links(message.id);+ } else if (message === undefined) {+ // A deleted message we haven't fetched can still have links+ // saved to it.+ refile_links_to_message(message_id, undefined);+ pending_message_link_targets.delete(message_id);}stored_messages.delete(message_id);}diff --git a/web/tests/message_store.test.cjs b/web/tests/message_store.test.cjsindex 059bceabc0d..8460093d22f 100644--- a/web/tests/message_store.test.cjs+++ b/web/tests/message_store.test.cjs@@ -1942,6 +1942,47 @@ test("links to a message that isn't in the store yet follow its moves", () => {assert.deepEqual(message_store.topic_links_to_narrow(design.stream_id, "Logo"), []);});+test("links to a message that isn't in the store yet are dropped when it is deleted", () => {+ 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 linked_message_id = 670;+ const linking_message = {+ id: 671,+ sender_id: bob.user_id,+ type: "stream",+ stream_id: sales.stream_id,+ topic: "Renewals",+ content: `<a href="/#narrow/channel/10-design/topic/Logo/near/${linked_message_id}">link</a><a href="/#narrow/channel/10-design/topic/Logo">topic link</a>`,+ };+ message_store.update_message_cache({type: "server_message", message: linking_message});+ assert.deepEqual(message_store.topic_links_from_narrow(sales.stream_id, "Renewals"), [+ {stream_id: design.stream_id, topic: "Logo", message_id: linked_message_id},+ {stream_id: design.stream_id, topic: "Logo", message_id: undefined},+ ]);++ // Deleting the linked message before it is fetched drops the link+ // to it, while the message's other links stay.+ message_store.remove([linked_message_id]);+ assert.deepEqual(message_store.topic_links_from_narrow(sales.stream_id, "Renewals"), [+ {stream_id: design.stream_id, topic: "Logo", message_id: undefined},+ ]);+ assert.deepEqual(message_store.topic_links_to_narrow(design.stream_id, "Logo"), [+ {stream_id: sales.stream_id, topic: "Renewals", message_id: linking_message.id},+ ]);+ assert.deepEqual(message_store.pending_message_link_targets_for_testing(), new Map());+ assert.deepEqual(+ message_store.topic_links_incoming_for_testing().get(design.stream_id).get("logo"),+ new Map([+ [linked_message_id, []],+ [0, [linking_message.id]],+ ]),+ );+});+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};