diff --git a/web/src/message_util.ts b/web/src/message_util.ts index b624e15936..6440661d02 100644 --- a/web/src/message_util.ts +++ b/web/src/message_util.ts @@ -94,6 +94,12 @@ export function get_messages_in_topic(stream_id: number, topic: string): Message ); } +export function get_messages_in_dm_conversations(user_ids_strings: Set): Message[] { + return all_messages_data + .all_messages() + .filter((x) => x.type === "private" && user_ids_strings.has(x.to_user_ids)); +} + export function get_max_message_id_in_stream(stream_id: number): number { let max_message_id = 0; for (const msg of all_messages_data.all_messages()) { diff --git a/web/src/recent_view_ui.ts b/web/src/recent_view_ui.ts index e2db87fa73..9a277a1984 100644 --- a/web/src/recent_view_ui.ts +++ b/web/src/recent_view_ui.ts @@ -794,6 +794,31 @@ export function update_topics_of_deleted_message_ids(message_ids: number[]): voi msgs_to_process.push(...msgs); } + const dm_conversations_to_rerender = new Set(); + for (const msg_id of message_ids) { + const msg = message_store.get(msg_id); + if (msg === undefined) { + continue; + } + + if (msg.type === "private") { + const key = recent_view_util.get_key_from_message(msg); + // Important to assert since we use the key in get_messages_in_dm_conversation. + assert(key === msg.to_user_ids); + dm_conversations_to_rerender.add(key); + } + } + + for (const key of dm_conversations_to_rerender) { + recent_view_data.conversations.delete(key); + } + if (dm_conversations_to_rerender.size > 0) { + const dm_messages_to_process = message_util.get_messages_in_dm_conversations( + dm_conversations_to_rerender, + ); + msgs_to_process.push(...dm_messages_to_process); + } + if (msgs_to_process.length > 0) { process_messages(msgs_to_process); } else {