diff --git a/frontend_tests/node_tests/filter.js b/frontend_tests/node_tests/filter.js index f89d26b118..0ae6161cc2 100644 --- a/frontend_tests/node_tests/filter.js +++ b/frontend_tests/node_tests/filter.js @@ -541,25 +541,25 @@ run_test('predicate_basics', () => { })); assert(!predicate({ type: 'private', - display_recipient: [{user_id: steve.user_id}], + display_recipient: [{id: steve.user_id}], })); assert(!predicate({ type: 'private', - display_recipient: [{user_id: 999999}], + display_recipient: [{id: 999999}], })); assert(!predicate({type: 'stream'})); predicate = get_predicate([['pm-with', 'Joe@example.com,steve@foo.com']]); assert(predicate({ type: 'private', - display_recipient: [{user_id: joe.user_id}, {user_id: steve.user_id}], + display_recipient: [{id: joe.user_id}, {id: steve.user_id}], })); // Make sure your own email is ignored predicate = get_predicate([['pm-with', 'Joe@example.com,steve@foo.com,me@example.com']]); assert(predicate({ type: 'private', - display_recipient: [{user_id: joe.user_id}, {user_id: steve.user_id}], + display_recipient: [{id: joe.user_id}, {id: steve.user_id}], })); predicate = get_predicate([['pm-with', 'nobody@example.com']]); diff --git a/frontend_tests/node_tests/hash_util.js b/frontend_tests/node_tests/hash_util.js index 42c041347d..1ce28ee7a6 100644 --- a/frontend_tests/node_tests/hash_util.js +++ b/frontend_tests/node_tests/hash_util.js @@ -140,7 +140,7 @@ run_test('test_by_conversation_and_time_uri', () => { type: 'private', display_recipient: [ { - user_id: hamlet.user_id, + id: hamlet.user_id, }, ], id: 43, diff --git a/frontend_tests/node_tests/message_store.js b/frontend_tests/node_tests/message_store.js index d53727a227..ae1b3351c3 100644 --- a/frontend_tests/node_tests/message_store.js +++ b/frontend_tests/node_tests/message_store.js @@ -66,12 +66,23 @@ people.add_in_realm(denise); global.people.initialize_current_user(me.user_id); +function convert_recipients(people) { + // Display_recipient uses `id` for user_ids. + return _.map(people, (p) => { + return { + email: p.email, + id: p.user_id, + full_name: p.full_name, + }; + }); +} + run_test('add_message_metadata', () => { let message = { sender_email: 'me@example.com', sender_id: me.user_id, type: 'private', - display_recipient: [me, bob, cindy], + display_recipient: convert_recipients([me, bob, cindy]), flags: ['has_alert_word'], is_me_message: false, id: 2067, @@ -172,7 +183,7 @@ run_test('errors', () => { // Test a user that doesn't exist let message = { type: 'private', - display_recipient: [{user_id: 92714}], + display_recipient: [{id: 92714}], }; blueslip.set_test_data('error', 'Unknown user_id in get_person_from_user_id: 92714'); @@ -254,7 +265,7 @@ run_test('message_id_change', () => { sender_email: 'me@example.com', sender_id: me.user_id, type: 'private', - display_recipient: [me, bob, cindy], + display_recipient: convert_recipients([me, bob, cindy]), flags: ['has_alert_word'], id: 401, }; diff --git a/frontend_tests/node_tests/narrow_unread.js b/frontend_tests/node_tests/narrow_unread.js index c97e740df0..67fbc179fc 100644 --- a/frontend_tests/node_tests/narrow_unread.js +++ b/frontend_tests/node_tests/narrow_unread.js @@ -62,7 +62,7 @@ run_test('get_unread_ids', () => { type: 'private', unread: true, display_recipient: [ - {user_id: alice.user_id}, + {id: alice.user_id}, ], }; diff --git a/frontend_tests/node_tests/people.js b/frontend_tests/node_tests/people.js index bf5b329f9f..692c98508e 100644 --- a/frontend_tests/node_tests/people.js +++ b/frontend_tests/node_tests/people.js @@ -465,7 +465,7 @@ run_test('message_methods', () => { display_recipient: [ {id: maria.user_id}, {id: me.user_id}, - {user_id: charles.user_id}, + {id: charles.user_id}, ], sender_id: charles.user_id, }; @@ -480,7 +480,7 @@ run_test('message_methods', () => { type: 'private', display_recipient: [ {id: maria.user_id}, - {user_id: me.user_id}, + {id: me.user_id}, ], avatar_url: 'legacy.png', }; @@ -511,7 +511,7 @@ run_test('message_methods', () => { message = { type: 'private', display_recipient: [ - {user_id: me.user_id}, + {id: me.user_id}, ], }; assert.equal(people.pm_with_url(message), '#narrow/pm-with/30-me'); @@ -621,17 +621,14 @@ run_test('maybe_incr_recipient_count', () => { user_id: 452, full_name: 'Maria Athens', }; - people.add_in_realm(maria); - - const unknown_user = { - email: 'unknown@example.com', - user_id: 500, - unknown_local_echo_user: true, + const maria_recip = { + id: maria.user_id, }; + people.add_in_realm(maria); let message = { type: 'private', - display_recipient: [maria], + display_recipient: [maria_recip], sent_by_me: true, }; assert.equal(people.get_recipient_count(maria), 0); @@ -643,15 +640,21 @@ run_test('maybe_incr_recipient_count', () => { message = { type: 'private', sent_by_me: false, - display_recipient: [maria], + display_recipient: [maria_recip], }; people.maybe_incr_recipient_count(message); assert.equal(people.get_recipient_count(maria), 1); + const unknown_recip = { + email: 'unknown@example.com', + id: 500, + unknown_local_echo_user: true, + }; + message = { type: 'private', sent_by_me: true, - display_recipient: [unknown_user], + display_recipient: [unknown_recip], }; people.maybe_incr_recipient_count(message); assert.equal(people.get_recipient_count(maria), 1); diff --git a/frontend_tests/node_tests/people_errors.js b/frontend_tests/node_tests/people_errors.js index 9baedb7c09..2c78680145 100644 --- a/frontend_tests/node_tests/people_errors.js +++ b/frontend_tests/node_tests/people_errors.js @@ -106,7 +106,7 @@ run_test('blueslip', () => { display_recipient: [ {id: maria.user_id}, {id: 42}, - {user_id: charles.user_id}, + {id: charles.user_id}, ], sender_id: charles.user_id, }; diff --git a/frontend_tests/node_tests/transmit.js b/frontend_tests/node_tests/transmit.js index 277f02d467..a8e0b9d303 100644 --- a/frontend_tests/node_tests/transmit.js +++ b/frontend_tests/node_tests/transmit.js @@ -224,7 +224,7 @@ run_test('reply_message_private', () => { const pm_message = { type: 'private', display_recipient: [ - {user_id: fred.user_id}, + {id: fred.user_id}, ], }; diff --git a/frontend_tests/node_tests/unread.js b/frontend_tests/node_tests/unread.js index eb773a7b9c..c269cc698d 100644 --- a/frontend_tests/node_tests/unread.js +++ b/frontend_tests/node_tests/unread.js @@ -408,7 +408,7 @@ run_test('private_messages', () => { id: 15, type: 'private', display_recipient: [ - {user_id: anybody.user_id}, + {id: anybody.user_id}, {id: me.user_id}, ], unread: true, diff --git a/static/js/people.js b/static/js/people.js index 552004cc72..53719577c8 100644 --- a/static/js/people.js +++ b/static/js/people.js @@ -386,8 +386,8 @@ exports.all_user_ids_in_pm = function (message) { return; } - let user_ids = _.map(message.display_recipient, function (elem) { - return elem.user_id || elem.id; + let user_ids = _.map(message.display_recipient, function (recip) { + return recip.id; }); user_ids = sort_numerically(user_ids); @@ -404,8 +404,8 @@ exports.pm_with_user_ids = function (message) { return; } - const user_ids = _.map(message.display_recipient, function (elem) { - return elem.user_id || elem.id; + const user_ids = _.map(message.display_recipient, function (recip) { + return recip.id; }); return sorted_other_user_ids(user_ids); @@ -420,8 +420,9 @@ exports.group_pm_with_user_ids = function (message) { blueslip.error('Empty recipient list in message'); return; } - const user_ids = _.map(message.display_recipient, function (elem) { - return elem.user_id || elem.id; + + const user_ids = _.map(message.display_recipient, function (recip) { + return recip.id; }); const is_user_present = _.some(user_ids, function (user_id) { return exports.is_my_user_id(user_id); @@ -1047,13 +1048,13 @@ exports.maybe_incr_recipient_count = function (message) { } // Track the number of PMs we've sent to this person to improve autocomplete - _.each(message.display_recipient, function (person) { + _.each(message.display_recipient, function (recip) { - if (person.unknown_local_echo_user) { + if (recip.unknown_local_echo_user) { return; } - const user_id = person.user_id || person.id; + const user_id = recip.id; exports.incr_recipient_count(user_id); }); };