Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
move_topic_popover: Show the number of messages to be moved.
whilstsomebody0ce7278edfe2
diff --git a/web/src/message_util.ts b/web/src/message_util.tsindex 5ba7cb12569..99608de45a3 100644--- a/web/src/message_util.ts+++ b/web/src/message_util.ts@@ -84,6 +84,15 @@ export function add_new_messages_data(return msg_list_data.add_messages(messages);}+export function get_count_of_messages_in_topic_sent_after_current_message(+ stream_id: number,+ topic: string,+ message_id: number,+): number {+ const all_messages = get_messages_in_topic(stream_id, topic);+ return all_messages.filter((msg) => msg.id >= message_id).length;+}+export function get_messages_in_topic(stream_id: number, topic: string): Message[] {return all_messages_data.all_messages()diff --git a/web/src/stream_popover.ts b/web/src/stream_popover.tsindex 22ca754acd4..8c381634411 100644--- a/web/src/stream_popover.ts+++ b/web/src/stream_popover.ts@@ -19,6 +19,7 @@ import {$t, $t_html} from "./i18n.ts";import * as message_edit from "./message_edit.ts";import * as message_lists from "./message_lists.ts";import type {Message} from "./message_store.ts";+import * as message_util from "./message_util.ts";import * as message_view from "./message_view.ts";import * as narrow_state from "./narrow_state.ts";import * as popover_menus from "./popover_menus.ts";@@ -586,6 +587,74 @@ export async function build_move_topic_to_stream_popover($("#move_topic_form .move_messages_edit_topic").trigger("focus");}+ // The following logic is correct only when+ // both message_lists.current.data.fetch_status.has_found_newest+ // and message_lists.current.data.fetch_status.has_found_oldest are true;+ // otherwise, we cannot be certain of the correct count.+ function get_count_of_messages_to_be_moved(+ selected_option: string,+ message_id?: number,+ ): number {+ if (selected_option === "change_one") {+ return 1;+ }+ if (selected_option === "change_later" && message_id !== undefined) {+ return message_util.get_count_of_messages_in_topic_sent_after_current_message(+ current_stream_id,+ topic_name,+ message_id,+ );+ }+ return message_util.get_messages_in_topic(current_stream_id, topic_name).length;+ }++ function update_move_messages_count_text(selected_option: string, message_id?: number): void {+ const message_move_count = get_count_of_messages_to_be_moved(selected_option, message_id);+ const is_topic_narrowed = narrow_state.narrowed_by_topic_reply();+ const is_stream_narrowed = narrow_state.narrowed_by_stream_reply();+ const is_same_stream = narrow_state.stream_id() === current_stream_id;+ const is_same_topic = narrow_state.topic() === topic_name;++ const can_have_exact_count_in_narrow =+ (is_stream_narrowed && is_same_stream) ||+ (is_topic_narrowed && is_same_stream && is_same_topic);+ let exact_message_count = false;+ if (selected_option === "change_one") {+ exact_message_count = true;+ } else if (can_have_exact_count_in_narrow) {+ const has_found_newest = message_lists.current?.data.fetch_status.has_found_newest();+ const has_found_oldest = message_lists.current?.data.fetch_status.has_found_oldest();++ if (selected_option === "change_later" && has_found_newest) {+ exact_message_count = true;+ }+ if (selected_option === "change_all" && has_found_newest && has_found_oldest) {+ exact_message_count = true;+ }+ }++ let message_text;+ if (exact_message_count) {+ message_text = $t(+ {+ defaultMessage:+ "{count, plural, one {# message} other {# messages}} will be moved.",+ },+ {count: message_move_count},+ );+ } else {+ message_text = $t(+ {+ defaultMessage:+ "At least {count, plural, one {# message} other {# messages}} will be moved.",+ },+ {count: message_move_count},+ );+ }++ $("#move_messages_count").text(message_text);+ }+function move_topic_post_render(): void {$("#move_topic_modal .dialog_submit_button").prop("disabled", true);@@ -635,6 +704,18 @@ export async function build_move_topic_to_stream_popover($("#move_topic_modal .move_messages_edit_topic").on("input", () => {update_submit_button_disabled_state(current_stream_id);});++ if (!args.from_message_actions_popover) {+ update_move_messages_count_text("change_all");+ } else {+ let selected_option = String($("#message_move_select_options").val());+ update_move_messages_count_text(selected_option, message?.id);++ $("#message_move_select_options").on("change", function () {+ selected_option = String($(this).val());+ update_move_messages_count_text(selected_option, message?.id);+ });+ }}function focus_on_move_modal_render(): void {diff --git a/web/styles/zulip.css b/web/styles/zulip.cssindex 6029a52fe90..604fb81add2 100644--- a/web/styles/zulip.css+++ b/web/styles/zulip.css@@ -938,7 +938,6 @@ div.focused-message-list {#move_topic_modal select {width: auto;- margin-bottom: 10px;max-width: 100%;}diff --git a/web/templates/move_topic_to_stream.hbs b/web/templates/move_topic_to_stream.hbsindex ae44a9201c3..55629840c9d 100644--- a/web/templates/move_topic_to_stream.hbs+++ b/web/templates/move_topic_to_stream.hbs@@ -16,12 +16,13 @@<input name="old_topic_name" type="hidden" value="{{topic_name}}" /><input name="current_stream_id" type="hidden" value="{{current_stream_id}}" />{{#if from_message_actions_popover}}- <select name="propagate_mode" class="message_edit_topic_propagate modal_select bootstrap-focus-style">+ <select id="message_move_select_options" class="message_edit_topic_propagate modal_select bootstrap-focus-style"><option value="change_one" {{#if (eq message_placement "last")}}selected{{/if}}> {{t "Move only this message" }}</option><option value="change_later" {{#if (eq message_placement "intermediate")}}selected{{/if}}> {{t "Move this and all following messages in this topic" }}</option><option value="change_all" {{#if (eq message_placement "first")}}selected{{/if}}> {{t "Move all messages in this topic" }}</option></select>{{/if}}+ <p id="move_messages_count"></p><div class="topic_move_breadcrumb_messages"><label class="checkbox"><input class="send_notification_to_new_thread" name="send_notification_to_new_thread" type="checkbox" {{#if notify_new_thread}}checked="checked"{{/if}} />