Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
message_edit: Extract `toggle_resolve_topic` helper function.
akshatdaltona7681d4a1701
diff --git a/static/js/message_edit.js b/static/js/message_edit.jsindex f0581f62c23..1c58fd9c1b6 100644--- a/static/js/message_edit.js+++ b/static/js/message_edit.js@@ -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);diff --git a/static/js/stream_popover.js b/static/js/stream_popover.jsindex 25471aaacb7..613a34b440b 100644--- a/static/js/stream_popover.js+++ b/static/js/stream_popover.js@@ -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();