Add people.pm_lookup_key

This commit is contained in:
Steve Howell
2017-08-01 09:51:56 -04:00
committed by Tim Abbott
parent 8a7397fef6
commit b446d96ed6
2 changed files with 17 additions and 0 deletions

View File

@@ -86,6 +86,12 @@ initialize();
assert.equal(people.is_my_user_id(undefined), false);
}());
(function test_pm_lookup_key() {
assert.equal(people.pm_lookup_key('30'), '30');
assert.equal(people.pm_lookup_key('32,30'), '32');
assert.equal(people.pm_lookup_key('101,32,30'), '32,101');
}());
(function test_get_recipients() {
assert.equal(people.get_recipients('30'), 'Me Myself');
assert.equal(people.get_recipients('30,32'), 'Isaac Newton');

View File

@@ -310,6 +310,17 @@ function sorted_other_user_ids(user_ids) {
return user_ids;
}
exports.pm_lookup_key = function (user_ids_string) {
/*
The server will sometimes include our own user id
in keys for PMs, but we only want our user id if
we sent a message to ourself.
*/
var user_ids = user_ids_string.split(',');
user_ids = sorted_other_user_ids(user_ids);
return user_ids.join(',');
};
exports.pm_with_user_ids = function (message) {
if (message.type !== 'private') {
return;