recent_senders: Fix exception in certain typeahead flows.

It appears that a regression introduced in
3f60074c33 caused undefined to be passed
as the subject to the recent_senders library much more often; this
fixing that, and makes the library handle such cases reasonably
without an exception regardless.

This was causing a huge number of "Tried to call a Dict method with an
undefined key." exceptions.
This commit is contained in:
Tim Abbott 2017-07-28 10:39:44 -07:00
parent 6536384e4b
commit e729814cfd
3 changed files with 10 additions and 2 deletions

View File

@ -35,6 +35,9 @@ var _ = require('node_modules/underscore/underscore.js');
assert.equal(
rs.compare_by_recency({user_id: sender1}, {user_id: sender2}, stream2, topic1) > 0,
true);
assert.equal(
rs.compare_by_recency({user_id: sender1}, {user_id: sender2}, stream2, undefined) === 0,
true);
// New topic
var message3 = {

View File

@ -395,7 +395,8 @@ exports.compose_matches_sorter = function (matches) {
return typeahead_helper.sort_emojis(matches, this.token);
} else if (this.completing === 'mention') {
return typeahead_helper.sort_recipients(matches, this.token,
compose_state.stream_name());
compose_state.stream_name(),
compose_state.subject());
} else if (this.completing === 'stream') {
return typeahead_helper.sort_streams(matches, this.token);
} else if (this.completing === 'syntax') {

View File

@ -22,7 +22,7 @@ exports.compare_by_recency = function (user_a, user_b, stream_id, topic) {
stream_id = stream_id.toString();
var topic_dict = senders.get(stream_id);
if (topic_dict !== undefined) {
if (topic !== undefined && topic_dict !== undefined) {
var sender_timestamps = topic_dict.get(topic);
if (sender_timestamps !== undefined) {
var b_timestamp = sender_timestamps.get(user_b.user_id) || Number.NEGATIVE_INFINITY;
@ -31,6 +31,10 @@ exports.compare_by_recency = function (user_a, user_b, stream_id, topic) {
}
}
// TODO: We should also compare by stream (and maybe also by
// overall message recency in the realm) in the common case where
// there's no traffic on the current topic from this user.
return 0;
};