compose: Distinguish get_message_type() from composing().

We now only call compose_state.composing() in a boolean context,
where we simply care whether or not the compose box is open.  The
function now also returns true/false.

Callers who need to know the actual message type (e.g. "stream" or
"private") now call compose_state.get_message_type().
This commit is contained in:
Steve Howell
2017-04-24 11:35:26 -07:00
committed by Tim Abbott
parent 2adf641b72
commit c999bdf823
8 changed files with 18 additions and 19 deletions

View File

@@ -67,7 +67,7 @@ people.add(bob);
}; };
}; };
global.compose_state.composing = function () { global.compose_state.get_message_type = function () {
return 'stream'; return 'stream';
}; };
@@ -81,7 +81,7 @@ people.add(bob);
assert.equal(message.subject, 'lunch'); assert.equal(message.subject, 'lunch');
assert.equal(message.content, 'burrito'); assert.equal(message.content, 'burrito');
global.compose_state.composing = function () { global.compose_state.get_message_type = function () {
return 'private'; return 'private';
}; };
message = compose.create_message_object(); message = compose.create_message_object();

View File

@@ -99,9 +99,12 @@ var draft_2 = {
(function test_snapshot_message() { (function test_snapshot_message() {
function stub_draft(draft) { function stub_draft(draft) {
global.compose_state.composing = function () { global.compose_state.get_message_type = function () {
return draft.type; return draft.type;
}; };
global.compose_state.composing = function () {
return !!draft.type;
};
global.compose_state.message_content = function () { global.compose_state.message_content = function () {
return draft.content; return draft.content;
}; };

View File

@@ -126,7 +126,7 @@ function create_message_object() {
// Changes here must also be kept in sync with echo.try_deliver_locally // Changes here must also be kept in sync with echo.try_deliver_locally
var message = { var message = {
type: compose_state.composing(), type: compose_state.get_message_type(),
content: content, content: content,
sender_id: page_params.user_id, sender_id: page_params.user_id,
queue_id: page_params.event_queue_id, queue_id: page_params.event_queue_id,
@@ -591,7 +591,7 @@ exports.validate = function () {
return false; return false;
} }
if (compose_state.composing() === 'private') { if (compose_state.get_message_type() === 'private') {
return validate_private_message(); return validate_private_message();
} }
return validate_stream_message(); return validate_stream_message();

View File

@@ -169,7 +169,7 @@ function fill_in_opts_from_current_narrowed_view(msg_type, opts) {
} }
function same_recipient_as_before(msg_type, opts) { function same_recipient_as_before(msg_type, opts) {
return (compose_state.composing() === msg_type) && return (compose_state.get_message_type() === msg_type) &&
((msg_type === "stream" && ((msg_type === "stream" &&
opts.stream === compose_state.stream_name() && opts.stream === compose_state.stream_name() &&
opts.subject === compose_state.subject()) || opts.subject === compose_state.subject()) ||

View File

@@ -13,14 +13,9 @@ exports.get_message_type = function () {
}; };
exports.composing = function () { exports.composing = function () {
// For legacy reasons, this is the same as get_message_type. // This is very similar to get_message_type(), but it returns
// Most callers use this in a boolean context, but there are // a boolean.
// some stragglers that inspect the string value. return !!message_type;
//
// TODO: Fix callers who care about stream/private to use
// get_message_type(), and then convert this to return
// `!!message_type` or something like that.
return message_type;
}; };
function get_or_set(fieldname, keep_leading_whitespace) { function get_or_set(fieldname, keep_leading_whitespace) {

View File

@@ -72,7 +72,7 @@ exports.snapshot_message = function () {
// Save what we can. // Save what we can.
var message = { var message = {
type: compose_state.composing(), type: compose_state.get_message_type(),
content: compose_state.message_content(), content: compose_state.message_content(),
}; };
if (message.type === "private") { if (message.type === "private") {

View File

@@ -22,16 +22,17 @@ function preserve_state(send_after_reload, save_pointer, save_narrow, save_compo
url += "+csrf_token=" + encodeURIComponent(csrf_token); url += "+csrf_token=" + encodeURIComponent(csrf_token);
if (save_compose) { if (save_compose) {
if (compose_state.composing() === 'stream') { var msg_type = compose_state.get_message_type();
if (msg_type === 'stream') {
url += "+msg_type=stream"; url += "+msg_type=stream";
url += "+stream=" + encodeURIComponent(compose_state.stream_name()); url += "+stream=" + encodeURIComponent(compose_state.stream_name());
url += "+subject=" + encodeURIComponent(compose_state.subject()); url += "+subject=" + encodeURIComponent(compose_state.subject());
} else if (compose_state.composing() === 'private') { } else if (msg_type === 'private') {
url += "+msg_type=private"; url += "+msg_type=private";
url += "+recipient=" + encodeURIComponent(compose_state.recipient()); url += "+recipient=" + encodeURIComponent(compose_state.recipient());
} }
if (compose_state.composing()) { if (msg_type) {
url += "+msg=" + encodeURIComponent(compose_state.message_content()); url += "+msg=" + encodeURIComponent(compose_state.message_content());
} }
} }

View File

@@ -39,7 +39,7 @@ function is_valid_conversation(recipient) {
return false; return false;
} }
if (compose_state.composing() !== 'private') { if (compose_state.get_message_type() !== 'private') {
// We only use typing indicators in PMs for now. // We only use typing indicators in PMs for now.
// There was originally some support for having // There was originally some support for having
// typing indicators related to stream conversations, // typing indicators related to stream conversations,