Skip to content

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

DEV: Close the pinned messages list on Esc (#38267)

Jarek Radosz4fc6fc975ce1
diff --git a/plugins/chat/assets/javascripts/discourse/initializers/chat-keyboard-shortcuts.js b/plugins/chat/assets/javascripts/discourse/initializers/chat-keyboard-shortcuts.js
index f28721b46da..ba79a245226 100644
--- a/plugins/chat/assets/javascripts/discourse/initializers/chat-keyboard-shortcuts.js
+++ b/plugins/chat/assets/javascripts/discourse/initializers/chat-keyboard-shortcuts.js
@@ -131,6 +131,16 @@ export default {
chatThreadListPane.close();
return;
}
+
+ if (chatStateManager.isPinnedMessagesPaneOpen) {
+ event.preventDefault();
+ event.stopPropagation();
+ router.transitionTo(
+ "chat.channel",
+ ...chatService.activeChannel.routeModels
+ );
+ return;
+ }
};
const markAllChannelsRead = (event) => {
diff --git a/plugins/chat/assets/javascripts/discourse/services/chat-state-manager.js b/plugins/chat/assets/javascripts/discourse/services/chat-state-manager.js
index d9416556d26..5cedc9531d6 100644
--- a/plugins/chat/assets/javascripts/discourse/services/chat-state-manager.js
+++ b/plugins/chat/assets/javascripts/discourse/services/chat-state-manager.js
@@ -165,6 +165,10 @@ export default class ChatStateManager extends Service {
return this.isFullPageActive || this.isDrawerActive;
}
+ get isPinnedMessagesPaneOpen() {
+ return this.router.currentRouteName === "chat.channel.pins";
+ }
+
storeAppURL(url = null) {
if (url) {
this._appURL = url;
diff --git a/plugins/chat/spec/system/shortcuts/full_page_spec.rb b/plugins/chat/spec/system/shortcuts/full_page_spec.rb
index df32ae4f0c0..930400102d6 100644
--- a/plugins/chat/spec/system/shortcuts/full_page_spec.rb
+++ b/plugins/chat/spec/system/shortcuts/full_page_spec.rb
@@ -24,6 +24,25 @@ RSpec.describe "Shortcuts | full page", type: :system do
end
end
+ context "when pressing Esc" do
+ fab!(:message) { Fabricate(:chat_message, chat_channel: channel_1, use_service: true) }
+ fab!(:pin) { Fabricate(:chat_pinned_message, chat_message: message, user: current_user) }
+
+ before { SiteSetting.chat_pinned_messages = true }
+
+ it "closes the pinned messages list" do
+ chat.visit_channel(channel_1)
+ find(".c-navbar__pinned-messages-btn").click
+
+ expect(page).to have_css(".c-routes.--channel-pins")
+
+ page.send_keys(:escape)
+
+ expect(page).to have_no_css(".c-routes.--channel-pins")
+ expect(page).to have_current_path(channel_1.url)
+ end
+ end
+
context "with chat search" do
context "when disabled" do
before { SiteSetting.chat_search_enabled = false }