From cb91b7f312fc5a822b2344eabdd6794da4ecca3e Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Fri, 14 Feb 2020 12:39:04 +0000 Subject: [PATCH] util: Kill off set_topic_links/get_topic_links. These functions were just shims that were used in the somewhat painful migration from subject_* to topic_*. The commit 4572be8c278c4404aa48f65acd79a277d6443de2 fixed it so that the client never needs to deal with "subject_links". So now we just go back to simpler code: message.topic_links = links links = message.topic_links --- frontend_tests/node_tests/markdown.js | 41 +++++++++++++-------------- static/js/echo.js | 2 +- static/js/markdown.js | 4 +-- static/js/message_events.js | 2 +- static/js/message_list_view.js | 2 +- static/js/util.js | 8 ------ 6 files changed, 25 insertions(+), 34 deletions(-) diff --git a/frontend_tests/node_tests/markdown.js b/frontend_tests/node_tests/markdown.js index 95a8305a4f..d39168cdd4 100644 --- a/frontend_tests/node_tests/markdown.js +++ b/frontend_tests/node_tests/markdown.js @@ -3,7 +3,6 @@ set_global('katex', zrequire('katex', 'katex/dist/katex.min.js')); set_global('marked', zrequire('marked', 'third/marked/lib/marked')); set_global('i18n', global.stub_i18n); -const util = zrequire('util'); zrequire('fenced_code'); zrequire('stream_data'); zrequire('people'); @@ -441,50 +440,50 @@ run_test('marked', () => { run_test('topic_links', () => { let message = {type: 'stream', topic: "No links here"}; markdown.add_topic_links(message); - assert.equal(util.get_topic_links(message).length, 0); + assert.equal(message.topic_links.length, 0); message = {type: 'stream', topic: "One #123 link here"}; markdown.add_topic_links(message); - assert.equal(util.get_topic_links(message).length, 1); - assert.equal(util.get_topic_links(message)[0], "https://trac.zulip.net/ticket/123"); + assert.equal(message.topic_links.length, 1); + assert.equal(message.topic_links[0], "https://trac.zulip.net/ticket/123"); message = {type: 'stream', topic: "Two #123 #456 link here"}; markdown.add_topic_links(message); - assert.equal(util.get_topic_links(message).length, 2); - assert.equal(util.get_topic_links(message)[0], "https://trac.zulip.net/ticket/123"); - assert.equal(util.get_topic_links(message)[1], "https://trac.zulip.net/ticket/456"); + assert.equal(message.topic_links.length, 2); + assert.equal(message.topic_links[0], "https://trac.zulip.net/ticket/123"); + assert.equal(message.topic_links[1], "https://trac.zulip.net/ticket/456"); message = {type: 'stream', topic: "New ZBUG_123 link here"}; markdown.add_topic_links(message); - assert.equal(util.get_topic_links(message).length, 1); - assert.equal(util.get_topic_links(message)[0], "https://trac2.zulip.net/ticket/123"); + assert.equal(message.topic_links.length, 1); + assert.equal(message.topic_links[0], "https://trac2.zulip.net/ticket/123"); message = {type: 'stream', topic: "New ZBUG_123 with #456 link here"}; markdown.add_topic_links(message); - assert.equal(util.get_topic_links(message).length, 2); - assert(util.get_topic_links(message).includes("https://trac2.zulip.net/ticket/123")); - assert(util.get_topic_links(message).includes("https://trac.zulip.net/ticket/456")); + assert.equal(message.topic_links.length, 2); + assert(message.topic_links.includes("https://trac2.zulip.net/ticket/123")); + assert(message.topic_links.includes("https://trac.zulip.net/ticket/456")); message = {type: 'stream', topic: "One ZGROUP_123:45 link here"}; markdown.add_topic_links(message); - assert.equal(util.get_topic_links(message).length, 1); - assert.equal(util.get_topic_links(message)[0], "https://zone_45.zulip.net/ticket/123"); + assert.equal(message.topic_links.length, 1); + assert.equal(message.topic_links[0], "https://zone_45.zulip.net/ticket/123"); message = {type: 'stream', topic: "Hello https://google.com"}; markdown.add_topic_links(message); - assert.equal(util.get_topic_links(message).length, 1); - assert.equal(util.get_topic_links(message)[0], "https://google.com"); + assert.equal(message.topic_links.length, 1); + assert.equal(message.topic_links[0], "https://google.com"); message = {type: 'stream', topic: "#456 https://google.com https://github.com"}; markdown.add_topic_links(message); - assert.equal(util.get_topic_links(message).length, 3); - assert(util.get_topic_links(message).includes("https://google.com")); - assert(util.get_topic_links(message).includes("https://github.com")); - assert(util.get_topic_links(message).includes("https://trac.zulip.net/ticket/456")); + assert.equal(message.topic_links.length, 3); + assert(message.topic_links.includes("https://google.com")); + assert(message.topic_links.includes("https://github.com")); + assert(message.topic_links.includes("https://trac.zulip.net/ticket/456")); message = {type: "not-stream"}; markdown.add_topic_links(message); - assert.equal(util.get_topic_links(message).length, 0); + assert.equal(message.topic_links.length, 0); }); run_test('message_flags', () => { diff --git a/static/js/echo.js b/static/js/echo.js index 1f217e6776..d3899e5b7e 100644 --- a/static/js/echo.js +++ b/static/js/echo.js @@ -292,7 +292,7 @@ exports.process_from_server = function process_from_server(messages) { // the backend. client_message.timestamp = message.timestamp; - util.set_topic_links(client_message, util.get_topic_links(message)); + client_message.topic_links = message.topic_links; client_message.is_me_message = message.is_me_message; client_message.submessages = message.submessages; diff --git a/static/js/markdown.js b/static/js/markdown.js index 291fad79eb..65925de996 100644 --- a/static/js/markdown.js +++ b/static/js/markdown.js @@ -175,7 +175,7 @@ exports.apply_markdown = function (message) { exports.add_topic_links = function (message) { if (message.type !== 'stream') { - util.set_topic_links(message, []); + message.topic_links = []; return; } const topic = util.get_message_topic(message); @@ -207,7 +207,7 @@ exports.add_topic_links = function (message) { links = links.concat(match); } - util.set_topic_links(message, links); + message.topic_links = links; }; exports.is_status_message = function (raw_content) { diff --git a/static/js/message_events.js b/static/js/message_events.js index 7d87826b7a..c3e441ee21 100644 --- a/static/js/message_events.js +++ b/static/js/message_events.js @@ -197,7 +197,7 @@ exports.update_messages = function update_messages(events) { unread.update_unread_topics(msg, event); util.set_message_topic(msg, new_topic); - util.set_topic_links(msg, util.get_topic_links(event)); + msg.topic_links = event.topic_links; // Add the recent topics entry for the new topics; must // be called after we call set_message_topic. diff --git a/static/js/message_list_view.js b/static/js/message_list_view.js index 5d25415601..0f7a549678 100644 --- a/static/js/message_list_view.js +++ b/static/js/message_list_view.js @@ -182,7 +182,7 @@ function populate_group_from_message_container(group, message_container) { group.display_reply_to = message_store.get_pm_full_names(message_container.msg); } group.display_recipient = message_container.msg.display_recipient; - group.topic_links = util.get_topic_links(message_container.msg); + group.topic_links = message_container.msg.topic_links; set_topic_edit_properties(group, message_container.msg); render_group_display_date(group, message_container); diff --git a/static/js/util.js b/static/js/util.js index ac3a2f7fe4..e52f874ae5 100644 --- a/static/js/util.js +++ b/static/js/util.js @@ -234,14 +234,6 @@ exports.sorted_ids = function (ids) { return id_list; }; -exports.set_topic_links = function (obj, topic_links) { - obj.topic_links = topic_links; -}; - -exports.get_topic_links = function (obj) { - return obj.topic_links; -}; - exports.set_match_data = function (target, source) { target.match_subject = source.match_subject; target.match_content = source.match_content;