2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
2021-02-28 00:51:57 +01:00
|
|
|
import _ from "lodash";
|
|
|
|
|
2021-04-14 13:10:34 +02:00
|
|
|
import render_compose from "../templates/compose.hbs";
|
2021-02-28 00:51:57 +01:00
|
|
|
import render_compose_all_everyone from "../templates/compose_all_everyone.hbs";
|
|
|
|
import render_compose_announce from "../templates/compose_announce.hbs";
|
|
|
|
import render_compose_invite_users from "../templates/compose_invite_users.hbs";
|
|
|
|
import render_compose_not_subscribed from "../templates/compose_not_subscribed.hbs";
|
|
|
|
import render_compose_private_stream_alert from "../templates/compose_private_stream_alert.hbs";
|
|
|
|
|
2021-03-16 23:38:59 +01:00
|
|
|
import * as blueslip from "./blueslip";
|
2021-02-28 00:51:57 +01:00
|
|
|
import * as channel from "./channel";
|
|
|
|
import * as common from "./common";
|
2021-02-28 21:32:22 +01:00
|
|
|
import * as compose_actions from "./compose_actions";
|
2021-02-28 00:51:57 +01:00
|
|
|
import * as compose_fade from "./compose_fade";
|
|
|
|
import * as compose_pm_pill from "./compose_pm_pill";
|
|
|
|
import * as compose_state from "./compose_state";
|
2021-02-28 01:26:48 +01:00
|
|
|
import * as compose_ui from "./compose_ui";
|
2021-02-28 00:51:57 +01:00
|
|
|
import * as drafts from "./drafts";
|
|
|
|
import * as echo from "./echo";
|
2021-04-13 06:51:54 +02:00
|
|
|
import {$t, $t_html} from "./i18n";
|
2021-02-28 00:51:57 +01:00
|
|
|
import * as loading from "./loading";
|
|
|
|
import * as markdown from "./markdown";
|
2021-02-28 01:06:34 +01:00
|
|
|
import * as notifications from "./notifications";
|
2021-03-25 22:35:45 +01:00
|
|
|
import {page_params} from "./page_params";
|
2021-02-28 00:51:57 +01:00
|
|
|
import * as peer_data from "./peer_data";
|
|
|
|
import * as people from "./people";
|
2021-02-28 01:16:59 +01:00
|
|
|
import * as reminder from "./reminder";
|
2021-02-28 00:51:57 +01:00
|
|
|
import * as rendered_markdown from "./rendered_markdown";
|
2021-02-28 00:57:20 +01:00
|
|
|
import * as resize from "./resize";
|
2021-04-21 15:46:11 +02:00
|
|
|
import * as rows from "./rows";
|
2021-02-28 00:51:57 +01:00
|
|
|
import * as rtl from "./rtl";
|
|
|
|
import * as sent_messages from "./sent_messages";
|
2021-02-28 01:11:47 +01:00
|
|
|
import * as server_events from "./server_events";
|
2021-02-28 00:51:57 +01:00
|
|
|
import * as settings_config from "./settings_config";
|
2021-02-28 00:53:59 +01:00
|
|
|
import * as stream_data from "./stream_data";
|
2021-02-28 00:55:38 +01:00
|
|
|
import * as stream_edit from "./stream_edit";
|
2021-04-15 17:02:54 +02:00
|
|
|
import * as sub_store from "./sub_store";
|
2021-02-28 21:32:47 +01:00
|
|
|
import * as subs from "./subs";
|
2021-02-28 00:51:57 +01:00
|
|
|
import * as transmit from "./transmit";
|
2021-02-28 00:58:55 +01:00
|
|
|
import * as ui_report from "./ui_report";
|
2021-02-28 00:52:20 +01:00
|
|
|
import * as upload from "./upload";
|
2021-02-28 00:51:57 +01:00
|
|
|
import * as util from "./util";
|
|
|
|
import * as zcommand from "./zcommand";
|
2020-07-24 06:02:07 +02:00
|
|
|
|
2018-11-30 00:48:13 +01:00
|
|
|
// Docs: https://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html
|
2012-10-03 22:53:15 +02:00
|
|
|
|
2016-12-02 15:16:33 +01:00
|
|
|
/* Track the state of the @all warning. The user must acknowledge that they are spamming the entire
|
|
|
|
stream before the warning will go away. If they try to send before explicitly dismissing the
|
|
|
|
warning, they will get an error message too.
|
|
|
|
|
|
|
|
undefined: no @all/@everyone in message;
|
|
|
|
false: user typed @all/@everyone;
|
|
|
|
true: user clicked YES */
|
2016-11-09 19:34:07 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let user_acknowledged_all_everyone;
|
|
|
|
let user_acknowledged_announce;
|
2020-01-23 07:22:26 +01:00
|
|
|
let wildcard_mention;
|
2019-11-21 05:24:55 +01:00
|
|
|
let uppy;
|
2016-06-04 04:31:35 +02:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export let wildcard_mention_large_stream_threshold = 15;
|
|
|
|
export const announce_warn_threshold = 60;
|
|
|
|
export const uploads_domain = document.location.protocol + "//" + document.location.host;
|
|
|
|
export const uploads_path = "/user_uploads";
|
2016-11-09 19:34:07 +01:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export const uploads_re = new RegExp(
|
|
|
|
"\\]\\(" + uploads_domain + "(" + uploads_path + "[^\\)]+)\\)",
|
2020-07-15 00:34:28 +02:00
|
|
|
"g",
|
|
|
|
);
|
2017-11-28 06:26:39 +01:00
|
|
|
|
2013-10-23 16:46:18 +02:00
|
|
|
function make_uploads_relative(content) {
|
2020-08-11 01:47:49 +02:00
|
|
|
// Rewrite uploads in Markdown links back to domain-relative form
|
2021-02-28 00:51:57 +01:00
|
|
|
return content.replace(uploads_re, "]($1)");
|
2013-10-23 16:46:18 +02:00
|
|
|
}
|
|
|
|
|
2020-07-06 12:36:55 +02:00
|
|
|
function show_all_everyone_warnings(stream_id) {
|
2021-01-12 21:38:01 +01:00
|
|
|
const stream_count = peer_data.get_subscriber_count(stream_id) || 0;
|
2016-06-04 04:31:35 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const all_everyone_template = render_compose_all_everyone({
|
|
|
|
count: stream_count,
|
|
|
|
mention: wildcard_mention,
|
|
|
|
});
|
2019-11-02 00:06:25 +01:00
|
|
|
const error_area_all_everyone = $("#compose-all-everyone");
|
2016-06-04 04:31:35 +02:00
|
|
|
|
|
|
|
// only show one error for any number of @all or @everyone mentions
|
2020-07-15 01:29:15 +02:00
|
|
|
if (!error_area_all_everyone.is(":visible")) {
|
2016-06-04 04:31:35 +02:00
|
|
|
error_area_all_everyone.append(all_everyone_template);
|
|
|
|
}
|
|
|
|
|
|
|
|
error_area_all_everyone.show();
|
|
|
|
user_acknowledged_all_everyone = false;
|
|
|
|
}
|
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function compute_show_video_chat_button() {
|
2020-04-08 00:23:15 +02:00
|
|
|
const available_providers = page_params.realm_available_video_chat_providers;
|
|
|
|
if (page_params.realm_video_chat_provider === available_providers.disabled.id) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
if (
|
|
|
|
page_params.realm_video_chat_provider === available_providers.jitsi_meet.id &&
|
|
|
|
!page_params.jitsi_server_url
|
|
|
|
) {
|
2020-04-08 00:23:15 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2020-04-08 00:23:15 +02:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function update_video_chat_button_display() {
|
|
|
|
const show_video_chat_button = compute_show_video_chat_button();
|
2020-04-08 00:23:15 +02:00
|
|
|
$("#below-compose-content .video_link").toggle(show_video_chat_button);
|
|
|
|
$(".message-edit-feature-group .video_link").toggle(show_video_chat_button);
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2020-04-08 00:23:15 +02:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function clear_all_everyone_warnings() {
|
2016-06-04 04:31:35 +02:00
|
|
|
$("#compose-all-everyone").hide();
|
|
|
|
$("#compose-all-everyone").empty();
|
2017-11-26 19:58:36 +01:00
|
|
|
$("#compose-send-status").hide();
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2016-06-04 04:31:35 +02:00
|
|
|
|
2018-01-04 22:28:25 +01:00
|
|
|
function show_sending_indicator(whats_happening) {
|
2020-05-27 23:03:16 +02:00
|
|
|
$("#sending-indicator").text(whats_happening);
|
2018-01-04 22:28:25 +01:00
|
|
|
$("#sending-indicator").show();
|
|
|
|
}
|
|
|
|
|
2020-07-06 12:36:55 +02:00
|
|
|
function show_announce_warnings(stream_id) {
|
2021-01-12 21:38:01 +01:00
|
|
|
const stream_count = peer_data.get_subscriber_count(stream_id) || 0;
|
2017-12-18 16:09:41 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const announce_template = render_compose_announce({count: stream_count});
|
|
|
|
const error_area_announce = $("#compose-announce");
|
2017-12-18 16:09:41 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
if (!error_area_announce.is(":visible")) {
|
2017-12-18 16:09:41 +01:00
|
|
|
error_area_announce.append(announce_template);
|
|
|
|
}
|
|
|
|
|
|
|
|
error_area_announce.show();
|
|
|
|
user_acknowledged_announce = false;
|
|
|
|
}
|
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function clear_announce_warnings() {
|
2017-12-18 16:09:41 +01:00
|
|
|
$("#compose-announce").hide();
|
|
|
|
$("#compose-announce").empty();
|
|
|
|
$("#compose-send-status").hide();
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2017-12-18 16:09:41 +01:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function clear_invites() {
|
2013-09-16 21:13:11 +02:00
|
|
|
$("#compose_invite_users").hide();
|
|
|
|
$("#compose_invite_users").empty();
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2017-04-14 15:09:13 +02:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function clear_private_stream_alert() {
|
2017-10-14 15:18:21 +02:00
|
|
|
$("#compose_private_stream_alert").hide();
|
|
|
|
$("#compose_private_stream_alert").empty();
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2017-10-14 15:18:21 +02:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function reset_user_acknowledged_all_everyone_flag() {
|
2016-06-04 04:31:35 +02:00
|
|
|
user_acknowledged_all_everyone = undefined;
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2013-07-12 23:26:18 +02:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function reset_user_acknowledged_announce_flag() {
|
2017-12-18 16:09:41 +01:00
|
|
|
user_acknowledged_announce = undefined;
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2017-12-18 16:09:41 +01:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function clear_preview_area() {
|
2017-11-26 20:37:44 +01:00
|
|
|
$("#compose-textarea").show();
|
2021-04-20 19:50:01 +02:00
|
|
|
$("#compose .undo_markdown_preview").hide();
|
|
|
|
$("#compose .preview_message_area").hide();
|
|
|
|
$("#compose .preview_content").empty();
|
|
|
|
$("#compose .markdown_preview").show();
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2016-08-29 22:37:27 +02:00
|
|
|
|
2019-02-27 15:16:50 +01:00
|
|
|
function update_stream_button(btn_text, title) {
|
|
|
|
$("#left_bar_compose_stream_button_big").text(btn_text);
|
2018-08-11 23:26:00 +02:00
|
|
|
$("#left_bar_compose_stream_button_big").prop("title", title);
|
|
|
|
}
|
|
|
|
|
2019-03-06 23:46:53 +01:00
|
|
|
function update_conversation_button(btn_text, title) {
|
|
|
|
$("#left_bar_compose_private_button_big").text(btn_text);
|
|
|
|
$("#left_bar_compose_private_button_big").prop("title", title);
|
|
|
|
}
|
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function update_closed_compose_buttons_for_private() {
|
2021-04-13 06:51:54 +02:00
|
|
|
const text_stream = $t({defaultMessage: "New stream message"});
|
2019-11-02 00:06:25 +01:00
|
|
|
const title_stream = text_stream + " (c)";
|
2021-04-13 06:51:54 +02:00
|
|
|
const text_conversation = $t({defaultMessage: "New private message"});
|
2019-11-02 00:06:25 +01:00
|
|
|
const title_conversation = text_conversation + " (x)";
|
2019-03-06 23:46:53 +01:00
|
|
|
update_stream_button(text_stream, title_stream);
|
|
|
|
update_conversation_button(text_conversation, title_conversation);
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2018-08-09 05:59:55 +02:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function update_closed_compose_buttons_for_stream() {
|
2021-04-13 06:51:54 +02:00
|
|
|
const text_stream = $t({defaultMessage: "New topic"});
|
2019-11-02 00:06:25 +01:00
|
|
|
const title_stream = text_stream + " (c)";
|
2021-04-13 06:51:54 +02:00
|
|
|
const text_conversation = $t({defaultMessage: "New private message"});
|
2019-11-02 00:06:25 +01:00
|
|
|
const title_conversation = text_conversation + " (x)";
|
2019-03-06 23:46:53 +01:00
|
|
|
update_stream_button(text_stream, title_stream);
|
|
|
|
update_conversation_button(text_conversation, title_conversation);
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2018-08-09 05:59:55 +02:00
|
|
|
|
2016-12-05 07:02:18 +01:00
|
|
|
function update_fade() {
|
2017-04-15 01:15:59 +02:00
|
|
|
if (!compose_state.composing()) {
|
2013-08-01 17:47:48 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-03-12 21:46:54 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const msg_type = compose_state.get_message_type();
|
2013-08-11 23:54:50 +02:00
|
|
|
compose_fade.set_focused_recipient(msg_type);
|
2018-04-22 16:25:46 +02:00
|
|
|
compose_fade.update_all();
|
2013-03-12 21:46:54 +01:00
|
|
|
}
|
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function abort_xhr() {
|
2017-06-30 00:57:46 +02:00
|
|
|
$("#compose-send-button").prop("disabled", false);
|
2019-11-21 05:24:55 +01:00
|
|
|
uppy.cancelAll();
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2013-03-27 18:49:28 +01:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export const zoom_token_callbacks = new Map();
|
|
|
|
export const video_call_xhrs = new Map();
|
2019-11-16 09:26:28 +01:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function abort_video_callbacks(edit_message_id = "") {
|
|
|
|
zoom_token_callbacks.delete(edit_message_id);
|
|
|
|
if (video_call_xhrs.has(edit_message_id)) {
|
|
|
|
video_call_xhrs.get(edit_message_id).abort();
|
|
|
|
video_call_xhrs.delete(edit_message_id);
|
2019-11-16 09:26:28 +01:00
|
|
|
}
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2019-11-16 09:26:28 +01:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function empty_topic_placeholder() {
|
2021-04-13 06:51:54 +02:00
|
|
|
return $t({defaultMessage: "(no topic)"});
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2013-05-20 22:52:03 +02:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function create_message_object() {
|
2018-11-04 17:04:17 +01:00
|
|
|
// Topics are optional, and we provide a placeholder if one isn't given.
|
2019-11-02 00:06:25 +01:00
|
|
|
let topic = compose_state.topic();
|
2018-11-15 18:34:16 +01:00
|
|
|
if (topic === "") {
|
2021-02-28 00:51:57 +01:00
|
|
|
topic = empty_topic_placeholder();
|
2013-05-20 22:52:03 +02:00
|
|
|
}
|
2013-10-23 16:46:18 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const content = make_uploads_relative(compose_state.message_content());
|
2013-10-23 16:46:18 +02:00
|
|
|
|
2013-12-19 17:03:08 +01:00
|
|
|
// Changes here must also be kept in sync with echo.try_deliver_locally
|
2019-11-02 00:06:25 +01:00
|
|
|
const message = {
|
2017-04-24 20:35:26 +02:00
|
|
|
type: compose_state.get_message_type(),
|
2020-07-20 22:18:43 +02:00
|
|
|
content,
|
2017-02-17 22:15:38 +01:00
|
|
|
sender_id: page_params.user_id,
|
2017-04-24 21:40:16 +02:00
|
|
|
queue_id: page_params.queue_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
stream: "",
|
2017-02-17 22:15:38 +01:00
|
|
|
};
|
2020-07-15 01:29:15 +02:00
|
|
|
message.topic = "";
|
2013-04-17 19:34:20 +02:00
|
|
|
|
|
|
|
if (message.type === "private") {
|
|
|
|
// TODO: this should be collapsed with the code in composebox_typeahead.js
|
2019-12-02 17:53:55 +01:00
|
|
|
const recipient = compose_state.private_message_recipient();
|
2019-11-02 00:06:25 +01:00
|
|
|
const emails = util.extract_pm_recipients(recipient);
|
2017-02-24 23:51:23 +01:00
|
|
|
message.to = emails;
|
2017-02-24 16:20:25 +01:00
|
|
|
message.reply_to = recipient;
|
|
|
|
message.private_message_recipient = recipient;
|
2017-02-24 23:51:23 +01:00
|
|
|
message.to_user_ids = people.email_list_to_user_ids_string(emails);
|
2019-05-23 22:18:58 +02:00
|
|
|
|
|
|
|
// Note: The `undefined` case is for situations like the
|
|
|
|
// is_zephyr_mirror_realm case where users may be
|
|
|
|
// automatically created when you try to send a private
|
|
|
|
// message to their email address.
|
|
|
|
if (message.to_user_ids !== undefined) {
|
2019-06-06 21:49:01 +02:00
|
|
|
message.to = people.user_ids_string_to_ids_array(message.to_user_ids);
|
2019-05-23 22:18:58 +02:00
|
|
|
}
|
2013-04-17 19:34:20 +02:00
|
|
|
} else {
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_name = compose_state.stream_name();
|
2017-02-23 04:08:05 +01:00
|
|
|
message.stream = stream_name;
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = stream_data.get_sub(stream_name);
|
2017-02-23 04:08:05 +01:00
|
|
|
if (sub) {
|
|
|
|
message.stream_id = sub.stream_id;
|
2020-02-07 21:18:20 +01:00
|
|
|
message.to = sub.stream_id;
|
|
|
|
} else {
|
|
|
|
// We should be validating streams in calling code. We'll
|
|
|
|
// try to fall back to stream_name here just in case the
|
|
|
|
// user started composing to the old stream name and
|
|
|
|
// manually entered the stream name, and it got past
|
|
|
|
// validation. We should try to kill this code off eventually.
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("Trying to send message with bad stream name: " + stream_name);
|
2020-02-07 21:18:20 +01:00
|
|
|
message.to = stream_name;
|
2017-02-23 04:08:05 +01:00
|
|
|
}
|
2020-02-19 02:44:17 +01:00
|
|
|
message.topic = topic;
|
2013-04-17 19:34:20 +02:00
|
|
|
}
|
|
|
|
return message;
|
|
|
|
}
|
2018-02-06 22:54:53 +01:00
|
|
|
|
2021-04-13 01:44:36 +02:00
|
|
|
export function compose_error(error_html, bad_input) {
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#compose-send-status")
|
|
|
|
.removeClass(common.status_classes)
|
2020-07-15 01:29:15 +02:00
|
|
|
.addClass("alert-error")
|
2020-07-15 00:34:28 +02:00
|
|
|
.stop(true)
|
|
|
|
.fadeTo(0, 1);
|
2021-04-13 01:44:36 +02:00
|
|
|
$("#compose-error-msg").html(error_html);
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#compose-send-button").prop("disabled", false);
|
2013-03-06 17:40:51 +01:00
|
|
|
$("#sending-indicator").hide();
|
2013-11-21 00:48:03 +01:00
|
|
|
if (bad_input !== undefined) {
|
2020-07-20 21:24:26 +02:00
|
|
|
bad_input.trigger("focus").trigger("select");
|
2013-11-21 00:48:03 +01:00
|
|
|
}
|
2013-02-01 17:04:23 +01:00
|
|
|
}
|
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function nonexistent_stream_reply_error() {
|
2017-12-11 11:39:49 +01:00
|
|
|
$("#nonexistent_stream_reply_error").show();
|
|
|
|
$("#compose-reply-error-msg").html("There are no messages to reply to yet.");
|
2020-07-02 01:45:54 +02:00
|
|
|
setTimeout(() => {
|
2017-12-11 11:39:49 +01:00
|
|
|
$("#nonexistent_stream_reply_error").hide();
|
|
|
|
}, 5000);
|
|
|
|
}
|
|
|
|
|
2021-04-13 01:44:36 +02:00
|
|
|
function compose_not_subscribed_error(error_html, bad_input) {
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#compose-send-status")
|
|
|
|
.removeClass(common.status_classes)
|
2020-07-15 01:29:15 +02:00
|
|
|
.addClass("home-error-bar")
|
2020-07-15 00:34:28 +02:00
|
|
|
.stop(true)
|
|
|
|
.fadeTo(0, 1);
|
2021-04-13 01:44:36 +02:00
|
|
|
$("#compose-error-msg").html(error_html);
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#compose-send-button").prop("disabled", false);
|
2018-04-04 19:38:09 +02:00
|
|
|
$("#sending-indicator").hide();
|
|
|
|
$(".compose-send-status-close").hide();
|
|
|
|
if (bad_input !== undefined) {
|
2020-07-20 21:24:26 +02:00
|
|
|
bad_input.trigger("focus").trigger("select");
|
2018-04-04 19:38:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function clear_compose_box() {
|
2020-07-20 21:24:26 +02:00
|
|
|
$("#compose-textarea").val("").trigger("focus");
|
2017-02-22 02:34:05 +01:00
|
|
|
drafts.delete_draft_after_send();
|
2020-09-04 23:49:49 +02:00
|
|
|
compose_ui.autosize_textarea($("#compose-textarea"));
|
2017-11-26 19:58:36 +01:00
|
|
|
$("#compose-send-status").hide(0);
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#compose-send-button").prop("disabled", false);
|
2013-12-03 20:59:23 +01:00
|
|
|
$("#sending-indicator").hide();
|
|
|
|
}
|
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function send_message_success(local_id, message_id, locally_echoed) {
|
2017-05-09 19:34:42 +02:00
|
|
|
if (!locally_echoed) {
|
2013-12-19 17:03:08 +01:00
|
|
|
clear_compose_box();
|
|
|
|
}
|
|
|
|
|
2017-07-14 19:30:23 +02:00
|
|
|
echo.reify_message_id(local_id, message_id);
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2017-07-13 15:01:02 +02:00
|
|
|
|
2021-03-24 21:44:43 +01:00
|
|
|
export function send_message(request = create_message_object()) {
|
2013-09-11 20:42:12 +02:00
|
|
|
if (request.type === "private") {
|
|
|
|
request.to = JSON.stringify(request.to);
|
|
|
|
} else {
|
|
|
|
request.to = JSON.stringify([request.to]);
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let local_id;
|
|
|
|
let locally_echoed;
|
2017-05-09 19:34:42 +02:00
|
|
|
|
2020-04-09 19:22:30 +02:00
|
|
|
const message = echo.try_deliver_locally(request);
|
|
|
|
if (message) {
|
sending messages: Extract sent_messages.js.
This commit extract send_messages.js to clean up code related
to the following things:
* sending data to /json/report_send_time
* restarting the event loop if events don't arrive on time
The code related to /json/report changes the following ways:
* We track the state almost completely in the new
send_messages.js module, with other modules just
making one-line calls.
* We no longer send "displayed" times to the servers, since
we were kind of lying about them anyway.
* We now explicitly track the state of each single sent
message in its own object.
* We now look up data related to the messages by local_id,
instead of message_id. The problem with message_id was
that is was mutable. Now we use local_id, and we extend
the local_id concept to messages that don't get rendered
client side. We no longer need to react to the
'message_id_changed' event to change our hash key.
* The code used to live in many places:
* various big chunks were scattered among compose.js,
and those were all moved or reduced to one-line
calls into the new module
* echo.js continues to make basically one-line calls,
but it no longer calls compose.report_as_received(),
nor does it set the "start" time.
* message_util.js used to report received events, but
only when they finally got drawn in the home view;
this code is gone now
The code related to restarting the event loop if events don't arrive
changes as follows:
* The timer now gets set up from within
send_messages.message_state.report_server_ack,
where we can easily inspect the current state of the
possibly-still-in-flight message.
* The code to confirm that an event was received happens now
in server_events.js, rather than later, so that we don't
falsely blame the event loop for a downstream bug. (Plus
it's easier to just do it one place.)
This change removes a fair amount of code from our node tests. Some
of the removal is good stuff related to us completing killing off
unnecessary code. Other removals are more expediency-driven, and
we should make another sweep at ramping up our coverage on compose.js,
with possibly a little more mocking of the new `send_messages` code
layer, since it's now abstracted better.
There is also some minor cleanup to echo.resend_message() in this
commit.
See #5968 for a detailed breakdown of the changes.
2017-07-30 12:56:46 +02:00
|
|
|
// We are rendering this message locally with an id
|
|
|
|
// like 92l99.01 that corresponds to a reasonable
|
|
|
|
// approximation of the id we'll get from the server
|
|
|
|
// in terms of sorting messages.
|
2020-04-09 19:22:30 +02:00
|
|
|
local_id = message.local_id;
|
sending messages: Extract sent_messages.js.
This commit extract send_messages.js to clean up code related
to the following things:
* sending data to /json/report_send_time
* restarting the event loop if events don't arrive on time
The code related to /json/report changes the following ways:
* We track the state almost completely in the new
send_messages.js module, with other modules just
making one-line calls.
* We no longer send "displayed" times to the servers, since
we were kind of lying about them anyway.
* We now explicitly track the state of each single sent
message in its own object.
* We now look up data related to the messages by local_id,
instead of message_id. The problem with message_id was
that is was mutable. Now we use local_id, and we extend
the local_id concept to messages that don't get rendered
client side. We no longer need to react to the
'message_id_changed' event to change our hash key.
* The code used to live in many places:
* various big chunks were scattered among compose.js,
and those were all moved or reduced to one-line
calls into the new module
* echo.js continues to make basically one-line calls,
but it no longer calls compose.report_as_received(),
nor does it set the "start" time.
* message_util.js used to report received events, but
only when they finally got drawn in the home view;
this code is gone now
The code related to restarting the event loop if events don't arrive
changes as follows:
* The timer now gets set up from within
send_messages.message_state.report_server_ack,
where we can easily inspect the current state of the
possibly-still-in-flight message.
* The code to confirm that an event was received happens now
in server_events.js, rather than later, so that we don't
falsely blame the event loop for a downstream bug. (Plus
it's easier to just do it one place.)
This change removes a fair amount of code from our node tests. Some
of the removal is good stuff related to us completing killing off
unnecessary code. Other removals are more expediency-driven, and
we should make another sweep at ramping up our coverage on compose.js,
with possibly a little more mocking of the new `send_messages` code
layer, since it's now abstracted better.
There is also some minor cleanup to echo.resend_message() in this
commit.
See #5968 for a detailed breakdown of the changes.
2017-07-30 12:56:46 +02:00
|
|
|
locally_echoed = true;
|
|
|
|
} else {
|
|
|
|
// We are not rendering this message locally, but we
|
|
|
|
// track the message's life cycle with an id like
|
|
|
|
// loc-1, loc-2, loc-3,etc.
|
|
|
|
locally_echoed = false;
|
|
|
|
local_id = sent_messages.get_new_local_id();
|
2013-12-19 17:03:08 +01:00
|
|
|
}
|
2017-07-14 19:30:23 +02:00
|
|
|
|
sending messages: Extract sent_messages.js.
This commit extract send_messages.js to clean up code related
to the following things:
* sending data to /json/report_send_time
* restarting the event loop if events don't arrive on time
The code related to /json/report changes the following ways:
* We track the state almost completely in the new
send_messages.js module, with other modules just
making one-line calls.
* We no longer send "displayed" times to the servers, since
we were kind of lying about them anyway.
* We now explicitly track the state of each single sent
message in its own object.
* We now look up data related to the messages by local_id,
instead of message_id. The problem with message_id was
that is was mutable. Now we use local_id, and we extend
the local_id concept to messages that don't get rendered
client side. We no longer need to react to the
'message_id_changed' event to change our hash key.
* The code used to live in many places:
* various big chunks were scattered among compose.js,
and those were all moved or reduced to one-line
calls into the new module
* echo.js continues to make basically one-line calls,
but it no longer calls compose.report_as_received(),
nor does it set the "start" time.
* message_util.js used to report received events, but
only when they finally got drawn in the home view;
this code is gone now
The code related to restarting the event loop if events don't arrive
changes as follows:
* The timer now gets set up from within
send_messages.message_state.report_server_ack,
where we can easily inspect the current state of the
possibly-still-in-flight message.
* The code to confirm that an event was received happens now
in server_events.js, rather than later, so that we don't
falsely blame the event loop for a downstream bug. (Plus
it's easier to just do it one place.)
This change removes a fair amount of code from our node tests. Some
of the removal is good stuff related to us completing killing off
unnecessary code. Other removals are more expediency-driven, and
we should make another sweep at ramping up our coverage on compose.js,
with possibly a little more mocking of the new `send_messages` code
layer, since it's now abstracted better.
There is also some minor cleanup to echo.resend_message() in this
commit.
See #5968 for a detailed breakdown of the changes.
2017-07-30 12:56:46 +02:00
|
|
|
request.local_id = local_id;
|
|
|
|
|
|
|
|
sent_messages.start_tracking_message({
|
2020-07-20 22:18:43 +02:00
|
|
|
local_id,
|
|
|
|
locally_echoed,
|
sending messages: Extract sent_messages.js.
This commit extract send_messages.js to clean up code related
to the following things:
* sending data to /json/report_send_time
* restarting the event loop if events don't arrive on time
The code related to /json/report changes the following ways:
* We track the state almost completely in the new
send_messages.js module, with other modules just
making one-line calls.
* We no longer send "displayed" times to the servers, since
we were kind of lying about them anyway.
* We now explicitly track the state of each single sent
message in its own object.
* We now look up data related to the messages by local_id,
instead of message_id. The problem with message_id was
that is was mutable. Now we use local_id, and we extend
the local_id concept to messages that don't get rendered
client side. We no longer need to react to the
'message_id_changed' event to change our hash key.
* The code used to live in many places:
* various big chunks were scattered among compose.js,
and those were all moved or reduced to one-line
calls into the new module
* echo.js continues to make basically one-line calls,
but it no longer calls compose.report_as_received(),
nor does it set the "start" time.
* message_util.js used to report received events, but
only when they finally got drawn in the home view;
this code is gone now
The code related to restarting the event loop if events don't arrive
changes as follows:
* The timer now gets set up from within
send_messages.message_state.report_server_ack,
where we can easily inspect the current state of the
possibly-still-in-flight message.
* The code to confirm that an event was received happens now
in server_events.js, rather than later, so that we don't
falsely blame the event loop for a downstream bug. (Plus
it's easier to just do it one place.)
This change removes a fair amount of code from our node tests. Some
of the removal is good stuff related to us completing killing off
unnecessary code. Other removals are more expediency-driven, and
we should make another sweep at ramping up our coverage on compose.js,
with possibly a little more mocking of the new `send_messages` code
layer, since it's now abstracted better.
There is also some minor cleanup to echo.resend_message() in this
commit.
See #5968 for a detailed breakdown of the changes.
2017-07-30 12:56:46 +02:00
|
|
|
});
|
2013-12-19 17:03:08 +01:00
|
|
|
|
2017-07-17 16:52:57 +02:00
|
|
|
request.locally_echoed = locally_echoed;
|
|
|
|
|
2013-11-06 18:57:38 +01:00
|
|
|
function success(data) {
|
2021-02-28 00:51:57 +01:00
|
|
|
send_message_success(local_id, data.id, locally_echoed);
|
2013-12-19 17:03:08 +01:00
|
|
|
}
|
2013-11-04 23:58:51 +01:00
|
|
|
|
2013-12-19 17:03:08 +01:00
|
|
|
function error(response) {
|
|
|
|
// If we're not local echo'ing messages, or if this message was not
|
|
|
|
// locally echoed, show error in compose box
|
sending messages: Extract sent_messages.js.
This commit extract send_messages.js to clean up code related
to the following things:
* sending data to /json/report_send_time
* restarting the event loop if events don't arrive on time
The code related to /json/report changes the following ways:
* We track the state almost completely in the new
send_messages.js module, with other modules just
making one-line calls.
* We no longer send "displayed" times to the servers, since
we were kind of lying about them anyway.
* We now explicitly track the state of each single sent
message in its own object.
* We now look up data related to the messages by local_id,
instead of message_id. The problem with message_id was
that is was mutable. Now we use local_id, and we extend
the local_id concept to messages that don't get rendered
client side. We no longer need to react to the
'message_id_changed' event to change our hash key.
* The code used to live in many places:
* various big chunks were scattered among compose.js,
and those were all moved or reduced to one-line
calls into the new module
* echo.js continues to make basically one-line calls,
but it no longer calls compose.report_as_received(),
nor does it set the "start" time.
* message_util.js used to report received events, but
only when they finally got drawn in the home view;
this code is gone now
The code related to restarting the event loop if events don't arrive
changes as follows:
* The timer now gets set up from within
send_messages.message_state.report_server_ack,
where we can easily inspect the current state of the
possibly-still-in-flight message.
* The code to confirm that an event was received happens now
in server_events.js, rather than later, so that we don't
falsely blame the event loop for a downstream bug. (Plus
it's easier to just do it one place.)
This change removes a fair amount of code from our node tests. Some
of the removal is good stuff related to us completing killing off
unnecessary code. Other removals are more expediency-driven, and
we should make another sweep at ramping up our coverage on compose.js,
with possibly a little more mocking of the new `send_messages` code
layer, since it's now abstracted better.
There is also some minor cleanup to echo.resend_message() in this
commit.
See #5968 for a detailed breakdown of the changes.
2017-07-30 12:56:46 +02:00
|
|
|
if (!locally_echoed) {
|
2021-04-10 02:26:13 +02:00
|
|
|
compose_error(_.escape(response), $("#compose-textarea"));
|
2013-12-19 17:03:08 +01:00
|
|
|
return;
|
2013-12-03 20:59:23 +01:00
|
|
|
}
|
2013-10-31 15:56:30 +01:00
|
|
|
|
2020-04-09 17:43:30 +02:00
|
|
|
echo.message_send_error(message.id, response);
|
2013-09-11 20:42:12 +02:00
|
|
|
}
|
|
|
|
|
2018-02-20 13:08:50 +01:00
|
|
|
transmit.send_message(request, success, error);
|
2020-07-15 00:34:28 +02:00
|
|
|
server_events.assert_get_events_running(
|
|
|
|
"Restarting get_events because it was not running during send",
|
|
|
|
);
|
2013-12-03 20:59:23 +01:00
|
|
|
|
2017-05-09 19:34:42 +02:00
|
|
|
if (locally_echoed) {
|
2013-12-03 20:59:23 +01:00
|
|
|
clear_compose_box();
|
|
|
|
}
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2012-10-29 18:06:53 +01:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function enter_with_preview_open() {
|
2017-02-19 07:43:02 +01:00
|
|
|
if (page_params.enter_sends) {
|
2017-07-07 19:31:32 +02:00
|
|
|
// If enter_sends is enabled, we attempt to send the message
|
2021-02-28 00:51:57 +01:00
|
|
|
finish();
|
2017-02-19 07:43:02 +01:00
|
|
|
} else {
|
|
|
|
// Otherwise, we return to the compose box and focus it
|
2020-07-20 21:24:26 +02:00
|
|
|
$("#compose-textarea").trigger("focus");
|
2017-02-19 07:43:02 +01:00
|
|
|
}
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2017-02-19 07:43:02 +01:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function finish() {
|
|
|
|
clear_preview_area();
|
|
|
|
clear_invites();
|
|
|
|
clear_private_stream_alert();
|
2018-01-04 21:31:23 +01:00
|
|
|
notifications.clear_compose_notifications();
|
2013-09-16 21:13:11 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const message_content = compose_state.message_content();
|
2018-06-02 13:59:02 +02:00
|
|
|
|
|
|
|
// Skip normal validation for zcommands, since they aren't
|
|
|
|
// actual messages with recipients; users only send them
|
|
|
|
// from the compose box for convenience sake.
|
|
|
|
if (zcommand.process(message_content)) {
|
2021-02-28 00:51:57 +01:00
|
|
|
do_post_send_tasks();
|
2018-06-02 13:59:02 +02:00
|
|
|
clear_compose_box();
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2018-06-02 13:59:02 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
if (!validate()) {
|
2012-10-29 22:37:34 +01:00
|
|
|
return false;
|
|
|
|
}
|
2018-01-04 21:31:23 +01:00
|
|
|
|
2018-02-06 22:54:53 +01:00
|
|
|
if (reminder.is_deferred_delivery(message_content)) {
|
|
|
|
reminder.schedule_message();
|
2018-01-04 21:31:23 +01:00
|
|
|
} else {
|
2021-02-28 00:51:57 +01:00
|
|
|
send_message();
|
2018-01-04 21:31:23 +01:00
|
|
|
}
|
2021-02-28 00:51:57 +01:00
|
|
|
do_post_send_tasks();
|
2018-06-02 13:38:40 +02:00
|
|
|
return true;
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2018-06-02 13:38:40 +02:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function do_post_send_tasks() {
|
|
|
|
clear_preview_area();
|
2012-11-07 19:59:35 +01:00
|
|
|
// TODO: Do we want to fire the event even if the send failed due
|
|
|
|
// to a server-side error?
|
2020-12-11 04:26:23 +01:00
|
|
|
$(document).trigger("compose_finished.zulip");
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2012-10-18 20:16:56 +02:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function update_email(user_id, new_email) {
|
2019-12-02 17:53:55 +01:00
|
|
|
let reply_to = compose_state.private_message_recipient();
|
2017-02-10 20:03:23 +01:00
|
|
|
|
|
|
|
if (!reply_to) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
reply_to = people.update_email_in_reply_to(reply_to, user_id, new_email);
|
|
|
|
|
2019-12-02 17:53:55 +01:00
|
|
|
compose_state.private_message_recipient(reply_to);
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2013-10-10 16:43:49 +02:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function get_invalid_recipient_emails() {
|
2019-12-02 17:53:55 +01:00
|
|
|
const private_recipients = util.extract_pm_recipients(
|
2020-07-15 00:34:28 +02:00
|
|
|
compose_state.private_message_recipient(),
|
|
|
|
);
|
2020-02-08 03:51:18 +01:00
|
|
|
const invalid_recipients = private_recipients.filter(
|
2020-07-02 02:16:03 +02:00
|
|
|
(email) => !people.is_valid_email_for_compose(email),
|
2020-02-08 03:51:18 +01:00
|
|
|
);
|
2017-03-22 14:28:16 +01:00
|
|
|
|
|
|
|
return invalid_recipients;
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2017-03-22 14:28:16 +01:00
|
|
|
|
2017-06-28 13:17:10 +02:00
|
|
|
function check_unsubscribed_stream_for_send(stream_name, autosubscribe) {
|
2019-11-02 00:06:25 +01:00
|
|
|
let result;
|
2017-02-12 05:42:47 +01:00
|
|
|
if (!autosubscribe) {
|
|
|
|
return "not-subscribed";
|
|
|
|
}
|
|
|
|
|
|
|
|
// In the rare circumstance of the autosubscribe option, we
|
|
|
|
// *Synchronously* try to subscribe to the stream before sending
|
|
|
|
// the message. This is deprecated and we hope to remove it; see
|
|
|
|
// #4650.
|
2017-04-28 23:47:35 +02:00
|
|
|
channel.post({
|
|
|
|
url: "/json/subscriptions/exists",
|
2017-02-12 05:42:47 +01:00
|
|
|
data: {stream: stream_name, autosubscribe: true},
|
2017-04-28 23:47:35 +02:00
|
|
|
async: false,
|
2020-07-20 22:18:43 +02:00
|
|
|
success(data) {
|
2017-04-28 23:47:35 +02:00
|
|
|
if (data.subscribed) {
|
|
|
|
result = "subscribed";
|
|
|
|
} else {
|
|
|
|
result = "not-subscribed";
|
|
|
|
}
|
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
error(xhr) {
|
2017-04-28 23:47:35 +02:00
|
|
|
if (xhr.status === 404) {
|
|
|
|
result = "does-not-exist";
|
|
|
|
} else {
|
|
|
|
result = "error";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return result;
|
2012-10-03 22:53:15 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function wildcard_mention_allowed() {
|
2020-09-11 16:07:06 +02:00
|
|
|
if (
|
|
|
|
page_params.realm_wildcard_mention_policy ===
|
|
|
|
settings_config.wildcard_mention_policy_values.by_everyone.code
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
page_params.realm_wildcard_mention_policy ===
|
|
|
|
settings_config.wildcard_mention_policy_values.nobody.code
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
page_params.realm_wildcard_mention_policy ===
|
|
|
|
settings_config.wildcard_mention_policy_values.by_stream_admins_only.code
|
|
|
|
) {
|
|
|
|
// TODO: Check the user's stream-level role once stream-level admins exist.
|
|
|
|
return page_params.is_admin;
|
|
|
|
}
|
|
|
|
// TODO: Uncomment when we add support for stream-level administrators.
|
|
|
|
// if (
|
|
|
|
// page_params.realm_wildcard_mention_policy ===
|
|
|
|
// settings_config.wildcard_mention_policy_values.by_admins_only.code
|
|
|
|
// ) {
|
|
|
|
// return page_params.is_admin;
|
|
|
|
// }
|
|
|
|
if (
|
|
|
|
page_params.realm_wildcard_mention_policy ===
|
|
|
|
settings_config.wildcard_mention_policy_values.by_full_members.code
|
|
|
|
) {
|
|
|
|
if (page_params.is_admin) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
const person = people.get_by_user_id(page_params.user_id);
|
|
|
|
const current_datetime = new Date(Date.now());
|
|
|
|
const person_date_joined = new Date(person.date_joined);
|
|
|
|
const days = (current_datetime - person_date_joined) / 1000 / 86400;
|
|
|
|
|
|
|
|
return days >= page_params.realm_waiting_period_threshold && !page_params.is_guest;
|
|
|
|
}
|
|
|
|
return !page_params.is_guest;
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2020-09-11 16:07:06 +02:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function set_wildcard_mention_large_stream_threshold(value) {
|
|
|
|
wildcard_mention_large_stream_threshold = value;
|
|
|
|
}
|
2021-02-28 08:26:49 +01:00
|
|
|
|
2020-07-06 12:36:55 +02:00
|
|
|
function validate_stream_message_mentions(stream_id) {
|
2021-01-12 21:38:01 +01:00
|
|
|
const stream_count = peer_data.get_subscriber_count(stream_id) || 0;
|
2016-11-09 19:34:07 +01:00
|
|
|
|
2020-09-11 16:07:06 +02:00
|
|
|
// If the user is attempting to do a wildcard mention in a large
|
|
|
|
// stream, check if they permission to do so.
|
2021-02-28 00:51:57 +01:00
|
|
|
if (wildcard_mention !== null && stream_count > wildcard_mention_large_stream_threshold) {
|
|
|
|
if (!wildcard_mention_allowed()) {
|
2020-09-11 16:07:06 +02:00
|
|
|
compose_error(
|
2021-04-13 01:44:36 +02:00
|
|
|
$t_html({
|
|
|
|
defaultMessage:
|
|
|
|
"You do not have permission to use wildcard mentions in this stream.",
|
|
|
|
}),
|
2020-09-11 16:07:06 +02:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
if (
|
|
|
|
user_acknowledged_all_everyone === undefined ||
|
|
|
|
user_acknowledged_all_everyone === false
|
|
|
|
) {
|
2016-06-04 04:31:35 +02:00
|
|
|
// user has not seen a warning message yet if undefined
|
2020-07-06 12:36:55 +02:00
|
|
|
show_all_everyone_warnings(stream_id);
|
2016-11-09 19:34:07 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#compose-send-button").prop("disabled", false);
|
2016-11-09 19:34:07 +01:00
|
|
|
$("#sending-indicator").hide();
|
2016-06-04 04:31:35 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// the message no longer contains @all or @everyone
|
2021-02-28 00:51:57 +01:00
|
|
|
clear_all_everyone_warnings();
|
2016-06-04 04:31:35 +02:00
|
|
|
}
|
|
|
|
// at this point, the user has either acknowledged the warning or removed @all / @everyone
|
|
|
|
user_acknowledged_all_everyone = undefined;
|
|
|
|
|
2017-01-05 12:05:51 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-06 12:36:55 +02:00
|
|
|
function validate_stream_message_announce(sub) {
|
2021-01-12 21:38:01 +01:00
|
|
|
const stream_count = peer_data.get_subscriber_count(sub.stream_id) || 0;
|
2017-12-18 16:09:41 +01:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
if (sub.name === "announce" && stream_count > announce_warn_threshold) {
|
2020-07-15 00:34:28 +02:00
|
|
|
if (user_acknowledged_announce === undefined || user_acknowledged_announce === false) {
|
2017-12-18 16:09:41 +01:00
|
|
|
// user has not seen a warning message yet if undefined
|
2020-07-06 12:36:55 +02:00
|
|
|
show_announce_warnings(sub.stream_id);
|
2017-12-18 16:09:41 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#compose-send-button").prop("disabled", false);
|
2017-12-18 16:09:41 +01:00
|
|
|
$("#sending-indicator").hide();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
2021-02-28 00:51:57 +01:00
|
|
|
clear_announce_warnings();
|
2017-12-18 16:09:41 +01:00
|
|
|
}
|
|
|
|
// at this point, the user has acknowledged the warning
|
|
|
|
user_acknowledged_announce = undefined;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-06 12:36:55 +02:00
|
|
|
function validate_stream_message_post_policy(sub) {
|
2020-02-04 21:50:55 +01:00
|
|
|
if (page_params.is_admin) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const stream_post_permission_type = stream_data.stream_post_policy_values;
|
2020-07-06 12:36:55 +02:00
|
|
|
const stream_post_policy = sub.stream_post_policy;
|
2020-02-04 21:50:55 +01:00
|
|
|
|
|
|
|
if (stream_post_policy === stream_post_permission_type.admins.code) {
|
2021-04-13 01:44:36 +02:00
|
|
|
compose_error(
|
|
|
|
$t_html({
|
|
|
|
defaultMessage: "Only organization admins are allowed to post to this stream.",
|
|
|
|
}),
|
|
|
|
);
|
2018-05-14 12:06:56 +02:00
|
|
|
return false;
|
|
|
|
}
|
2020-02-04 21:50:55 +01:00
|
|
|
|
2020-10-08 20:30:11 +02:00
|
|
|
if (page_params.is_guest && stream_post_policy !== stream_post_permission_type.everyone.code) {
|
2021-04-13 01:44:36 +02:00
|
|
|
compose_error($t_html({defaultMessage: "Guests are not allowed to post to this stream."}));
|
2020-10-08 20:30:11 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-05 14:30:59 +01:00
|
|
|
const person = people.get_by_user_id(page_params.user_id);
|
2020-02-04 21:50:55 +01:00
|
|
|
const current_datetime = new Date(Date.now());
|
|
|
|
const person_date_joined = new Date(person.date_joined);
|
2020-08-01 07:04:06 +02:00
|
|
|
const days = (current_datetime - person_date_joined) / 1000 / 86400;
|
2021-04-13 01:44:36 +02:00
|
|
|
let error_html;
|
2020-07-15 00:34:28 +02:00
|
|
|
if (
|
|
|
|
stream_post_policy === stream_post_permission_type.non_new_members.code &&
|
|
|
|
days < page_params.realm_waiting_period_threshold
|
|
|
|
) {
|
2021-04-13 01:44:36 +02:00
|
|
|
error_html = $t_html(
|
|
|
|
{
|
|
|
|
defaultMessage:
|
|
|
|
"New members are not allowed to post to this stream.<br />Permission will be granted in {days} days.",
|
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
{days},
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2021-04-13 01:44:36 +02:00
|
|
|
compose_error(error_html);
|
2020-02-04 21:50:55 +01:00
|
|
|
return false;
|
|
|
|
}
|
2018-05-14 12:06:56 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function validation_error(error_type, stream_name) {
|
2019-11-02 00:06:25 +01:00
|
|
|
let response;
|
2013-02-01 17:04:23 +01:00
|
|
|
|
2018-01-23 21:06:47 +01:00
|
|
|
switch (error_type) {
|
2020-07-15 02:14:03 +02:00
|
|
|
case "does-not-exist":
|
2021-04-13 01:44:36 +02:00
|
|
|
response = $t_html(
|
|
|
|
{
|
|
|
|
defaultMessage:
|
|
|
|
"<p>The stream <b>{stream_name}</b> does not exist.</p><p>Manage your subscriptions <z-link>on your Streams page</z-link>.</p>",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
stream_name,
|
|
|
|
"z-link": (content_html) => `<a href='#streams/all'>${content_html}</a>`,
|
|
|
|
},
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2020-07-15 02:14:03 +02:00
|
|
|
compose_error(response, $("#stream_message_recipient_stream"));
|
|
|
|
return false;
|
|
|
|
case "error":
|
2020-07-15 00:34:28 +02:00
|
|
|
compose_error(
|
2021-04-13 01:44:36 +02:00
|
|
|
$t_html({defaultMessage: "Error checking subscription"}),
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#stream_message_recipient_stream"),
|
|
|
|
);
|
2020-07-15 02:14:03 +02:00
|
|
|
return false;
|
|
|
|
case "not-subscribed": {
|
|
|
|
const sub = stream_data.get_sub(stream_name);
|
|
|
|
const new_row = render_compose_not_subscribed({
|
2021-04-04 17:23:40 +02:00
|
|
|
should_display_sub_button: stream_data.can_toggle_subscription(sub),
|
2020-07-15 00:34:28 +02:00
|
|
|
});
|
2020-07-15 02:14:03 +02:00
|
|
|
compose_not_subscribed_error(new_row, $("#stream_message_recipient_stream"));
|
|
|
|
return false;
|
|
|
|
}
|
2019-10-25 23:55:37 +02:00
|
|
|
}
|
2017-06-28 18:34:39 +02:00
|
|
|
return true;
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2017-01-05 12:05:51 +01:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function validate_stream_message_address_info(stream_name) {
|
2018-01-23 21:06:47 +01:00
|
|
|
if (stream_data.is_subscribed(stream_name)) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-11-02 00:06:25 +01:00
|
|
|
const autosubscribe = page_params.narrow_stream !== undefined;
|
|
|
|
const error_type = check_unsubscribed_stream_for_send(stream_name, autosubscribe);
|
2021-02-28 00:51:57 +01:00
|
|
|
return validation_error(error_type, stream_name);
|
|
|
|
}
|
2018-01-23 21:06:47 +01:00
|
|
|
|
2017-01-05 12:05:51 +01:00
|
|
|
function validate_stream_message() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_name = compose_state.stream_name();
|
2017-01-05 12:05:51 +01:00
|
|
|
if (stream_name === "") {
|
2021-04-13 01:44:36 +02:00
|
|
|
compose_error(
|
|
|
|
$t_html({defaultMessage: "Please specify a stream"}),
|
|
|
|
$("#stream_message_recipient_stream"),
|
|
|
|
);
|
2017-01-05 12:05:51 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-20 07:50:34 +02:00
|
|
|
if (page_params.realm_mandatory_topics) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const topic = compose_state.topic();
|
2017-01-05 12:05:51 +01:00
|
|
|
if (topic === "") {
|
2021-04-13 01:44:36 +02:00
|
|
|
compose_error(
|
|
|
|
$t_html({defaultMessage: "Please specify a topic"}),
|
|
|
|
$("#stream_message_recipient_topic"),
|
|
|
|
);
|
2017-01-05 12:05:51 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-06 12:36:55 +02:00
|
|
|
const sub = stream_data.get_sub(stream_name);
|
|
|
|
if (!sub) {
|
2021-02-28 00:51:57 +01:00
|
|
|
return validation_error("does-not-exist", stream_name);
|
2020-07-06 12:36:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!validate_stream_message_post_policy(sub)) {
|
2018-05-14 12:06:56 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-06 22:22:19 +02:00
|
|
|
/* Note: This is a global and thus accessible in the functions
|
|
|
|
below; it's important that we update this state here before
|
|
|
|
proceeding with further validation. */
|
|
|
|
wildcard_mention = util.find_wildcard_mentions(compose_state.message_content());
|
|
|
|
|
2017-12-18 16:09:41 +01:00
|
|
|
// If both `@all` is mentioned and it's in `#announce`, just validate
|
|
|
|
// for `@all`. Users shouldn't have to hit "yes" more than once.
|
2020-01-23 07:22:26 +01:00
|
|
|
if (wildcard_mention !== null && stream_name === "announce") {
|
2020-07-15 00:34:28 +02:00
|
|
|
if (
|
2021-02-28 00:51:57 +01:00
|
|
|
!validate_stream_message_address_info(stream_name) ||
|
2020-07-15 00:34:28 +02:00
|
|
|
!validate_stream_message_mentions(sub.stream_id)
|
|
|
|
) {
|
2017-12-18 16:09:41 +01:00
|
|
|
return false;
|
|
|
|
}
|
2020-07-15 00:34:28 +02:00
|
|
|
// If either criteria isn't met, just do the normal validation.
|
2017-12-18 16:09:41 +01:00
|
|
|
} else {
|
2020-07-15 00:34:28 +02:00
|
|
|
if (
|
2021-02-28 00:51:57 +01:00
|
|
|
!validate_stream_message_address_info(stream_name) ||
|
2020-07-06 12:36:55 +02:00
|
|
|
!validate_stream_message_mentions(sub.stream_id) ||
|
2020-07-15 00:34:28 +02:00
|
|
|
!validate_stream_message_announce(sub)
|
|
|
|
) {
|
2018-05-06 21:43:17 +02:00
|
|
|
return false;
|
|
|
|
}
|
2017-01-05 12:05:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-03-22 14:28:16 +01:00
|
|
|
|
2016-12-02 15:16:33 +01:00
|
|
|
// The function checks whether the recipients are users of the realm or cross realm users (bots
|
|
|
|
// for now)
|
2012-11-08 00:38:21 +01:00
|
|
|
function validate_private_message() {
|
2020-01-08 01:49:44 +01:00
|
|
|
if (page_params.realm_private_message_policy === 2) {
|
|
|
|
// Frontend check for for PRIVATE_MESSAGE_POLICY_DISABLED
|
|
|
|
const user_ids = compose_pm_pill.get_user_ids();
|
2020-02-05 14:30:59 +01:00
|
|
|
if (user_ids.length !== 1 || !people.get_by_user_id(user_ids[0]).is_bot) {
|
2020-01-08 01:49:44 +01:00
|
|
|
// Unless we're composing to a bot
|
2020-07-15 00:34:28 +02:00
|
|
|
compose_error(
|
2021-04-13 01:44:36 +02:00
|
|
|
$t_html({defaultMessage: "Private messages are disabled in this organization."}),
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#private_message_recipient"),
|
|
|
|
);
|
2020-01-08 01:49:44 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-02 17:53:55 +01:00
|
|
|
if (compose_state.private_message_recipient().length === 0) {
|
2020-07-15 00:34:28 +02:00
|
|
|
compose_error(
|
2021-04-13 01:44:36 +02:00
|
|
|
$t_html({defaultMessage: "Please specify at least one valid recipient"}),
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#private_message_recipient"),
|
|
|
|
);
|
2012-10-03 22:39:05 +02:00
|
|
|
return false;
|
2017-04-20 08:03:44 +02:00
|
|
|
} else if (page_params.realm_is_zephyr_mirror_realm) {
|
2016-08-11 00:35:52 +02:00
|
|
|
// For Zephyr mirroring realms, the frontend doesn't know which users exist
|
|
|
|
return true;
|
2016-12-02 21:34:35 +01:00
|
|
|
}
|
2017-03-22 14:28:16 +01:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
const invalid_recipients = get_invalid_recipient_emails();
|
2017-03-22 14:28:16 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let context = {};
|
2016-12-02 21:34:35 +01:00
|
|
|
if (invalid_recipients.length === 1) {
|
2016-12-03 03:08:47 +01:00
|
|
|
context = {recipient: invalid_recipients.join()};
|
2020-07-15 00:34:28 +02:00
|
|
|
compose_error(
|
2021-04-13 01:44:36 +02:00
|
|
|
$t_html({defaultMessage: "The recipient {recipient} is not valid"}, context),
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#private_message_recipient"),
|
|
|
|
);
|
2016-12-02 21:34:35 +01:00
|
|
|
return false;
|
|
|
|
} else if (invalid_recipients.length > 1) {
|
2016-12-03 03:08:47 +01:00
|
|
|
context = {recipients: invalid_recipients.join()};
|
2020-07-15 00:34:28 +02:00
|
|
|
compose_error(
|
2021-04-13 01:44:36 +02:00
|
|
|
$t_html({defaultMessage: "The recipients {recipients} are not valid"}, context),
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#private_message_recipient"),
|
|
|
|
);
|
2016-12-02 21:34:35 +01:00
|
|
|
return false;
|
2016-06-10 19:46:53 +02:00
|
|
|
}
|
2016-12-02 21:34:35 +01:00
|
|
|
return true;
|
2012-10-03 22:39:05 +02:00
|
|
|
}
|
2012-10-03 23:13:38 +02:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function validate() {
|
2020-07-22 02:59:06 +02:00
|
|
|
$("#compose-send-button").prop("disabled", true).trigger("blur");
|
2019-11-02 00:06:25 +01:00
|
|
|
const message_content = compose_state.message_content();
|
2018-02-06 22:54:53 +01:00
|
|
|
if (reminder.is_deferred_delivery(message_content)) {
|
2021-04-13 06:51:54 +02:00
|
|
|
show_sending_indicator($t({defaultMessage: "Scheduling..."}));
|
2018-01-04 21:31:23 +01:00
|
|
|
} else {
|
2021-04-13 06:51:54 +02:00
|
|
|
show_sending_indicator($t({defaultMessage: "Sending..."}));
|
2018-01-04 21:31:23 +01:00
|
|
|
}
|
2012-10-03 23:13:38 +02:00
|
|
|
|
2018-01-04 21:31:23 +01:00
|
|
|
if (/^\s*$/.test(message_content)) {
|
2021-04-13 01:44:36 +02:00
|
|
|
compose_error(
|
|
|
|
$t_html({defaultMessage: "You have nothing to send!"}),
|
|
|
|
$("#compose-textarea"),
|
|
|
|
);
|
2012-10-31 22:18:48 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-21 00:48:03 +01:00
|
|
|
if ($("#zephyr-mirror-error").is(":visible")) {
|
2021-04-13 01:44:36 +02:00
|
|
|
compose_error(
|
|
|
|
$t_html({
|
|
|
|
defaultMessage:
|
|
|
|
"You need to be running Zephyr mirroring in order to send messages!",
|
|
|
|
}),
|
|
|
|
);
|
2013-11-21 00:48:03 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
if (compose_state.get_message_type() === "private") {
|
2012-11-08 00:38:21 +01:00
|
|
|
return validate_private_message();
|
2012-10-03 23:13:38 +02:00
|
|
|
}
|
2016-12-02 21:34:35 +01:00
|
|
|
return validate_stream_message();
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2012-10-18 20:29:16 +02:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function handle_keydown(event, textarea) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const code = event.keyCode || event.which;
|
|
|
|
const isBold = code === 66;
|
|
|
|
const isItalic = code === 73 && !event.shiftKey;
|
|
|
|
const isLink = code === 76 && event.shiftKey;
|
2017-12-06 14:46:23 +01:00
|
|
|
|
2020-08-11 02:09:14 +02:00
|
|
|
// detect Cmd and Ctrl key
|
2019-11-02 00:06:25 +01:00
|
|
|
const isCmdOrCtrl = common.has_mac_keyboard() ? event.metaKey : event.ctrlKey;
|
2018-02-17 17:21:45 +01:00
|
|
|
|
|
|
|
if ((isBold || isItalic || isLink) && isCmdOrCtrl) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const range = textarea.range();
|
2018-07-19 17:10:48 +02:00
|
|
|
function wrap_text_with_markdown(prefix, suffix) {
|
2020-07-15 01:29:15 +02:00
|
|
|
if (!document.execCommand("insertText", false, prefix + range.text + suffix)) {
|
2018-07-19 17:10:48 +02:00
|
|
|
textarea.range(range.start, range.end).range(prefix + range.text + suffix);
|
2017-12-06 14:46:23 +01:00
|
|
|
}
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
|
2018-01-24 12:10:52 +01:00
|
|
|
if (isBold) {
|
2020-08-11 02:09:14 +02:00
|
|
|
// Ctrl + B: Convert selected text to bold text
|
2018-07-19 17:10:48 +02:00
|
|
|
wrap_text_with_markdown("**", "**");
|
2017-12-06 14:46:23 +01:00
|
|
|
if (!range.length) {
|
|
|
|
textarea.caret(textarea.caret() - 2);
|
|
|
|
}
|
|
|
|
}
|
2018-01-24 12:10:52 +01:00
|
|
|
if (isItalic) {
|
2020-08-11 02:09:14 +02:00
|
|
|
// Ctrl + I: Convert selected text to italic text
|
2018-07-19 17:10:48 +02:00
|
|
|
wrap_text_with_markdown("*", "*");
|
2017-12-06 14:46:23 +01:00
|
|
|
if (!range.length) {
|
|
|
|
textarea.caret(textarea.caret() - 1);
|
|
|
|
}
|
|
|
|
}
|
2018-01-24 12:10:52 +01:00
|
|
|
if (isLink) {
|
2020-08-11 02:09:14 +02:00
|
|
|
// Ctrl + L: Insert a link to selected text
|
2018-07-19 17:10:48 +02:00
|
|
|
wrap_text_with_markdown("[", "](url)");
|
2019-11-02 00:06:25 +01:00
|
|
|
const position = textarea.caret();
|
2020-10-07 10:13:26 +02:00
|
|
|
const txt = textarea[0];
|
2017-12-06 14:46:23 +01:00
|
|
|
|
2020-03-28 01:25:56 +01:00
|
|
|
// Include selected text in between [] parentheses and insert '(url)'
|
2017-12-06 14:46:23 +01:00
|
|
|
// where "url" should be automatically selected.
|
|
|
|
// Position of cursor depends on whether browser supports exec
|
2020-03-28 01:25:56 +01:00
|
|
|
// command or not. So set cursor position accordingly.
|
2018-02-01 19:09:37 +01:00
|
|
|
if (range.length > 0) {
|
2020-07-15 01:29:15 +02:00
|
|
|
if (document.queryCommandEnabled("insertText")) {
|
2018-02-01 19:09:37 +01:00
|
|
|
txt.selectionStart = position - 4;
|
|
|
|
txt.selectionEnd = position - 1;
|
|
|
|
} else {
|
|
|
|
txt.selectionStart = position + range.length + 3;
|
|
|
|
txt.selectionEnd = position + range.length + 6;
|
|
|
|
}
|
2017-12-06 14:46:23 +01:00
|
|
|
} else {
|
2018-02-01 19:09:37 +01:00
|
|
|
textarea.caret(textarea.caret() - 6);
|
2017-12-06 14:46:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-04 23:49:49 +02:00
|
|
|
compose_ui.autosize_textarea(textarea);
|
2017-12-06 14:46:23 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2017-12-06 14:46:23 +01:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function handle_keyup(event, textarea) {
|
2018-08-11 06:43:38 +02:00
|
|
|
// Set the rtl class if the text has an rtl direction, remove it otherwise
|
|
|
|
rtl.set_rtl_class_for_textarea(textarea);
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2018-08-11 06:43:38 +02:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function needs_subscribe_warning(user_id, stream_id) {
|
2018-04-24 22:40:00 +02:00
|
|
|
// This returns true if all of these conditions are met:
|
|
|
|
// * the user is valid
|
|
|
|
// * the user is not already subscribed to the stream
|
|
|
|
// * the user has no back-door way to see stream messages
|
2018-05-18 12:41:05 +02:00
|
|
|
// (i.e. bots on public/private streams)
|
2018-04-24 22:40:00 +02:00
|
|
|
//
|
|
|
|
// You can think of this as roughly answering "is there an
|
|
|
|
// actionable way to subscribe the user and do they actually
|
|
|
|
// need it?".
|
|
|
|
//
|
|
|
|
// We expect the caller to already have verified that we're
|
2020-06-22 21:36:21 +02:00
|
|
|
// sending to a valid stream and trying to mention the user.
|
2018-04-24 22:40:00 +02:00
|
|
|
|
2020-06-05 16:21:22 +02:00
|
|
|
const user = people.get_by_user_id(user_id);
|
2018-04-24 22:40:00 +02:00
|
|
|
|
2020-06-22 21:36:21 +02:00
|
|
|
if (!user) {
|
2018-04-24 22:40:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-18 12:41:05 +02:00
|
|
|
if (user.is_bot) {
|
|
|
|
// Bots may receive messages on public/private streams even if they are
|
2018-04-24 22:40:00 +02:00
|
|
|
// not subscribed.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-08 22:28:35 +02:00
|
|
|
if (stream_data.is_user_subscribed(stream_id, user_id)) {
|
2018-04-24 22:40:00 +02:00
|
|
|
// If our user is already subscribed
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2018-04-24 22:40:00 +02:00
|
|
|
|
2019-01-23 08:04:53 +01:00
|
|
|
function insert_video_call_url(url, target_textarea) {
|
2021-04-13 06:51:54 +02:00
|
|
|
const link_text = $t({defaultMessage: "Click to join video call"});
|
2020-07-25 02:56:31 +02:00
|
|
|
compose_ui.insert_syntax_and_focus(`[${link_text}](${url})`, target_textarea);
|
2018-12-28 20:45:54 +01:00
|
|
|
}
|
2018-04-24 22:40:00 +02:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function render_and_show_preview(preview_spinner, preview_content_box, content) {
|
2019-02-05 15:21:30 +01:00
|
|
|
function show_preview(rendered_content, raw_content) {
|
|
|
|
// content is passed to check for status messages ("/me ...")
|
|
|
|
// and will be undefined in case of errors
|
2019-11-02 00:06:25 +01:00
|
|
|
let rendered_preview_html;
|
2020-07-15 00:34:28 +02:00
|
|
|
if (raw_content !== undefined && markdown.is_status_message(raw_content)) {
|
2019-02-05 15:21:30 +01:00
|
|
|
// Handle previews of /me messages
|
2020-07-15 00:34:28 +02:00
|
|
|
rendered_preview_html =
|
|
|
|
"<p><strong>" +
|
2021-02-03 23:48:26 +01:00
|
|
|
_.escape(page_params.full_name) +
|
2020-07-15 00:34:28 +02:00
|
|
|
"</strong>" +
|
|
|
|
rendered_content.slice("<p>/me".length);
|
2019-02-05 15:21:30 +01:00
|
|
|
} else {
|
|
|
|
rendered_preview_html = rendered_content;
|
|
|
|
}
|
|
|
|
|
2020-02-28 23:59:07 +01:00
|
|
|
preview_content_box.html(util.clean_user_content_links(rendered_preview_html));
|
2020-06-21 08:55:58 +02:00
|
|
|
rendered_markdown.update_elements(preview_content_box);
|
2019-02-05 15:21:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (content.length === 0) {
|
2021-04-14 00:59:25 +02:00
|
|
|
show_preview($t_html({defaultMessage: "Nothing to preview"}));
|
2019-02-05 15:21:30 +01:00
|
|
|
} else {
|
2020-07-16 23:29:01 +02:00
|
|
|
if (markdown.contains_backend_only_syntax(content)) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const spinner = preview_spinner.expectOne();
|
2019-02-05 15:21:30 +01:00
|
|
|
loading.make_indicator(spinner);
|
|
|
|
} else {
|
2020-06-29 23:20:51 +02:00
|
|
|
// For messages that don't appear to contain syntax that
|
2020-08-11 01:47:49 +02:00
|
|
|
// is only supported by our backend Markdown processor, we
|
|
|
|
// render using the frontend Markdown processor (but still
|
2020-06-29 23:20:51 +02:00
|
|
|
// render server-side to ensure the preview is accurate;
|
|
|
|
// if the `markdown.contains_backend_only_syntax` logic is
|
|
|
|
// wrong, users will see a brief flicker of the locally
|
|
|
|
// echoed frontend rendering before receiving the
|
|
|
|
// authoritative backend rendering from the server).
|
2019-11-02 00:06:25 +01:00
|
|
|
const message_obj = {
|
2019-02-05 15:21:30 +01:00
|
|
|
raw_content: content,
|
|
|
|
};
|
|
|
|
markdown.apply_markdown(message_obj);
|
|
|
|
}
|
|
|
|
channel.post({
|
2020-07-15 01:29:15 +02:00
|
|
|
url: "/json/messages/render",
|
2019-02-05 15:21:30 +01:00
|
|
|
idempotent: true,
|
2020-07-20 22:18:43 +02:00
|
|
|
data: {content},
|
|
|
|
success(response_data) {
|
2019-02-05 15:21:30 +01:00
|
|
|
if (markdown.contains_backend_only_syntax(content)) {
|
|
|
|
loading.destroy_indicator(preview_spinner);
|
|
|
|
}
|
|
|
|
show_preview(response_data.rendered, content);
|
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
error() {
|
2019-02-05 15:21:30 +01:00
|
|
|
if (markdown.contains_backend_only_syntax(content)) {
|
|
|
|
loading.destroy_indicator(preview_spinner);
|
|
|
|
}
|
2021-04-14 00:59:25 +02:00
|
|
|
show_preview($t_html({defaultMessage: "Failed to generate preview"}));
|
2019-02-05 15:21:30 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2019-02-05 15:21:30 +01:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function warn_if_private_stream_is_linked(linked_stream) {
|
2020-01-14 22:23:27 +01:00
|
|
|
// For PMs, we currently don't warn about links to private
|
|
|
|
// streams, since you are specifically sharing the existence of
|
|
|
|
// the private stream with someone. One could imagine changing
|
|
|
|
// this policy if user feedback suggested it was useful.
|
2020-07-15 01:29:15 +02:00
|
|
|
if (compose_state.get_message_type() !== "stream") {
|
2020-01-14 15:57:16 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const compose_stream = stream_data.get_sub(compose_state.stream_name());
|
|
|
|
if (compose_stream === undefined) {
|
|
|
|
// We have an invalid stream name, don't warn about this here as
|
|
|
|
// we show an error to the user when they try to send the message.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the stream we're linking to is not invite-only, then it's
|
|
|
|
// public, and there is no need to warn about it, since all
|
2020-01-14 22:23:27 +01:00
|
|
|
// members can already see all the public streams.
|
|
|
|
//
|
|
|
|
// Theoretically, we could still do a warning if there are any
|
|
|
|
// guest users subscribed to the stream we're posting to; we may
|
|
|
|
// change this policy if user feedback suggests it'd be an
|
|
|
|
// improvement.
|
2020-01-14 15:57:16 +01:00
|
|
|
if (!linked_stream.invite_only) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-29 22:26:56 +01:00
|
|
|
// Don't warn if subscribers list of current compose_stream is
|
|
|
|
// a subset of linked_stream's subscribers list, because
|
|
|
|
// everyone will be subscribed to the linked stream and so
|
|
|
|
// knows it exists. (But always warn Zephyr users, since
|
|
|
|
// we may not know their stream's subscribers.)
|
|
|
|
if (
|
|
|
|
peer_data.is_subscriber_subset(compose_stream.stream_id, linked_stream.stream_id) &&
|
|
|
|
!page_params.realm_is_zephyr_mirror_realm
|
|
|
|
) {
|
refactor: Extract is_subscriber_subset().
Extracting the function makes it a bit easier to
test and use in a generic way.
Also, I wanted this to live in stream_data, so that
it's easier to find if we change how we model
subscriber data.
Finally, I use _.every to do the subset check
instead of `_.difference`, since _.difference
is actually N-squared:
_.difference = restArguments(function(array, rest) {
rest = flatten(rest, true, true);
return _.filter(array, function(value){
return !_.contains(rest, value);
});
});
And we don't actually want to build a list only
to check that it's zero vs. nonzero length.
We now do this, which short circuits as soon
as it finds any key that is only in sub1:
return _.every(sub1.subscribers.keys(), (key) => {
return sub2_set.has(key);
});
2020-01-14 19:35:33 +01:00
|
|
|
return;
|
2020-01-14 15:57:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const stream_name = linked_stream.name;
|
|
|
|
|
|
|
|
const warning_area = $("#compose_private_stream_alert");
|
2020-07-20 22:18:43 +02:00
|
|
|
const context = {stream_name};
|
2020-01-14 15:57:16 +01:00
|
|
|
const new_row = render_compose_private_stream_alert(context);
|
|
|
|
|
|
|
|
warning_area.append(new_row);
|
|
|
|
warning_area.show();
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2020-01-14 15:57:16 +01:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function warn_if_mentioning_unsubscribed_user(mentioned) {
|
2020-07-15 01:29:15 +02:00
|
|
|
if (compose_state.get_message_type() !== "stream") {
|
2020-01-14 17:21:45 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disable for Zephyr mirroring realms, since we never have subscriber lists there
|
|
|
|
if (page_params.realm_is_zephyr_mirror_realm) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-04 19:41:45 +02:00
|
|
|
const user_id = mentioned.user_id;
|
2020-01-14 17:21:45 +01:00
|
|
|
|
2020-01-14 18:39:10 +01:00
|
|
|
if (mentioned.is_broadcast) {
|
|
|
|
return; // don't check if @all/@everyone/@stream
|
2020-01-14 17:21:45 +01:00
|
|
|
}
|
|
|
|
|
2020-06-22 21:36:21 +02:00
|
|
|
const stream_name = compose_state.stream_name();
|
|
|
|
|
|
|
|
if (!stream_name) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const sub = stream_data.get_sub(stream_name);
|
|
|
|
|
|
|
|
if (!sub) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
if (needs_subscribe_warning(user_id, sub.stream_id)) {
|
2020-01-14 17:21:45 +01:00
|
|
|
const error_area = $("#compose_invite_users");
|
2020-07-15 01:29:15 +02:00
|
|
|
const existing_invites_area = $("#compose_invite_users .compose_invite_user");
|
2020-01-14 17:21:45 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const existing_invites = Array.from($(existing_invites_area), (user_row) =>
|
2020-10-07 09:17:30 +02:00
|
|
|
Number.parseInt($(user_row).data("user-id"), 10),
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2020-01-14 17:21:45 +01:00
|
|
|
|
2020-06-04 19:41:45 +02:00
|
|
|
if (!existing_invites.includes(user_id)) {
|
2020-01-14 17:21:45 +01:00
|
|
|
const context = {
|
2020-07-20 22:18:43 +02:00
|
|
|
user_id,
|
2020-06-22 21:36:21 +02:00
|
|
|
stream_id: sub.stream_id,
|
2020-01-14 17:21:45 +01:00
|
|
|
name: mentioned.full_name,
|
|
|
|
can_subscribe_other_users: page_params.can_subscribe_other_users,
|
|
|
|
};
|
2020-06-22 21:36:21 +02:00
|
|
|
|
2020-01-14 17:21:45 +01:00
|
|
|
const new_row = render_compose_invite_users(context);
|
|
|
|
error_area.append(new_row);
|
|
|
|
}
|
|
|
|
|
|
|
|
error_area.show();
|
|
|
|
}
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|
2020-01-14 17:21:45 +01:00
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
export function initialize() {
|
2021-04-14 13:10:34 +02:00
|
|
|
const $compose = $("#compose");
|
|
|
|
$compose.append(
|
|
|
|
render_compose({
|
|
|
|
embedded: $compose.attr("data-embedded") === "",
|
|
|
|
file_upload_enabled: page_params.max_file_upload_size_mib > 0,
|
2021-04-15 16:18:36 +02:00
|
|
|
giphy_enabled: page_params.giphy_api_key !== "",
|
2021-04-14 13:10:34 +02:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
$("#below-compose-content .video_link").toggle(compute_show_video_chat_button());
|
2020-07-15 00:34:28 +02:00
|
|
|
$(
|
|
|
|
"#stream_message_recipient_stream,#stream_message_recipient_topic,#private_message_recipient",
|
|
|
|
).on("keyup", update_fade);
|
|
|
|
$(
|
|
|
|
"#stream_message_recipient_stream,#stream_message_recipient_topic,#private_message_recipient",
|
|
|
|
).on("change", update_fade);
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#compose-textarea").on("keydown", (event) => {
|
2021-02-28 00:51:57 +01:00
|
|
|
handle_keydown(event, $("#compose-textarea").expectOne());
|
2018-08-11 06:43:38 +02:00
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#compose-textarea").on("keyup", (event) => {
|
2021-02-28 00:51:57 +01:00
|
|
|
handle_keyup(event, $("#compose-textarea").expectOne());
|
2018-07-18 05:59:55 +02:00
|
|
|
});
|
2017-06-26 21:29:08 +02:00
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$("#compose form").on("submit", (e) => {
|
2018-05-06 21:43:17 +02:00
|
|
|
e.preventDefault();
|
2021-02-28 00:51:57 +01:00
|
|
|
finish();
|
2017-06-26 21:29:08 +02:00
|
|
|
});
|
|
|
|
|
2017-11-26 20:37:44 +01:00
|
|
|
resize.watch_manual_resize("#compose-textarea");
|
2013-05-03 22:16:52 +02:00
|
|
|
|
2021-04-20 16:22:50 +02:00
|
|
|
upload.feature_check($("#compose .compose_upload_file"));
|
2013-08-26 19:00:38 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#compose-all-everyone").on("click", ".compose-all-everyone-confirm", (event) => {
|
2016-06-04 04:31:35 +02:00
|
|
|
event.preventDefault();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$(event.target).parents(".compose-all-everyone").remove();
|
2016-06-04 04:31:35 +02:00
|
|
|
user_acknowledged_all_everyone = true;
|
2021-02-28 00:51:57 +01:00
|
|
|
clear_all_everyone_warnings();
|
|
|
|
finish();
|
2013-09-16 21:13:11 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#compose-announce").on("click", ".compose-announce-confirm", (event) => {
|
2017-12-18 16:09:41 +01:00
|
|
|
event.preventDefault();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$(event.target).parents(".compose-announce").remove();
|
2017-12-18 16:09:41 +01:00
|
|
|
user_acknowledged_announce = true;
|
2021-02-28 00:51:57 +01:00
|
|
|
clear_announce_warnings();
|
|
|
|
finish();
|
2017-12-18 16:09:41 +01:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#compose-send-status").on("click", ".sub_unsub_button", (event) => {
|
2018-04-04 19:38:09 +02:00
|
|
|
event.preventDefault();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const stream_name = $("#stream_message_recipient_stream").val();
|
2018-04-04 19:38:09 +02:00
|
|
|
if (stream_name === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = stream_data.get_sub(stream_name);
|
2018-04-04 19:38:09 +02:00
|
|
|
subs.sub_or_unsub(sub);
|
|
|
|
$("#compose-send-status").hide();
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#compose-send-status").on("click", "#compose_not_subscribed_close", (event) => {
|
2018-04-07 04:53:32 +02:00
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
$("#compose-send-status").hide();
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#compose_invite_users").on("click", ".compose_invite_link", (event) => {
|
2013-09-16 21:13:11 +02:00
|
|
|
event.preventDefault();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const invite_row = $(event.target).parents(".compose_invite_user");
|
2013-09-16 21:13:11 +02:00
|
|
|
|
2020-10-07 09:17:30 +02:00
|
|
|
const user_id = Number.parseInt($(invite_row).data("user-id"), 10);
|
|
|
|
const stream_id = Number.parseInt($(invite_row).data("stream-id"), 10);
|
2020-06-04 19:41:45 +02:00
|
|
|
|
2017-03-04 23:02:59 +01:00
|
|
|
function success() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const all_invites = $("#compose_invite_users");
|
2017-03-04 21:42:17 +01:00
|
|
|
invite_row.remove();
|
2013-09-16 21:13:11 +02:00
|
|
|
|
2017-03-04 21:42:17 +01:00
|
|
|
if (all_invites.children().length === 0) {
|
|
|
|
all_invites.hide();
|
|
|
|
}
|
2017-03-04 23:02:59 +01:00
|
|
|
}
|
|
|
|
|
2018-08-12 22:02:50 +02:00
|
|
|
function failure(error_msg) {
|
2021-02-28 00:51:57 +01:00
|
|
|
clear_invites();
|
2021-04-10 02:26:13 +02:00
|
|
|
compose_error(_.escape(error_msg), $("#compose-textarea"));
|
2020-07-22 02:59:06 +02:00
|
|
|
$(event.target).prop("disabled", true);
|
2017-03-04 23:02:59 +01:00
|
|
|
}
|
|
|
|
|
2018-08-12 22:02:50 +02:00
|
|
|
function xhr_failure(xhr) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const error = JSON.parse(xhr.responseText);
|
2018-08-12 22:02:50 +02:00
|
|
|
failure(error.msg);
|
|
|
|
}
|
|
|
|
|
2021-04-15 17:02:54 +02:00
|
|
|
const sub = sub_store.get(stream_id);
|
2017-03-04 23:02:59 +01:00
|
|
|
|
2020-06-03 21:38:43 +02:00
|
|
|
stream_edit.invite_user_to_stream([user_id], sub, success, xhr_failure);
|
2013-09-16 21:13:11 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#compose_invite_users").on("click", ".compose_invite_close", (event) => {
|
|
|
|
const invite_row = $(event.target).parents(".compose_invite_user");
|
2019-11-02 00:06:25 +01:00
|
|
|
const all_invites = $("#compose_invite_users");
|
2013-09-16 21:13:11 +02:00
|
|
|
|
|
|
|
invite_row.remove();
|
|
|
|
|
|
|
|
if (all_invites.children().length === 0) {
|
|
|
|
all_invites.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#compose_private_stream_alert").on(
|
|
|
|
"click",
|
|
|
|
".compose_private_stream_alert_close",
|
|
|
|
(event) => {
|
|
|
|
const stream_alert_row = $(event.target).parents(".compose_private_stream_alert");
|
|
|
|
const stream_alert = $("#compose_private_stream_alert");
|
2017-10-14 15:18:21 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
stream_alert_row.remove();
|
2017-10-14 15:18:21 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
if (stream_alert.children().length === 0) {
|
|
|
|
stream_alert.hide();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2017-10-14 15:18:21 +02:00
|
|
|
|
2013-08-11 19:57:44 +02:00
|
|
|
// Click event binding for "Attach files" button
|
|
|
|
// Triggers a click on a hidden file input field
|
|
|
|
|
2021-04-20 16:22:50 +02:00
|
|
|
$("#compose").on("click", ".compose_upload_file", (e) => {
|
2013-08-11 19:57:44 +02:00
|
|
|
e.preventDefault();
|
2021-04-20 16:14:55 +02:00
|
|
|
$("#compose .file_input").trigger("click");
|
2017-10-06 21:36:39 +02:00
|
|
|
});
|
2013-08-11 19:57:44 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".video_link", (e) => {
|
2017-08-11 01:51:48 +02:00
|
|
|
e.preventDefault();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let target_textarea;
|
2021-04-21 15:46:11 +02:00
|
|
|
let edit_message_id;
|
|
|
|
if ($(e.target).parents(".message_edit_form").length === 1) {
|
|
|
|
edit_message_id = rows.id($(e.target).parents(".message_row"));
|
|
|
|
target_textarea = $(`#edit_form_${CSS.escape(edit_message_id)} .message_edit_content`);
|
2019-01-23 08:04:53 +01:00
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let video_call_link;
|
|
|
|
const available_providers = page_params.realm_available_video_chat_providers;
|
2021-02-28 00:51:57 +01:00
|
|
|
const show_video_chat_button = compute_show_video_chat_button();
|
2020-04-08 00:23:15 +02:00
|
|
|
|
|
|
|
if (!show_video_chat_button) {
|
|
|
|
return;
|
|
|
|
}
|
2019-05-09 09:54:38 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
if (
|
|
|
|
available_providers.zoom &&
|
|
|
|
page_params.realm_video_chat_provider === available_providers.zoom.id
|
|
|
|
) {
|
2021-02-28 00:51:57 +01:00
|
|
|
abort_video_callbacks(edit_message_id);
|
2019-11-16 09:26:28 +01:00
|
|
|
const key = edit_message_id || "";
|
|
|
|
|
|
|
|
const make_zoom_call = () => {
|
2021-02-28 00:51:57 +01:00
|
|
|
video_call_xhrs.set(
|
2020-07-15 00:34:28 +02:00
|
|
|
key,
|
|
|
|
channel.post({
|
|
|
|
url: "/json/calls/zoom/create",
|
|
|
|
success(res) {
|
2021-02-28 00:51:57 +01:00
|
|
|
video_call_xhrs.delete(key);
|
2020-07-15 00:34:28 +02:00
|
|
|
insert_video_call_url(res.url, target_textarea);
|
|
|
|
},
|
|
|
|
error(xhr, status) {
|
2021-02-28 00:51:57 +01:00
|
|
|
video_call_xhrs.delete(key);
|
2020-07-15 00:34:28 +02:00
|
|
|
if (
|
|
|
|
status === "error" &&
|
|
|
|
xhr.responseJSON &&
|
|
|
|
xhr.responseJSON.code === "INVALID_ZOOM_TOKEN"
|
|
|
|
) {
|
|
|
|
page_params.has_zoom_token = false;
|
|
|
|
}
|
|
|
|
if (status !== "abort") {
|
|
|
|
ui_report.generic_embed_error(
|
2021-04-13 05:18:25 +02:00
|
|
|
$t_html({defaultMessage: "Failed to create video call."}),
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
2019-11-16 09:26:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
if (page_params.has_zoom_token) {
|
|
|
|
make_zoom_call();
|
|
|
|
} else {
|
2021-02-28 00:51:57 +01:00
|
|
|
zoom_token_callbacks.set(key, make_zoom_call);
|
2019-11-16 09:26:28 +01:00
|
|
|
window.open(
|
2020-07-15 00:34:28 +02:00
|
|
|
window.location.protocol + "//" + window.location.host + "/calls/zoom/register",
|
2019-11-16 09:26:28 +01:00
|
|
|
"_blank",
|
2020-07-02 02:16:03 +02:00
|
|
|
"width=800,height=500,noopener,noreferrer",
|
2019-11-16 09:26:28 +01:00
|
|
|
);
|
|
|
|
}
|
2020-04-27 22:41:31 +02:00
|
|
|
} else if (
|
2020-07-15 00:34:28 +02:00
|
|
|
available_providers.big_blue_button &&
|
|
|
|
page_params.realm_video_chat_provider === available_providers.big_blue_button.id
|
2020-06-23 02:29:27 +02:00
|
|
|
) {
|
2020-04-27 22:41:31 +02:00
|
|
|
channel.get({
|
2020-07-15 01:29:15 +02:00
|
|
|
url: "/json/calls/bigbluebutton/create",
|
2020-07-20 22:18:43 +02:00
|
|
|
success(response) {
|
2020-04-27 22:41:31 +02:00
|
|
|
insert_video_call_url(response.url, target_textarea);
|
|
|
|
},
|
|
|
|
});
|
2018-04-23 14:51:30 +02:00
|
|
|
} else {
|
2020-10-28 11:35:48 +01:00
|
|
|
const video_call_id = util.random_int(100000000000000, 999999999999999);
|
2020-07-16 23:29:01 +02:00
|
|
|
video_call_link = page_params.jitsi_server_url + "/" + video_call_id;
|
2019-01-23 08:04:53 +01:00
|
|
|
insert_video_call_url(video_call_link, target_textarea);
|
2018-04-23 14:51:30 +02:00
|
|
|
}
|
2017-08-11 01:51:48 +02:00
|
|
|
});
|
|
|
|
|
2021-04-20 19:50:01 +02:00
|
|
|
$("#compose").on("click", ".markdown_preview", (e) => {
|
2016-08-29 22:37:27 +02:00
|
|
|
e.preventDefault();
|
2019-11-02 00:06:25 +01:00
|
|
|
const content = $("#compose-textarea").val();
|
2017-11-26 20:37:44 +01:00
|
|
|
$("#compose-textarea").hide();
|
2021-04-20 19:50:01 +02:00
|
|
|
$("#compose .markdown_preview").hide();
|
|
|
|
$("#compose .undo_markdown_preview").show();
|
|
|
|
$("#compose .preview_message_area").show();
|
|
|
|
|
|
|
|
render_and_show_preview(
|
|
|
|
$("#compose .markdown_preview_spinner"),
|
|
|
|
$("#compose .preview_content"),
|
|
|
|
content,
|
|
|
|
);
|
2016-08-29 22:37:27 +02:00
|
|
|
});
|
|
|
|
|
2021-04-20 19:50:01 +02:00
|
|
|
$("#compose").on("click", ".undo_markdown_preview", (e) => {
|
2016-08-29 22:37:27 +02:00
|
|
|
e.preventDefault();
|
2021-02-28 00:51:57 +01:00
|
|
|
clear_preview_area();
|
2016-08-29 22:37:27 +02:00
|
|
|
});
|
|
|
|
|
2019-11-21 05:24:55 +01:00
|
|
|
uppy = upload.setup_upload({
|
|
|
|
mode: "compose",
|
|
|
|
});
|
2014-01-14 17:21:41 +01:00
|
|
|
|
2020-07-20 21:26:58 +02:00
|
|
|
$("#compose-textarea").on("focus", () => {
|
2020-07-27 16:07:38 +02:00
|
|
|
compose_actions.update_placeholder_text();
|
2019-07-23 20:13:43 +02:00
|
|
|
});
|
|
|
|
|
2020-09-01 17:46:14 +02:00
|
|
|
$("#stream_message_recipient_topic").on("focus", () => {
|
|
|
|
compose_actions.update_placeholder_text();
|
|
|
|
});
|
|
|
|
|
2014-01-14 17:21:41 +01:00
|
|
|
if (page_params.narrow !== undefined) {
|
2014-01-17 00:05:35 +01:00
|
|
|
if (page_params.narrow_topic !== undefined) {
|
2018-11-15 19:14:16 +01:00
|
|
|
compose_actions.start("stream", {topic: page_params.narrow_topic});
|
2014-01-17 00:05:35 +01:00
|
|
|
} else {
|
2017-03-18 17:41:47 +01:00
|
|
|
compose_actions.start("stream", {});
|
2014-01-17 00:05:35 +01:00
|
|
|
}
|
2014-01-14 17:21:41 +01:00
|
|
|
}
|
2021-02-28 00:51:57 +01:00
|
|
|
}
|