mirror of https://github.com/zulip/zulip.git
compose_box: Prepopulate stream if possible.
When users are only subbed to a single stream, this autofills the stream field of the compose box. Fixes #12507.
This commit is contained in:
parent
997fd714d1
commit
7a6f4630dc
|
@ -21,6 +21,7 @@ zrequire('compose');
|
|||
zrequire('util');
|
||||
zrequire('compose_state');
|
||||
zrequire('compose_actions');
|
||||
zrequire('stream_data');
|
||||
|
||||
set_global('document', 'document-stub');
|
||||
|
||||
|
@ -137,6 +138,52 @@ run_test('start', () => {
|
|||
assert.equal(compose_state.get_message_type(), 'stream');
|
||||
assert(compose_state.composing());
|
||||
|
||||
// Autofill stream field for single subscription
|
||||
var denmark = {
|
||||
subscribed: true,
|
||||
color: 'blue',
|
||||
name: 'Denmark',
|
||||
stream_id: 1,
|
||||
};
|
||||
stream_data.add_sub('Denmark', denmark);
|
||||
|
||||
global.narrow_state.set_compose_defaults = function () {
|
||||
var opts = {};
|
||||
opts.trigger = "new topic button";
|
||||
return opts;
|
||||
};
|
||||
|
||||
opts = {};
|
||||
start('stream', opts);
|
||||
assert.equal($('#stream_message_recipient_stream').val(), 'Denmark');
|
||||
assert.equal($('#stream_message_recipient_topic').val(), '');
|
||||
|
||||
global.narrow_state.set_compose_defaults = function () {
|
||||
var opts = {};
|
||||
opts.trigger = "compose_hotkey";
|
||||
return opts;
|
||||
};
|
||||
|
||||
opts = {};
|
||||
start('stream', opts);
|
||||
assert.equal($('#stream_message_recipient_stream').val(), 'Denmark');
|
||||
assert.equal($('#stream_message_recipient_topic').val(), '');
|
||||
|
||||
var social = {
|
||||
subscribed: true,
|
||||
color: 'red',
|
||||
name: 'social',
|
||||
stream_id: 2,
|
||||
};
|
||||
stream_data.add_sub('social', social);
|
||||
|
||||
// More than 1 subscription, do not autofill
|
||||
opts = {};
|
||||
start('stream', opts);
|
||||
assert.equal($('#stream_message_recipient_stream').val(), '');
|
||||
assert.equal($('#stream_message_recipient_topic').val(), '');
|
||||
stream_data.clear_subscriptions();
|
||||
|
||||
// Start PM
|
||||
global.narrow_state.set_compose_defaults = function () {
|
||||
var opts = {};
|
||||
|
|
|
@ -221,6 +221,11 @@ exports.start = function (msg_type, opts) {
|
|||
opts.private_message_recipient = '';
|
||||
}
|
||||
|
||||
var subbed_streams = stream_data.subscribed_subs();
|
||||
if (subbed_streams.length === 1 && (opts.trigger === "new topic button" || opts.trigger === "compose_hotkey" && msg_type === "stream")) {
|
||||
opts.stream = subbed_streams[0].name;
|
||||
}
|
||||
|
||||
if (compose_state.composing() && !same_recipient_as_before(msg_type, opts)) {
|
||||
// Clear the compose box if the existing message is to a different recipient
|
||||
clear_box();
|
||||
|
|
Loading…
Reference in New Issue