mirror of
https://github.com/zulip/zulip.git
synced 2025-11-07 15:33:30 +00:00
Add recipient() and composing() shims.
This commit is contained in:
@@ -18,6 +18,10 @@ add_dependencies({
|
||||
|
||||
var compose = require('js/compose.js');
|
||||
|
||||
set_global('compose_state', {
|
||||
recipient: compose.recipient,
|
||||
});
|
||||
|
||||
var me = {
|
||||
email: 'me@example.com',
|
||||
user_id: 30,
|
||||
@@ -66,7 +70,7 @@ people.add(bob);
|
||||
};
|
||||
};
|
||||
|
||||
compose.composing = function () {
|
||||
global.compose_state.composing = function () {
|
||||
return 'stream';
|
||||
};
|
||||
|
||||
@@ -80,7 +84,7 @@ people.add(bob);
|
||||
assert.equal(message.subject, 'lunch');
|
||||
assert.equal(message.content, 'burrito');
|
||||
|
||||
compose.composing = function () {
|
||||
global.compose_state.composing = function () {
|
||||
return 'private';
|
||||
};
|
||||
message = compose.snapshot_message();
|
||||
|
||||
@@ -560,7 +560,7 @@ $(function () {
|
||||
|
||||
// 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.
|
||||
if (compose.composing() && !$(e.target).is("a") &&
|
||||
if (compose_state.composing() && !$(e.target).is("a") &&
|
||||
($(e.target).closest(".modal").length === 0) &&
|
||||
window.getSelection().toString() === "" &&
|
||||
($(e.target).closest('#emoji_map').length === 0)) {
|
||||
|
||||
@@ -201,12 +201,12 @@ function fill_in_opts_from_current_narrowed_view(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" &&
|
||||
opts.stream === compose.stream_name() &&
|
||||
opts.subject === compose.subject()) ||
|
||||
(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) {
|
||||
@@ -245,7 +245,7 @@ exports.start = function (msg_type, opts) {
|
||||
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_box();
|
||||
}
|
||||
@@ -254,7 +254,7 @@ exports.start = function (msg_type, opts) {
|
||||
compose.subject(opts.subject);
|
||||
|
||||
// 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
|
||||
// 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
|
||||
var message = {
|
||||
type: compose.composing(),
|
||||
type: compose_state.composing(),
|
||||
content: content,
|
||||
sender_id: page_params.user_id,
|
||||
queue_id: page_params.event_queue_id,
|
||||
@@ -339,7 +339,7 @@ function create_message_object() {
|
||||
|
||||
if (message.type === "private") {
|
||||
// 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);
|
||||
message.to = emails;
|
||||
message.reply_to = recipient;
|
||||
@@ -359,7 +359,7 @@ function create_message_object() {
|
||||
}
|
||||
|
||||
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
|
||||
// message, don't try to snapshot.
|
||||
return;
|
||||
@@ -833,7 +833,7 @@ function validate_private_message() {
|
||||
// For Zephyr mirroring realms, the frontend doesn't know which users exist
|
||||
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 context = {};
|
||||
_.each(private_recipients, function (email) {
|
||||
@@ -1160,7 +1160,7 @@ $(function () {
|
||||
var filename = split_uri[split_uri.length - 1];
|
||||
// Urgh, yet another hack to make sure we're "composing"
|
||||
// when text gets added into the composebox.
|
||||
if (!compose.composing()) {
|
||||
if (!compose_state.composing()) {
|
||||
compose_actions.start('stream');
|
||||
}
|
||||
|
||||
@@ -1211,7 +1211,7 @@ $(function () {
|
||||
uploadFinished: uploadFinished,
|
||||
rawDrop: function (contents) {
|
||||
var textbox = $("#new_message_content");
|
||||
if (!compose.composing()) {
|
||||
if (!compose_state.composing()) {
|
||||
compose_actions.start('stream');
|
||||
}
|
||||
textbox.val(textbox.val() + contents);
|
||||
|
||||
@@ -81,8 +81,8 @@ function _fade_messages() {
|
||||
var all_groups = rows.get_table(current_msg_list.table_name).find(".recipient_row");
|
||||
|
||||
if (current_msg_list !== expected_msg_list ||
|
||||
!compose.composing() ||
|
||||
compose.recipient() !== expected_recipient) {
|
||||
!compose_state.composing() ||
|
||||
compose_state.recipient() !== expected_recipient) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ function _fade_messages() {
|
||||
}
|
||||
|
||||
floating_recipient_bar.update();
|
||||
}, 0, current_msg_list, compose.recipient());
|
||||
}, 0, current_msg_list, compose_state.recipient());
|
||||
}
|
||||
|
||||
exports.would_receive_message = function (email) {
|
||||
|
||||
@@ -10,7 +10,7 @@ function do_narrow_action(action) {
|
||||
|
||||
function focus_in_empty_compose() {
|
||||
return (
|
||||
compose.composing() &&
|
||||
compose_state.composing() &&
|
||||
compose.message_content() === "" &&
|
||||
$('#new_message_content').is(':focus'));
|
||||
}
|
||||
@@ -217,7 +217,7 @@ exports.process_escape_key = function (e) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (compose.composing()) {
|
||||
if (compose_state.composing()) {
|
||||
// If the user hit the escape key, cancel the current compose
|
||||
compose_actions.cancel();
|
||||
return true;
|
||||
@@ -235,7 +235,7 @@ exports.process_escape_key = function (e) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (compose.composing()) {
|
||||
if (compose_state.composing()) {
|
||||
compose_actions.cancel();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -21,16 +21,16 @@ function preserve_state(send_after_reload, save_pointer, save_narrow, save_compo
|
||||
url += "+csrf_token=" + encodeURIComponent(csrf_token);
|
||||
|
||||
if (save_compose) {
|
||||
if (compose.composing() === 'stream') {
|
||||
if (compose_state.composing() === 'stream') {
|
||||
url += "+msg_type=stream";
|
||||
url += "+stream=" + encodeURIComponent(compose.stream_name());
|
||||
url += "+subject=" + encodeURIComponent(compose.subject());
|
||||
} else if (compose.composing() === 'private') {
|
||||
} else if (compose_state.composing() === '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());
|
||||
}
|
||||
}
|
||||
@@ -261,7 +261,7 @@ exports.initiate = function (options) {
|
||||
compose_done_handler);
|
||||
};
|
||||
|
||||
if (compose.composing()) {
|
||||
if (compose_state.composing()) {
|
||||
idle_control = $(document).idle({idle: composing_timeout,
|
||||
onIdle: reload_from_idle});
|
||||
$(document).on('compose_canceled.zulip compose_finished.zulip',
|
||||
|
||||
@@ -18,3 +18,5 @@ hash_util.encodeHashComponent = hashchange.encodeHashComponent;
|
||||
|
||||
var compose_state = {};
|
||||
compose_state.has_message_content = compose.has_message_content;
|
||||
compose_state.recipient = compose.recipient;
|
||||
compose_state.composing = compose.composing;
|
||||
|
||||
@@ -35,7 +35,7 @@ function send_typing_notification_ajax(recipients, 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();
|
||||
|
||||
// If we currently have an active typing notification out, and we
|
||||
|
||||
@@ -105,9 +105,7 @@ ignore_modules = [
|
||||
'ui', # initializes all the other widgets
|
||||
|
||||
# some are just not very core:
|
||||
'compose_fade',
|
||||
'drafts',
|
||||
'message_edit',
|
||||
'notifications',
|
||||
'stream_popover',
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user