2021-02-28 00:56:21 +01:00
|
|
|
import ClipboardJS from "clipboard";
|
2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
2020-08-01 03:43:15 +02:00
|
|
|
|
2022-03-07 22:25:54 +01:00
|
|
|
import * as resolved_topic from "../shared/js/resolved_topic";
|
2021-06-21 11:16:55 +02:00
|
|
|
import render_delete_message_modal from "../templates/confirm_dialog/confirm_delete_message.hbs";
|
2021-02-28 00:56:21 +01:00
|
|
|
import render_message_edit_form from "../templates/message_edit_form.hbs";
|
|
|
|
import render_topic_edit_form from "../templates/topic_edit_form.hbs";
|
2020-07-28 00:14:57 +02:00
|
|
|
|
2021-03-16 23:38:59 +01:00
|
|
|
import * as blueslip from "./blueslip";
|
2021-02-28 00:56:21 +01:00
|
|
|
import * as channel from "./channel";
|
|
|
|
import * as compose from "./compose";
|
2021-02-28 21:32:22 +01:00
|
|
|
import * as compose_actions from "./compose_actions";
|
2021-07-28 18:23:34 +02:00
|
|
|
import * as compose_ui from "./compose_ui";
|
2021-02-28 21:33:26 +01:00
|
|
|
import * as composebox_typeahead from "./composebox_typeahead";
|
2021-02-28 00:56:48 +01:00
|
|
|
import * as condense from "./condense";
|
2021-05-09 11:19:58 +02:00
|
|
|
import * as confirm_dialog from "./confirm_dialog";
|
2021-07-05 19:15:37 +02:00
|
|
|
import * as dialog_widget from "./dialog_widget";
|
2021-02-28 00:56:21 +01:00
|
|
|
import * as echo from "./echo";
|
2021-04-13 06:51:54 +02:00
|
|
|
import {$t, $t_html} from "./i18n";
|
2021-02-28 00:56:21 +01:00
|
|
|
import * as loading from "./loading";
|
|
|
|
import * as markdown from "./markdown";
|
2021-03-30 02:21:21 +02:00
|
|
|
import * as message_lists from "./message_lists";
|
2021-02-28 01:10:03 +01:00
|
|
|
import * as message_store from "./message_store";
|
2021-02-28 00:56:21 +01:00
|
|
|
import * as message_viewport from "./message_viewport";
|
2021-03-25 22:35:45 +01:00
|
|
|
import {page_params} from "./page_params";
|
2021-02-28 00:57:20 +01:00
|
|
|
import * as resize from "./resize";
|
2021-02-28 00:56:21 +01:00
|
|
|
import * as rows from "./rows";
|
2021-04-30 09:35:20 +02:00
|
|
|
import * as settings_data from "./settings_data";
|
2021-02-28 00:56:21 +01:00
|
|
|
import * as stream_data from "./stream_data";
|
2021-02-28 00:58:55 +01:00
|
|
|
import * as ui_report from "./ui_report";
|
2021-02-28 00:56:21 +01:00
|
|
|
import * as upload from "./upload";
|
2022-03-17 16:58:10 +01:00
|
|
|
import * as util from "./util";
|
2021-02-10 16:53:37 +01:00
|
|
|
|
2020-02-06 06:23:06 +01:00
|
|
|
const currently_editing_messages = new Map();
|
2019-11-02 00:06:25 +01:00
|
|
|
let currently_deleting_messages = [];
|
2020-08-25 17:52:39 +02:00
|
|
|
let currently_topic_editing_messages = [];
|
2020-02-06 06:24:12 +01:00
|
|
|
const currently_echoing_messages = new Map();
|
2013-05-15 00:22:16 +02:00
|
|
|
|
2020-06-03 16:44:57 +02:00
|
|
|
// These variables are designed to preserve the user's most recent
|
|
|
|
// choices when editing a group of messages, to make it convenient to
|
|
|
|
// move several topics in a row with the same settings.
|
2022-06-04 02:33:06 +02:00
|
|
|
export let notify_old_thread_default = false;
|
2021-02-28 00:56:21 +01:00
|
|
|
|
|
|
|
export let notify_new_thread_default = true;
|
2020-06-03 16:44:57 +02:00
|
|
|
|
2021-02-28 00:56:21 +01:00
|
|
|
export const editability_types = {
|
2016-10-22 04:26:35 +02:00
|
|
|
NO: 1,
|
|
|
|
// Note: TOPIC_ONLY does not include stream messages with no topic sent
|
|
|
|
// by someone else. You can edit the topic of such a message by editing
|
|
|
|
// the topic of the whole recipient_row it appears in, but you can't
|
|
|
|
// directly edit the topic of such a message.
|
|
|
|
// Similar story for messages whose topic you can change only because
|
|
|
|
// you are an admin.
|
|
|
|
TOPIC_ONLY: 3,
|
2017-01-12 00:17:43 +01:00
|
|
|
FULL: 4,
|
2016-10-22 04:26:35 +02:00
|
|
|
};
|
|
|
|
|
2021-02-28 00:56:21 +01:00
|
|
|
export function is_topic_editable(message, edit_limit_seconds_buffer = 0) {
|
2018-10-09 09:54:57 +02:00
|
|
|
if (!page_params.realm_allow_message_editing) {
|
|
|
|
// If message editing is disabled, so is topic editing.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Organization admins and message senders can edit message topics indefinitely.
|
|
|
|
if (page_params.is_admin) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (message.sent_by_me) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-10-17 12:38:24 +02:00
|
|
|
if (message.topic === compose.empty_topic_placeholder()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-26 21:20:11 +02:00
|
|
|
if (!settings_data.user_can_edit_topic_of_any_message()) {
|
2018-10-09 09:54:57 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-05-26 21:20:11 +02:00
|
|
|
// moderators can edit the topic if edit_topic_policy allows them to do so,
|
|
|
|
// irrespective of the topic editing deadline.
|
|
|
|
if (page_params.is_moderator) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-09 09:54:57 +02:00
|
|
|
// If you're using community topic editing, there's a deadline.
|
2020-07-15 00:34:28 +02:00
|
|
|
return (
|
|
|
|
page_params.realm_community_topic_editing_limit_seconds +
|
|
|
|
edit_limit_seconds_buffer +
|
2021-02-05 21:20:14 +01:00
|
|
|
(message.timestamp - Date.now() / 1000) >
|
2020-07-15 00:34:28 +02:00
|
|
|
0
|
|
|
|
);
|
2018-04-25 23:15:04 +02:00
|
|
|
}
|
|
|
|
|
2021-01-31 18:23:48 +01:00
|
|
|
function is_widget_message(message) {
|
|
|
|
if (message.submessages && message.submessages.length !== 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-10-20 12:45:08 +02:00
|
|
|
export function is_message_editable_ignoring_permissions(message) {
|
2017-12-03 00:56:17 +01:00
|
|
|
if (!message) {
|
2022-10-20 12:45:08 +02:00
|
|
|
return false;
|
2016-11-10 21:17:30 +01:00
|
|
|
}
|
2021-01-31 18:23:48 +01:00
|
|
|
|
2016-11-10 21:17:30 +01:00
|
|
|
if (message.failed_request) {
|
2017-07-18 14:44:29 +02:00
|
|
|
// TODO: For completely failed requests, we should be able
|
|
|
|
// to "edit" the message, but it won't really be like
|
|
|
|
// other message updates. This commit changed the result
|
|
|
|
// from FULL to NO, since the prior implementation was
|
|
|
|
// buggy.
|
2022-10-20 12:45:08 +02:00
|
|
|
return false;
|
2016-11-10 21:17:30 +01:00
|
|
|
}
|
2017-07-18 14:44:29 +02:00
|
|
|
|
2016-12-29 23:50:24 +01:00
|
|
|
// Locally echoed messages are not editable, since the message hasn't
|
|
|
|
// finished being sent yet.
|
2017-07-17 16:52:57 +02:00
|
|
|
if (message.locally_echoed) {
|
2022-10-20 12:45:08 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currently_echoing_messages.has(message.id)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function get_editability(message, edit_limit_seconds_buffer = 0) {
|
|
|
|
if (!is_message_editable_ignoring_permissions(message)) {
|
|
|
|
return editability_types.NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_topic_editable(message, edit_limit_seconds_buffer)) {
|
2016-11-10 21:17:30 +01:00
|
|
|
return editability_types.NO;
|
|
|
|
}
|
2017-07-18 14:44:29 +02:00
|
|
|
|
2016-11-10 21:17:30 +01:00
|
|
|
if (!page_params.realm_allow_message_editing) {
|
2016-10-22 04:26:35 +02:00
|
|
|
return editability_types.NO;
|
|
|
|
}
|
2017-07-18 14:44:29 +02:00
|
|
|
|
2021-01-31 18:23:48 +01:00
|
|
|
if (
|
2022-04-12 13:13:02 +02:00
|
|
|
page_params.realm_message_content_edit_limit_seconds === null &&
|
2021-01-31 18:23:48 +01:00
|
|
|
message.sent_by_me &&
|
|
|
|
!is_widget_message(message)
|
|
|
|
) {
|
2016-10-22 04:26:35 +02:00
|
|
|
return editability_types.FULL;
|
|
|
|
}
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
if (
|
|
|
|
page_params.realm_message_content_edit_limit_seconds +
|
|
|
|
edit_limit_seconds_buffer +
|
2021-02-05 21:20:14 +01:00
|
|
|
(message.timestamp - Date.now() / 1000) >
|
2020-07-15 00:34:28 +02:00
|
|
|
0 &&
|
2021-01-31 18:23:48 +01:00
|
|
|
message.sent_by_me &&
|
|
|
|
!is_widget_message(message)
|
2020-07-15 00:34:28 +02:00
|
|
|
) {
|
2016-10-22 04:26:35 +02:00
|
|
|
return editability_types.FULL;
|
|
|
|
}
|
2017-12-03 00:56:17 +01:00
|
|
|
|
2016-10-22 04:26:35 +02:00
|
|
|
// time's up!
|
2020-07-15 01:29:15 +02:00
|
|
|
if (message.type === "stream") {
|
2016-10-22 04:26:35 +02:00
|
|
|
return editability_types.TOPIC_ONLY;
|
|
|
|
}
|
2022-10-13 08:58:53 +02:00
|
|
|
return editability_types.NO;
|
2016-10-22 04:26:35 +02:00
|
|
|
}
|
2013-08-16 23:45:13 +02:00
|
|
|
|
2021-02-28 00:56:21 +01:00
|
|
|
export function get_deletability(message) {
|
2017-11-26 09:12:10 +01:00
|
|
|
if (page_params.is_admin) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!message.sent_by_me) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (message.locally_echoed) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-06-23 12:53:38 +02:00
|
|
|
if (!settings_data.user_can_delete_own_message()) {
|
2017-11-26 09:12:10 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-06-14 18:49:28 +02:00
|
|
|
if (page_params.realm_message_content_delete_limit_seconds === null) {
|
2017-11-26 09:12:10 +01:00
|
|
|
// This means no time limit for message deletion.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
if (
|
|
|
|
page_params.realm_message_content_delete_limit_seconds +
|
|
|
|
(message.timestamp - Date.now() / 1000) >
|
2021-06-09 15:49:51 +02:00
|
|
|
0
|
2021-02-05 21:20:14 +01:00
|
|
|
) {
|
|
|
|
return true;
|
2017-11-26 09:12:10 +01:00
|
|
|
}
|
|
|
|
return false;
|
2021-02-28 00:56:21 +01:00
|
|
|
}
|
2017-11-26 09:12:10 +01:00
|
|
|
|
2022-10-13 08:47:36 +02:00
|
|
|
export function can_move_message(message) {
|
|
|
|
if (!page_params.realm_allow_message_editing) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!message.is_stream) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
get_editability(message) !== editability_types.NO ||
|
|
|
|
settings_data.user_can_move_messages_between_streams()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-03-17 16:58:10 +01:00
|
|
|
export function stream_and_topic_exist_in_edit_history(message, stream_id, topic) {
|
|
|
|
/* Checks to see if a stream_id and a topic match any historical
|
|
|
|
stream_id and topic state in the message's edit history.
|
|
|
|
|
|
|
|
Does not check the message's current stream_id and topic for
|
|
|
|
a match to the stream_id and topic parameters.
|
|
|
|
*/
|
|
|
|
const narrow_dict = {stream_id, topic};
|
|
|
|
const message_dict = {stream_id: message.stream_id, topic: message.topic};
|
|
|
|
|
|
|
|
if (!message.edit_history) {
|
|
|
|
// If message edit history is disabled in the organization,
|
|
|
|
// the client does not have the information locally to answer
|
|
|
|
// this question correctly.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const edit_history_event of message.edit_history) {
|
|
|
|
if (!edit_history_event.prev_stream && !edit_history_event.prev_topic) {
|
|
|
|
// Message was not moved in this edit event.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (edit_history_event.prev_stream) {
|
|
|
|
// This edit event changed the stream. We expect the
|
|
|
|
// following to be true due to the invariants of the edit
|
|
|
|
// history data structure:
|
|
|
|
// edit_history_event.stream === message_dict.stream_id
|
|
|
|
message_dict.stream_id = edit_history_event.prev_stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (edit_history_event.prev_topic) {
|
|
|
|
// This edit event changed the topic. We expect the
|
|
|
|
// following to be true due to the invariants of the edit
|
|
|
|
// history data structure:
|
|
|
|
// util.lower_same(edit_history_event.topic, message_dict.topic)
|
|
|
|
message_dict.topic = edit_history_event.prev_topic;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (util.same_stream_and_topic(narrow_dict, message_dict)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-02-28 00:56:21 +01:00
|
|
|
export function update_message_topic_editing_pencil() {
|
2018-03-05 18:28:37 +01:00
|
|
|
if (page_params.realm_allow_message_editing) {
|
|
|
|
$(".on_hover_topic_edit, .always_visible_topic_edit").show();
|
|
|
|
} else {
|
|
|
|
$(".on_hover_topic_edit, .always_visible_topic_edit").hide();
|
|
|
|
}
|
2021-02-28 00:56:21 +01:00
|
|
|
}
|
2018-03-05 18:28:37 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
export function hide_message_edit_spinner($row) {
|
|
|
|
$row.find(".loader").hide();
|
|
|
|
$row.find(".message_edit_save span").show();
|
|
|
|
$row.find(".message_edit_save").removeClass("disable-btn");
|
|
|
|
$row.find(".message_edit_cancel").removeClass("disable-btn");
|
2021-02-28 00:56:21 +01:00
|
|
|
}
|
2020-08-21 07:34:21 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
export function show_message_edit_spinner($row) {
|
2021-07-16 08:45:23 +02:00
|
|
|
const using_dark_theme = settings_data.using_dark_theme();
|
2022-01-25 11:36:19 +01:00
|
|
|
loading.show_button_spinner($row.find(".loader"), using_dark_theme);
|
|
|
|
$row.find(".message_edit_save span").hide();
|
|
|
|
$row.find(".message_edit_save").addClass("disable-btn");
|
|
|
|
$row.find(".message_edit_cancel").addClass("disable-btn");
|
2021-02-28 00:56:21 +01:00
|
|
|
}
|
2020-08-21 07:34:21 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
export function show_topic_edit_spinner($row) {
|
|
|
|
const $spinner = $row.find(".topic_edit_spinner");
|
|
|
|
loading.make_indicator($spinner);
|
|
|
|
$spinner.css({height: ""});
|
2018-03-23 08:44:55 +01:00
|
|
|
$(".topic_edit_save").hide();
|
|
|
|
$(".topic_edit_cancel").hide();
|
2021-01-27 07:34:22 +01:00
|
|
|
$(".topic_edit_spinner").show();
|
2021-02-28 00:56:21 +01:00
|
|
|
}
|
2018-03-23 08:44:55 +01:00
|
|
|
|
2021-02-28 00:56:21 +01:00
|
|
|
export function end_if_focused_on_inline_topic_edit() {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $focused_elem = $(".topic_edit_form").find(":focus");
|
|
|
|
if ($focused_elem.length === 1) {
|
|
|
|
$focused_elem.trigger("blur");
|
|
|
|
const $recipient_row = $focused_elem.closest(".recipient_row");
|
|
|
|
end_inline_topic_edit($recipient_row);
|
2020-04-16 12:50:09 +02:00
|
|
|
}
|
2021-02-28 00:56:21 +01:00
|
|
|
}
|
2020-04-02 19:39:10 +02:00
|
|
|
|
2021-02-28 00:56:21 +01:00
|
|
|
export function end_if_focused_on_message_row_edit() {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $focused_elem = $(".message_edit").find(":focus");
|
|
|
|
if ($focused_elem.length === 1) {
|
|
|
|
$focused_elem.trigger("blur");
|
|
|
|
const $row = $focused_elem.closest(".message_row");
|
|
|
|
end_message_row_edit($row);
|
2020-04-02 19:39:10 +02:00
|
|
|
}
|
2021-02-28 00:56:21 +01:00
|
|
|
}
|
2020-04-02 19:39:10 +02:00
|
|
|
|
2020-04-19 12:48:19 +02:00
|
|
|
function handle_message_row_edit_keydown(e) {
|
2021-05-29 22:08:55 +02:00
|
|
|
switch (e.key) {
|
|
|
|
case "Enter":
|
2020-07-15 02:14:03 +02:00
|
|
|
if ($(e.target).hasClass("message_edit_content")) {
|
2020-08-11 02:09:14 +02:00
|
|
|
// Pressing Enter to save edits is coupled with Enter to send
|
2020-07-15 02:14:03 +02:00
|
|
|
if (composebox_typeahead.should_enter_send(e)) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $row = $(".message_edit_content:focus").closest(".message_row");
|
|
|
|
const $message_edit_save_button = $row.find(".message_edit_save");
|
|
|
|
if ($message_edit_save_button.prop("disabled")) {
|
2020-07-15 00:34:28 +02:00
|
|
|
// In cases when the save button is disabled
|
2020-08-11 02:09:14 +02:00
|
|
|
// we need to disable save on pressing Enter
|
2020-07-15 00:34:28 +02:00
|
|
|
// Prevent default to avoid new-line on pressing
|
2020-08-11 02:09:14 +02:00
|
|
|
// Enter inside the textarea in this case
|
2020-07-15 02:14:03 +02:00
|
|
|
e.preventDefault();
|
|
|
|
return;
|
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
save_message_row_edit($row);
|
2020-07-15 02:14:03 +02:00
|
|
|
e.stopPropagation();
|
2020-04-19 12:48:19 +02:00
|
|
|
e.preventDefault();
|
2020-07-15 02:14:03 +02:00
|
|
|
} else {
|
|
|
|
composebox_typeahead.handle_enter($(e.target), e);
|
2020-04-20 07:23:19 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-07-07 22:56:58 +02:00
|
|
|
} else if ($(".typeahead:visible").length > 0) {
|
|
|
|
// Accepting typeahead is handled by the typeahead library.
|
|
|
|
return;
|
2020-07-15 00:34:28 +02:00
|
|
|
} else if (
|
|
|
|
$(e.target).hasClass("message_edit_topic") ||
|
|
|
|
$(e.target).hasClass("message_edit_topic_propagate")
|
|
|
|
) {
|
2021-07-07 22:56:58 +02:00
|
|
|
// Enter should save the topic edit, as long as it's
|
|
|
|
// not being used to accept typeahead.
|
2022-01-25 11:36:19 +01:00
|
|
|
const $row = $(e.target).closest(".message_row");
|
|
|
|
save_message_row_edit($row);
|
2020-04-20 07:23:19 +02:00
|
|
|
e.stopPropagation();
|
2019-04-16 03:37:33 +02:00
|
|
|
}
|
2020-07-15 02:14:03 +02:00
|
|
|
return;
|
2021-05-29 22:08:55 +02:00
|
|
|
case "Escape": // Handle escape keys in the message_edit form.
|
2021-02-28 00:56:21 +01:00
|
|
|
end_if_focused_on_message_row_edit();
|
2020-04-20 07:23:19 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
2020-07-15 02:14:03 +02:00
|
|
|
return;
|
|
|
|
default:
|
|
|
|
return;
|
2020-04-19 12:48:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function handle_inline_topic_edit_keydown(e) {
|
2022-01-25 11:36:19 +01:00
|
|
|
let $row;
|
2021-05-29 22:08:55 +02:00
|
|
|
switch (e.key) {
|
|
|
|
case "Enter": // Handle Enter key in the recipient bar/inline topic edit form
|
2021-07-07 22:56:58 +02:00
|
|
|
if ($(".typeahead:visible").length > 0) {
|
|
|
|
// Accepting typeahead should not trigger a save.
|
|
|
|
e.preventDefault();
|
|
|
|
return;
|
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
$row = $(e.target).closest(".recipient_row");
|
|
|
|
save_inline_topic_edit($row);
|
2020-07-15 02:14:03 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
return;
|
2021-05-29 22:08:55 +02:00
|
|
|
case "Escape": // handle Esc
|
2021-02-28 00:56:21 +01:00
|
|
|
end_if_focused_on_inline_topic_edit();
|
2020-07-15 02:14:03 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
return;
|
2016-10-26 01:15:23 +02:00
|
|
|
}
|
2013-08-02 19:25:37 +02:00
|
|
|
}
|
|
|
|
|
2016-07-08 02:25:55 +02:00
|
|
|
function timer_text(seconds_left) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const minutes = Math.floor(seconds_left / 60);
|
|
|
|
const seconds = seconds_left % 60;
|
2016-07-08 02:25:55 +02:00
|
|
|
if (minutes >= 1) {
|
2021-04-13 06:51:54 +02:00
|
|
|
return $t({defaultMessage: "{minutes} min to edit"}, {minutes: minutes.toString()});
|
2016-07-08 02:25:55 +02:00
|
|
|
} else if (seconds_left >= 10) {
|
2021-04-13 06:51:54 +02:00
|
|
|
return $t(
|
|
|
|
{defaultMessage: "{seconds} sec to edit"},
|
|
|
|
{seconds: (seconds - (seconds % 5)).toString()},
|
|
|
|
);
|
2016-07-08 02:25:55 +02:00
|
|
|
}
|
2021-04-13 06:51:54 +02:00
|
|
|
return $t({defaultMessage: "{seconds} sec to edit"}, {seconds: seconds.toString()});
|
2016-07-08 02:25:55 +02:00
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
function create_copy_to_clipboard_handler($row, source, message_id) {
|
2021-06-28 11:31:18 +02:00
|
|
|
const clipboard = new ClipboardJS(source, {
|
2021-04-20 19:50:01 +02:00
|
|
|
target: () =>
|
|
|
|
document.querySelector(`#edit_form_${CSS.escape(message_id)} .message_edit_content`),
|
2021-04-11 15:24:38 +02:00
|
|
|
});
|
2021-06-28 11:31:18 +02:00
|
|
|
|
|
|
|
clipboard.on("success", () => {
|
2022-01-25 11:36:19 +01:00
|
|
|
end_message_row_edit($row);
|
|
|
|
$row.find(".alert-msg").text($t({defaultMessage: "Copied!"}));
|
|
|
|
$row.find(".alert-msg").css("display", "block");
|
|
|
|
$row.find(".alert-msg").delay(1000).fadeOut(300);
|
2021-06-28 11:31:18 +02:00
|
|
|
if ($(".tooltip").is(":visible")) {
|
|
|
|
$(".tooltip").hide();
|
|
|
|
}
|
|
|
|
});
|
2021-04-11 15:24:38 +02:00
|
|
|
}
|
|
|
|
|
2021-12-27 10:27:03 +01:00
|
|
|
export function get_available_streams_for_moving_messages(current_stream_id) {
|
|
|
|
return stream_data
|
|
|
|
.subscribed_subs()
|
|
|
|
.filter((stream) => {
|
|
|
|
if (stream.id === current_stream_id) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return stream_data.can_post_messages_in_stream(stream);
|
|
|
|
})
|
|
|
|
.map((stream) => ({
|
|
|
|
name: stream.name,
|
|
|
|
value: stream.stream_id.toString(),
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
function edit_message($row, raw_content) {
|
|
|
|
$row.find(".message_reactions").hide();
|
|
|
|
condense.hide_message_expander($row);
|
|
|
|
condense.hide_message_condenser($row);
|
|
|
|
const content_top = $row.find(".message_top_line")[0].getBoundingClientRect().top;
|
2013-07-22 20:19:35 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const message = message_lists.current.get(rows.id($row));
|
2013-08-02 19:25:37 +02:00
|
|
|
|
2016-07-08 02:25:55 +02:00
|
|
|
// We potentially got to this function by clicking a button that implied the
|
|
|
|
// user would be able to edit their message. Give a little bit of buffer in
|
|
|
|
// case the button has been around for a bit, e.g. we show the
|
|
|
|
// edit_content_button (hovering pencil icon) as long as the user would have
|
|
|
|
// been able to click it at the time the mouse entered the message_row. Also
|
|
|
|
// a buffer in case their computer is slow, or stalled for a second, etc
|
|
|
|
// If you change this number also change edit_limit_buffer in
|
2022-04-14 23:55:52 +02:00
|
|
|
// zerver.actions.message_edit.check_update_message
|
2019-11-02 00:06:25 +01:00
|
|
|
const seconds_left_buffer = 5;
|
|
|
|
const editability = get_editability(message, seconds_left_buffer);
|
2020-05-08 06:57:19 +02:00
|
|
|
const max_file_upload_size = page_params.max_file_upload_size_mib;
|
2019-11-02 00:06:25 +01:00
|
|
|
let file_upload_enabled = false;
|
2019-05-04 20:24:36 +02:00
|
|
|
|
|
|
|
if (max_file_upload_size > 0) {
|
|
|
|
file_upload_enabled = true;
|
|
|
|
}
|
2016-10-23 03:19:16 +02:00
|
|
|
|
2022-10-01 13:50:44 +02:00
|
|
|
const is_editable = editability === editability_types.FULL;
|
2021-05-12 21:41:14 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $form = $(
|
2020-07-15 00:34:28 +02:00
|
|
|
render_message_edit_form({
|
|
|
|
message_id: message.id,
|
2020-07-20 22:18:43 +02:00
|
|
|
is_editable,
|
2020-07-15 00:34:28 +02:00
|
|
|
content: raw_content,
|
2020-07-20 22:18:43 +02:00
|
|
|
file_upload_enabled,
|
2020-07-15 00:34:28 +02:00
|
|
|
minutes_to_edit: Math.floor(page_params.realm_message_content_edit_limit_seconds / 60),
|
2022-07-15 03:05:53 +02:00
|
|
|
max_message_length: page_params.max_message_length,
|
2020-07-15 00:34:28 +02:00
|
|
|
}),
|
|
|
|
);
|
2016-10-23 03:19:16 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const edit_obj = {$form, raw_content};
|
2020-02-06 06:23:06 +01:00
|
|
|
currently_editing_messages.set(message.id, edit_obj);
|
2022-01-25 11:36:19 +01:00
|
|
|
message_lists.current.show_edit_message($row, edit_obj);
|
2016-10-23 03:19:16 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$form.on("keydown", handle_message_row_edit_keydown);
|
2016-10-23 03:19:16 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$form
|
|
|
|
.find(".message-edit-feature-group .video_link")
|
|
|
|
.toggle(compose.compute_show_video_chat_button());
|
|
|
|
upload.feature_check($(`#edit_form_${CSS.escape(rows.id($row))} .compose_upload_file`));
|
2017-11-28 22:36:58 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $message_edit_content = $row.find("textarea.message_edit_content");
|
|
|
|
const $message_edit_countdown_timer = $row.find(".message_edit_countdown_timer");
|
|
|
|
const $copy_message = $row.find(".copy_message");
|
2017-03-26 11:02:37 +02:00
|
|
|
|
2022-10-01 13:50:44 +02:00
|
|
|
if (editability !== editability_types.FULL) {
|
|
|
|
$message_edit_content.attr("readonly", "readonly");
|
|
|
|
create_copy_to_clipboard_handler($row, $copy_message[0], message.id);
|
|
|
|
} else {
|
|
|
|
$copy_message.remove();
|
|
|
|
const edit_id = `#edit_form_${CSS.escape(rows.id($row))} .message_edit_content`;
|
|
|
|
const listeners = resize.watch_manual_resize(edit_id);
|
|
|
|
if (listeners) {
|
|
|
|
currently_editing_messages.get(rows.id($row)).listeners = listeners;
|
2017-05-11 18:28:33 +02:00
|
|
|
}
|
2022-10-01 13:50:44 +02:00
|
|
|
composebox_typeahead.initialize_compose_typeahead(edit_id);
|
|
|
|
compose_ui.handle_keyup(null, $(edit_id).expectOne());
|
|
|
|
$(edit_id).on("keydown", function (event) {
|
|
|
|
compose_ui.handle_keydown(event, $(this).expectOne());
|
|
|
|
});
|
|
|
|
$(edit_id).on("keyup", function (event) {
|
|
|
|
compose_ui.handle_keyup(event, $(this).expectOne());
|
|
|
|
});
|
2016-07-08 02:25:55 +02:00
|
|
|
}
|
|
|
|
|
2022-10-01 13:50:44 +02:00
|
|
|
// Add tooltip and timer
|
2020-07-15 00:34:28 +02:00
|
|
|
if (
|
2022-08-03 07:48:43 +02:00
|
|
|
editability === editability_types.FULL &&
|
2020-07-15 00:34:28 +02:00
|
|
|
page_params.realm_message_content_edit_limit_seconds > 0
|
|
|
|
) {
|
2022-08-07 06:57:14 +02:00
|
|
|
$row.find(".message-edit-timer").show();
|
2016-10-23 03:31:39 +02:00
|
|
|
|
2016-10-22 02:33:50 +02:00
|
|
|
// Give them at least 10 seconds.
|
|
|
|
// If you change this number also change edit_limit_buffer in
|
2022-04-14 23:55:52 +02:00
|
|
|
// zerver.actions.message_edit.check_update_message
|
2019-11-02 00:06:25 +01:00
|
|
|
const min_seconds_to_edit = 10;
|
2020-07-15 00:34:28 +02:00
|
|
|
let seconds_left =
|
|
|
|
page_params.realm_message_content_edit_limit_seconds +
|
2021-02-05 21:20:14 +01:00
|
|
|
(message.timestamp - Date.now() / 1000);
|
2016-10-22 02:33:50 +02:00
|
|
|
seconds_left = Math.floor(Math.max(seconds_left, min_seconds_to_edit));
|
2016-10-23 03:35:42 +02:00
|
|
|
|
2016-11-02 23:46:34 +01:00
|
|
|
// I believe this needs to be defined outside the countdown_timer, since
|
2016-10-23 03:35:42 +02:00
|
|
|
// row just refers to something like the currently selected message, and
|
|
|
|
// can change out from under us
|
2022-01-25 11:36:19 +01:00
|
|
|
const $message_edit_save = $row.find("button.message_edit_save");
|
2016-10-23 03:35:42 +02:00
|
|
|
// Do this right away, rather than waiting for the timer to do its first update,
|
|
|
|
// since otherwise there is a noticeable lag
|
2022-01-25 11:36:19 +01:00
|
|
|
$message_edit_countdown_timer.text(timer_text(seconds_left));
|
2020-07-02 01:45:54 +02:00
|
|
|
const countdown_timer = setInterval(() => {
|
2017-02-21 06:41:07 +01:00
|
|
|
seconds_left -= 1;
|
|
|
|
if (seconds_left <= 0) {
|
2016-10-23 03:35:42 +02:00
|
|
|
clearInterval(countdown_timer);
|
2022-09-10 01:34:43 +02:00
|
|
|
$message_edit_content.prop("readonly", "readonly");
|
2016-10-22 04:26:35 +02:00
|
|
|
// We don't go directly to a "TOPIC_ONLY" type state (with an active Save button),
|
2016-10-23 03:35:42 +02:00
|
|
|
// since it isn't clear what to do with the half-finished edit. It's nice to keep
|
|
|
|
// the half-finished edit around so that they can copy-paste it, but we don't want
|
|
|
|
// people to think "Save" will save the half-finished edit.
|
2022-01-25 11:36:19 +01:00
|
|
|
$message_edit_save.addClass("disabled");
|
|
|
|
$message_edit_countdown_timer.text($t({defaultMessage: "Time's up!"}));
|
2016-10-23 03:35:42 +02:00
|
|
|
} else {
|
2022-01-25 11:36:19 +01:00
|
|
|
$message_edit_countdown_timer.text(timer_text(seconds_left));
|
2016-10-23 03:35:42 +02:00
|
|
|
}
|
|
|
|
}, 1000);
|
2016-07-08 02:25:55 +02:00
|
|
|
}
|
|
|
|
|
2016-10-22 02:38:56 +02:00
|
|
|
if (!is_editable) {
|
2022-01-25 11:36:19 +01:00
|
|
|
$row.find(".message_edit_close").trigger("focus");
|
2013-07-17 16:24:54 +02:00
|
|
|
} else {
|
2022-01-25 11:36:19 +01:00
|
|
|
$message_edit_content.trigger("focus");
|
2016-11-03 02:03:02 +01:00
|
|
|
// Put cursor at end of input.
|
2022-01-25 11:36:19 +01:00
|
|
|
const contents = $message_edit_content.val();
|
|
|
|
$message_edit_content.val("");
|
|
|
|
$message_edit_content.val(contents);
|
2013-07-17 16:24:54 +02:00
|
|
|
}
|
2013-07-22 20:19:35 +02:00
|
|
|
|
2019-06-25 07:53:57 +02:00
|
|
|
// Scroll to keep the top of the message content text in the same
|
|
|
|
// place visually, adjusting for border and padding.
|
2022-01-25 11:36:19 +01:00
|
|
|
const edit_top = $message_edit_content[0].getBoundingClientRect().top;
|
2019-11-02 00:06:25 +01:00
|
|
|
const scroll_by = edit_top - content_top + 5 - 14;
|
2019-06-25 08:26:53 +02:00
|
|
|
|
2013-07-22 20:19:35 +02:00
|
|
|
edit_obj.scrolled_by = scroll_by;
|
2017-03-10 23:48:51 +01:00
|
|
|
message_viewport.scrollTop(message_viewport.scrollTop() + scroll_by);
|
2013-05-15 00:22:16 +02:00
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
function start_edit_maintaining_scroll($row, content) {
|
|
|
|
edit_message($row, content);
|
|
|
|
const row_bottom = $row.height() + $row.offset().top;
|
2019-11-02 00:06:25 +01:00
|
|
|
const composebox_top = $("#compose").offset().top;
|
2014-01-02 19:39:22 +01:00
|
|
|
if (row_bottom > composebox_top) {
|
2017-03-10 23:48:51 +01:00
|
|
|
message_viewport.scrollTop(message_viewport.scrollTop() + row_bottom - composebox_top);
|
2014-01-02 19:39:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
function start_edit_with_content($row, content, edit_box_open_callback) {
|
|
|
|
start_edit_maintaining_scroll($row, content);
|
2017-06-06 18:51:05 +02:00
|
|
|
if (edit_box_open_callback) {
|
|
|
|
edit_box_open_callback();
|
|
|
|
}
|
2018-03-05 09:10:05 +01:00
|
|
|
|
2019-11-21 05:24:55 +01:00
|
|
|
upload.setup_upload({
|
2020-07-15 01:29:15 +02:00
|
|
|
mode: "edit",
|
2022-01-25 11:36:19 +01:00
|
|
|
row: rows.id($row),
|
2019-11-21 05:24:55 +01:00
|
|
|
});
|
2017-06-06 18:51:05 +02:00
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
export function start($row, edit_box_open_callback) {
|
|
|
|
const message = message_lists.current.get(rows.id($row));
|
2017-08-28 01:10:55 +02:00
|
|
|
if (message === undefined) {
|
2022-01-25 11:36:19 +01:00
|
|
|
blueslip.error("Couldn't find message ID for edit " + rows.id($row));
|
2017-08-28 01:10:55 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-06 18:51:05 +02:00
|
|
|
if (message.raw_content) {
|
2022-01-25 11:36:19 +01:00
|
|
|
start_edit_with_content($row, message.raw_content, edit_box_open_callback);
|
2017-06-06 18:51:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-30 02:21:21 +02:00
|
|
|
const msg_list = message_lists.current;
|
2016-12-21 20:31:16 +01:00
|
|
|
channel.get({
|
2020-07-15 01:29:15 +02:00
|
|
|
url: "/json/messages/" + message.id,
|
2020-07-20 22:18:43 +02:00
|
|
|
success(data) {
|
2021-03-30 02:21:21 +02:00
|
|
|
if (message_lists.current === msg_list) {
|
2013-05-15 00:22:16 +02:00
|
|
|
message.raw_content = data.raw_content;
|
2022-01-25 11:36:19 +01:00
|
|
|
start_edit_with_content($row, message.raw_content, edit_box_open_callback);
|
2013-05-15 00:22:16 +02:00
|
|
|
}
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2013-05-15 00:22:16 +02:00
|
|
|
});
|
2021-02-28 00:56:21 +01:00
|
|
|
}
|
2013-05-15 00:22:16 +02:00
|
|
|
|
2021-06-26 20:46:08 +02:00
|
|
|
export function toggle_resolve_topic(message_id, old_topic_name) {
|
|
|
|
let new_topic_name;
|
2022-03-07 23:25:06 +01:00
|
|
|
if (resolved_topic.is_resolved(old_topic_name)) {
|
|
|
|
new_topic_name = resolved_topic.unresolve_name(old_topic_name);
|
2021-06-26 20:46:08 +02:00
|
|
|
} else {
|
2022-03-07 23:25:06 +01:00
|
|
|
new_topic_name = resolved_topic.resolve_name(old_topic_name);
|
2021-06-26 20:46:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const request = {
|
|
|
|
propagate_mode: "change_all",
|
|
|
|
topic: new_topic_name,
|
|
|
|
send_notification_to_old_thread: false,
|
|
|
|
send_notification_to_new_thread: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
channel.patch({
|
|
|
|
url: "/json/messages/" + message_id,
|
|
|
|
data: request,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
export function start_inline_topic_edit($recipient_row) {
|
2022-07-15 03:29:38 +02:00
|
|
|
const $form = $(
|
|
|
|
render_topic_edit_form({
|
|
|
|
max_topic_length: page_params.max_topic_length,
|
|
|
|
}),
|
|
|
|
);
|
2022-01-25 11:36:19 +01:00
|
|
|
message_lists.current.show_edit_topic_on_recipient_row($recipient_row, $form);
|
|
|
|
$form.on("keydown", handle_inline_topic_edit_keydown);
|
2021-01-27 07:34:22 +01:00
|
|
|
$(".topic_edit_spinner").hide();
|
2022-01-25 11:36:19 +01:00
|
|
|
const msg_id = rows.id_for_recipient_row($recipient_row);
|
2021-03-30 02:21:21 +02:00
|
|
|
const message = message_lists.current.get(msg_id);
|
2020-02-19 00:04:12 +01:00
|
|
|
let topic = message.topic;
|
2016-08-27 04:47:53 +02:00
|
|
|
if (topic === compose.empty_topic_placeholder()) {
|
2020-07-15 01:29:15 +02:00
|
|
|
topic = "";
|
2013-11-21 00:28:14 +01:00
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
const $inline_topic_edit_input = $form.find(".inline_topic_edit");
|
|
|
|
$inline_topic_edit_input.val(topic).trigger("select").trigger("focus");
|
2021-07-07 22:56:58 +02:00
|
|
|
composebox_typeahead.initialize_topic_edit_typeahead(
|
2022-01-25 11:36:19 +01:00
|
|
|
$inline_topic_edit_input,
|
2021-07-07 22:56:58 +02:00
|
|
|
message.stream,
|
|
|
|
false,
|
|
|
|
);
|
2021-02-28 00:56:21 +01:00
|
|
|
}
|
2013-08-16 23:45:13 +02:00
|
|
|
|
2021-02-28 00:56:21 +01:00
|
|
|
export function is_editing(id) {
|
2020-02-06 06:23:06 +01:00
|
|
|
return currently_editing_messages.has(id);
|
2021-02-28 00:56:21 +01:00
|
|
|
}
|
2013-06-11 18:54:07 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
export function end_inline_topic_edit($row) {
|
|
|
|
message_lists.current.hide_edit_topic_on_recipient_row($row);
|
2021-02-28 00:56:21 +01:00
|
|
|
}
|
2020-04-13 15:46:41 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
export function end_message_row_edit($row) {
|
|
|
|
const message = message_lists.current.get(rows.id($row));
|
2020-07-15 00:34:28 +02:00
|
|
|
if (message !== undefined && currently_editing_messages.has(message.id)) {
|
2020-02-06 06:23:06 +01:00
|
|
|
const scroll_by = currently_editing_messages.get(message.id).scrolled_by;
|
2021-07-03 19:39:57 +02:00
|
|
|
const original_scrollTop = message_viewport.scrollTop();
|
2017-04-26 04:30:35 +02:00
|
|
|
|
|
|
|
// Clean up resize event listeners
|
2020-02-06 06:23:06 +01:00
|
|
|
const listeners = currently_editing_messages.get(message.id).listeners;
|
2021-04-20 19:50:01 +02:00
|
|
|
const edit_box = document.querySelector(
|
|
|
|
`#edit_form_${CSS.escape(message.id)} .message_edit_content`,
|
|
|
|
);
|
2017-05-02 00:07:10 +02:00
|
|
|
if (listeners !== undefined) {
|
docs: Add missing space to compound verbs “log in”, “set up”, etc.
Noun: backup, checkout, cleanup, login, logout, setup, shutdown, signup,
timeout.
Verb: back up, check out, clean up, log in, log out, set up, shut
down, sign up, time out.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-04-25 23:05:38 +02:00
|
|
|
// Event listeners to clean up are only set in some edit types
|
2017-05-02 00:07:10 +02:00
|
|
|
edit_box.removeEventListener("mousedown", listeners[0]);
|
|
|
|
document.body.removeEventListener("mouseup", listeners[1]);
|
|
|
|
}
|
2017-04-26 04:30:35 +02:00
|
|
|
|
2020-02-06 06:23:06 +01:00
|
|
|
currently_editing_messages.delete(message.id);
|
2022-01-25 11:36:19 +01:00
|
|
|
message_lists.current.hide_edit_message($row);
|
2021-07-03 19:39:57 +02:00
|
|
|
message_viewport.scrollTop(original_scrollTop - scroll_by);
|
2019-11-16 09:26:28 +01:00
|
|
|
|
2020-10-28 11:35:48 +01:00
|
|
|
compose.abort_video_callbacks(message.id);
|
2013-05-28 22:13:49 +02:00
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
if ($row.find(".condensed").length !== 0) {
|
|
|
|
condense.show_message_expander($row);
|
2021-03-04 11:09:34 +01:00
|
|
|
} else {
|
2022-01-25 11:36:19 +01:00
|
|
|
condense.show_message_condenser($row);
|
2021-03-04 11:09:34 +01:00
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
$row.find(".message_reactions").show();
|
2017-07-19 15:24:03 +02:00
|
|
|
|
|
|
|
// We have to blur out text fields, or else hotkeys.js
|
|
|
|
// thinks we are still editing.
|
2022-01-25 11:36:19 +01:00
|
|
|
$row.find(".message_edit").trigger("blur");
|
2021-07-07 22:56:58 +02:00
|
|
|
// We should hide the editing typeahead if it is visible
|
2022-01-25 11:36:19 +01:00
|
|
|
$row.find("input.message_edit_topic").trigger("blur");
|
2021-02-28 00:56:21 +01:00
|
|
|
}
|
2013-05-15 00:22:16 +02:00
|
|
|
|
2022-08-09 23:23:32 +02:00
|
|
|
export function end_message_edit(message_id) {
|
|
|
|
const $row = message_lists.current.get_row(message_id);
|
|
|
|
if ($row.length > 0) {
|
|
|
|
end_message_row_edit($row);
|
|
|
|
} else if (currently_editing_messages.has(message_id)) {
|
|
|
|
// We should delete the message_id from currently_editing_messages
|
|
|
|
// if it exists there but we cannot find the row.
|
|
|
|
currently_editing_messages.delete(message_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
export function save_inline_topic_edit($row) {
|
2021-03-30 02:21:21 +02:00
|
|
|
const msg_list = message_lists.current;
|
2022-01-25 11:36:19 +01:00
|
|
|
let message_id = rows.id_for_recipient_row($row);
|
2021-03-30 02:21:21 +02:00
|
|
|
const message = message_lists.current.get(message_id);
|
2019-11-21 00:06:44 +01:00
|
|
|
|
2020-04-13 15:46:41 +02:00
|
|
|
const old_topic = message.topic;
|
2022-01-25 11:36:19 +01:00
|
|
|
const new_topic = $row.find(".inline_topic_edit").val();
|
2020-04-13 15:46:41 +02:00
|
|
|
const topic_changed = new_topic !== old_topic && new_topic.trim() !== "";
|
|
|
|
|
|
|
|
if (!topic_changed) {
|
|
|
|
// this means the inline_topic_edit was opened and submitted without
|
|
|
|
// changing anything, therefore, we should just close the inline topic edit.
|
2022-01-25 11:36:19 +01:00
|
|
|
end_inline_topic_edit($row);
|
2020-04-13 15:46:41 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
show_topic_edit_spinner($row);
|
2020-04-18 18:53:45 +02:00
|
|
|
|
2020-04-13 15:46:41 +02:00
|
|
|
if (message.locally_echoed) {
|
|
|
|
if (topic_changed) {
|
2020-07-20 22:18:43 +02:00
|
|
|
echo.edit_locally(message, {new_topic});
|
2022-01-25 11:36:19 +01:00
|
|
|
$row = message_lists.current.get_row(message_id);
|
2020-04-13 15:46:41 +02:00
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
end_inline_topic_edit($row);
|
2020-04-13 15:46:41 +02:00
|
|
|
return;
|
2019-11-21 00:06:44 +01:00
|
|
|
}
|
2020-04-13 15:46:41 +02:00
|
|
|
|
|
|
|
const request = {
|
|
|
|
message_id: message.id,
|
|
|
|
topic: new_topic,
|
|
|
|
propagate_mode: "change_later",
|
2022-07-17 13:34:04 +02:00
|
|
|
send_notification_to_old_thread: false,
|
|
|
|
send_notification_to_new_thread: false,
|
2020-04-13 15:46:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
channel.patch({
|
2020-07-15 01:29:15 +02:00
|
|
|
url: "/json/messages/" + message.id,
|
2020-04-13 15:46:41 +02:00
|
|
|
data: request,
|
2020-07-20 22:18:43 +02:00
|
|
|
success() {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $spinner = $row.find(".topic_edit_spinner");
|
|
|
|
loading.destroy_indicator($spinner);
|
2020-04-13 15:46:41 +02:00
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
error(xhr) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $spinner = $row.find(".topic_edit_spinner");
|
|
|
|
loading.destroy_indicator($spinner);
|
2021-03-30 02:21:21 +02:00
|
|
|
if (msg_list === message_lists.current) {
|
2022-01-25 11:36:19 +01:00
|
|
|
message_id = rows.id_for_recipient_row($row);
|
2021-04-13 06:51:54 +02:00
|
|
|
const message = channel.xhr_error_message(
|
|
|
|
$t({defaultMessage: "Error saving edit"}),
|
|
|
|
xhr,
|
|
|
|
);
|
2022-01-25 11:36:19 +01:00
|
|
|
$row.find(".edit_error").text(message).css("display", "inline-block");
|
2020-04-13 12:39:50 +02:00
|
|
|
}
|
2020-04-13 15:46:41 +02:00
|
|
|
},
|
|
|
|
});
|
2021-02-28 00:56:21 +01:00
|
|
|
}
|
2020-04-13 15:46:41 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
export function save_message_row_edit($row) {
|
2021-03-30 02:21:21 +02:00
|
|
|
const msg_list = message_lists.current;
|
2022-01-25 11:36:19 +01:00
|
|
|
let message_id = rows.id($row);
|
2021-03-30 02:21:21 +02:00
|
|
|
const message = message_lists.current.get(message_id);
|
2019-11-02 00:06:25 +01:00
|
|
|
let changed = false;
|
|
|
|
let edit_locally_echoed = false;
|
2019-11-21 00:06:44 +01:00
|
|
|
|
2022-08-08 13:24:37 +02:00
|
|
|
let new_content;
|
|
|
|
const old_content = message.raw_content;
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
show_message_edit_spinner($row);
|
2020-08-21 07:34:21 +02:00
|
|
|
|
2022-08-09 00:56:18 +02:00
|
|
|
const $edit_content_input = $row.find(".message_edit_content");
|
2022-09-10 01:34:43 +02:00
|
|
|
const can_edit_content = $edit_content_input.attr("readonly") !== "readonly";
|
2022-08-09 00:56:18 +02:00
|
|
|
if (can_edit_content) {
|
2022-08-08 13:24:37 +02:00
|
|
|
new_content = $edit_content_input.val();
|
2022-10-01 13:50:44 +02:00
|
|
|
changed = old_content !== new_content;
|
2019-11-21 00:06:44 +01:00
|
|
|
}
|
2022-08-09 00:56:18 +02:00
|
|
|
|
2019-11-21 00:06:44 +01:00
|
|
|
// Editing a not-yet-acked message (because the original send attempt failed)
|
|
|
|
// just results in the in-memory message being changed
|
|
|
|
if (message.locally_echoed) {
|
2022-10-01 13:50:44 +02:00
|
|
|
if (new_content !== message.raw_content) {
|
2020-05-06 12:07:34 +02:00
|
|
|
// `edit_locally` handles the case where `new_topic/new_stream_id` is undefined
|
2019-11-21 00:06:44 +01:00
|
|
|
echo.edit_locally(message, {
|
|
|
|
raw_content: new_content,
|
|
|
|
});
|
2022-01-25 11:36:19 +01:00
|
|
|
$row = message_lists.current.get_row(message_id);
|
2019-11-21 00:06:44 +01:00
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
end_message_row_edit($row);
|
2019-11-21 00:06:44 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!changed) {
|
|
|
|
// If they didn't change anything, just cancel it.
|
2022-01-25 11:36:19 +01:00
|
|
|
end_message_row_edit($row);
|
2019-11-21 00:06:44 +01:00
|
|
|
return;
|
|
|
|
}
|
2019-04-22 20:13:23 +02:00
|
|
|
|
2022-10-01 13:50:44 +02:00
|
|
|
const request = {message_id: message.id, content: new_content};
|
|
|
|
|
|
|
|
if (!markdown.contains_backend_only_syntax(new_content)) {
|
|
|
|
// If the new message content could have been locally echoed,
|
|
|
|
// than we can locally echo the edit.
|
2020-02-06 06:24:12 +01:00
|
|
|
currently_echoing_messages.set(message_id, {
|
2019-04-22 20:13:23 +02:00
|
|
|
raw_content: new_content,
|
|
|
|
orig_content: message.content,
|
|
|
|
orig_raw_content: message.raw_content,
|
|
|
|
|
|
|
|
// Store flags that are about user interaction with the
|
|
|
|
// message so that echo.edit_locally() can restore these
|
|
|
|
// flags.
|
|
|
|
starred: message.starred,
|
|
|
|
historical: message.historical,
|
|
|
|
collapsed: message.collapsed,
|
|
|
|
|
|
|
|
// These flags are rendering artifacts we'll want if the
|
|
|
|
// edit fails and we need to revert to the original
|
|
|
|
// rendering of the message.
|
|
|
|
alerted: message.alerted,
|
|
|
|
mentioned: message.mentioned,
|
|
|
|
mentioned_me_directly: message.mentioned,
|
2020-02-06 06:24:12 +01:00
|
|
|
});
|
2019-04-22 20:13:23 +02:00
|
|
|
edit_locally_echoed = true;
|
|
|
|
|
|
|
|
// Settings these attributes causes a "SAVING" notice to
|
|
|
|
// briefly appear where "EDITED" would normally appear until
|
|
|
|
// the message is acknowledged by the server.
|
2020-12-22 11:54:49 +01:00
|
|
|
message.local_edit_timestamp = Math.round(Date.now() / 1000);
|
2019-04-22 20:13:23 +02:00
|
|
|
|
2020-02-06 06:24:12 +01:00
|
|
|
echo.edit_locally(message, currently_echoing_messages.get(message_id));
|
2019-04-22 20:13:23 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$row = message_lists.current.get_row(message_id);
|
|
|
|
end_message_row_edit($row);
|
2019-04-22 20:13:23 +02:00
|
|
|
}
|
|
|
|
|
2019-11-21 00:06:44 +01:00
|
|
|
channel.patch({
|
2020-07-15 01:29:15 +02:00
|
|
|
url: "/json/messages/" + message.id,
|
2019-11-21 00:06:44 +01:00
|
|
|
data: request,
|
2020-07-20 22:18:43 +02:00
|
|
|
success() {
|
2019-04-22 20:13:23 +02:00
|
|
|
if (edit_locally_echoed) {
|
|
|
|
delete message.local_edit_timestamp;
|
2020-02-06 06:24:12 +01:00
|
|
|
currently_echoing_messages.delete(message_id);
|
2019-04-22 20:13:23 +02:00
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
hide_message_edit_spinner($row);
|
2019-11-21 00:06:44 +01:00
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
error(xhr) {
|
2021-03-30 02:21:21 +02:00
|
|
|
if (msg_list === message_lists.current) {
|
2022-01-25 11:36:19 +01:00
|
|
|
message_id = rows.id($row);
|
2019-04-22 20:13:23 +02:00
|
|
|
|
|
|
|
if (edit_locally_echoed) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const echoed_message = message_store.get(message_id);
|
2020-02-06 06:24:12 +01:00
|
|
|
const echo_data = currently_echoing_messages.get(message_id);
|
2019-04-22 20:13:23 +02:00
|
|
|
|
|
|
|
delete echoed_message.local_edit_timestamp;
|
2020-02-06 06:24:12 +01:00
|
|
|
currently_echoing_messages.delete(message_id);
|
2019-04-22 20:13:23 +02:00
|
|
|
|
|
|
|
// Restore the original content.
|
|
|
|
echo.edit_locally(echoed_message, {
|
|
|
|
content: echo_data.orig_content,
|
|
|
|
raw_content: echo_data.orig_raw_content,
|
|
|
|
mentioned: echo_data.mentioned,
|
|
|
|
mentioned_me_directly: echo_data.mentioned_me_directly,
|
|
|
|
alerted: echo_data.alerted,
|
|
|
|
});
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$row = message_lists.current.get_row(message_id);
|
2021-02-28 00:56:21 +01:00
|
|
|
if (!is_editing(message_id)) {
|
2021-04-14 08:55:49 +02:00
|
|
|
// Return to the message editing open UI state with the edited content.
|
2022-01-25 11:36:19 +01:00
|
|
|
start_edit_maintaining_scroll($row, echo_data.raw_content);
|
2019-04-22 20:13:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
hide_message_edit_spinner($row);
|
2021-04-13 06:51:54 +02:00
|
|
|
const message = channel.xhr_error_message(
|
|
|
|
$t({defaultMessage: "Error saving edit"}),
|
|
|
|
xhr,
|
|
|
|
);
|
2022-01-25 11:36:19 +01:00
|
|
|
$row.find(".edit_error").text(message).show();
|
2019-11-21 00:06:44 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
// The message will automatically get replaced via message_list.update_message.
|
2021-02-28 00:56:21 +01:00
|
|
|
}
|
2019-11-21 00:06:44 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
export function maybe_show_edit($row, id) {
|
2020-02-06 06:23:06 +01:00
|
|
|
if (currently_editing_messages.has(id)) {
|
2022-01-25 11:36:19 +01:00
|
|
|
message_lists.current.show_edit_message($row, currently_editing_messages.get(id));
|
2013-05-15 00:22:16 +02:00
|
|
|
}
|
2021-02-28 00:56:21 +01:00
|
|
|
}
|
2013-05-15 00:22:16 +02:00
|
|
|
|
2021-02-28 00:56:21 +01:00
|
|
|
export function edit_last_sent_message() {
|
2021-03-30 02:21:21 +02:00
|
|
|
const msg = message_lists.current.get_last_message_sent_by_me();
|
2017-03-27 18:00:31 +02:00
|
|
|
|
|
|
|
if (!msg) {
|
|
|
|
return;
|
2016-11-23 05:06:34 +01:00
|
|
|
}
|
2017-03-27 18:00:31 +02:00
|
|
|
|
|
|
|
if (!msg.id) {
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("Message has invalid id in edit_last_sent_message.");
|
2017-03-27 18:00:31 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-28 00:56:21 +01:00
|
|
|
const msg_editability_type = get_editability(msg, 5);
|
2017-03-27 18:00:31 +02:00
|
|
|
if (msg_editability_type !== editability_types.FULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $msg_row = message_lists.current.get_row(msg.id);
|
|
|
|
if (!$msg_row) {
|
2017-03-27 18:00:31 +02:00
|
|
|
// This should never happen, since we got the message above
|
2021-03-30 02:21:21 +02:00
|
|
|
// from message_lists.current.
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("Could not find row for id " + msg.id);
|
2017-03-27 18:00:31 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-30 02:21:21 +02:00
|
|
|
message_lists.current.select_id(msg.id, {then_scroll: true, from_scroll: true});
|
2017-03-27 18:00:31 +02:00
|
|
|
|
|
|
|
// Finally do the real work!
|
2017-03-27 19:15:05 +02:00
|
|
|
compose_actions.cancel();
|
2022-01-25 11:36:19 +01:00
|
|
|
start($msg_row, () => {
|
2021-04-20 19:50:01 +02:00
|
|
|
$(".message_edit_content").trigger("focus");
|
2017-03-27 18:00:31 +02:00
|
|
|
});
|
2021-02-28 00:56:21 +01:00
|
|
|
}
|
2016-11-23 05:06:34 +01:00
|
|
|
|
2021-02-28 00:56:21 +01:00
|
|
|
export function delete_message(msg_id) {
|
2021-05-09 11:19:58 +02:00
|
|
|
const html_body = render_delete_message_modal();
|
|
|
|
|
|
|
|
function do_delete_message() {
|
|
|
|
currently_deleting_messages.push(msg_id);
|
|
|
|
channel.del({
|
|
|
|
url: "/json/messages/" + msg_id,
|
|
|
|
success() {
|
|
|
|
currently_deleting_messages = currently_deleting_messages.filter(
|
|
|
|
(id) => id !== msg_id,
|
|
|
|
);
|
2021-07-05 19:15:37 +02:00
|
|
|
dialog_widget.hide_dialog_spinner();
|
2021-07-27 18:48:19 +02:00
|
|
|
dialog_widget.close_modal();
|
2021-05-09 11:19:58 +02:00
|
|
|
},
|
|
|
|
error(xhr) {
|
|
|
|
currently_deleting_messages = currently_deleting_messages.filter(
|
|
|
|
(id) => id !== msg_id,
|
|
|
|
);
|
|
|
|
|
2021-07-05 19:15:37 +02:00
|
|
|
dialog_widget.hide_dialog_spinner();
|
2021-05-09 11:19:58 +02:00
|
|
|
ui_report.error(
|
|
|
|
$t_html({defaultMessage: "Error deleting message"}),
|
|
|
|
xhr,
|
2021-07-05 12:41:37 +02:00
|
|
|
$("#dialog_error"),
|
2021-05-09 11:19:58 +02:00
|
|
|
);
|
|
|
|
},
|
2017-05-14 21:14:26 +02:00
|
|
|
});
|
2021-05-09 11:19:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
confirm_dialog.launch({
|
2022-07-28 15:42:36 +02:00
|
|
|
html_heading: $t_html({defaultMessage: "Delete message?"}),
|
2021-05-09 11:19:58 +02:00
|
|
|
html_body,
|
|
|
|
help_link: "/help/edit-or-delete-a-message#delete-a-message",
|
|
|
|
on_click: do_delete_message,
|
|
|
|
loading_spinner: true,
|
|
|
|
});
|
2021-02-28 00:56:21 +01:00
|
|
|
}
|
2017-05-14 21:14:26 +02:00
|
|
|
|
2022-09-22 22:26:20 +02:00
|
|
|
export function delete_topic(stream_id, topic_name, failures = 0) {
|
2019-01-18 17:40:54 +01:00
|
|
|
channel.post({
|
|
|
|
url: "/json/streams/" + stream_id + "/delete_topic",
|
|
|
|
data: {
|
2020-07-20 22:18:43 +02:00
|
|
|
topic_name,
|
2019-01-18 17:40:54 +01:00
|
|
|
},
|
2022-09-22 22:26:20 +02:00
|
|
|
success() {},
|
|
|
|
error(xhr) {
|
|
|
|
if (failures >= 9) {
|
|
|
|
// Don't keep retrying indefinitely to avoid DoSing the server.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (xhr.status === 502) {
|
|
|
|
/* When trying to delete a very large topic, it's
|
|
|
|
possible for the request to the server to
|
|
|
|
time out after making some progress. Retry the
|
|
|
|
request, so that the user can just do nothing and
|
|
|
|
watch the topic slowly be deleted.
|
|
|
|
|
|
|
|
TODO: Show a nice loading indicator experience.
|
|
|
|
*/
|
|
|
|
failures += 1;
|
|
|
|
delete_topic(stream_id, topic_name, failures);
|
|
|
|
}
|
|
|
|
},
|
2019-01-18 17:40:54 +01:00
|
|
|
});
|
2021-02-28 00:56:21 +01:00
|
|
|
}
|
2019-01-18 17:40:54 +01:00
|
|
|
|
2021-02-28 00:56:21 +01:00
|
|
|
export function handle_narrow_deactivated() {
|
2020-02-06 06:23:06 +01:00
|
|
|
for (const [idx, elem] of currently_editing_messages) {
|
2021-03-30 02:21:21 +02:00
|
|
|
if (message_lists.current.get(idx) !== undefined) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $row = message_lists.current.get_row(idx);
|
|
|
|
message_lists.current.show_edit_message($row, elem);
|
2013-05-15 00:22:16 +02:00
|
|
|
}
|
2020-02-06 06:23:06 +01:00
|
|
|
}
|
2021-02-28 00:56:21 +01:00
|
|
|
}
|
2013-05-15 00:22:16 +02:00
|
|
|
|
2021-02-28 00:56:21 +01:00
|
|
|
export function move_topic_containing_message_to_stream(
|
2020-07-15 00:34:28 +02:00
|
|
|
message_id,
|
|
|
|
new_stream_id,
|
|
|
|
new_topic_name,
|
|
|
|
send_notification_to_new_thread,
|
|
|
|
send_notification_to_old_thread,
|
2022-10-03 09:41:13 +02:00
|
|
|
propagate_mode,
|
2020-07-15 00:34:28 +02:00
|
|
|
) {
|
2020-08-25 17:52:39 +02:00
|
|
|
function reset_modal_ui() {
|
|
|
|
currently_topic_editing_messages = currently_topic_editing_messages.filter(
|
|
|
|
(id) => id !== message_id,
|
|
|
|
);
|
2021-07-18 11:18:03 +02:00
|
|
|
dialog_widget.hide_dialog_spinner();
|
2020-08-25 17:52:39 +02:00
|
|
|
}
|
|
|
|
if (currently_topic_editing_messages.includes(message_id)) {
|
2021-11-24 16:03:21 +01:00
|
|
|
ui_report.client_error(
|
|
|
|
$t_html({defaultMessage: "A Topic Move already in progress."}),
|
|
|
|
$("#move_topic_modal #dialog_error"),
|
2020-08-25 17:52:39 +02:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currently_topic_editing_messages.push(message_id);
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const request = {
|
|
|
|
stream_id: new_stream_id,
|
2022-10-03 09:41:13 +02:00
|
|
|
propagate_mode,
|
2020-07-15 00:34:28 +02:00
|
|
|
topic: new_topic_name,
|
2020-07-20 22:18:43 +02:00
|
|
|
send_notification_to_old_thread,
|
|
|
|
send_notification_to_new_thread,
|
2020-02-19 01:38:34 +01:00
|
|
|
};
|
2021-02-28 00:56:21 +01:00
|
|
|
notify_old_thread_default = send_notification_to_old_thread;
|
|
|
|
notify_new_thread_default = send_notification_to_new_thread;
|
2020-07-15 00:34:28 +02:00
|
|
|
channel.patch({
|
|
|
|
url: "/json/messages/" + message_id,
|
|
|
|
data: request,
|
2020-07-20 22:18:43 +02:00
|
|
|
success() {
|
2020-07-15 00:34:28 +02:00
|
|
|
// The main UI will update via receiving the event
|
|
|
|
// from server_events.js.
|
2020-08-25 17:52:39 +02:00
|
|
|
reset_modal_ui();
|
2022-10-07 12:57:49 +02:00
|
|
|
dialog_widget.close_modal();
|
2020-07-15 00:34:28 +02:00
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
error(xhr) {
|
2020-08-25 17:52:39 +02:00
|
|
|
reset_modal_ui();
|
2022-10-07 12:57:49 +02:00
|
|
|
ui_report.error($t_html({defaultMessage: "Failed"}), xhr, $("#dialog_error"));
|
2020-07-15 00:34:28 +02:00
|
|
|
},
|
|
|
|
});
|
2021-02-28 00:56:21 +01:00
|
|
|
}
|
2021-07-27 21:14:18 +02:00
|
|
|
|
|
|
|
export function with_first_message_id(stream_id, topic_name, success_cb, error_cb) {
|
|
|
|
// The API endpoint for editing messages to change their
|
|
|
|
// content, topic, or stream requires a message ID.
|
|
|
|
//
|
|
|
|
// Because we don't have full data in the browser client, it's
|
|
|
|
// possible that we might display a topic in the left sidebar
|
|
|
|
// (and thus expose the UI for moving its topic to another
|
|
|
|
// stream) without having a message ID that is definitely
|
|
|
|
// within the topic. (The comments in stream_topic_history.js
|
|
|
|
// discuss the tricky issues around message deletion that are
|
|
|
|
// involved here).
|
|
|
|
//
|
|
|
|
// To ensure this option works reliably at a small latency
|
|
|
|
// cost for a rare operation, we just ask the server for the
|
|
|
|
// latest message ID in the topic.
|
|
|
|
const data = {
|
|
|
|
anchor: "newest",
|
|
|
|
num_before: 1,
|
|
|
|
num_after: 0,
|
|
|
|
narrow: JSON.stringify([
|
|
|
|
{operator: "stream", operand: stream_id},
|
|
|
|
{operator: "topic", operand: topic_name},
|
|
|
|
]),
|
|
|
|
};
|
|
|
|
|
|
|
|
channel.get({
|
|
|
|
url: "/json/messages",
|
|
|
|
data,
|
|
|
|
success(data) {
|
|
|
|
const message_id = data.messages[0].id;
|
|
|
|
success_cb(message_id);
|
|
|
|
},
|
2022-08-19 01:36:37 +02:00
|
|
|
error: error_cb,
|
2021-07-27 21:14:18 +02:00
|
|
|
});
|
|
|
|
}
|