2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let message_type = false; // 'stream', 'private', or false-y
|
2017-04-15 01:15:59 +02:00
|
|
|
|
|
|
|
exports.set_message_type = function (msg_type) {
|
|
|
|
message_type = msg_type;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.get_message_type = function () {
|
|
|
|
return message_type;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.composing = function () {
|
2017-04-24 20:35:26 +02:00
|
|
|
// This is very similar to get_message_type(), but it returns
|
|
|
|
// a boolean.
|
2020-10-07 12:54:16 +02:00
|
|
|
return Boolean(message_type);
|
2017-04-15 01:15:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function get_or_set(fieldname, keep_leading_whitespace) {
|
|
|
|
// We can't hoist the assignment of 'elem' out of this lambda,
|
|
|
|
// because the DOM element might not exist yet when get_or_set
|
|
|
|
// is called.
|
|
|
|
return function (newval) {
|
2021-02-03 23:23:32 +01:00
|
|
|
const elem = $(`#${CSS.escape(fieldname)}`);
|
2019-11-02 00:06:25 +01:00
|
|
|
const oldval = elem.val();
|
2017-04-15 01:15:59 +02:00
|
|
|
if (newval !== undefined) {
|
|
|
|
elem.val(newval);
|
|
|
|
}
|
2020-10-07 11:55:58 +02:00
|
|
|
return keep_leading_whitespace ? oldval.trimEnd() : oldval.trim();
|
2017-04-15 01:15:59 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Break out setters and getter into their own functions.
|
2020-07-16 23:29:01 +02:00
|
|
|
exports.stream_name = get_or_set("stream_message_recipient_stream");
|
|
|
|
exports.topic = get_or_set("stream_message_recipient_topic");
|
2017-11-26 20:37:44 +01:00
|
|
|
// We can't trim leading whitespace in `compose_textarea` because
|
2017-04-15 01:15:59 +02:00
|
|
|
// of the indented syntax for multi-line code blocks.
|
2020-07-15 01:29:15 +02:00
|
|
|
exports.message_content = get_or_set("compose-textarea", true);
|
2021-02-27 18:19:48 +01:00
|
|
|
|
|
|
|
exports.focus_in_empty_compose = function () {
|
|
|
|
return (
|
|
|
|
exports.composing() &&
|
|
|
|
exports.message_content() === "" &&
|
|
|
|
$("#compose-textarea").is(":focus")
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-12-02 17:53:55 +01:00
|
|
|
exports.private_message_recipient = function (value) {
|
2018-03-06 15:07:55 +01:00
|
|
|
if (typeof value === "string") {
|
|
|
|
compose_pm_pill.set_from_emails(value);
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2018-03-06 15:07:55 +01:00
|
|
|
}
|
2020-09-24 07:50:36 +02:00
|
|
|
return compose_pm_pill.get_emails();
|
2018-03-06 15:07:55 +01:00
|
|
|
};
|
2017-04-15 01:15:59 +02:00
|
|
|
|
|
|
|
exports.has_message_content = function () {
|
|
|
|
return exports.message_content() !== "";
|
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.compose_state = exports;
|