Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
message_store: Record whether a topic link is to a message.
Evy Kassirerc4c98559b179
diff --git a/web/src/message_store.ts b/web/src/message_store.tsindex 2da8dc9c866..29babe691a8 100644--- a/web/src/message_store.ts+++ b/web/src/message_store.ts@@ -462,11 +462,18 @@ export function reify_message_id({old_id, new_id}: {old_id: number; new_id: numb// A cross-conversation link found in a message, to a stream>topic or to// a specific message in a stream>topic. Links to a whole channel (with// no topic) aren't tracked.-export type TopicLink = {- stream_id: number;- topic: string;- message_id: number | undefined;-};+type TopicLinkMessage =+ {kind: "message"; message_id: number} | {kind: "topic"; message_id: undefined};+export type TopicLink = {stream_id: number; topic: string} & TopicLinkMessage;++// The message a link is tracked by: the linked message for a message+// link, and none for a topic link.+function linked_message_from_url({message_id}: {message_id?: string}): TopicLinkMessage {+ if (message_id !== undefined) {+ return {kind: "message", message_id: Number.parseInt(message_id, 10)};+ }+ return {kind: "topic", message_id: undefined};+}const NO_MESSAGE_ID = 0;@@ -643,6 +650,7 @@ function refile_pending_link_from_message(stream_id: to_narrow.stream_id,topic: to_narrow.topic,message_id: to_message_id,+ kind: "message",});}}@@ -723,6 +731,7 @@ export function topic_links_from_narrow(stream_id: number, topic: string): Topicstream_id: message.stream_id,topic: message.topic,message_id: message.id,+ kind: link.kind,};}}@@ -794,6 +803,7 @@ export function topic_links_to_narrow(stream_id: number, topic: string): TopicListream_id: message.stream_id,topic: message.topic,message_id: message.id,+ kind: "message",});}return topic_links_content;@@ -957,9 +967,8 @@ export function save_topic_links(message: Message): void {let to_stream_id = link_data.stream_id;let to_topic = link_data.topic_name;- const to_message_id = link_data.message_id- ? Number.parseInt(link_data.message_id, 10)- : undefined;+ const linked_message = linked_message_from_url(link_data);+ const to_message_id = linked_message.message_id;// A link to just a channel (no topic) isn't information-rich// enough to be worth tracking as a cross-conversation link.@@ -1004,7 +1013,7 @@ export function save_topic_links(message: Message): void {add_link_from_message(message.id, topic_links_from_message, {stream_id: to_stream_id,topic: to_topic,- message_id: to_message_id,+ ...linked_message,});topic_links_from_message_narrow.set(message.id, topic_links_from_message);}diff --git a/web/src/topic_popover.ts b/web/src/topic_popover.tsindex 689ad528ba1..911f6909f76 100644--- a/web/src/topic_popover.ts+++ b/web/src/topic_popover.ts@@ -93,7 +93,7 @@ function get_cross_conversation_link_render_context(link: message_store.TopicLinchannel_name: stream?.name ?? "",topic_display_name_html: _.escape(util.get_final_topic_display_name(topic_name)),is_empty_string_topic: topic_name === "",- is_message_link: link.message_id !== undefined,+ is_message_link: link.kind === "message",};}diff --git a/web/tests/message_events.test.cjs b/web/tests/message_events.test.cjsindex 52c9e38b7ba..b6d41e4f2be 100644--- a/web/tests/message_events.test.cjs+++ b/web/tests/message_events.test.cjs@@ -268,7 +268,12 @@ run_test(const old_topic = "weekend plans";const new_topic = "Weekend plans";- const link = {stream_id: denmark.stream_id, topic: "dinner", message_id: undefined};+ const link = {+ stream_id: denmark.stream_id,+ topic: "dinner",+ message_id: undefined,+ kind: "topic",+ };const raw_message = {id: 333,display_recipient: denmark.name,@@ -290,7 +295,12 @@ run_test(link,]);assert.deepEqual(message_store.topic_links_to_narrow(denmark.stream_id, "dinner"), [- {stream_id: denmark.stream_id, topic: old_topic, message_id: message.id},+ {+ stream_id: denmark.stream_id,+ topic: old_topic,+ message_id: message.id,+ kind: "message",+ },]);const events = [@@ -319,7 +329,12 @@ run_test(link,]);assert.deepEqual(message_store.topic_links_to_narrow(denmark.stream_id, "dinner"), [- {stream_id: denmark.stream_id, topic: new_topic, message_id: message.id},+ {+ stream_id: denmark.stream_id,+ topic: new_topic,+ message_id: message.id,+ kind: "message",+ },]);// Deleting the message finds its links and removes them.diff --git a/web/tests/message_store.test.cjs b/web/tests/message_store.test.cjsindex df85e6bc91f..6b26b80b43a 100644--- a/web/tests/message_store.test.cjs+++ b/web/tests/message_store.test.cjs@@ -587,11 +587,11 @@ test("maybe_update_raw_content", () => {// Expected cross-conversation links, as message_store returns them.function message_link(stream_id, topic, message_id) {- return {stream_id, topic, message_id};+ return {stream_id, topic, message_id, kind: "message"};}function topic_link(stream_id, topic) {- return {stream_id, topic, message_id: undefined};+ return {stream_id, topic, message_id: undefined, kind: "topic"};}test("save_topic_links", () => {