Skip to content

A platform for community discussion. Free, open, simple.

FIX: Emoji autocomplete “more” button not working in chat (#20113)

Jan Cernik6325e641d8c4
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-composer.js b/plugins/chat/assets/javascripts/discourse/components/chat-composer.js
index 932ca8f84f3..88f02c986af 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-composer.js
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-composer.js
@@ -464,7 +464,9 @@ export default Component.extend(TextareaTextManipulation, {
return `${v.code}:`;
} else {
$textarea.autocomplete({ cancel: true });
- this.set("emojiPickerIsActive", true);
+ this.chatEmojiPickerManager.startFromComposer(this.emojiSelected, {
+ filter: v.term,
+ });
return "";
}
},
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-emoji-picker.hbs b/plugins/chat/assets/javascripts/discourse/components/chat-emoji-picker.hbs
index 4b6273b5aa3..70fe2c5b466 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-emoji-picker.hbs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-emoji-picker.hbs
@@ -13,6 +13,7 @@
<div class="chat-emoji-picker__filter-container">
<DcFilterInput
@class="chat-emoji-picker__filter"
+ @value={{this.chatEmojiPickerManager.initialFilter}}
@filterAction={{this.didInputFilter}}
@icons={{hash left="search"}}
placeholder={{i18n "chat.emoji_picker.search_placeholder"}}
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-message.js b/plugins/chat/assets/javascripts/discourse/components/chat-message.js
index c5ad03d6048..6e89eee1731 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-message.js
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-message.js
@@ -518,8 +518,8 @@ export default Component.extend({
startReactionForMessageActions() {
this.chatEmojiPickerManager.startFromMessageActions(
this.message,
- this.site.desktopView,
- this.selectReaction
+ this.selectReaction,
+ { desktop: this.site.desktopView }
);
},
@@ -527,8 +527,8 @@ export default Component.extend({
startReactionForReactionList() {
this.chatEmojiPickerManager.startFromMessageReactionList(
this.message,
- this.site.desktopView,
- this.selectReaction
+ this.selectReaction,
+ { desktop: this.site.desktopView }
);
},
diff --git a/plugins/chat/assets/javascripts/discourse/components/dc-filter-input.hbs b/plugins/chat/assets/javascripts/discourse/components/dc-filter-input.hbs
index 17ac5f4ef40..a3d465fe24e 100644
--- a/plugins/chat/assets/javascripts/discourse/components/dc-filter-input.hbs
+++ b/plugins/chat/assets/javascripts/discourse/components/dc-filter-input.hbs
@@ -11,6 +11,7 @@
<Input
class="dc-filter-input"
+ @value={{@value}}
{{on "input" (if @filterAction @filterAction (noop))}}
{{on "focusin" (action (mut this.isFocused) true)}}
{{on "focusout" (action (mut this.isFocused) false)}}
diff --git a/plugins/chat/assets/javascripts/discourse/services/chat-emoji-picker-manager.js b/plugins/chat/assets/javascripts/discourse/services/chat-emoji-picker-manager.js
index b19d53b61a5..95dda5430c9 100644
--- a/plugins/chat/assets/javascripts/discourse/services/chat-emoji-picker-manager.js
+++ b/plugins/chat/assets/javascripts/discourse/services/chat-emoji-picker-manager.js
@@ -23,6 +23,7 @@ export default class ChatEmojiPickerManager extends Service {
@tracked emojis = null;
@tracked visibleSections = DEFAULT_VISIBLE_SECTIONS;
@tracked lastVisibleSection = DEFAULT_LAST_SECTION;
+ @tracked initialFilter = null;
@tracked element = null;
@tracked callback;
@@ -35,6 +36,7 @@ export default class ChatEmojiPickerManager extends Service {
closeExisting() {
this.callback = null;
this.opened = false;
+ this.initialFilter = null;
this.visibleSections = DEFAULT_VISIBLE_SECTIONS;
this.lastVisibleSection = DEFAULT_LAST_SECTION;
}
@@ -51,6 +53,7 @@ export default class ChatEmojiPickerManager extends Service {
this.visibleSections = DEFAULT_VISIBLE_SECTIONS;
this.lastVisibleSection = DEFAULT_LAST_SECTION;
+ this.initialFilter = null;
this.closing = false;
this.opened = false;
}, TRANSITION_TIME);
@@ -68,27 +71,32 @@ export default class ChatEmojiPickerManager extends Service {
this.close();
}
- startFromMessageReactionList(message, isDesktop, callback) {
+ startFromMessageReactionList(message, callback, options = {}) {
const trigger = document.querySelector(
`.chat-message-container[data-id="${message.id}"] .chat-message-react-btn`
);
- this.startFromMessage(callback, isDesktop, trigger);
+ this.startFromMessage(callback, trigger, options);
}
- startFromMessageActions(message, isDesktop, callback) {
+ startFromMessageActions(message, callback, options = {}) {
const trigger = document.querySelector(
`.chat-message-actions-container[data-id="${message.id}"] .chat-message-actions`
);
- this.startFromMessage(callback, isDesktop, trigger);
+ this.startFromMessage(callback, trigger, options);
}
- startFromMessage(callback, isDesktop, trigger) {
+ startFromMessage(
+ callback,
+ trigger,
+ options = { filter: null, desktop: true }
+ ) {
+ this.initialFilter = options.filter;
this.context = "chat-message";
this.element = document.querySelector(".chat-message-emoji-picker-anchor");
this.open(callback);
this._popper?.destroy();
- if (isDesktop) {
+ if (options.desktop) {
schedule("afterRender", () => {
this._popper = createPopper(trigger, this.element, {
placement: "top",
@@ -112,7 +120,8 @@ export default class ChatEmojiPickerManager extends Service {
}
}
- startFromComposer(callback) {
+ startFromComposer(callback, options = { filter: null }) {
+ this.initialFilter = options.filter;
this.context = "chat-composer";
this.element = document.querySelector(".chat-composer-emoji-picker-anchor");
this.open(callback);
@@ -140,7 +149,6 @@ export default class ChatEmojiPickerManager extends Service {
.then((emojis) => {
this.emojis = emojis;
})
-
.catch(popupAjaxError)
.finally(() => {
this.loading = false;
diff --git a/plugins/chat/spec/system/chat_composer_spec.rb b/plugins/chat/spec/system/chat_composer_spec.rb
index 28b1016ea23..6ca2fb7ca6a 100644
--- a/plugins/chat/spec/system/chat_composer_spec.rb
+++ b/plugins/chat/spec/system/chat_composer_spec.rb
@@ -94,6 +94,22 @@ RSpec.describe "Chat composer", type: :system, js: true do
end
end
+ context "when opening emoji picker through more button of the autocomplete" do
+ before do
+ channel_1.add(current_user)
+ sign_in(current_user)
+ end
+
+ it "prefills the emoji picker filter input" do
+ chat.visit_channel(channel_1)
+ find(".chat-composer-input").fill_in(with: ":gri")
+
+ click_link(I18n.t("js.composer.more_emoji"))
+
+ expect(find(".chat-emoji-picker .dc-filter-input").value).to eq("gri")
+ end
+ end
+
context "when typing on keyboard" do
before do
channel_1.add(current_user)
diff --git a/plugins/chat/test/javascripts/unit/services/chat-emoji-picker-manager-test.js b/plugins/chat/test/javascripts/unit/services/chat-emoji-picker-manager-test.js
index 052a31a683d..cb86fedae3b 100644
--- a/plugins/chat/test/javascripts/unit/services/chat-emoji-picker-manager-test.js
+++ b/plugins/chat/test/javascripts/unit/services/chat-emoji-picker-manager-test.js
@@ -24,7 +24,7 @@ module(
test("startFromMessageReactionList", async function (assert) {
const callback = () => {};
- this.manager.startFromMessageReactionList({ id: 1 }, false, callback);
+ this.manager.startFromMessageReactionList({ id: 1 }, callback);
assert.ok(this.manager.loading);
assert.ok(this.manager.opened);
@@ -44,7 +44,7 @@ module(
test("startFromMessageActions", async function (assert) {
const callback = () => {};
- this.manager.startFromMessageReactionList({ id: 1 }, false, callback);
+ this.manager.startFromMessageReactionList({ id: 1 }, callback);
assert.ok(this.manager.loading);
assert.ok(this.manager.opened);
@@ -104,6 +104,14 @@ module(
assert.strictEqual(this.manager.loading, false);
});
+ test("startFromComposer with filter option", async function (assert) {
+ const callback = () => {};
+ this.manager.startFromComposer(callback, { filter: "foofilter" });
+ await settled();
+
+ assert.strictEqual(this.manager.initialFilter, "foofilter");
+ });
+
test("closeExisting", async function (assert) {
const callback = () => {
return;