Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
message_quoting: Add a "Forward message" option below "Quote message".
Emil Grehnf9b95bd4f331
diff --git a/help/keyboard-shortcuts.md b/help/keyboard-shortcuts.mdindex 9b4b76f188d..cc505b5e1c1 100644--- a/help/keyboard-shortcuts.md+++ b/help/keyboard-shortcuts.md@@ -133,6 +133,8 @@ in the Zulip app to add more to your repertoire as needed.* **Quote message**: <kbd>></kbd>+* **Forward message**: <kbd><</kbd>+* **Reply directly to sender**: <kbd>Shift</kbd> + <kbd>R</kbd>* **Reply @-mentioning sender**: <kbd>@</kbd>diff --git a/help/quote-and-reply.md b/help/quote-and-reply.mdindex 60a70f1f258..d276a8361c3 100644--- a/help/quote-and-reply.md+++ b/help/quote-and-reply.md@@ -52,12 +52,12 @@ to avoid unnecessarily mentioning someone twice.{tab|desktop-web}-1. *(optional)* To quote only part of a message, select the part that you want- to quote.+1. *(optional)* To forward only part of a message, select the part that you want+ to forward.{!message-actions-menu.md!}-1. Click **Quote message**.+1. Click **Forward message**.1. Select the desired destination channel or **Direct message** from the dropdownin the top left of the compose box.@@ -68,7 +68,7 @@ to avoid unnecessarily mentioning someone twice.!!! keyboard_tip ""- You can also use <kbd>></kbd> to forward the selected message.+ You can also use <kbd><</kbd> to forward the selected message.{tab|mobile}diff --git a/web/shared/icons/forward-message.svg b/web/shared/icons/forward-message.svgnew file mode 100644index 00000000000..1f3f2860d06--- /dev/null+++ b/web/shared/icons/forward-message.svg@@ -0,0 +1 @@+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none"><g fill="#000"><path d="M8.378 7.008c-.255.54-.343 1.296-.075 2.365a.665.665 0 11-1.29.324c-.321-1.279-.258-2.366.163-3.257.422-.892 1.16-1.498 2.017-1.893 1.177-.544 2.646-.725 4.08-.708l-1.26-1.26a.665.665 0 11.94-.94l2.51 2.508a.663.663 0 01-.016.956l-2.493 2.494a.665.665 0 01-.94-.94l1.482-1.483c-1.39-.04-2.744.118-3.745.58-.654.302-1.117.715-1.373 1.254z"/><path d="M8.335 1.67a.665.665 0 110 1.33H2.833a.668.668 0 00-.668.668V13.73l1.531-1.531a.665.665 0 01.47-.195h9a.668.668 0 00.669-.668V9.083a.665.665 0 111.33 0v2.252a1.998 1.998 0 01-1.998 1.998H4.442L1.97 15.805a.665.665 0 01-1.135-.47V3.668A1.998 1.998 0 012.833 1.67h5.502z"/></g></svg>\ No newline at end of filediff --git a/web/src/compose_reply.ts b/web/src/compose_reply.tsindex ee925614e7c..9987b1569dc 100644--- a/web/src/compose_reply.ts+++ b/web/src/compose_reply.ts@@ -1,11 +1,13 @@import $ from "jquery";import assert from "minimalistic-assert";+import type * as tippy from "tippy.js";import {z} from "zod";import * as fenced_code from "../shared/src/fenced_code.ts";import * as channel from "./channel.ts";import * as compose_actions from "./compose_actions.ts";+import * as compose_recipient from "./compose_recipient.ts";import * as compose_state from "./compose_state.ts";import * as compose_ui from "./compose_ui.ts";import * as copy_and_paste from "./copy_and_paste.ts";@@ -233,6 +235,7 @@ export function quote_message(opts: {keep_composebox_empty?: boolean;reply_type?: "personal";trigger?: string;+ forward_message?: boolean;}): void {const {message_id, message, quote_content} = get_quote_target(opts);const quoting_placeholder = $t({defaultMessage: "[Quoting…]"});@@ -240,25 +243,37 @@ export function quote_message(opts: {// If the last compose type textarea focused on is still in the DOM, we add// the quote in that textarea, else we default to the compose box.const last_focused_compose_type_input = compose_state.get_last_focused_compose_type_input();- const $textarea = last_focused_compose_type_input?.isConnected- ? $(last_focused_compose_type_input)- : $<HTMLTextAreaElement>("textarea#compose-textarea");-- if ($textarea.attr("id") === "compose-textarea" && !compose_state.has_message_content()) {- // The user has not started typing a message,- // but is quoting into the compose box,- // so we will re-open the compose box.- // (If you did re-open the compose box, you- // are prone to glitches where you select the- // text, plus it's a complicated codepath that- // can have other unintended consequences.)- respond_to_message({- ...opts,- keep_composebox_empty: true,+ const $textarea =+ last_focused_compose_type_input?.isConnected && !opts.forward_message+ ? $(last_focused_compose_type_input)+ : $<HTMLTextAreaElement>("textarea#compose-textarea");++ if (opts.forward_message) {+ // Setting the stream_id to undefined will automatically open the recipient popover+ compose_actions.start({+ message_type: message.type,+ topic: "",+ keep_composebox_empty: opts.keep_composebox_empty,+ content: quoting_placeholder,});- }+ compose_recipient.open_compose_recipient_dropdown();+ } else {+ if ($textarea.attr("id") === "compose-textarea" && !compose_state.has_message_content()) {+ // The user has not started typing a message,+ // but is quoting into the compose box,+ // so we will re-open the compose box.+ // (If you did re-open the compose box, you+ // are prone to glitches where you select the+ // text, plus it's a complicated codepath that+ // can have other unintended consequences.)+ respond_to_message({+ ...opts,+ keep_composebox_empty: true,+ });+ }- compose_ui.insert_syntax_and_focus(quoting_placeholder, $textarea, "block");+ compose_ui.insert_syntax_and_focus(quoting_placeholder, $textarea, "block");+ }function replace_content(message: Message, raw_content: string): void {// Final message looks like:@@ -277,8 +292,18 @@ export function quote_message(opts: {const fence = fenced_code.get_unused_fence(raw_content);content += `${fence}quote\n${raw_content}\n${fence}`;- compose_ui.replace_syntax(quoting_placeholder, content, $textarea);+ compose_ui.replace_syntax(quoting_placeholder, content, $textarea, opts.forward_message);compose_ui.autosize_textarea($textarea);++ if (!opts.forward_message) {+ return;+ }+ const select_recipient_widget: tippy.ReferenceElement | undefined = $(+ "#compose_select_recipient_widget",+ )[0];+ if (select_recipient_widget !== undefined) {+ void select_recipient_widget._tippy?.popperInstance?.update();+ }}if (message && quote_content) {diff --git a/web/src/compose_state.ts b/web/src/compose_state.tsindex 3ebbab86000..725c4929f4b 100644--- a/web/src/compose_state.ts+++ b/web/src/compose_state.ts@@ -127,7 +127,11 @@ export function set_compose_recipient_id(recipient_id: number | "direct"): void}// TODO: Break out setter and getter into their own functions.-export const topic = get_or_set("input#stream_message_recipient_topic");+export let topic = get_or_set("input#stream_message_recipient_topic");++export function rewire_topic(value: typeof topic): void {+ topic = value;+}export function empty_topic_placeholder(): string {return $t({defaultMessage: "(no topic)"});diff --git a/web/src/compose_ui.ts b/web/src/compose_ui.tsindex 261dcd89fe3..034a17a50f2 100644--- a/web/src/compose_ui.ts+++ b/web/src/compose_ui.ts@@ -306,6 +306,7 @@ export let replace_syntax = (old_syntax: string,new_syntax: string,$textarea = $<HTMLTextAreaElement>("textarea#compose-textarea"),+ ignore_caret = false,): boolean => {// The following couple lines are needed to later restore the initial// logical position of the cursor after the replacement@@ -325,6 +326,14 @@ export let replace_syntax = (const old_text = $textarea.val();replaceFieldText(util.the($textarea), old_syntax, () => new_syntax, "after-replacement");const new_text = $textarea.val();+ const has_changed = old_text !== new_text;++ // If the caller wants to ignore the caret position, we return early.+ // This is useful e.g. when we are replacing content without affecting+ // which element has focus.+ if (ignore_caret) {+ return has_changed;+ }// When replacing content in a textarea, we need to move the cursor// to preserve its logical position if and only if the content we@@ -344,7 +353,7 @@ export let replace_syntax = (}// Return if anything was actually replaced.- return old_text !== new_text;+ return has_changed;};export function rewire_replace_syntax(value: typeof replace_syntax): void {diff --git a/web/src/hotkey.js b/web/src/hotkey.jsindex c2bc87ea91b..44af6b58ce6 100644--- a/web/src/hotkey.js+++ b/web/src/hotkey.js@@ -155,6 +155,7 @@ const keypress_mappings = {45: {name: "toggle_message_collapse", message_view_only: true}, // '-'47: {name: "search", message_view_only: false}, // '/'58: {name: "toggle_reactions_popover", message_view_only: true}, // ':'+ 60: {name: "compose_forward_message", message_view_only: true}, // '<'62: {name: "compose_quote_message", message_view_only: true}, // '>'63: {name: "show_shortcuts", message_view_only: false}, // '?'64: {name: "compose_reply_with_mention", message_view_only: true}, // '@'@@ -1198,6 +1199,9 @@ export function process_hotkey(e, hotkey) {case "compose_quote_message": // > : respond to selected message with quotecompose_reply.quote_message({trigger: "hotkey"});return true;+ case "compose_forward_message": // < : forward selected message+ compose_reply.quote_message({trigger: "hotkey", forward_message: true});+ return true;case "edit_message": {const $row = message_lists.current.get_row(msg.id);message_edit.start($row);diff --git a/web/src/message_actions_popover.ts b/web/src/message_actions_popover.tsindex ebc7ec31f04..c60756caa0a 100644--- a/web/src/message_actions_popover.ts+++ b/web/src/message_actions_popover.ts@@ -119,6 +119,18 @@ export function initialize(): void {popover_menus.hide_current_popover_if_visible(instance);});+ $popper.one("click", ".forward_button", (e) => {+ compose_reply.quote_message({+ trigger: "popover respond",+ message_id,+ quote_content,+ forward_message: true,+ });+ e.preventDefault();+ e.stopPropagation();+ popover_menus.hide_current_popover_if_visible(instance);+ });+$popper.one("click", ".popover_edit_message, .popover_view_source", (e) => {const message_id = Number($(e.currentTarget).attr("data-message-id"));assert(message_lists.current !== undefined);diff --git a/web/templates/keyboard_shortcuts.hbs b/web/templates/keyboard_shortcuts.hbsindex e7403841361..28ec953384e 100644--- a/web/templates/keyboard_shortcuts.hbs+++ b/web/templates/keyboard_shortcuts.hbs@@ -216,6 +216,10 @@<td class="definition">{{t 'Quote message' }}</td><td><span class="hotkey"><kbd>></kbd></span></td></tr>+ <tr>+ <td class="definition">{{t 'Forward message' }}</td>+ <td><span class="hotkey"><kbd><</kbd></span></td> <!-- < is the HTML entity for < -->+ </tr><tr><td class="definition">{{t 'Reply directly to sender' }}</td><td><span class="hotkey"><kbd>Shift</kbd> + <kbd>R</kbd></span></td>diff --git a/web/templates/popovers/message_actions_popover.hbs b/web/templates/popovers/message_actions_popover.hbsindex e3a78cb50d6..7616553a3a9 100644--- a/web/templates/popovers/message_actions_popover.hbs+++ b/web/templates/popovers/message_actions_popover.hbs@@ -9,6 +9,13 @@{{popover_hotkey_hints ">"}}</a></li>+ <li role="none" class="link-item popover-menu-list-item">+ <a role="menuitem" data-message-id="{{message_id}}" class="forward_button popover-menu-link" tabindex="0">+ <i class="popover-menu-icon zulip-icon zulip-icon-forward-message" aria-hidden="true"></i>+ <span class="popover-menu-label">{{t "Forward message" }}</span>+ {{popover_hotkey_hints "<"}}+ </a>+ </li>{{/if}}{{!-- Group 2 --}}{{#if (or editability_menu_item move_message_menu_item should_display_delete_option)}}diff --git a/web/tests/compose_actions.test.cjs b/web/tests/compose_actions.test.cjsindex 06ec6f845ca..3e82bd2a568 100644--- a/web/tests/compose_actions.test.cjs+++ b/web/tests/compose_actions.test.cjs@@ -480,11 +480,17 @@ test("quote_message", ({disallow, override, override_rewire}) => {assert.equal(mode, "block");});- const opts = {+ let opts = {reply_type: "personal",message_id: 100,};+ override_rewire(compose_state, "topic", (topic) => {+ if (opts.forward_message) {+ assert.equal(topic, "");+ }+ });+$("textarea#compose-textarea").caret = noop;$("textarea#compose-textarea").attr("id", "compose-textarea");@@ -499,6 +505,27 @@ test("quote_message", ({disallow, override, override_rewire}) => {});assert.ok(replaced);+ opts = {+ reply_type: "personal",+ message_id: 100,+ forward_message: true,+ };+ replaced = false;++ override(compose_ui, "insert_and_scroll_into_view", noop);++ quote_message(opts);++ success_function({+ raw_content: "Testing.",+ });+ assert.ok(replaced);++ opts = {+ reply_type: "personal",+ message_id: 100,+ };+selected_message = {type: "stream",stream_id: denmark_stream.stream_id,@@ -513,7 +540,18 @@ test("quote_message", ({disallow, override, override_rewire}) => {quote_message(opts);assert.ok(replaced);- delete opts.message_id;+ opts = {+ reply_type: "personal",+ message_id: 100,+ forward_message: true,+ };+ replaced = false;+ quote_message(opts);+ assert.ok(replaced);++ opts = {+ reply_type: "personal",+ };override(message_lists.current, "selected_id", () => 100);override(message_lists.current, "selected_message", () => selected_message);@@ -531,6 +569,14 @@ test("quote_message", ({disallow, override, override_rewire}) => {"translated: @_**Steve Stephenson|90** [said](https://chat.zulip.org/#narrow/channel/92-learning/topic/Tornado):\n````quote\n```\nmultiline code block\nshoudln't mess with quotes\n```\n````";quote_message(opts);assert.ok(replaced);++ opts = {+ reply_type: "personal",+ forward_message: true,+ };+ replaced = false;+ quote_message(opts);+ assert.ok(replaced);});test("focus_in_empty_compose", () => {diff --git a/web/tests/compose_ui.test.cjs b/web/tests/compose_ui.test.cjsindex ee7a93cddd1..8c42ba27d96 100644--- a/web/tests/compose_ui.test.cjs+++ b/web/tests/compose_ui.test.cjs@@ -24,6 +24,7 @@ const user_status = zrequire("user_status");const hash_util = mock_esm("../src/hash_util");const channel = mock_esm("../src/channel");const compose_reply = zrequire("compose_reply");+const compose_actions = zrequire("compose_actions");const message_lists = zrequire("message_lists");const text_field_edit = mock_esm("text-field-edit");const {set_realm} = zrequire("state_data");@@ -434,6 +435,27 @@ run_test("quote_message", ({override, override_rewire}) => {reset_test_state();+ // If forwarding a message, the quoted message should be inserted into+ // an empty compose box, even if compose box wasn't previously empty.+ let new_message = false;+ override_rewire(compose_actions, "start", (opts) => {+ assert.equal(opts.message_type, "stream");+ assert.equal(opts.topic, "");+ assert.equal(opts.content, "translated: [Quoting…]");+ new_message = true;+ });++ set_compose_content_with_caret("hello %there");+ compose_reply.quote_message({forward_message: true});+ assert.ok(new_message);++ override_with_quote_text(quote_text);+ success_function({+ raw_content: quote_text,+ });++ reset_test_state();+// When there is already 1 newline before and after the caret,// only 1 newline is added before and after the quoted message.override(text_field_edit, "insertTextIntoField", (elt, syntax) => {diff --git a/web/tests/hotkey.test.cjs b/web/tests/hotkey.test.cjsindex 83a4a755ee6..e831aa9089c 100644--- a/web/tests/hotkey.test.cjs+++ b/web/tests/hotkey.test.cjs@@ -376,6 +376,7 @@ run_test("misc", ({override}) => {assert_mapping("i", message_actions_popover, "toggle_message_actions_menu");assert_mapping(":", emoji_picker, "toggle_emoji_popover", true);assert_mapping(">", compose_reply, "quote_message");+ assert_mapping("<", compose_reply, "quote_message");assert_mapping("e", message_edit, "start");override(narrow_state, "narrowed_by_topic_reply", () => true);