Skip to content

Commit

Permalink
message_move: Show confirmation toast.
Browse files Browse the repository at this point in the history
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 zulip#29702
  • Loading branch information
kuv2707 authored and timabbott committed Apr 22, 2024
1 parent cdb06ff commit cb65b61
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
27 changes: 27 additions & 0 deletions web/src/message_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -1280,13 +1284,33 @@ 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,
new_topic_name,
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(
Expand Down Expand Up @@ -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();
Expand Down
12 changes: 10 additions & 2 deletions web/src/stream_popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -440,13 +440,21 @@ 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,
new_topic_name,
send_notification_to_new_thread,
send_notification_to_old_thread,
propagate_mode,
toast_params,
);
return;
}
Expand Down
6 changes: 6 additions & 0 deletions web/templates/message_moved_widget_body.hbs
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit cb65b61

Please sign in to comment.