composebox_typeahead: Properly populate stream topic data for message edits.

Previously, we would always pick up the stream and topic name from
compose_state. This would work for message edits as well when the
composebox was open.

Now, if we are in a message edit, we get the stream and topic of the
message being edited before falling back on trying to populate using
the composebox state.

Fixes #14545.
This commit is contained in:
Rohitt Vashishtha 2020-04-20 12:10:56 +05:30 committed by Tim Abbott
parent 19afa77173
commit e94b151ff6
2 changed files with 26 additions and 5 deletions

View File

@ -816,6 +816,7 @@ run_test('initialize', () => {
caret_called = true;
return 7;
};
fake_this.$element.closest = () => [];
fake_this.options = options;
let actual_value = options.source.call(fake_this, 'test #s');
assert.deepEqual(

View File

@ -414,11 +414,12 @@ exports.slash_commands = [
},
];
exports.filter_and_sort_mentions = function (is_silent, query) {
const opts = {
exports.filter_and_sort_mentions = function (is_silent, query, opts) {
opts = {
want_broadcast: !is_silent,
want_groups: !is_silent,
filter_pills: false,
...opts,
};
return exports.get_person_suggestions(query, opts);
};
@ -509,13 +510,30 @@ exports.get_person_suggestions = function (query, opts) {
return typeahead_helper.sort_recipients(
filtered_persons,
query,
compose_state.stream_name(),
compose_state.topic(),
opts.stream,
opts.topic,
filtered_groups,
exports.max_num_items
);
};
exports.get_stream_topic_data = (hacky_this) => {
const opts = {};
const message_row = hacky_this.$element.closest(".message_row");
if (message_row.length === 1) {
// we are editting a message so we try to use it's keys.
const msg = message_store.get(rows.id(message_row));
if (msg.type === 'stream') {
opts.stream = msg.stream;
opts.topic = msg.topic;
}
} else {
opts.stream = compose_state.stream_name();
opts.topic = compose_state.topic();
}
return opts;
};
exports.get_sorted_filtered_items = function (query) {
/*
This is just a "glue" function to work
@ -553,9 +571,11 @@ exports.get_sorted_filtered_items = function (query) {
const completing = hacky_this.completing;
const token = hacky_this.token;
const opts = exports.get_stream_topic_data(hacky_this);
if (completing === 'mention' || completing === 'silent_mention') {
return exports.filter_and_sort_mentions(
big_results.is_silent, token);
big_results.is_silent, token, opts);
}
return exports.filter_and_sort_candidates(completing, big_results, token);