mirror of https://github.com/zulip/zulip.git
message_edit: Extract `toggle_resolve_topic` helper function.
This is a prep commit for #18988. Extracting it here, we can avoid duplication which helps to avoid future bugs.
This commit is contained in:
parent
d17e5d080c
commit
a7681d4a17
|
@ -1,5 +1,6 @@
|
|||
import ClipboardJS from "clipboard";
|
||||
import $ from "jquery";
|
||||
import _ from "lodash";
|
||||
|
||||
import render_delete_message_modal from "../templates/confirm_dialog/confirm_delete_message.hbs";
|
||||
import render_message_edit_form from "../templates/message_edit_form.hbs";
|
||||
|
@ -594,6 +595,27 @@ export function start(row, edit_box_open_callback) {
|
|||
});
|
||||
}
|
||||
|
||||
export function toggle_resolve_topic(message_id, old_topic_name) {
|
||||
let new_topic_name;
|
||||
if (old_topic_name.startsWith(RESOLVED_TOPIC_PREFIX)) {
|
||||
new_topic_name = _.trimStart(old_topic_name, RESOLVED_TOPIC_PREFIX);
|
||||
} else {
|
||||
new_topic_name = RESOLVED_TOPIC_PREFIX + old_topic_name;
|
||||
}
|
||||
|
||||
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,
|
||||
});
|
||||
}
|
||||
|
||||
export function start_inline_topic_edit(recipient_row) {
|
||||
const form = $(render_topic_edit_form());
|
||||
message_lists.current.show_edit_topic_on_recipient_row(recipient_row, form);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import ClipboardJS from "clipboard";
|
||||
import $ from "jquery";
|
||||
import _ from "lodash";
|
||||
|
||||
import render_all_messages_sidebar_actions from "../templates/all_messages_sidebar_actions.hbs";
|
||||
import render_delete_topic_modal from "../templates/confirm_dialog/confirm_delete_topic.hbs";
|
||||
|
@ -681,45 +680,13 @@ export function register_topic_handlers() {
|
|||
e.stopPropagation();
|
||||
});
|
||||
|
||||
function mark_topic_as_resolved(stream_id, topic_name) {
|
||||
const request = {
|
||||
propagate_mode: "change_all",
|
||||
topic: message_edit.RESOLVED_TOPIC_PREFIX + topic_name,
|
||||
send_notification_to_old_thread: false,
|
||||
send_notification_to_new_thread: true,
|
||||
};
|
||||
with_first_message_id(stream_id, topic_name, (message_id) => {
|
||||
channel.patch({
|
||||
url: "/json/messages/" + message_id,
|
||||
data: request,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function mark_topic_as_unresolved(stream_id, topic_name) {
|
||||
const request = {
|
||||
propagate_mode: "change_all",
|
||||
topic: _.trimStart(topic_name, message_edit.RESOLVED_TOPIC_PREFIX),
|
||||
send_notification_to_old_thread: false,
|
||||
send_notification_to_new_thread: true,
|
||||
};
|
||||
with_first_message_id(stream_id, topic_name, (message_id) => {
|
||||
channel.patch({
|
||||
url: "/json/messages/" + message_id,
|
||||
data: request,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$("body").on("click", ".sidebar-popover-toggle-resolved", (e) => {
|
||||
const topic_row = $(e.currentTarget);
|
||||
const stream_id = Number.parseInt(topic_row.attr("data-stream-id"), 10);
|
||||
const topic_name = topic_row.attr("data-topic-name");
|
||||
if (topic_name.startsWith(message_edit.RESOLVED_TOPIC_PREFIX)) {
|
||||
mark_topic_as_unresolved(stream_id, topic_name);
|
||||
} else {
|
||||
mark_topic_as_resolved(stream_id, topic_name);
|
||||
}
|
||||
with_first_message_id(stream_id, topic_name, (message_id) => {
|
||||
message_edit.toggle_resolve_topic(message_id, topic_name);
|
||||
});
|
||||
|
||||
hide_topic_popover();
|
||||
e.stopPropagation();
|
||||
|
|
Loading…
Reference in New Issue