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.

message_actions_popover: Hide >/< hints when they disagree with the menu.

Aman Agrawal96967d276661
diff --git a/web/src/compose_reply.ts b/web/src/compose_reply.ts
index 36cc74dc6bf..0162fed05d3 100644
--- a/web/src/compose_reply.ts
+++ b/web/src/compose_reply.ts
@@ -248,27 +248,35 @@ function get_highlighted_selection(): HighlightedSelection {
// What the message actions menu opened on `message_id` should quote or
// forward, given the text selection at the time the menu was opened.
-export type QuoteMenuSelection =
+export type QuoteMenuSelection = {
+ // Whether > and < would do the same thing as the menu item. They act on
+ // the selection wherever it is, so they disagree with a menu opened on a
+ // message the selection does not cover.
+ hotkeys_agree: boolean;
+} & (
| {kind: "full_message"}
| {kind: "message_selection"; quote_content: string}
- | {kind: "selected_messages"; message_ids: number[]};
+ | {kind: "selected_messages"; message_ids: number[]}
+);
export function get_quote_menu_selection(message_id: number): QuoteMenuSelection {
const selection = get_highlighted_selection();
if (selection.type === "multi_message" && selection.message_ids.includes(message_id)) {
- return {kind: "selected_messages", message_ids: selection.message_ids};
+ return {kind: "selected_messages", message_ids: selection.message_ids, hotkeys_agree: true};
}
if (selection.type === "single_message" && selection.message_id === message_id) {
const quote_content = get_message_selection();
// Selecting only a sender name or timestamp lands outside
- // `.message_content`, leaving nothing quotable to offer.
+ // `.message_content`, leaving nothing quotable to offer. The hotkeys
+ // fall back to the whole message too, so they still agree.
if (quote_content.trim() !== "") {
- return {kind: "message_selection", quote_content};
+ return {kind: "message_selection", quote_content, hotkeys_agree: true};
}
+ return {kind: "full_message", hotkeys_agree: true};
}
// With no selection, or one that does not cover this message, the menu
// acts on the message it was opened from.
- return {kind: "full_message"};
+ return {kind: "full_message", hotkeys_agree: selection.type === "none"};
}
function get_quote_target_for_single_message(opts: {
diff --git a/web/src/popover_menus_data.ts b/web/src/popover_menus_data.ts
index 1069acc40c1..5168b6a8783 100644
--- a/web/src/popover_menus_data.ts
+++ b/web/src/popover_menus_data.ts
@@ -45,6 +45,7 @@ type ActionPopoverContext = {
should_display_quote_message: boolean;
quote_message_menu_item: string;
forward_message_menu_item: string;
+ show_quote_and_forward_hotkey_hints: boolean;
conversation_time_url: string;
should_display_delete_option: boolean;
should_display_read_receipts_option: boolean;
@@ -252,6 +253,9 @@ export function get_actions_popover_content_context(
const {quote_message_menu_item, forward_message_menu_item} = get_quote_menu_labels(
quote_menu_selection.kind,
);
+ // Showing a hotkey next to a menu item that does something else would be
+ // a lie, so we drop the hint rather than the item.
+ const show_quote_and_forward_hotkey_hints = quote_menu_selection.hotkeys_agree;
const conversation_time_url = hash_util.by_conversation_and_time_url(message);
@@ -302,6 +306,7 @@ export function get_actions_popover_content_context(
should_display_quote_message,
quote_message_menu_item,
forward_message_menu_item,
+ show_quote_and_forward_hotkey_hints,
should_display_message_report_option: should_display_message_report_option(),
};
}
diff --git a/web/templates/popovers/message_actions_popover.hbs b/web/templates/popovers/message_actions_popover.hbs
index 128cabe3a92..3a56db851d3 100644
--- a/web/templates/popovers/message_actions_popover.hbs
+++ b/web/templates/popovers/message_actions_popover.hbs
@@ -6,14 +6,18 @@
<a role="menuitem" data-message-id="{{message_id}}" class="respond_button popover-menu-link" tabindex="0">
<i class="popover-menu-icon zulip-icon zulip-icon-quote-message" aria-hidden="true"></i>
<span class="popover-menu-label">{{quote_message_menu_item}}</span>
+ {{#if show_quote_and_forward_hotkey_hints}}
{{popover_hotkey_hints ">"}}
+ {{/if}}
</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">{{forward_message_menu_item}}</span>
+ {{#if show_quote_and_forward_hotkey_hints}}
{{popover_hotkey_hints "<"}}
+ {{/if}}
</a>
</li>
{{/if}}
diff --git a/web/tests/compose_reply.test.cjs b/web/tests/compose_reply.test.cjs
index c4cc2f69f4f..4e156667b83 100644
--- a/web/tests/compose_reply.test.cjs
+++ b/web/tests/compose_reply.test.cjs
@@ -393,22 +393,33 @@ run_test("build_and_process_quote_assets_for_messages", ({override}) => {
run_test("get_quote_menu_selection", ({override_rewire}) => {
override_rewire(compose_reply, "get_highlighted_message_ids", () => undefined);
- assert.deepEqual(compose_reply.get_quote_menu_selection(10), {kind: "full_message"});
+ assert.deepEqual(compose_reply.get_quote_menu_selection(10), {
+ kind: "full_message",
+ hotkeys_agree: true,
+ });
override_rewire(compose_reply, "get_highlighted_message_ids", () => [10]);
override_rewire(compose_reply, "get_message_selection", () => "partial text");
assert.deepEqual(compose_reply.get_quote_menu_selection(10), {
kind: "message_selection",
quote_content: "partial text",
+ hotkeys_agree: true,
});
- // The selection is inside a different message than the menu was opened on.
- assert.deepEqual(compose_reply.get_quote_menu_selection(99), {kind: "full_message"});
+ // The selection is inside a different message than the menu was opened
+ // on, so > and < would act on the selection instead: hide their hints.
+ assert.deepEqual(compose_reply.get_quote_menu_selection(99), {
+ kind: "full_message",
+ hotkeys_agree: false,
+ });
// Selecting only a sender name or timestamp lands outside
// `.message_content`, so there is nothing quotable to offer.
override_rewire(compose_reply, "get_message_selection", () => " ".repeat(3));
- assert.deepEqual(compose_reply.get_quote_menu_selection(10), {kind: "full_message"});
+ assert.deepEqual(compose_reply.get_quote_menu_selection(10), {
+ kind: "full_message",
+ hotkeys_agree: true,
+ });
// A selection spanning several messages, opened from inside the range;
// we return early without consulting the selected text at all.
@@ -416,9 +427,13 @@ run_test("get_quote_menu_selection", ({override_rewire}) => {
assert.deepEqual(compose_reply.get_quote_menu_selection(11), {
kind: "selected_messages",
message_ids: [10, 11, 12],
+ hotkeys_agree: true,
});
// ...and opened from a message outside the range, where the menu acts on
- // that one message only.
- assert.deepEqual(compose_reply.get_quote_menu_selection(99), {kind: "full_message"});
+ // that one message only and the hotkeys would not.
+ assert.deepEqual(compose_reply.get_quote_menu_selection(99), {
+ kind: "full_message",
+ hotkeys_agree: false,
+ });
});
diff --git a/web/tests/i18n.test.cjs b/web/tests/i18n.test.cjs
index 217e84df5ea..0cf205cd758 100644
--- a/web/tests/i18n.test.cjs
+++ b/web/tests/i18n.test.cjs
@@ -66,6 +66,7 @@ run_test("t_tag", ({mock_template}) => {
should_display_quote_message: true,
quote_message_menu_item: "Citer le message",
forward_message_menu_item: "Transférer le message",
+ show_quote_and_forward_hotkey_hints: true,
editability_menu_item: "Edit message",
conversation_time_url:
"http://zulip.zulipdev.com/#narrow/channel/101-devel/topic/testing/near/99",
diff --git a/web/tests/popover_menus_data.test.cjs b/web/tests/popover_menus_data.test.cjs
index 37ad5d7119d..71debbdb342 100644
--- a/web/tests/popover_menus_data.test.cjs
+++ b/web/tests/popover_menus_data.test.cjs
@@ -242,6 +242,7 @@ test("my_message_all_actions", ({override}) => {
add_message_with_view(list, messages);
const response = popover_menus_data.get_actions_popover_content_context(1, {
kind: "full_message",
+ hotkeys_agree: true,
});
assert.equal(response.message_id, 1);
assert.equal(response.stream_id, 1);
@@ -256,6 +257,15 @@ test("my_message_all_actions", ({override}) => {
assert.equal(response.should_display_delete_option, true);
assert.equal(response.should_display_read_receipts_option, true);
assert.equal(response.should_display_quote_message, true);
+ assert.equal(response.show_quote_and_forward_hotkey_hints, true);
+
+ // A menu opened on a message the selection does not cover quotes just
+ // that message, which is not what > and < would do.
+ const diverging_response = popover_menus_data.get_actions_popover_content_context(1, {
+ kind: "full_message",
+ hotkeys_agree: false,
+ });
+ assert.equal(diverging_response.show_quote_and_forward_hotkey_hints, false);
assert.equal(response.quote_message_menu_item, "translated: Quote message");
assert.equal(response.forward_message_menu_item, "translated: Forward message");
@@ -312,6 +322,7 @@ test("not_my_message_view_actions", ({override}) => {
const response = popover_menus_data.get_actions_popover_content_context(1, {
kind: "full_message",
+ hotkeys_agree: true,
});
assert.equal(response.view_source_menu_item, "translated: View original message");
@@ -358,6 +369,7 @@ test("not_my_message_view_source_and_move", ({override}) => {
const response = popover_menus_data.get_actions_popover_content_context(1, {
kind: "full_message",
+ hotkeys_agree: true,
});
assert.equal(response.view_source_menu_item, "translated: View original message");
assert.equal(response.editability_menu_item, undefined);