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.

reaction-view: Create has reaction operator.

Kenneth Rodriguesf53a7cdffa70
diff --git a/help/search-for-messages.md b/help/search-for-messages.md
index 12b004ddea2..a6237b678b7 100644
--- a/help/search-for-messages.md
+++ b/help/search-for-messages.md
@@ -96,6 +96,7 @@ Zulip offers the following filters based on the location of the message.
* `has:attachment`: Search messages that contain an [uploaded
file](/help/share-and-upload-files).
* `has:image`: Search messages that contain uploaded or linked images or videos.
+* `has:reaction`: Search messages with [emoji reactions](/help/emoji-reactions).
!!! tip ""
diff --git a/web/src/filter.ts b/web/src/filter.ts
index f62c84be1f0..8a3d8dfbcd8 100644
--- a/web/src/filter.ts
+++ b/web/src/filter.ts
@@ -145,6 +145,8 @@ function message_matches_search_term(message: Message, operator: string, operand
return message_parser.message_has_link(message);
case "attachment":
return message_parser.message_has_attachment(message);
+ case "reaction":
+ return message_parser.message_has_reaction(message);
default:
return false; // has:something_else returns false
}
@@ -618,6 +620,8 @@ export class Filter {
"links",
"attachment",
"attachments",
+ "reaction",
+ "reactions",
];
if (!valid_has_operands.includes(operand)) {
return {
@@ -849,6 +853,12 @@ export class Filter {
if (_.isEqual(term_types, ["sender"])) {
return true;
}
+ if (
+ _.isEqual(term_types, ["sender", "has-reaction"]) &&
+ this.operands("sender")[0] === people.my_current_email()
+ ) {
+ return true;
+ }
return false;
}
@@ -863,6 +873,12 @@ export class Filter {
const term_types = this.sorted_term_types();
// this comes first because it has 3 term_types but is not a "complex filter"
+ if (
+ _.isEqual(term_types, ["sender", "search", "has-reaction"]) &&
+ this.operands("sender")[0] === people.my_current_email()
+ ) {
+ return "/#narrow/has/reaction/sender/me";
+ }
if (_.isEqual(term_types, ["channel", "topic", "search"])) {
// if channel does not exist, redirect to home view
if (!this._sub) {
@@ -928,6 +944,15 @@ export class Filter {
const term_types = this.sorted_term_types();
let icon;
let zulip_icon;
+
+ if (
+ _.isEqual(term_types, ["sender", "has-reaction"]) &&
+ this.operands("sender")[0] === people.my_current_email()
+ ) {
+ zulip_icon = "smile";
+ return {...context, zulip_icon};
+ }
+
switch (term_types[0]) {
case "in-home":
case "in-all":
@@ -1053,6 +1078,12 @@ export class Filter {
return $t({defaultMessage: "Unread messages"});
}
}
+ if (
+ _.isEqual(term_types, ["sender", "has-reaction"]) &&
+ this.operands("sender")[0] === people.my_current_email()
+ ) {
+ return $t({defaultMessage: "Reactions"});
+ }
/* istanbul ignore next */
return undefined;
}
@@ -1073,6 +1104,17 @@ export class Filter {
link: "/help/star-a-message#view-your-starred-messages",
};
}
+ if (
+ _.isEqual(term_types, ["sender", "has-reaction"]) &&
+ this.operands("sender")[0] === people.my_current_email()
+ ) {
+ return {
+ description: $t({
+ defaultMessage: "Emoji reactions to your messages.",
+ }),
+ link: "/help/emoji-reactions",
+ };
+ }
return undefined;
}
diff --git a/web/src/left_sidebar_navigation_area.ts b/web/src/left_sidebar_navigation_area.ts
index 4863fb80bfd..99863eeddd7 100644
--- a/web/src/left_sidebar_navigation_area.ts
+++ b/web/src/left_sidebar_navigation_area.ts
@@ -1,8 +1,10 @@
import $ from "jquery";
+import _ from "lodash";
import type {Filter} from "./filter";
import {localstorage} from "./localstorage";
import {page_params} from "./page_params";
+import * as people from "./people";
import * as resize from "./resize";
import * as scheduled_messages from "./scheduled_messages";
import * as settings_config from "./settings_config";
@@ -86,6 +88,7 @@ function deselect_top_left_corner_items(): void {
remove($(".top_left_mentions"));
remove($(".top_left_recent_view"));
remove($(".top_left_inbox"));
+ remove($(".top_left_my_reactions"));
}
export function handle_narrow_activated(filter: Filter): void {
@@ -114,6 +117,14 @@ export function handle_narrow_activated(filter: Filter): void {
$filter_li.addClass("active-filter");
}
}
+ const term_types = filter.sorted_term_types();
+ if (
+ _.isEqual(term_types, ["sender", "has-reaction"]) &&
+ filter.operands("sender")[0] === people.my_current_email()
+ ) {
+ $filter_li = $(".top_left_my_reactions");
+ $filter_li.addClass("active-filter");
+ }
}
function toggle_condensed_navigation_area(): void {
diff --git a/web/src/message_feed_top_notices.ts b/web/src/message_feed_top_notices.ts
index 681f3cf4b16..9c56671993d 100644
--- a/web/src/message_feed_top_notices.ts
+++ b/web/src/message_feed_top_notices.ts
@@ -1,4 +1,5 @@
import $ from "jquery";
+import _ from "lodash";
import assert from "minimalistic-assert";
import * as hash_util from "./hash_util";
@@ -6,6 +7,7 @@ import * as message_lists from "./message_lists";
import type {MessageList} from "./message_lists";
import * as narrow_banner from "./narrow_banner";
import * as narrow_state from "./narrow_state";
+import * as people from "./people";
function show_history_limit_notice(): void {
$(".top-messages-logo").hide();
@@ -54,7 +56,11 @@ export function update_top_of_narrow_notices(msg_list: MessageList): void {
!filter.is_in_home() &&
!filter.contains_only_private_messages() &&
!filter.includes_full_stream_history() &&
- !filter.is_personal_filter()
+ !filter.is_personal_filter() &&
+ !(
+ _.isEqual(filter._sorted_term_types, ["sender", "has-reaction"]) &&
+ filter.operands("sender")[0] === people.my_current_email()
+ )
) {
show_end_of_results_notice();
}
diff --git a/web/src/message_parser.ts b/web/src/message_parser.ts
index d8e8b23acb6..5091f1df5bd 100644
--- a/web/src/message_parser.ts
+++ b/web/src/message_parser.ts
@@ -23,3 +23,7 @@ export function message_has_image(message: Message): boolean {
export function message_has_attachment(message: Message): boolean {
return is_element_in_message_content(message, "a[href^='/user_uploads']");
}
+
+export function message_has_reaction(message: Message): boolean {
+ return message.clean_reactions.size > 0;
+}
diff --git a/web/src/narrow_banner.ts b/web/src/narrow_banner.ts
index 8418d3be39a..66c1e197a3f 100644
--- a/web/src/narrow_banner.ts
+++ b/web/src/narrow_banner.ts
@@ -1,4 +1,5 @@
import $ from "jquery";
+import _ from "lodash";
import assert from "minimalistic-assert";
import {$t, $t_html} from "./i18n";
@@ -97,6 +98,7 @@ function pick_empty_narrow_banner(): NarrowBannerData {
}
const first_term = current_filter.terms()[0]!;
+ const current_terms_types = current_filter.sorted_term_types();
const first_operator = first_term.operator;
const first_operand = first_term.operand;
const num_terms = current_filter.terms().length;
@@ -160,6 +162,26 @@ function pick_empty_narrow_banner(): NarrowBannerData {
return default_banner;
}
+ if (
+ _.isEqual(current_terms_types, ["sender", "has-reaction"]) &&
+ current_filter.operands("sender")[0] === people.my_current_email()
+ ) {
+ return {
+ title: $t({defaultMessage: "None of your messages have emoji reactions yet."}),
+ html: $t_html(
+ {
+ defaultMessage: "Learn more about emoji reactions <z-link>here</z-link>.",
+ },
+ {
+ "z-link": (content_html) =>
+ `<a target="_blank" rel="noopener noreferrer" href="/help/emoji-reactions">${content_html.join(
+ "",
+ )}</a>`,
+ },
+ ),
+ };
+ }
+
// For other multi-operator narrows, we just use the default banner
return {
title: default_banner_for_multiple_filters,
diff --git a/web/src/search_suggestion.ts b/web/src/search_suggestion.ts
index 83100df3cd8..8eecf214be0 100644
--- a/web/src/search_suggestion.ts
+++ b/web/src/search_suggestion.ts
@@ -635,6 +635,11 @@ function get_has_filter_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Sugg
description_html: "messages that contain attachments",
incompatible_patterns: [{operator: "has", operand: "attachment"}],
},
+ {
+ search_string: "has:reaction",
+ description_html: "messages that contain reactions",
+ incompatible_patterns: [{operator: "has", operand: "reaction"}],
+ },
];
return get_special_filter_suggestions(last, terms, suggestions);
}
diff --git a/web/styles/left_sidebar.css b/web/styles/left_sidebar.css
index e7406937607..c47e6487fc3 100644
--- a/web/styles/left_sidebar.css
+++ b/web/styles/left_sidebar.css
@@ -642,6 +642,7 @@ li.active-sub-filter {
}
/* Don't show unread counts on views... */
+.top_left_my_reactions,
.top_left_inbox,
.top_left_recent_view,
.top_left_all_messages {
diff --git a/web/templates/left_sidebar.hbs b/web/templates/left_sidebar.hbs
index 41fa84a39b9..0c3db48bae1 100644
--- a/web/templates/left_sidebar.hbs
+++ b/web/templates/left_sidebar.hbs
@@ -98,6 +98,16 @@
<span class="unread_count"></span>
</a>
</li>
+ <li class="tippy-views-tooltip top_left_my_reactions top_left_row hidden-for-spectators" data-tooltip-template-id="my-reactions-tooltip-template">
+ <a class="left-sidebar-navigation-label-container" href="#narrow/has/reaction/sender/me">
+ <span class="filter-icon">
+ <i class="zulip-icon zulip-icon-smile" aria-hidden="true"></i>
+ </span>
+ {{~!-- squash whitespace --~}}
+ <span class="left-sidebar-navigation-label">{{t 'Reactions' }}</span>
+ <span class="unread_count"></span>
+ </a>
+ </li>
<li class="top_left_starred_messages top_left_row hidden-for-spectators">
<a class="left-sidebar-navigation-label-container" href="#narrow/is/starred">
<span class="filter-icon">
diff --git a/web/templates/popovers/left_sidebar/left_sidebar_condensed_views_popover.hbs b/web/templates/popovers/left_sidebar/left_sidebar_condensed_views_popover.hbs
index 289fbe81f15..0003ddfeeb7 100644
--- a/web/templates/popovers/left_sidebar/left_sidebar_condensed_views_popover.hbs
+++ b/web/templates/popovers/left_sidebar/left_sidebar_condensed_views_popover.hbs
@@ -1,5 +1,14 @@
{{! Contents of the condensed nav vdots popup }}
<ul class="nav nav-list condensed-views-popover-menu">
+ <li class="condensed-views-popover-menu-reactions">
+ {{! tabindex="0" Makes anchor tag focusable. Needed for keyboard support. }}
+ <a tabindex="0" href="#narrow/has/reaction/sender/me" class="left-sidebar-popover-icon-label-count tippy-left-sidebar-tooltip" data-tooltip-template-id="my-reactions-tooltip-template">
+ <span class="filter-icon">
+ <i class="zulip-icon zulip-icon-smile" aria-hidden="true"></i>
+ </span>
+ <span class="left-sidebar-navigation-label">{{t 'Reactions' }}</span>
+ </a>
+ </li>
<li class="condensed-views-popover-menu-drafts">
{{! tabindex="0" Makes anchor tag focusable. Needed for keyboard support. }}
<a tabindex="0" href="#drafts" class="left-sidebar-popover-icon-label-count tippy-left-sidebar-tooltip" data-tooltip-template-id="drafts-tooltip-template">
diff --git a/web/templates/search_operators.hbs b/web/templates/search_operators.hbs
index 1577a137ac3..770d9d8c5df 100644
--- a/web/templates/search_operators.hbs
+++ b/web/templates/search_operators.hbs
@@ -99,6 +99,12 @@
{{t 'Narrow to messages containing images.'}}
</td>
</tr>
+ <tr>
+ <td class="operator">has:reaction</td>
+ <td class="definition">
+ {{t 'Narrow to messages with emoji reactions.'}}
+ </td>
+ </tr>
<tr>
<td class="operator">is:alerted</td>
<td class="definition">
diff --git a/web/templates/tooltip_templates.hbs b/web/templates/tooltip_templates.hbs
index f6826adb181..980f717b300 100644
--- a/web/templates/tooltip_templates.hbs
+++ b/web/templates/tooltip_templates.hbs
@@ -121,6 +121,11 @@
</div>
{{tooltip_hotkey_hints "T"}}
</template>
+<template id="my-reactions-tooltip-template">
+ <div class="views-tooltip-container" data-view-code="recent_topics">
+ <div>{{t 'Reactions to your messages' }}</div>
+ </div>
+</template>
<template id="inbox-tooltip-template">
<div class="views-tooltip-container" data-view-code="inbox">
<div>{{t 'Inbox' }}</div>
diff --git a/web/tests/filter.test.js b/web/tests/filter.test.js
index 32ecbdba85a..d0e2bb9510f 100644
--- a/web/tests/filter.test.js
+++ b/web/tests/filter.test.js
@@ -420,6 +420,10 @@ function assert_not_mark_read_with_has_operands(additional_terms_to_test) {
has_link_term = [{operator: "has", operand: "attachment"}];
filter = new Filter([...additional_terms_to_test, ...has_link_term]);
assert.ok(!filter.can_mark_messages_read());
+
+ has_link_term = [{operator: "has", operand: "reaction"}];
+ filter = new Filter([...additional_terms_to_test, ...has_link_term]);
+ assert.ok(!filter.can_mark_messages_read());
}
function assert_not_mark_read_with_is_operands(additional_terms_to_test) {
additional_terms_to_test = additional_terms_to_test || [];
@@ -752,6 +756,10 @@ test("canonicalization", () => {
term = Filter.canonicalize_term({operator: "has", operand: "links"});
assert.equal(term.operator, "has");
assert.equal(term.operand, "link");
+
+ term = Filter.canonicalize_term({operator: "has", operand: "reactions"});
+ assert.equal(term.operator, "has");
+ assert.equal(term.operand, "reaction");
});
test("predicate_basics", ({override}) => {
@@ -975,6 +983,30 @@ test("predicate_basics", ({override}) => {
content: "<p>Testing</p>",
};
+ const clean_reactions_message = {
+ clean_reactions: new Map(
+ Object.entries({
+ "unicode_emoji,1f3b1": {
+ class: "message_reaction reacted",
+ count: 2,
+ emoji_alt_code: false,
+ emoji_code: "1f3b1",
+ emoji_name: "8ball",
+ is_realm_emoji: false,
+ label: "translated: You (click to remove) and Bob van Roberts reacted with :8ball:",
+ local_id: "unicode_emoji,1f3b1",
+ reaction_type: "unicode_emoji",
+ user_ids: [alice.user_id],
+ vote_text: "translated: You, Bob van Roberts",
+ },
+ }),
+ ),
+ };
+
+ const non_reaction_msg = {
+ clean_reactions: new Map(),
+ };
+
predicate = get_predicate([["has", "non_valid_operand"]]);
assert.ok(!predicate(img_msg));
assert.ok(!predicate(non_img_attachment_msg));
@@ -1017,6 +1049,10 @@ test("predicate_basics", ({override}) => {
assert.ok(!has_image(link_msg));
set_find_results_for_msg_content(no_has_filter_matching_msg, ".message_inline_image", false);
assert.ok(!has_image(no_has_filter_matching_msg));
+
+ const has_reaction = get_predicate([["has", "reaction"]]);
+ assert.ok(has_reaction(clean_reactions_message));
+ assert.ok(!has_reaction(non_reaction_msg));
});
test("negated_predicates", () => {
@@ -1688,6 +1724,10 @@ test("navbar_helpers", () => {
{operator: "channel", operand: "foo"},
{operator: "topic", operand: "bar"},
];
+ const has_reaction_sender_me = [
+ {operator: "has", operand: "reaction"},
+ {operator: "sender", operand: "me"},
+ ];
// foo channel exists
const channel_term = [{operator: "channel", operand: "foo"}];
make_private_sub("psub", "22");
@@ -1872,6 +1912,15 @@ test("navbar_helpers", () => {
]),
redirect_url_with_search: "/#narrow/dm/undefined",
},
+ {
+ terms: has_reaction_sender_me,
+ is_common_narrow: true,
+ zulip_icon: "smile",
+ title: "translated: Reactions",
+ redirect_url_with_search: "/#narrow/has/reaction/sender/me",
+ description: "translated: Emoji reactions to your messages.",
+ link: "/help/emoji-reactions",
+ },
{
terms: is_alerted,
is_common_narrow: false,
diff --git a/web/tests/message_view.test.js b/web/tests/message_view.test.js
index 30084eb93b5..dad65e4d05c 100644
--- a/web/tests/message_view.test.js
+++ b/web/tests/message_view.test.js
@@ -526,6 +526,19 @@ run_test("show_empty_narrow_message", ({mock_template}) => {
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: This channel does not exist or is private."),
);
+
+ set_filter([
+ ["has", "reaction"],
+ ["sender", "me"],
+ ]);
+ narrow_banner.show_empty_narrow_message();
+ assert.equal(
+ $(".empty_feed_notice_main").html(),
+ empty_narrow_html(
+ "translated: None of your messages have emoji reactions yet.",
+ 'translated HTML: Learn more about emoji reactions <a target="_blank" rel="noopener noreferrer" href="/help/emoji-reactions">here</a>.',
+ ),
+ );
});
run_test("show_empty_narrow_message_with_search", ({mock_template}) => {
diff --git a/web/tests/search_suggestion.test.js b/web/tests/search_suggestion.test.js
index 6b8d2719920..bfba2d65370 100644
--- a/web/tests/search_suggestion.test.js
+++ b/web/tests/search_suggestion.test.js
@@ -95,7 +95,12 @@ test("basic_get_suggestions_for_spectator", () => {
const query = "";
const suggestions = get_suggestions(query);
- assert.deepEqual(suggestions.strings, ["has:link", "has:image", "has:attachment"]);
+ assert.deepEqual(suggestions.strings, [
+ "has:link",
+ "has:image",
+ "has:attachment",
+ "has:reaction",
+ ]);
page_params.is_spectator = false;
});
@@ -432,6 +437,7 @@ test("empty_query_suggestions", () => {
"has:link",
"has:image",
"has:attachment",
+ "has:reaction",
];
assert.deepEqual(suggestions.strings, expected);
@@ -462,7 +468,7 @@ test("has_suggestions", ({override, mock_template}) => {
override(narrow_state, "stream_name", noop);
let suggestions = get_suggestions(query);
- let expected = ["h", "has:link", "has:image", "has:attachment"];
+ let expected = ["h", "has:link", "has:image", "has:attachment", "has:reaction"];
assert.deepEqual(suggestions.strings, expected);
function describe(q) {
@@ -475,7 +481,7 @@ test("has_suggestions", ({override, mock_template}) => {
query = "-h";
suggestions = get_suggestions(query);
- expected = ["-h", "-has:link", "-has:image", "-has:attachment"];
+ expected = ["-h", "-has:link", "-has:image", "-has:attachment", "-has:reaction"];
assert.deepEqual(suggestions.strings, expected);
assert.equal(describe("-has:link"), "Exclude messages that contain links");
assert.equal(describe("-has:image"), "Exclude messages that contain images");
@@ -485,7 +491,7 @@ test("has_suggestions", ({override, mock_template}) => {
query = "has:";
suggestions = get_suggestions(query);
- expected = ["has:link", "has:image", "has:attachment"];
+ expected = ["has:link", "has:image", "has:attachment", "has:reaction"];
assert.deepEqual(suggestions.strings, expected);
query = "has:im";