diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.js index 48d2bcd26c..5f66f88d8e 100644 --- a/frontend_tests/node_tests/compose.js +++ b/frontend_tests/node_tests/compose.js @@ -1,8 +1,6 @@ set_global('bridge', false); -set_global('blueslip', global.make_zblueslip({ - error: false, // Ignore errors. We only check for warnings in this module. -})); +set_global('blueslip', global.make_zblueslip({})); const noop = function () {}; @@ -876,6 +874,7 @@ function test_raw_file_drop(raw_drop_func) { run_test('warn_if_private_stream_is_linked', () => { stream_data.add_sub(compose_state.stream_name(), { subscribers: new LazySet([1, 2]), + stream_id: 99, }); let denmark = { @@ -1660,7 +1659,15 @@ run_test('create_message_object', () => { let message = compose.create_message_object(); - assert.equal(message.to, 'social'); + assert.equal(message.to, sub.stream_id); + assert.equal(message.topic, 'lunch'); + assert.equal(message.content, 'burrito'); + + blueslip.set_test_data('error', 'Trying to send message with bad stream name: BOGUS STREAM'); + + page['#stream_message_recipient_stream'] = 'BOGUS STREAM'; + message = compose.create_message_object(); + assert.equal(message.to, 'BOGUS STREAM'); assert.equal(message.topic, 'lunch'); assert.equal(message.content, 'burrito'); diff --git a/static/js/compose.js b/static/js/compose.js index 8864c07336..ebdaa44576 100644 --- a/static/js/compose.js +++ b/static/js/compose.js @@ -195,11 +195,19 @@ function create_message_object() { } else { const stream_name = compose_state.stream_name(); - message.to = stream_name; message.stream = stream_name; const sub = stream_data.get_sub(stream_name); if (sub) { message.stream_id = sub.stream_id; + message.to = sub.stream_id; + } else { + // We should be validating streams in calling code. We'll + // try to fall back to stream_name here just in case the + // user started composing to the old stream name and + // manually entered the stream name, and it got past + // validation. We should try to kill this code off eventually. + blueslip.error('Trying to send message with bad stream name: ' + stream_name); + message.to = stream_name; } util.set_message_topic(message, topic); }