From b446d96ed678ee0211be2197904587189a02c4dd Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Tue, 1 Aug 2017 09:51:56 -0400 Subject: [PATCH] Add people.pm_lookup_key --- frontend_tests/node_tests/people.js | 6 ++++++ static/js/people.js | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/frontend_tests/node_tests/people.js b/frontend_tests/node_tests/people.js index bbb41fa389..294741bae2 100644 --- a/frontend_tests/node_tests/people.js +++ b/frontend_tests/node_tests/people.js @@ -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'); diff --git a/static/js/people.js b/static/js/people.js index c2c6218ec5..48d26c9679 100644 --- a/static/js/people.js +++ b/static/js/people.js @@ -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;