mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	util: Replace util.get_message_topic().
Replace `util.get_message_topic(message)` with `message.topic`. Fixes #13931
This commit is contained in:
		
				
					committed by
					
						
						showell
					
				
			
			
				
	
			
			
			
						parent
						
							9d598d95a6
						
					
				
				
					commit
					efda2684ea
				
			@@ -108,13 +108,6 @@ run_test('robust_uri_decode', () => {
 | 
			
		||||
    }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
run_test('get_message_topic', () => {
 | 
			
		||||
    blueslip.set_test_data('error', 'programming error: message has no topic');
 | 
			
		||||
    assert.equal(util.get_message_topic({subject: 'foo'}), 'foo');
 | 
			
		||||
    blueslip.clear_test_data();
 | 
			
		||||
    assert.equal(util.get_message_topic({topic: 'bar'}), 'bar');
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
run_test('dumb_strcmp', () => {
 | 
			
		||||
    Intl.Collator = undefined;
 | 
			
		||||
    const strcmp = util.make_strcmp();
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,3 @@
 | 
			
		||||
const util = require("./util");
 | 
			
		||||
const autosize = require('autosize');
 | 
			
		||||
 | 
			
		||||
function update_lock_icon_for_stream(stream_name) {
 | 
			
		||||
@@ -335,7 +334,7 @@ exports.respond_to_message = function (opts) {
 | 
			
		||||
    let pm_recipient = '';
 | 
			
		||||
    if (msg_type === "stream") {
 | 
			
		||||
        stream = message.stream;
 | 
			
		||||
        topic = util.get_message_topic(message);
 | 
			
		||||
        topic = message.topic;
 | 
			
		||||
    } else {
 | 
			
		||||
        pm_recipient = message.reply_to;
 | 
			
		||||
        if (opts.reply_type === "personal") {
 | 
			
		||||
 
 | 
			
		||||
@@ -180,14 +180,14 @@ exports.edit_locally = function edit_locally(message, request) {
 | 
			
		||||
        const new_topic = request.new_topic;
 | 
			
		||||
        topic_data.remove_message({
 | 
			
		||||
            stream_id: message.stream_id,
 | 
			
		||||
            topic_name: util.get_message_topic(message),
 | 
			
		||||
            topic_name: message.topic,
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        util.set_message_topic(message, new_topic);
 | 
			
		||||
 | 
			
		||||
        topic_data.add_message({
 | 
			
		||||
            stream_id: message.stream_id,
 | 
			
		||||
            topic_name: util.get_message_topic(message),
 | 
			
		||||
            topic_name: message.topic,
 | 
			
		||||
            message_id: message.id,
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -30,7 +30,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(util.get_message_topic(message));
 | 
			
		||||
    return related_regexp.test(message.topic);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function message_in_home(message) {
 | 
			
		||||
@@ -107,7 +107,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 util.get_message_topic(message).toLowerCase() === operand;
 | 
			
		||||
        return message.topic.toLowerCase() === operand;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    case 'sender':
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,3 @@
 | 
			
		||||
const util = require("./util");
 | 
			
		||||
 | 
			
		||||
exports.get_hash_category = function (hash) {
 | 
			
		||||
    // given "#streams/subscribed", returns "streams"
 | 
			
		||||
    return hash ? hash.replace(/^#/, "").split(/\//)[0] : "";
 | 
			
		||||
@@ -138,7 +136,7 @@ exports.by_conversation_and_time_uri = function (message) {
 | 
			
		||||
 | 
			
		||||
    if (message.type === "stream") {
 | 
			
		||||
        return absolute_url +
 | 
			
		||||
            exports.by_stream_topic_uri(message.stream_id, util.get_message_topic(message)) +
 | 
			
		||||
            exports.by_stream_topic_uri(message.stream_id, message.topic) +
 | 
			
		||||
            suffix;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -223,7 +223,7 @@ function edit_message(row, raw_content) {
 | 
			
		||||
        is_editable: is_editable,
 | 
			
		||||
        is_content_editable: editability === exports.editability_types.FULL,
 | 
			
		||||
        has_been_editable: editability !== editability_types.NO,
 | 
			
		||||
        topic: util.get_message_topic(message),
 | 
			
		||||
        topic: message.topic,
 | 
			
		||||
        content: raw_content,
 | 
			
		||||
        file_upload_enabled: file_upload_enabled,
 | 
			
		||||
        minutes_to_edit: Math.floor(page_params.realm_message_content_edit_limit_seconds / 60),
 | 
			
		||||
@@ -331,7 +331,7 @@ function edit_message(row, raw_content) {
 | 
			
		||||
 | 
			
		||||
    if (!is_editable) {
 | 
			
		||||
        row.find(".message_edit_close").focus();
 | 
			
		||||
    } else if (message.type === 'stream' && util.get_message_topic(message) === compose.empty_topic_placeholder()) {
 | 
			
		||||
    } else if (message.type === 'stream' && message.topic === compose.empty_topic_placeholder()) {
 | 
			
		||||
        message_edit_topic.val('');
 | 
			
		||||
        message_edit_topic.focus();
 | 
			
		||||
    } else if (editability === editability_types.TOPIC_ONLY) {
 | 
			
		||||
@@ -353,7 +353,7 @@ function edit_message(row, raw_content) {
 | 
			
		||||
    message_viewport.scrollTop(message_viewport.scrollTop() + scroll_by);
 | 
			
		||||
 | 
			
		||||
    if (feature_flags.propagate_topic_edits && !message.locally_echoed) {
 | 
			
		||||
        const original_topic = util.get_message_topic(message);
 | 
			
		||||
        const original_topic = message.topic;
 | 
			
		||||
        message_edit_topic.keyup(function () {
 | 
			
		||||
            const new_topic = message_edit_topic.val();
 | 
			
		||||
            message_edit_topic_propagate.toggle(new_topic !== original_topic && new_topic !== "");
 | 
			
		||||
@@ -413,7 +413,7 @@ exports.start_topic_edit = function (recipient_row) {
 | 
			
		||||
    form.keydown(_.partial(handle_edit_keydown, true));
 | 
			
		||||
    const msg_id = rows.id_for_recipient_row(recipient_row);
 | 
			
		||||
    const message = current_msg_list.get(msg_id);
 | 
			
		||||
    let topic = util.get_message_topic(message);
 | 
			
		||||
    let topic = message.topic;
 | 
			
		||||
    if (topic === compose.empty_topic_placeholder()) {
 | 
			
		||||
        topic = '';
 | 
			
		||||
    }
 | 
			
		||||
@@ -470,7 +470,7 @@ exports.save = function (row, from_topic_edited_only) {
 | 
			
		||||
    const new_content = row.find(".message_edit_content").val();
 | 
			
		||||
    let topic_changed = false;
 | 
			
		||||
    let new_topic;
 | 
			
		||||
    const old_topic = util.get_message_topic(message);
 | 
			
		||||
    const old_topic = message.topic;
 | 
			
		||||
 | 
			
		||||
    if (message.type === "stream") {
 | 
			
		||||
        if (from_topic_edited_only) {
 | 
			
		||||
 
 | 
			
		||||
@@ -189,7 +189,7 @@ exports.update_messages = function update_messages(events) {
 | 
			
		||||
                // must be called before we call set_message_topic.
 | 
			
		||||
                topic_data.remove_message({
 | 
			
		||||
                    stream_id: msg.stream_id,
 | 
			
		||||
                    topic_name: util.get_message_topic(msg),
 | 
			
		||||
                    topic_name: msg.topic,
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
                // Update the unread counts; again, this must be called
 | 
			
		||||
@@ -203,7 +203,7 @@ exports.update_messages = function update_messages(events) {
 | 
			
		||||
                // be called after we call set_message_topic.
 | 
			
		||||
                topic_data.add_message({
 | 
			
		||||
                    stream_id: msg.stream_id,
 | 
			
		||||
                    topic_name: util.get_message_topic(msg),
 | 
			
		||||
                    topic_name: msg.topic,
 | 
			
		||||
                    message_id: msg.id,
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -168,7 +168,7 @@ MessageListData.prototype = {
 | 
			
		||||
    unmuted_messages: function (messages) {
 | 
			
		||||
        return messages.filter(
 | 
			
		||||
            message =>
 | 
			
		||||
                !muting.is_topic_muted(message.stream_id, util.get_message_topic(message)) ||
 | 
			
		||||
                !muting.is_topic_muted(message.stream_id, message.topic) ||
 | 
			
		||||
                message.mentioned
 | 
			
		||||
        );
 | 
			
		||||
    },
 | 
			
		||||
 
 | 
			
		||||
@@ -148,7 +148,7 @@ function set_topic_edit_properties(group, message) {
 | 
			
		||||
 | 
			
		||||
    // Messages with no topics should always have an edit icon visible
 | 
			
		||||
    // to encourage updating them. Admins can also edit any topic.
 | 
			
		||||
    if (util.get_message_topic(message) === compose.empty_topic_placeholder()) {
 | 
			
		||||
    if (message.topic === compose.empty_topic_placeholder()) {
 | 
			
		||||
        group.always_visible_topic_edit = true;
 | 
			
		||||
    } else if (message_edit.is_topic_editable(message)) {
 | 
			
		||||
        group.on_hover_topic_edit = true;
 | 
			
		||||
@@ -163,7 +163,7 @@ function populate_group_from_message_container(group, message_container) {
 | 
			
		||||
        group.background_color = stream_data.get_color(message_container.msg.stream);
 | 
			
		||||
        group.color_class = stream_color.get_color_class(group.background_color);
 | 
			
		||||
        group.invite_only = stream_data.get_invite_only(message_container.msg.stream);
 | 
			
		||||
        group.topic = util.get_message_topic(message_container.msg);
 | 
			
		||||
        group.topic = message_container.msg.topic;
 | 
			
		||||
        group.match_topic = util.get_match_topic(message_container.msg);
 | 
			
		||||
        group.stream_url = message_container.stream_url;
 | 
			
		||||
        group.topic_url = message_container.topic_url;
 | 
			
		||||
@@ -328,7 +328,7 @@ MessageListView.prototype = {
 | 
			
		||||
                    message_container.topic_url =
 | 
			
		||||
                        hash_util.by_stream_topic_uri(
 | 
			
		||||
                            message_container.msg.stream_id,
 | 
			
		||||
                            util.get_message_topic(message_container.msg));
 | 
			
		||||
                            message_container.msg.topic);
 | 
			
		||||
                } else {
 | 
			
		||||
                    message_container.pm_with_url =
 | 
			
		||||
                        message_container.msg.pm_with_url;
 | 
			
		||||
 
 | 
			
		||||
@@ -158,7 +158,7 @@ exports.add_message_metadata = function (message) {
 | 
			
		||||
 | 
			
		||||
        topic_data.add_message({
 | 
			
		||||
            stream_id: message.stream_id,
 | 
			
		||||
            topic_name: util.get_message_topic(message),
 | 
			
		||||
            topic_name: message.topic,
 | 
			
		||||
            message_id: message.id,
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,3 @@
 | 
			
		||||
const util = require("./util");
 | 
			
		||||
const render_muted_topic_ui_row = require('../templates/muted_topic_ui_row.hbs');
 | 
			
		||||
const render_topic_muted = require('../templates/topic_muted.hbs');
 | 
			
		||||
 | 
			
		||||
@@ -133,7 +132,7 @@ exports.unmute = function (stream_id, topic) {
 | 
			
		||||
 | 
			
		||||
exports.toggle_mute = function (message) {
 | 
			
		||||
    const stream_id = message.stream_id;
 | 
			
		||||
    const topic = util.get_message_topic(message);
 | 
			
		||||
    const topic = message.topic;
 | 
			
		||||
 | 
			
		||||
    if (muting.is_topic_muted(stream_id, topic)) {
 | 
			
		||||
        exports.unmute(stream_id, topic);
 | 
			
		||||
 
 | 
			
		||||
@@ -549,7 +549,7 @@ exports.stream_topic = function () {
 | 
			
		||||
    if (msg) {
 | 
			
		||||
        return {
 | 
			
		||||
            stream: msg.stream || undefined,
 | 
			
		||||
            topic: util.get_message_topic(msg) || undefined,
 | 
			
		||||
            topic: msg.topic || undefined,
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -676,7 +676,7 @@ exports.by_topic = function (target_id, opts) {
 | 
			
		||||
 | 
			
		||||
    const search_terms = [
 | 
			
		||||
        {operator: 'stream', operand: original.stream},
 | 
			
		||||
        {operator: 'topic', operand: util.get_message_topic(original)},
 | 
			
		||||
        {operator: 'topic', operand: original.topic},
 | 
			
		||||
    ];
 | 
			
		||||
    opts = _.defaults({}, opts, {then_select_id: target_id});
 | 
			
		||||
    exports.activate(search_terms, opts);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,3 @@
 | 
			
		||||
const util = require("./util");
 | 
			
		||||
const render_compose_notification = require('../templates/compose_notification.hbs');
 | 
			
		||||
const render_notification = require('../templates/notification.hbs');
 | 
			
		||||
 | 
			
		||||
@@ -278,7 +277,7 @@ if (window.electron_bridge !== undefined) {
 | 
			
		||||
            type: message.type,
 | 
			
		||||
            content: reply,
 | 
			
		||||
            to: message.type === 'private' ? message.reply_to : message.stream,
 | 
			
		||||
            topic: util.get_message_topic(message),
 | 
			
		||||
            topic: message.topic,
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        function success() {
 | 
			
		||||
@@ -323,7 +322,7 @@ function process_notification(notification) {
 | 
			
		||||
    ui.replace_emoji_with_text(content);
 | 
			
		||||
    content = content.text();
 | 
			
		||||
 | 
			
		||||
    const topic = util.get_message_topic(message);
 | 
			
		||||
    const topic = message.topic;
 | 
			
		||||
 | 
			
		||||
    if (message.is_me_message) {
 | 
			
		||||
        content = message.sender_full_name + content.slice(3);
 | 
			
		||||
@@ -483,7 +482,7 @@ exports.message_is_notifiable = function (message) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (message.type === "stream" &&
 | 
			
		||||
        muting.is_topic_muted(message.stream_id, util.get_message_topic(message))) {
 | 
			
		||||
        muting.is_topic_muted(message.stream_id, message.topic)) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -604,7 +603,7 @@ exports.received_messages = function (messages) {
 | 
			
		||||
 | 
			
		||||
function get_message_header(message) {
 | 
			
		||||
    if (message.type === "stream") {
 | 
			
		||||
        return message.stream + " > " + util.get_message_topic(message);
 | 
			
		||||
        return message.stream + " > " + message.topic;
 | 
			
		||||
    }
 | 
			
		||||
    if (message.display_recipient.length > 2) {
 | 
			
		||||
        return i18n.t("group private messages with __recipient__",
 | 
			
		||||
@@ -625,7 +624,7 @@ exports.get_local_notify_mix_reason = function (message) {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (message.type === "stream" && muting.is_topic_muted(message.stream_id, util.get_message_topic(message))) {
 | 
			
		||||
    if (message.type === "stream" && muting.is_topic_muted(message.stream_id, message.topic)) {
 | 
			
		||||
        return i18n.t("Sent! Your message was sent to a topic you have muted.");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -430,7 +430,7 @@ exports.toggle_actions_popover = function (element, id) {
 | 
			
		||||
            use_edit_icon = false;
 | 
			
		||||
            editability_menu_item = i18n.t("View source");
 | 
			
		||||
        }
 | 
			
		||||
        const topic = util.get_message_topic(message);
 | 
			
		||||
        const topic = message.topic;
 | 
			
		||||
        const can_mute_topic =
 | 
			
		||||
                message.stream &&
 | 
			
		||||
                topic &&
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,3 @@
 | 
			
		||||
const util = require("./util");
 | 
			
		||||
const FoldDict = require('./fold_dict').FoldDict;
 | 
			
		||||
const IntDict = require('./int_dict').IntDict;
 | 
			
		||||
 | 
			
		||||
@@ -7,7 +6,7 @@ const stream_senders = new IntDict(); // key is stream-id, value is Dict
 | 
			
		||||
 | 
			
		||||
exports.process_message_for_senders = function (message) {
 | 
			
		||||
    const stream_id = message.stream_id;
 | 
			
		||||
    const topic = util.get_message_topic(message);
 | 
			
		||||
    const topic = message.topic;
 | 
			
		||||
 | 
			
		||||
    // Process most recent sender to topic
 | 
			
		||||
    const topic_dict = topic_senders.get(stream_id) || new FoldDict();
 | 
			
		||||
 
 | 
			
		||||
@@ -83,7 +83,7 @@ exports.reply_message = function (opts) {
 | 
			
		||||
        reply.type = 'stream';
 | 
			
		||||
        reply.to  = stream;
 | 
			
		||||
        reply.content = content;
 | 
			
		||||
        util.set_message_topic(reply, util.get_message_topic(message));
 | 
			
		||||
        util.set_message_topic(reply, message.topic);
 | 
			
		||||
 | 
			
		||||
        exports.send_message(reply, success, error);
 | 
			
		||||
        return;
 | 
			
		||||
 
 | 
			
		||||
@@ -430,14 +430,14 @@ exports.process_loaded_messages = function (messages) {
 | 
			
		||||
        if (message.type === 'stream') {
 | 
			
		||||
            exports.unread_topic_counter.add(
 | 
			
		||||
                message.stream_id,
 | 
			
		||||
                util.get_message_topic(message),
 | 
			
		||||
                message.topic,
 | 
			
		||||
                message.id
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const is_unmuted_mention = message.type === 'stream' && message.mentioned &&
 | 
			
		||||
                                   !muting.is_topic_muted(message.stream_id,
 | 
			
		||||
                                                          util.get_message_topic(message));
 | 
			
		||||
                                                          message.topic);
 | 
			
		||||
        if (message.mentioned_me_directly || is_unmuted_mention) {
 | 
			
		||||
            exports.unread_mentions_counter.add(message.id);
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -59,10 +59,7 @@ function lower_same(a, b) {
 | 
			
		||||
exports.same_stream_and_topic = function util_same_stream_and_topic(a, b) {
 | 
			
		||||
    // Streams and topics are case-insensitive.
 | 
			
		||||
    return a.stream_id === b.stream_id &&
 | 
			
		||||
            lower_same(
 | 
			
		||||
                exports.get_message_topic(a),
 | 
			
		||||
                exports.get_message_topic(b)
 | 
			
		||||
            );
 | 
			
		||||
        lower_same(a.topic, b.topic);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.is_pm_recipient = function (email, message) {
 | 
			
		||||
@@ -259,27 +256,6 @@ exports.set_message_topic = function (obj, topic) {
 | 
			
		||||
    obj.topic = topic;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.get_message_topic = function (obj) {
 | 
			
		||||
    // TODO: Kill off the below defensive code by the
 | 
			
		||||
    //       end of February 2020 (giving ourselves a
 | 
			
		||||
    //       little bit of time to make sure we don't
 | 
			
		||||
    //       have any obscure codepaths left that weren't
 | 
			
		||||
    //       properly handled in our subject/topic migration).
 | 
			
		||||
    //
 | 
			
		||||
    //       Also, once we are confident that all of our
 | 
			
		||||
    //       internal objects have been migrated from
 | 
			
		||||
    //       "subject" to "topic", we can start having
 | 
			
		||||
    //       our callers just do `foo = message.topic`
 | 
			
		||||
    //       and phase out the use of this function.  Or
 | 
			
		||||
    //       we can just sweep the codebase.
 | 
			
		||||
    if (obj.topic === undefined) {
 | 
			
		||||
        blueslip.error('programming error: message has no topic');
 | 
			
		||||
        return obj.subject;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return obj.topic;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.get_edit_event_topic = function (obj) {
 | 
			
		||||
    if (obj.topic === undefined) {
 | 
			
		||||
        return obj.subject;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user