Add recipient() and composing() shims.

This commit is contained in:
Steve Howell
2017-03-18 10:48:43 -07:00
committed by Tim Abbott
parent 27f37e6378
commit 16a37754cf
9 changed files with 31 additions and 27 deletions

View File

@@ -18,6 +18,10 @@ add_dependencies({
var compose = require('js/compose.js'); var compose = require('js/compose.js');
set_global('compose_state', {
recipient: compose.recipient,
});
var me = { var me = {
email: 'me@example.com', email: 'me@example.com',
user_id: 30, user_id: 30,
@@ -66,7 +70,7 @@ people.add(bob);
}; };
}; };
compose.composing = function () { global.compose_state.composing = function () {
return 'stream'; return 'stream';
}; };
@@ -80,7 +84,7 @@ people.add(bob);
assert.equal(message.subject, 'lunch'); assert.equal(message.subject, 'lunch');
assert.equal(message.content, 'burrito'); assert.equal(message.content, 'burrito');
compose.composing = function () { global.compose_state.composing = function () {
return 'private'; return 'private';
}; };
message = compose.snapshot_message(); message = compose.snapshot_message();

View File

@@ -560,7 +560,7 @@ $(function () {
// Unfocus our compose area if we click out of it. Don't let exits out // Unfocus our compose area if we click out of it. Don't let exits out
// of modals or selecting text (for copy+paste) trigger cancelling. // of modals or selecting text (for copy+paste) trigger cancelling.
if (compose.composing() && !$(e.target).is("a") && if (compose_state.composing() && !$(e.target).is("a") &&
($(e.target).closest(".modal").length === 0) && ($(e.target).closest(".modal").length === 0) &&
window.getSelection().toString() === "" && window.getSelection().toString() === "" &&
($(e.target).closest('#emoji_map').length === 0)) { ($(e.target).closest('#emoji_map').length === 0)) {

View File

@@ -201,12 +201,12 @@ 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.composing() === msg_type) && return (compose_state.composing() === msg_type) &&
((msg_type === "stream" && ((msg_type === "stream" &&
opts.stream === compose.stream_name() && opts.stream === compose.stream_name() &&
opts.subject === compose.subject()) || opts.subject === compose.subject()) ||
(msg_type === "private" && (msg_type === "private" &&
opts.private_message_recipient === compose.recipient())); opts.private_message_recipient === compose_state.recipient()));
} }
function show_box_for_msg_type(msg_type, opts) { function show_box_for_msg_type(msg_type, opts) {
@@ -245,7 +245,7 @@ exports.start = function (msg_type, opts) {
opts.private_message_recipient = ''; opts.private_message_recipient = '';
} }
if (compose.composing() && !same_recipient_as_before(msg_type, opts)) { 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 the compose box if the existing message is to a different recipient
clear_box(); clear_box();
} }
@@ -254,7 +254,7 @@ exports.start = function (msg_type, opts) {
compose.subject(opts.subject); compose.subject(opts.subject);
// Set the recipients with a space after each comma, so it looks nice. // Set the recipients with a space after each comma, so it looks nice.
compose.recipient(opts.private_message_recipient.replace(/,\s*/g, ", ")); compose_state.recipient(opts.private_message_recipient.replace(/,\s*/g, ", "));
// If the user opens the compose box, types some text, and then clicks on a // If the user opens the compose box, types some text, and then clicks on a
// different stream/subject, we want to keep the text in the compose box // different stream/subject, we want to keep the text in the compose box
@@ -329,7 +329,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.composing(), type: compose_state.composing(),
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,
@@ -339,7 +339,7 @@ function create_message_object() {
if (message.type === "private") { if (message.type === "private") {
// TODO: this should be collapsed with the code in composebox_typeahead.js // TODO: this should be collapsed with the code in composebox_typeahead.js
var recipient = compose.recipient(); var recipient = compose_state.recipient();
var emails = util.extract_pm_recipients(recipient); var emails = util.extract_pm_recipients(recipient);
message.to = emails; message.to = emails;
message.reply_to = recipient; message.reply_to = recipient;
@@ -359,7 +359,7 @@ function create_message_object() {
} }
exports.snapshot_message = function () { exports.snapshot_message = function () {
if (!exports.composing() || (exports.message_content() === "")) { if (!compose_state.composing() || (exports.message_content() === "")) {
// If you aren't in the middle of composing the body of a // If you aren't in the middle of composing the body of a
// message, don't try to snapshot. // message, don't try to snapshot.
return; return;
@@ -833,7 +833,7 @@ function validate_private_message() {
// For Zephyr mirroring realms, the frontend doesn't know which users exist // For Zephyr mirroring realms, the frontend doesn't know which users exist
return true; return true;
} }
var private_recipients = util.extract_pm_recipients(compose.recipient()); var private_recipients = util.extract_pm_recipients(compose_state.recipient());
var invalid_recipients = []; var invalid_recipients = [];
var context = {}; var context = {};
_.each(private_recipients, function (email) { _.each(private_recipients, function (email) {
@@ -1160,7 +1160,7 @@ $(function () {
var filename = split_uri[split_uri.length - 1]; var filename = split_uri[split_uri.length - 1];
// Urgh, yet another hack to make sure we're "composing" // Urgh, yet another hack to make sure we're "composing"
// when text gets added into the composebox. // when text gets added into the composebox.
if (!compose.composing()) { if (!compose_state.composing()) {
compose_actions.start('stream'); compose_actions.start('stream');
} }
@@ -1211,7 +1211,7 @@ $(function () {
uploadFinished: uploadFinished, uploadFinished: uploadFinished,
rawDrop: function (contents) { rawDrop: function (contents) {
var textbox = $("#new_message_content"); var textbox = $("#new_message_content");
if (!compose.composing()) { if (!compose_state.composing()) {
compose_actions.start('stream'); compose_actions.start('stream');
} }
textbox.val(textbox.val() + contents); textbox.val(textbox.val() + contents);

View File

@@ -81,8 +81,8 @@ function _fade_messages() {
var all_groups = rows.get_table(current_msg_list.table_name).find(".recipient_row"); var all_groups = rows.get_table(current_msg_list.table_name).find(".recipient_row");
if (current_msg_list !== expected_msg_list || if (current_msg_list !== expected_msg_list ||
!compose.composing() || !compose_state.composing() ||
compose.recipient() !== expected_recipient) { compose_state.recipient() !== expected_recipient) {
return; return;
} }
@@ -97,7 +97,7 @@ function _fade_messages() {
} }
floating_recipient_bar.update(); floating_recipient_bar.update();
}, 0, current_msg_list, compose.recipient()); }, 0, current_msg_list, compose_state.recipient());
} }
exports.would_receive_message = function (email) { exports.would_receive_message = function (email) {

View File

@@ -10,7 +10,7 @@ function do_narrow_action(action) {
function focus_in_empty_compose() { function focus_in_empty_compose() {
return ( return (
compose.composing() && compose_state.composing() &&
compose.message_content() === "" && compose.message_content() === "" &&
$('#new_message_content').is(':focus')); $('#new_message_content').is(':focus'));
} }
@@ -217,7 +217,7 @@ exports.process_escape_key = function (e) {
return true; return true;
} }
if (compose.composing()) { if (compose_state.composing()) {
// If the user hit the escape key, cancel the current compose // If the user hit the escape key, cancel the current compose
compose_actions.cancel(); compose_actions.cancel();
return true; return true;
@@ -235,7 +235,7 @@ exports.process_escape_key = function (e) {
return true; return true;
} }
if (compose.composing()) { if (compose_state.composing()) {
compose_actions.cancel(); compose_actions.cancel();
return true; return true;
} }

View File

@@ -21,16 +21,16 @@ 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.composing() === 'stream') { if (compose_state.composing() === 'stream') {
url += "+msg_type=stream"; url += "+msg_type=stream";
url += "+stream=" + encodeURIComponent(compose.stream_name()); url += "+stream=" + encodeURIComponent(compose.stream_name());
url += "+subject=" + encodeURIComponent(compose.subject()); url += "+subject=" + encodeURIComponent(compose.subject());
} else if (compose.composing() === 'private') { } else if (compose_state.composing() === 'private') {
url += "+msg_type=private"; url += "+msg_type=private";
url += "+recipient=" + encodeURIComponent(compose.recipient()); url += "+recipient=" + encodeURIComponent(compose_state.recipient());
} }
if (compose.composing()) { if (compose_state.composing()) {
url += "+msg=" + encodeURIComponent(compose.message_content()); url += "+msg=" + encodeURIComponent(compose.message_content());
} }
} }
@@ -261,7 +261,7 @@ exports.initiate = function (options) {
compose_done_handler); compose_done_handler);
}; };
if (compose.composing()) { if (compose_state.composing()) {
idle_control = $(document).idle({idle: composing_timeout, idle_control = $(document).idle({idle: composing_timeout,
onIdle: reload_from_idle}); onIdle: reload_from_idle});
$(document).on('compose_canceled.zulip compose_finished.zulip', $(document).on('compose_canceled.zulip compose_finished.zulip',

View File

@@ -18,3 +18,5 @@ hash_util.encodeHashComponent = hashchange.encodeHashComponent;
var compose_state = {}; var compose_state = {};
compose_state.has_message_content = compose.has_message_content; compose_state.has_message_content = compose.has_message_content;
compose_state.recipient = compose.recipient;
compose_state.composing = compose.composing;

View File

@@ -35,7 +35,7 @@ function send_typing_notification_ajax(recipients, operation) {
} }
function check_and_send(operation) { function check_and_send(operation) {
var compose_recipient = compose.recipient(); var compose_recipient = compose_state.recipient();
var compose_nonempty = compose_state.has_message_content(); var compose_nonempty = compose_state.has_message_content();
// If we currently have an active typing notification out, and we // If we currently have an active typing notification out, and we

View File

@@ -105,9 +105,7 @@ ignore_modules = [
'ui', # initializes all the other widgets 'ui', # initializes all the other widgets
# some are just not very core: # some are just not very core:
'compose_fade',
'drafts', 'drafts',
'message_edit',
'notifications', 'notifications',
'stream_popover', 'stream_popover',
] ]