Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

compose: Allow `message_id` to be passed into `quote_and_reply`.

N-Shar-ma0d4a74b2c21d
diff --git a/web/src/compose_reply.js b/web/src/compose_reply.js
index e12c947e670..79777eac006 100644
--- a/web/src/compose_reply.js
+++ b/web/src/compose_reply.js
@@ -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()) {
diff --git a/web/tests/compose_actions.test.js b/web/tests/compose_actions.test.js
index e4c8e8e0bbf..a75c9547865 100644
--- a/web/tests/compose_actions.test.js
+++ b/web/tests/compose_actions.test.js
@@ -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,
diff --git a/web/tests/compose_ui.test.js b/web/tests/compose_ui.test.js
index bb73b557f78..0f4585e13de 100644
--- a/web/tests/compose_ui.test.js
+++ b/web/tests/compose_ui.test.js
@@ -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);