compose: Allow message_id to be passed into quote_and_reply.

Up until now, the currently selected message was the one that was always
quoted. Now if there's a message_id passed in, we'll quote that message
instead, otherwise we'll fall back on the selected message.

This is a prep commit for allowing quoting and replying while editing a
message sent earlier.
This commit is contained in:
N-Shar-ma
2023-10-06 03:00:37 +05:30
committed by Tim Abbott
parent 5ba178a54f
commit 0d4a74b2c2
3 changed files with 16 additions and 14 deletions

View File

@@ -126,8 +126,8 @@ export function reply_with_mention(opts) {
export function quote_and_reply(opts) {
const $textarea = $("textarea#compose-textarea");
const message_id = message_lists.current.selected_id();
const message = message_lists.current.selected_message();
const message_id = opts.message_id || message_lists.current.selected_id();
const message = message_lists.current.get(message_id);
const quoting_placeholder = $t({defaultMessage: "[Quoting…]"});
if (!compose_state.has_message_content()) {

View File

@@ -372,8 +372,7 @@ test("quote_and_reply", ({disallow, override, override_rewire}) => {
override_private_message_recipient({override});
let selected_message;
override(message_lists.current, "get", (_id) => undefined);
override(message_lists.current, "selected_message", () => selected_message);
override(message_lists.current, "get", (id) => (id === 100 ? selected_message : undefined));
let expected_replacement;
let replaced;
@@ -404,8 +403,6 @@ test("quote_and_reply", ({disallow, override, override_rewire}) => {
success_function = opts.success;
});
override(message_lists.current, "selected_id", () => 100);
override(compose_ui, "insert_syntax_and_focus", (syntax, _$textarea, mode) => {
assert.equal(syntax, "translated: [Quoting…]");
assert.equal(mode, "block");
@@ -413,6 +410,7 @@ test("quote_and_reply", ({disallow, override, override_rewire}) => {
const opts = {
reply_type: "personal",
message_id: 100,
};
$("textarea#compose-textarea").caret = noop;
@@ -442,6 +440,10 @@ test("quote_and_reply", ({disallow, override, override_rewire}) => {
quote_and_reply(opts);
assert.ok(replaced);
delete opts.message_id;
override(message_lists.current, "selected_id", () => 100);
override(message_lists.current, "selected_message", () => selected_message);
selected_message = {
type: "stream",
stream_id: denmark_stream.stream_id,

View File

@@ -285,8 +285,7 @@ run_test("quote_and_reply", ({override, override_rewire}) => {
() => "https://chat.zulip.org/#narrow/stream/92-learning/topic/Tornado",
);
override(message_lists.current, "selected_message", () => selected_message);
override(message_lists.current, "selected_id", () => 100);
override(message_lists.current, "get", (id) => (id === 100 ? selected_message : undefined));
let success_function;
override(channel, "get", (opts) => {
@@ -368,7 +367,7 @@ run_test("quote_and_reply", ({override, override_rewire}) => {
let quote_text = "Testing caret position";
override_with_quote_text(quote_text);
set_compose_content_with_caret("hello %there"); // "%" is used to encode/display position of focus before change
compose_reply.quote_and_reply();
compose_reply.quote_and_reply({message_id: 100});
success_function({
raw_content: quote_text,
@@ -383,7 +382,7 @@ run_test("quote_and_reply", ({override, override_rewire}) => {
assert.equal(syntax, "translated: [Quoting…]\n\n");
});
set_compose_content_with_caret("%hello there");
compose_reply.quote_and_reply();
compose_reply.quote_and_reply({message_id: 100});
quote_text = "Testing with caret initially positioned at 0.";
override_with_quote_text(quote_text);
@@ -403,7 +402,8 @@ run_test("quote_and_reply", ({override, override_rewire}) => {
// If the compose-box is close, or open with no content while
// quoting a message, the quoted message should be placed
// at the beginning of compose-box.
compose_reply.quote_and_reply();
override(message_lists.current, "selected_id", () => 100);
compose_reply.quote_and_reply({});
quote_text = "Testing with compose-box closed initially.";
override_with_quote_text(quote_text);
@@ -418,7 +418,7 @@ run_test("quote_and_reply", ({override, override_rewire}) => {
// newlines), the compose-box should re-open and thus the quoted
// message should start from the beginning of compose-box.
set_compose_content_with_caret(" \n\n \n %");
compose_reply.quote_and_reply();
compose_reply.quote_and_reply({});
quote_text = "Testing with compose-box containing whitespaces and newlines only.";
override_with_quote_text(quote_text);
@@ -435,7 +435,7 @@ run_test("quote_and_reply", ({override, override_rewire}) => {
assert.equal(syntax, "\ntranslated: [Quoting…]\n");
});
set_compose_content_with_caret("1st line\n%\n2nd line");
compose_reply.quote_and_reply();
compose_reply.quote_and_reply({});
quote_text = "Testing with caret on a new line between 2 lines of text.";
override_with_quote_text(quote_text);
@@ -452,7 +452,7 @@ run_test("quote_and_reply", ({override, override_rewire}) => {
assert.equal(syntax, "translated: [Quoting…]");
});
set_compose_content_with_caret("lots of\n\n\n\n%\n\n\nnewlines");
compose_reply.quote_and_reply();
compose_reply.quote_and_reply({});
quote_text = "Testing with caret on a new line between many empty newlines.";
override_with_quote_text(quote_text);