mirror of
https://github.com/zulip/zulip.git
synced 2026-07-12 21:04:41 +08:00
Fill in default recipient when composing while narrowed
Fixes #977. (imported from commit 1abe26d94d5179a3dd1e970224a36c63bba9ff48)
This commit is contained in:
parent
bfbdb94ecf
commit
ac1c111489
@ -129,11 +129,17 @@ exports.start = function (msg_type, opts) {
|
||||
|
||||
compose.clear();
|
||||
|
||||
opts = $.extend({ message_type: msg_type,
|
||||
stream: '',
|
||||
subject: '',
|
||||
private_message_recipient: ''
|
||||
}, opts);
|
||||
var default_opts = {
|
||||
message_type: msg_type,
|
||||
stream: '',
|
||||
subject: '',
|
||||
private_message_recipient: ''
|
||||
};
|
||||
|
||||
// Set default parameters based on the current narrowed view.
|
||||
narrow.set_compose_defaults(default_opts);
|
||||
|
||||
opts = $.extend(default_opts, opts);
|
||||
|
||||
compose.stream_name(opts.stream);
|
||||
compose.subject(opts.subject);
|
||||
|
||||
@ -99,6 +99,43 @@ exports.describe = function (operators) {
|
||||
}).join(', ');
|
||||
};
|
||||
|
||||
// Collect operators which appear only once into an object,
|
||||
// and discard those which appear more than once.
|
||||
function collect_single(operators) {
|
||||
var seen = {};
|
||||
var result = {};
|
||||
$.each(operators, function (index, elem) {
|
||||
var key = elem[0];
|
||||
if (seen.hasOwnProperty(key)) {
|
||||
delete result[key];
|
||||
} else {
|
||||
result[key] = elem[1];
|
||||
seen [key] = true;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
// Modify default compose parameters (stream etc.) based on
|
||||
// the current narrowed view.
|
||||
//
|
||||
// This logic is here and not in the 'compose' module because
|
||||
// it will get more complicated as we add things to the narrow
|
||||
// operator language.
|
||||
exports.set_compose_defaults = function (opts) {
|
||||
var single = collect_single(exports.operators());
|
||||
|
||||
// Set the stream, subject, and/or PM recipient if they are
|
||||
// uniquely specified in the narrow view.
|
||||
$.each(['stream', 'subject'], function (idx, key) {
|
||||
if (single[key] !== undefined)
|
||||
opts[key] = single[key];
|
||||
});
|
||||
|
||||
if (single['pm-with'] !== undefined)
|
||||
opts.private_message_recipient = single['pm-with'];
|
||||
};
|
||||
|
||||
// Parse a string into a list of operators (see below).
|
||||
exports.parse = function (str) {
|
||||
var operators = [];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user