Make compose replies for PMs more robust.

We now use user_ids from the message to generate the
reply_to more dynamically.
This commit is contained in:
Steve Howell
2017-02-08 18:18:40 -08:00
committed by Tim Abbott
parent 37509da20d
commit f8d59c8108
2 changed files with 49 additions and 5 deletions

View File

@@ -636,11 +636,15 @@ exports.respond_to_message = function (opts) {
} }
var pm_recipient = message.reply_to; var pm_recipient = message.reply_to;
if (opts.reply_type === "personal" && message.type === "private") { if (message.type === "private") {
if (opts.reply_type === "personal") {
// reply_to for private messages is everyone involved, so for // reply_to for private messages is everyone involved, so for
// personals replies we need to set the private message // personals replies we need to set the private message
// recipient to just the sender // recipient to just the sender
pm_recipient = message.sender_email; pm_recipient = people.get_person_from_user_id(message.sender_id).email;
} else {
pm_recipient = people.pm_reply_to(message);
}
} }
if (opts.reply_type === 'personal' || message.type === 'private') { if (opts.reply_type === 'personal' || message.type === 'private') {
msg_type = 'private'; msg_type = 'private';

View File

@@ -188,6 +188,46 @@ exports.get_recipients = function (user_ids_string) {
return names.join(', '); return names.join(', ');
}; };
exports.pm_reply_to = function (message) {
if (message.type !== 'private') {
return;
}
if (message.display_recipient.length === 0) {
blueslip.error('Empty recipient list in message');
return;
}
var user_ids = _.map(message.display_recipient, function (elem) {
return elem.user_id || elem.id;
});
var other_user_ids = _.filter(user_ids, function (user_id) {
return !people.is_my_user_id(user_id);
});
if (other_user_ids.length >= 1) {
user_ids = other_user_ids;
} else {
user_ids = [my_user_id];
}
var emails = _.map(user_ids, function (user_id) {
var person = people_by_user_id_dict.get(user_id);
if (!person) {
blueslip.error('Unknown user id in message: ' + user_id);
return '?';
}
return person.email;
});
emails.sort();
var reply_to = emails.join(',');
return reply_to;
};
exports.pm_with_user_ids = function (message) { exports.pm_with_user_ids = function (message) {
if (message.type !== 'private') { if (message.type !== 'private') {
return; return;