message_list: Fix handling of deleted user groups.

You can now render message lists containing them and click on them
without throwing an exception.
This commit is contained in:
Tim Abbott
2019-02-15 14:50:28 -08:00
parent 7a49611a94
commit 4e53110350
3 changed files with 17 additions and 5 deletions

View File

@@ -532,6 +532,15 @@ MessageListView.prototype = {
content.find('.user-group-mention').each(function () { content.find('.user-group-mention').each(function () {
var user_group_id = get_user_group_id_for_mention_button(this); var user_group_id = get_user_group_id_for_mention_button(this);
var user_group = user_groups.get_user_group_from_id(user_group_id, true);
if (user_group === undefined) {
// This is a user group the current user doesn't have
// data on. This can happen when user groups are
// deleted.
blueslip.info("Rendered unexpected user group " + user_group_id);
return;
}
var my_user_id = people.my_current_user_id(); var my_user_id = people.my_current_user_id();
// Mark user group you're a member of. // Mark user group you're a member of.
if (user_groups.is_member_of(user_group_id, my_user_id)) { if (user_groups.is_member_of(user_group_id, my_user_id)) {
@@ -541,7 +550,7 @@ MessageListView.prototype = {
if (user_group_id && !$(this).find(".highlight").length) { if (user_group_id && !$(this).find(".highlight").length) {
// Edit the mention to show the current name for the // Edit the mention to show the current name for the
// user group, if its not in search. // user group, if its not in search.
$(this).text("@" + user_groups.get_user_group_from_id(user_group_id).name); $(this).text("@" + user_group.name);
} }
}); });

View File

@@ -708,9 +708,10 @@ exports.register_click_handlers = function () {
var row = $(this).closest(".message_row"); var row = $(this).closest(".message_row");
e.stopPropagation(); e.stopPropagation();
var message = current_msg_list.get(rows.id(row)); var message = current_msg_list.get(rows.id(row));
var group = user_groups.get_user_group_from_id(id); var group = user_groups.get_user_group_from_id(id, true);
if (group === undefined) { if (group === undefined) {
blueslip.error('Unable to find user group in message' + message.sender_id); // This user group has likely been deleted.
blueslip.info('Unable to find user group in message' + message.sender_id);
} else { } else {
show_user_group_info_popover(this, group, message); show_user_group_info_popover(this, group, message);
} }

View File

@@ -27,9 +27,11 @@ exports.remove = function (user_group) {
user_group_by_id_dict.del(user_group.id); user_group_by_id_dict.del(user_group.id);
}; };
exports.get_user_group_from_id = function (group_id) { exports.get_user_group_from_id = function (group_id, suppress_errors) {
if (!user_group_by_id_dict.has(group_id)) { if (!user_group_by_id_dict.has(group_id)) {
blueslip.error('Unknown group_id in get_user_group_from_id: ' + group_id); if (suppress_errors === undefined) {
blueslip.error('Unknown group_id in get_user_group_from_id: ' + group_id);
}
return; return;
} }
return user_group_by_id_dict.get(group_id); return user_group_by_id_dict.get(group_id);