mirror of https://github.com/zulip/zulip.git
Add people.update_email_in_reply_to() helper.
This will be used for live updating.
This commit is contained in:
parent
f8d59c8108
commit
f56d3807cc
|
@ -332,3 +332,31 @@ initialize();
|
||||||
assert(/Obsolete email.*FOO.*bar/.test(warning));
|
assert(/Obsolete email.*FOO.*bar/.test(warning));
|
||||||
assert.equal(person.user_id, user_id);
|
assert.equal(person.user_id, user_id);
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
initialize();
|
||||||
|
|
||||||
|
(function test_update_email_in_reply_to() {
|
||||||
|
var charles = {
|
||||||
|
email: 'charles@example.com',
|
||||||
|
user_id: 601,
|
||||||
|
full_name: 'Charles Dickens',
|
||||||
|
};
|
||||||
|
var maria = {
|
||||||
|
email: 'athens@example.com',
|
||||||
|
user_id: 602,
|
||||||
|
full_name: 'Maria Athens',
|
||||||
|
};
|
||||||
|
people.add(charles);
|
||||||
|
people.add(maria);
|
||||||
|
|
||||||
|
var reply_to = ' charles@example.com, athens@example.com';
|
||||||
|
assert.equal(
|
||||||
|
people.update_email_in_reply_to(reply_to, 9999, 'whatever'),
|
||||||
|
reply_to
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
people.update_email_in_reply_to(reply_to, maria.user_id, 'maria@example.com'),
|
||||||
|
'charles@example.com,maria@example.com'
|
||||||
|
);
|
||||||
|
}());
|
||||||
|
|
||||||
|
|
|
@ -283,6 +283,37 @@ exports.pm_with_url = function (message) {
|
||||||
return uri;
|
return uri;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.update_email_in_reply_to = function (reply_to, user_id, new_email) {
|
||||||
|
// We try to replace an old email with a new email in a reply_to,
|
||||||
|
// but we try to avoid changing the reply_to if we don't have to,
|
||||||
|
// and we don't warn on any errors.
|
||||||
|
var emails = reply_to.split(',');
|
||||||
|
|
||||||
|
var persons = _.map(emails, function (email) {
|
||||||
|
return people_dict.get(email.trim());
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!_.all(persons)) {
|
||||||
|
return reply_to;
|
||||||
|
}
|
||||||
|
|
||||||
|
var needs_patch = _.any(persons, function (person) {
|
||||||
|
return person.user_id === user_id;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!needs_patch) {
|
||||||
|
return reply_to;
|
||||||
|
}
|
||||||
|
|
||||||
|
emails = _.map(persons, function (person) {
|
||||||
|
if (person.user_id === user_id) {
|
||||||
|
return new_email;
|
||||||
|
}
|
||||||
|
return person.email;
|
||||||
|
});
|
||||||
|
|
||||||
|
return emails.join(',');
|
||||||
|
};
|
||||||
|
|
||||||
exports.pm_with_operand_ids = function (operand) {
|
exports.pm_with_operand_ids = function (operand) {
|
||||||
var emails = operand.split(',');
|
var emails = operand.split(',');
|
||||||
|
|
Loading…
Reference in New Issue