message_events: Remove message from message_store on deletion.

We did not remove the deleted messages from message_store
previously. This commit adds the code to remove the deleted
messages from message_store.

Co-authored-by: Sahil Batra <sahil@zulip.com>
This commit is contained in:
Aman Agrawal 2024-06-25 21:36:55 +00:00 committed by Tim Abbott
parent 281ce39a0d
commit d381a358d0
3 changed files with 49 additions and 0 deletions

View File

@ -584,4 +584,5 @@ export function remove_messages(message_ids) {
recent_view_ui.update_topics_of_deleted_message_ids(message_ids);
starred_messages.remove(message_ids);
starred_messages_ui.rerender_ui();
message_store.remove(message_ids);
}

View File

@ -301,3 +301,9 @@ export function reify_message_id({old_id, new_id}: {old_id: number; new_id: numb
stored_messages.delete(old_id);
}
}
export function remove(message_ids: number[]): void {
for (const message_id of message_ids) {
stored_messages.delete(message_id);
}
}

View File

@ -357,3 +357,45 @@ test("update_property", () => {
assert.equal(message2.stream_id, denmark.stream_id);
assert.equal(message2.display_recipient, denmark.name);
});
test("remove", () => {
const message1 = {
type: "stream",
sender_full_name: alice.full_name,
sender_id: alice.user_id,
stream_id: devel.stream_id,
stream: devel.name,
display_recipient: devel.name,
topic: "test",
id: 100,
};
const message2 = {
type: "stream",
sender_full_name: bob.full_name,
sender_id: bob.user_id,
stream_id: denmark.stream_id,
stream: denmark.name,
display_recipient: denmark.name,
topic: "test",
id: 101,
};
const message3 = {
type: "stream",
sender_full_name: cindy.full_name,
sender_id: cindy.user_id,
stream_id: denmark.stream_id,
stream: denmark.name,
display_recipient: denmark.name,
topic: "test",
id: 102,
};
for (const message of [message1, message2]) {
message_helper.process_new_message(message);
}
const deleted_message_ids = [message1.id, message3.id, 104];
message_store.remove(deleted_message_ids);
assert.equal(message_store.get(message1.id), undefined);
assert.equal(message_store.get(message2.id).id, message2.id);
assert.equal(message_store.get(message3.id), undefined);
});