compose: Use new ID-based api for sending messages.

This only happens if the realm is not a zephyr realm.

Finishes part of #9474.
This commit is contained in:
Priyank Patel 2019-05-23 20:18:58 +00:00 committed by Tim Abbott
parent eed09527d5
commit 3f32ffc4eb
2 changed files with 23 additions and 3 deletions

View File

@ -607,13 +607,14 @@ run_test('send_message', () => {
queue_id: undefined,
stream: '',
topic: '',
to: '["alice@example.com"]',
to: `[${alice.user_id}]`,
reply_to: 'alice@example.com',
private_message_recipient: 'alice@example.com',
to_user_ids: '31',
local_id: 1,
locally_echoed: true,
};
assert.deepEqual(payload, single_msg);
payload.id = stub_state.local_id_counter;
success(payload);
@ -1672,14 +1673,19 @@ run_test('create_message_object', () => {
return 'private';
};
compose_state.recipient = function () {
return 'alice@example.com, bob@example.com';
return 'alice@example.com, bob@example.com';
};
message = compose.create_message_object();
assert.deepEqual(message.to, ['alice@example.com', 'bob@example.com']);
assert.deepEqual(message.to, [alice.user_id, bob.user_id]);
assert.equal(message.to_user_ids, '31,32');
assert.equal(message.content, 'burrito');
var { email_list_to_user_ids_string } = people;
people.email_list_to_user_ids_string = () => undefined;
message = compose.create_message_object();
assert.deepEqual(message.to, [alice.email, bob.email]);
people.email_list_to_user_ids_string = email_list_to_user_ids_string;
});
run_test('nonexistent_stream_reply_error', () => {

View File

@ -179,6 +179,20 @@ function create_message_object() {
message.reply_to = recipient;
message.private_message_recipient = recipient;
message.to_user_ids = people.email_list_to_user_ids_string(emails);
// Note: The `undefined` case is for situations like the
// is_zephyr_mirror_realm case where users may be
// automatically created when you try to send a private
// message to their email address.
if (message.to_user_ids !== undefined) {
// to_user_ids is a string containing a comma-separated
// list of user IDs for the recipients; convert this into
// an array of integers.
message.to = _.map(message.to_user_ids.split(','), function (id) {
return Number(id);
});
}
} else {
var stream_name = compose_state.stream_name();
message.to = stream_name;