message_move: Show confirmation toast.

A confirmation toast is shown when a message is moved
using the "Move only this message" option. The toast
contains the link to the new location of the message.

Fixes #29702
This commit is contained in:
Kislay Verma
2024-04-19 07:27:47 +05:30
committed by Tim Abbott
parent cdb06ff9f0
commit cb65b617fb
3 changed files with 43 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ import render_delete_message_modal from "../templates/confirm_dialog/confirm_del
import render_confirm_merge_topics_with_rename from "../templates/confirm_dialog/confirm_merge_topics_with_rename.hbs";
import render_confirm_moving_messages_modal from "../templates/confirm_dialog/confirm_moving_messages.hbs";
import render_message_edit_form from "../templates/message_edit_form.hbs";
import render_message_moved_widget_body from "../templates/message_moved_widget_body.hbs";
import render_resolve_topic_time_limit_error_modal from "../templates/resolve_topic_time_limit_error_modal.hbs";
import render_topic_edit_form from "../templates/topic_edit_form.hbs";
@@ -25,7 +26,9 @@ import * as confirm_dialog from "./confirm_dialog";
import {show_copied_confirmation} from "./copied_tooltip";
import * as dialog_widget from "./dialog_widget";
import * as echo from "./echo";
import * as feedback_widget from "./feedback_widget";
import * as giphy from "./giphy";
import * as hash_util from "./hash_util";
import {$t, $t_html} from "./i18n";
import * as keydown_util from "./keydown_util";
import * as loading from "./loading";
@@ -41,6 +44,7 @@ import * as settings_data from "./settings_data";
import {current_user, realm} from "./state_data";
import * as stream_data from "./stream_data";
import * as stream_topic_history from "./stream_topic_history";
import * as sub_store from "./sub_store";
import * as timerender from "./timerender";
import * as ui_report from "./ui_report";
import * as upload from "./upload";
@@ -1280,6 +1284,25 @@ function handle_message_move_failure_due_to_time_limit(xhr, handle_confirm, on_h
});
}
function show_message_moved_toast(toast_params) {
const new_stream_name = sub_store.maybe_get_stream_name(toast_params.new_stream_id);
const stream_topic = `#${new_stream_name} > ${toast_params.new_topic_name}`;
const new_location_url = hash_util.by_stream_topic_url(
toast_params.new_stream_id,
toast_params.new_topic_name,
);
feedback_widget.show({
populate($container) {
const widget_body_html = render_message_moved_widget_body({
stream_topic,
new_location_url,
});
$container.html(widget_body_html);
},
title_text: $t({defaultMessage: "Message moved"}),
});
}
export function move_topic_containing_message_to_stream(
message_id,
new_stream_id,
@@ -1287,6 +1310,7 @@ export function move_topic_containing_message_to_stream(
send_notification_to_new_thread,
send_notification_to_old_thread,
propagate_mode,
toast_params,
) {
function reset_modal_ui() {
currently_topic_editing_messages = currently_topic_editing_messages.filter(
@@ -1320,6 +1344,9 @@ export function move_topic_containing_message_to_stream(
// from server_events.js.
reset_modal_ui();
dialog_widget.close();
if (toast_params) {
show_message_moved_toast(toast_params);
}
},
error(xhr) {
reset_modal_ui();

View File

@@ -397,7 +397,7 @@ export async function build_move_topic_to_stream_popover(
function move_topic() {
const params = get_params_from_form();
const {old_topic_name} = params;
const old_topic_name = params.old_topic_name.trim();
let select_stream_id;
if (only_topic_edit) {
select_stream_id = undefined;
@@ -421,7 +421,7 @@ export async function build_move_topic_to_stream_popover(
// user does not have permission to edit topic.
new_topic_name = new_topic_name.trim();
}
if (old_topic_name.trim() === new_topic_name) {
if (old_topic_name === new_topic_name) {
// We use `undefined` to tell the server that
// there has been no change in the topic name.
new_topic_name = undefined;
@@ -440,6 +440,13 @@ export async function build_move_topic_to_stream_popover(
// We already have the message_id here which means that modal is opened using
// message popover.
propagate_mode = $("#move_topic_modal select.message_edit_topic_propagate").val();
const toast_params =
propagate_mode === "change_one"
? {
new_stream_id: select_stream_id || current_stream_id,
new_topic_name: new_topic_name ?? old_topic_name,
}
: undefined;
message_edit.move_topic_containing_message_to_stream(
message.id,
select_stream_id,
@@ -447,6 +454,7 @@ export async function build_move_topic_to_stream_popover(
send_notification_to_new_thread,
send_notification_to_old_thread,
propagate_mode,
toast_params,
);
return;
}

View File

@@ -0,0 +1,6 @@
<div>
{{#tr}}
Message moved to <z-link>{stream_topic}</z-link>.
{{#*inline "z-link"}}<a href="{{new_location_url}}">{{> @partial-block}}</a>{{/inline}}
{{/tr}}
</div>