From 1ad30c68583444ca6627d65e4c6b2aa5a493fe80 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Sun, 23 Dec 2018 15:01:30 +0000 Subject: [PATCH] subject -> topic: Sweep "message.subject" in frontend. These were the last remaining files. After this, only util.js has a non-email-related use of "subject". --- frontend_tests/node_tests/recent_senders.js | 1 + frontend_tests/node_tests/topic_data.js | 1 + static/js/echo.js | 4 ++-- static/js/filter.js | 4 ++-- static/js/markdown.js | 2 +- static/js/message_edit.js | 12 +++++++----- static/js/message_list_data.js | 2 +- static/js/message_store.js | 2 +- static/js/popovers.js | 11 ++++++----- static/js/recent_senders.js | 5 +++-- static/js/transmit.js | 2 +- static/js/unread.js | 2 +- 12 files changed, 27 insertions(+), 21 deletions(-) diff --git a/frontend_tests/node_tests/recent_senders.js b/frontend_tests/node_tests/recent_senders.js index 0eabcd5b31..a42d1cbcd3 100644 --- a/frontend_tests/node_tests/recent_senders.js +++ b/frontend_tests/node_tests/recent_senders.js @@ -1,3 +1,4 @@ +zrequire('util'); var rs = zrequire('recent_senders'); run_test('process_message_for_senders', () => { diff --git a/frontend_tests/node_tests/topic_data.js b/frontend_tests/node_tests/topic_data.js index 6bf58940e9..cb24b95619 100644 --- a/frontend_tests/node_tests/topic_data.js +++ b/frontend_tests/node_tests/topic_data.js @@ -1,4 +1,5 @@ zrequire('unread'); +zrequire('util'); zrequire('topic_data'); set_global('channel', {}); diff --git a/static/js/echo.js b/static/js/echo.js index 24068a34ed..a72f7ec410 100644 --- a/static/js/echo.js +++ b/static/js/echo.js @@ -128,14 +128,14 @@ exports.edit_locally = function edit_locally(message, raw_content, new_topic) { if (new_topic !== undefined) { topic_data.remove_message({ stream_id: message.stream_id, - topic_name: message.subject, + topic_name: util.get_message_topic(message), }); util.set_message_topic(message, new_topic); topic_data.add_message({ stream_id: message.stream_id, - topic_name: message.subject, + topic_name: util.get_message_topic(message), message_id: message.id, }); } diff --git a/static/js/filter.js b/static/js/filter.js index 9d328cf23b..5a746c21e7 100644 --- a/static/js/filter.js +++ b/static/js/filter.js @@ -31,7 +31,7 @@ function zephyr_topic_name_match(message, operand) { related_regexp = new RegExp(/^/.source + util.escape_regexp(base_topic) + /(\.d)*$/.source, 'i'); } - return related_regexp.test(message.subject); + return related_regexp.test(util.get_message_topic(message)); } function message_in_home(message) { @@ -106,7 +106,7 @@ function message_matches_search_term(message, operator, operand) { if (page_params.realm_is_zephyr_mirror_realm) { return zephyr_topic_name_match(message, operand); } - return message.subject.toLowerCase() === operand; + return util.get_message_topic(message).toLowerCase() === operand; case 'sender': diff --git a/static/js/markdown.js b/static/js/markdown.js index d8f5f6b3ef..97adf7b0dc 100644 --- a/static/js/markdown.js +++ b/static/js/markdown.js @@ -111,7 +111,7 @@ exports.add_topic_links = function (message) { util.set_topic_links(message, []); return; } - var topic = message.subject; + var topic = util.get_message_topic(message); var links = []; _.each(realm_filter_list, function (realm_filter) { var pattern = realm_filter[0]; diff --git a/static/js/message_edit.js b/static/js/message_edit.js index d811aab5e3..fa0e9e3295 100644 --- a/static/js/message_edit.js +++ b/static/js/message_edit.js @@ -135,13 +135,15 @@ exports.save = function (row, from_topic_edited_only) { var new_content = row.find(".message_edit_content").val(); var topic_changed = false; var new_topic; + var old_topic = util.get_message_topic(message); + if (message.type === "stream") { if (from_topic_edited_only) { new_topic = row.find(".inline_topic_edit").val(); } else { new_topic = row.find(".message_edit_topic").val(); } - topic_changed = new_topic !== message.subject && new_topic.trim() !== ""; + topic_changed = new_topic !== old_topic && new_topic.trim() !== ""; } // Editing a not-yet-acked message (because the original send attempt failed) // just results in the in-memory message being changed @@ -264,7 +266,7 @@ function edit_message(row, raw_content) { message_id: message.id, is_editable: is_editable, has_been_editable: editability !== editability_types.NO, - topic: message.subject, + topic: util.get_message_topic(message), content: raw_content, minutes_to_edit: Math.floor(page_params.realm_message_content_edit_limit_seconds / 60)})); @@ -370,7 +372,7 @@ function edit_message(row, raw_content) { if (!is_editable) { row.find(".message_edit_close").focus(); - } else if (message.type === 'stream' && message.subject === compose.empty_topic_placeholder()) { + } else if (message.type === 'stream' && util.get_message_topic(message) === compose.empty_topic_placeholder()) { message_edit_topic.val(''); message_edit_topic.focus(); } else if (editability === editability_types.TOPIC_ONLY) { @@ -390,7 +392,7 @@ function edit_message(row, raw_content) { message_viewport.scrollTop(message_viewport.scrollTop() + scroll_by); if (feature_flags.propagate_topic_edits && !message.locally_echoed) { - var original_topic = message.subject; + var original_topic = util.get_message_topic(message); message_edit_topic.keyup(function () { var new_topic = message_edit_topic.val(); message_edit_topic_propagate.toggle(new_topic !== original_topic && new_topic !== ""); @@ -452,7 +454,7 @@ exports.start_topic_edit = function (recipient_row) { form.keydown(_.partial(handle_edit_keydown, true)); var msg_id = rows.id_for_recipient_row(recipient_row); var message = current_msg_list.get(msg_id); - var topic = message.subject; + var topic = util.get_message_topic(message); if (topic === compose.empty_topic_placeholder()) { topic = ''; } diff --git a/static/js/message_list_data.js b/static/js/message_list_data.js index 063c072d15..e7a73022f6 100644 --- a/static/js/message_list_data.js +++ b/static/js/message_list_data.js @@ -166,7 +166,7 @@ MessageListData.prototype = { unmuted_messages: function (messages) { return _.reject(messages, function (message) { - return muting.is_topic_muted(message.stream_id, message.subject) && + return muting.is_topic_muted(message.stream_id, util.get_message_topic(message)) && !message.mentioned; }); }, diff --git a/static/js/message_store.js b/static/js/message_store.js index 85f4b3a25a..44c2459366 100644 --- a/static/js/message_store.js +++ b/static/js/message_store.js @@ -135,7 +135,7 @@ exports.add_message_metadata = function (message) { topic_data.add_message({ stream_id: message.stream_id, - topic_name: message.subject, + topic_name: util.get_message_topic(message), message_id: message.id, }); diff --git a/static/js/popovers.js b/static/js/popovers.js index 943cab0d71..a237ce9349 100644 --- a/static/js/popovers.js +++ b/static/js/popovers.js @@ -382,14 +382,15 @@ exports.toggle_actions_popover = function (element, id) { use_edit_icon = false; editability_menu_item = i18n.t("View source"); } + var topic = util.get_message_topic(message); var can_mute_topic = message.stream && - message.subject && - !muting.is_topic_muted(message.stream_id, message.subject); + topic && + !muting.is_topic_muted(message.stream_id, topic); var can_unmute_topic = message.stream && - message.subject && - muting.is_topic_muted(message.stream_id, message.subject); + topic && + muting.is_topic_muted(message.stream_id, topic); var should_display_edit_history_option = _.any(message.edit_history, function (entry) { return entry.prev_content !== undefined; @@ -409,7 +410,7 @@ exports.toggle_actions_popover = function (element, id) { message_id: message.id, historical: message.historical, stream_id: message.stream_id, - topic: util.get_message_topic(message), + topic: topic, use_edit_icon: use_edit_icon, editability_menu_item: editability_menu_item, can_mute_topic: can_mute_topic, diff --git a/static/js/recent_senders.js b/static/js/recent_senders.js index 3c90955cab..93960cb788 100644 --- a/static/js/recent_senders.js +++ b/static/js/recent_senders.js @@ -7,17 +7,18 @@ var stream_senders = new Dict(); // key is stream-id, value is Dict exports.process_message_for_senders = function (message) { var stream_id = message.stream_id.toString(); + var topic = util.get_message_topic(message); // Process most recent sender to topic var topic_dict = topic_senders.get(stream_id) || new Dict({fold_case: true}); - var sender_message_ids = topic_dict.get(message.subject) || new Dict(); + var sender_message_ids = topic_dict.get(topic) || new Dict(); var old_message_id = sender_message_ids.get(message.sender_id); if (old_message_id === undefined || old_message_id < message.id) { sender_message_ids.set(message.sender_id, message.id); } - topic_dict.set(message.subject, sender_message_ids); + topic_dict.set(topic, sender_message_ids); topic_senders.set(stream_id, topic_dict); // Process most recent sender to whole stream diff --git a/static/js/transmit.js b/static/js/transmit.js index 400763b24e..c5db12c718 100644 --- a/static/js/transmit.js +++ b/static/js/transmit.js @@ -112,7 +112,7 @@ exports.reply_message = function (opts) { reply.type = 'stream'; reply.to = stream; reply.content = content; - util.set_message_topic(reply, message.subject); + util.set_message_topic(reply, util.get_message_topic(message)); transmit.send_message(reply, success, error); return; diff --git a/static/js/unread.js b/static/js/unread.js index d53729edc1..872ce2b827 100644 --- a/static/js/unread.js +++ b/static/js/unread.js @@ -482,7 +482,7 @@ exports.process_loaded_messages = function (messages) { if (message.type === 'stream') { exports.unread_topic_counter.add( message.stream_id, - message.subject, + util.get_message_topic(message), message.id ); }