reactions: Only warn for unknown user ids.

If we get reactions for deactivated users, or otherwise missing
users, we only issue a blueslip warning now.  The function
get_message_reactions() was indirectly causing blueslip errors
before this fix, but we can downgrade to warnings now that this
function has better unit tests around it.

We eventually want to track deactivated users on the client.

Fixes #4289
This commit is contained in:
Steve Howell 2017-03-26 11:38:47 -07:00
parent 3da047e10e
commit cf6545a71f
2 changed files with 16 additions and 1 deletions

View File

@ -14,6 +14,10 @@ set_global('emoji', {
realm_emojis: {},
});
set_global('blueslip', {
warn: function () {},
});
set_global('page_params', {user_id: 1});
(function make_people() {
@ -44,6 +48,10 @@ set_global('page_params', {user_id: 1});
{emoji_name: 'smile', user: {id: 5}},
{emoji_name: 'smile', user: {id: 6}},
{emoji_name: 'frown', user: {id: 7}},
// add some bogus user_ids
{emoji_name: 'octopus', user: {id: 8888}},
{emoji_name: 'frown', user: {id: 9999}},
],
};

View File

@ -222,8 +222,15 @@ exports.get_emojis_used_by_user_for_message_id = function (message_id) {
exports.get_message_reactions = function (message) {
var message_reactions = new Dict();
_.each(message.reactions, function (reaction) {
var user_id = reaction.user.id;
if (!people.is_known_user_id(user_id)) {
blueslip.warn('Unknown user_id ' + user_id +
'in reaction for message ' + message.id);
return;
}
var user_list = message_reactions.setdefault(reaction.emoji_name, []);
user_list.push(reaction.user.id);
user_list.push(user_id);
});
var reactions = message_reactions.items().map(function (item) {
var emoji_name = item[0];