Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
recent_topics: Use get_topic_key everywhere.
Aman Agrawal2d6ada436075
diff --git a/frontend_tests/node_tests/recent_topics.js b/frontend_tests/node_tests/recent_topics.jsindex 94007c87787..e43f859bb28 100644--- a/frontend_tests/node_tests/recent_topics.js+++ b/frontend_tests/node_tests/recent_topics.js@@ -243,6 +243,10 @@ messages[10] = {type: 'stream',};+function get_topic_key(stream_id, topic) {+ return stream_id + ":" + topic.toLowerCase();+}+function generate_topic_data(topic_info_array) {// Since most of the fields are common, this function helps generate fixtures// with non common fields.@@ -251,7 +255,7 @@ function generate_topic_data(topic_info_array) {const selectors = [];for (const [stream_id, topic, unread_count, muted, participated] of topic_info_array) {- const topic_selector = $.create('#recent_topic:' + stream_id + ":" + topic);+ const topic_selector = $.create('#recent_topic:' + get_topic_key(stream_id, topic));topic_selector.data = function () {return {participated: participated,@@ -275,6 +279,7 @@ function generate_topic_data(topic_info_array) {stream_id: stream_id,stream_url: 'https://www.example.com',topic: topic,+ topic_key: get_topic_key(stream_id, topic),topic_url: 'https://www.example.com',unread_count: unread_count,muted: muted,@@ -506,7 +511,7 @@ run_test('test_update_unread_count', () => {// update a messagegenerate_topic_data([[1, 'topic-7', 1, false, true]]);- rt.update_topic_unread_count([messages[9]]);+ rt.update_topic_unread_count(messages[9]);});// template rendering is tested in test_recent_topics_launch.@@ -636,9 +641,9 @@ run_test('test_topic_edit', () => {////////////////// test change topic //////////////////verify_topic_data(all_topics, stream1, topic6, messages[8].id, true);- assert.equal(all_topics.get(stream1 + ":" + topic8), undefined);+ assert.equal(all_topics.get(get_topic_key(stream1, topic8)), undefined);- let topic_selector = $.create('#recent_topic:' + stream1 + ":" + topic8);+ let topic_selector = $.create('#recent_topic:' + get_topic_key(stream1, topic8));topic_selector.data = function () {return {participated: true,@@ -653,13 +658,13 @@ run_test('test_topic_edit', () => {all_topics = rt.get();verify_topic_data(all_topics, stream1, topic8, messages[8].id, true);- assert.equal(all_topics.get(stream1 + ":" + topic6), undefined);+ assert.equal(all_topics.get(get_topic_key(stream1, topic6)), undefined);////////////////// test stream change //////////////////verify_topic_data(all_topics, stream1, topic1, messages[0].id, true);- assert.equal(all_topics.get(stream2 + ":" + topic1), undefined);+ assert.equal(all_topics.get(get_topic_key(stream2, topic1)), undefined);- topic_selector = $.create('#recent_topic:' + stream2 + ":" + topic1);+ topic_selector = $.create('#recent_topic:' + get_topic_key(stream2, topic1));topic_selector.data = function () {return {participated: true,@@ -671,14 +676,14 @@ run_test('test_topic_edit', () => {rt.process_topic_edit(stream1, topic1, topic1, stream2);all_topics = rt.get();- assert.equal(all_topics.get(stream1 + ":" + topic1), undefined);+ assert.equal(all_topics.get(get_topic_key(stream1, topic1)), undefined);verify_topic_data(all_topics, stream2, topic1, messages[0].id, true);////////////////// test stream & topic change //////////////////verify_topic_data(all_topics, stream2, topic1, messages[0].id, true);- assert.equal(all_topics.get(stream3 + ":" + topic9), undefined);+ assert.equal(all_topics.get(get_topic_key(stream3, topic9)), undefined);- topic_selector = $.create('#recent_topic:' + stream3 + ":" + topic9);+ topic_selector = $.create('#recent_topic:' + get_topic_key(stream3, topic9));topic_selector.data = function () {return {participated: false,@@ -691,6 +696,6 @@ run_test('test_topic_edit', () => {rt.process_topic_edit(stream2, topic1, topic9, stream3);all_topics = rt.get();- assert.equal(all_topics.get(stream2 + ":" + topic1), undefined);+ assert.equal(all_topics.get(get_topic_key(stream2, topic1)), undefined);verify_topic_data(all_topics, stream3, topic9, messages[0].id, true);});diff --git a/static/js/recent_topics.js b/static/js/recent_topics.jsindex 5d1622fa045..3281f7b55c3 100644--- a/static/js/recent_topics.js+++ b/static/js/recent_topics.js@@ -9,6 +9,10 @@ const MAX_AVATAR = 4;// This variable can be used to set default filters.let filters = new Set(['unread', 'participated']);+function get_topic_key(stream_id, topic) {+ return stream_id + ":" + topic.toLowerCase();+}+exports.process_messages = function (messages) {// FIX: Currently, we do a complete_rerender everytime// we process a new message.@@ -27,7 +31,7 @@ exports.process_message = function (msg) {return false;}// Initialize topic data- const key = msg.stream_id + ':' + msg.topic;+ const key = get_topic_key(msg.stream_id, msg.topic);if (!topics.has(key)) {topics.set(key, {last_msg_id: -1,@@ -112,6 +116,7 @@ function format_topic(topic_data) {stream_url: hash_util.by_stream_uri(stream_id),topic: topic,+ topic_key: get_topic_key(stream_id, topic),unread_count: unread_count,last_msg_time: last_msg_time,topic_url: hash_util.by_stream_topic_uri(stream_id, topic),@@ -125,14 +130,14 @@ function format_topic(topic_data) {function get_topic_row(topic_data) {const msg = message_store.get(topic_data.last_msg_id);- const topic_key = msg.stream_id + ":" + msg.topic;+ const topic_key = get_topic_key(msg.stream_id, msg.topic);return $("#" + $.escapeSelector("recent_topic:" + topic_key));}exports.process_topic_edit = function (old_stream_id, old_topic, new_topic, new_stream_id) {// See `recent_senders.process_topic_edit` for// logic behind this and important notes on use of this function.- topics.delete(old_stream_id + ':' + old_topic);+ topics.delete(get_topic_key(old_stream_id, old_topic));const old_topic_msgs = message_util.get_messages_in_topic(old_stream_id, old_topic);exports.process_messages(old_topic_msgs);@@ -205,7 +210,7 @@ exports.inplace_rerender = function (topic_key) {};exports.update_topic_is_muted = function (stream_id, topic) {- const key = stream_id + ":" + topic;+ const key = get_topic_key(stream_id, topic);if (!topics.has(key)) {// we receive mute request for a topic we are// not tracking currently@@ -217,7 +222,7 @@ exports.update_topic_is_muted = function (stream_id, topic) {};exports.update_topic_unread_count = function (message) {- const topic_key = message.stream_id + ":" + message.topic;+ const topic_key = get_topic_key(message.stream_id, message.topic);exports.inplace_rerender(topic_key);};diff --git a/static/templates/recent_topic_row.hbs b/static/templates/recent_topic_row.hbsindex b92b67f1d8f..7bc4999ddf3 100644--- a/static/templates/recent_topic_row.hbs+++ b/static/templates/recent_topic_row.hbs@@ -1,4 +1,4 @@-<tr id="recent_topic:{{stream_id}}:{{topic}}" data-unread-count="{{unread_count}}" data-muted="{{muted}}" data-participated="{{participated}}">+<tr id="recent_topic:{{topic_key}}" data-unread-count="{{unread_count}}" data-muted="{{muted}}" data-participated="{{participated}}"><td class="recent_topic_stream"><span id="stream_sidebar_privacy_swatch_{{stream_id}}" class="stream-privacy filter-icon" style="color: {{stream_color}}">{{> stream_privacy }}