From ea7effbe8aefa8c74e41b46f573da61ed9c44fd2 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 22 Jul 2020 20:52:37 -0700 Subject: [PATCH] recent_topics: Skip non-stream messages in update_topics_of_message_ids. Fixes an exception when deleting a private message, introduced by commit 5d5434ec2f41e50873f6843baadb85843dca3e58 (#15803). Signed-off-by: Anders Kaseorg --- frontend_tests/node_tests/recent_senders.js | 9 +++++++++ static/js/recent_senders.js | 8 +++++--- static/js/recent_topics.js | 6 ++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/frontend_tests/node_tests/recent_senders.js b/frontend_tests/node_tests/recent_senders.js index 4f745205b0..dd6933689d 100644 --- a/frontend_tests/node_tests/recent_senders.js +++ b/frontend_tests/node_tests/recent_senders.js @@ -28,12 +28,14 @@ run_test("process_message_for_senders", () => { // New stream const message1 = { + type: "stream", stream_id: stream1, id: (next_id += 1), topic: topic1, sender_id: sender1, }; const message2 = { + type: "stream", stream_id: stream2, id: (next_id += 1), topic: topic1, @@ -62,6 +64,7 @@ run_test("process_message_for_senders", () => { // New topic const message3 = { + type: "stream", stream_id: stream1, id: (next_id += 1), topic: topic2, @@ -77,6 +80,7 @@ run_test("process_message_for_senders", () => { // New sender const message4 = { + type: "stream", stream_id: stream1, id: (next_id += 1), topic: topic1, @@ -92,6 +96,7 @@ run_test("process_message_for_senders", () => { // More recent message const message5 = { + type: "stream", stream_id: stream1, id: (next_id += 1), topic: topic1, @@ -107,18 +112,21 @@ run_test("process_message_for_senders", () => { // Same stream, but different topics const message6 = { + type: "stream", stream_id: stream3, id: (next_id += 1), topic: topic1, sender_id: sender1, }; const message7 = { + type: "stream", stream_id: stream3, id: (next_id += 1), topic: topic2, sender_id: sender2, }; const message8 = { + type: "stream", stream_id: stream3, id: (next_id += 1), topic: topic3, @@ -144,6 +152,7 @@ run_test("process_message_for_senders", () => { // new message in topic2 const message9 = { + type: "stream", stream_id: stream3, id: (next_id += 1), topic: topic2, diff --git a/static/js/recent_senders.js b/static/js/recent_senders.js index f55e794044..b450fc1e40 100644 --- a/static/js/recent_senders.js +++ b/static/js/recent_senders.js @@ -76,9 +76,11 @@ exports.update_topics_of_message_ids = function (message_ids) { for (const msg_id of message_ids) { // Note: message_store retians data of msg post deletion. const message = message_store.get(msg_id); - // Create unique keys for stream_id and topic. - const topic_key = message.stream_id + ":" + message.topic; - topics_to_update.set(topic_key, [message.stream_id, message.topic]); + if (message.type === "stream") { + // Create unique keys for stream_id and topic. + const topic_key = message.stream_id + ":" + message.topic; + topics_to_update.set(topic_key, [message.stream_id, message.topic]); + } } for (const [stream_id, topic] of topics_to_update.values()) { diff --git a/static/js/recent_topics.js b/static/js/recent_topics.js index 9bda62c7d5..322e68a76f 100644 --- a/static/js/recent_topics.js +++ b/static/js/recent_topics.js @@ -242,8 +242,10 @@ exports.update_topics_of_message_ids = function (message_ids) { const topics_to_rerender = new Map(); for (const msg_id of message_ids) { const message = message_store.get(msg_id); - const topic_key = get_topic_key(message.stream_id, message.topic); - topics_to_rerender.set(topic_key, [message.stream_id, message.topic]); + if (message.type === "stream") { + const topic_key = get_topic_key(message.stream_id, message.topic); + topics_to_rerender.set(topic_key, [message.stream_id, message.topic]); + } } for (const [stream_id, topic] of topics_to_rerender.values()) {