From 9e6dc4c5c808a44ee4ba5b38133679d6504241ba Mon Sep 17 00:00:00 2001 From: David Battersby Date: Fri, 7 Jun 2024 10:47:01 +0400 Subject: [PATCH] DEV: prevent duplication of chat drawer routes (#27381) This change prevents explicitly declaring each route that should be intercepted for chat drawer mode. In theory all chat drawer routes should be intercepted from the main chat routes file and therefore we would only need to add new drawer routes directly within chat-drawer-router.js. --- .../javascripts/discourse/routes/chat.js | 22 ++----------------- .../discourse/services/chat-drawer-router.js | 4 ++++ 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/plugins/chat/assets/javascripts/discourse/routes/chat.js b/plugins/chat/assets/javascripts/discourse/routes/chat.js index 8a7e5202f74..c2e969d7568 100644 --- a/plugins/chat/assets/javascripts/discourse/routes/chat.js +++ b/plugins/chat/assets/javascripts/discourse/routes/chat.js @@ -15,6 +15,7 @@ export default class ChatRoute extends DiscourseRoute { @service chat; @service router; @service chatStateManager; + @service chatDrawerRouter; @service currentUser; titleToken() { @@ -26,29 +27,10 @@ export default class ChatRoute extends DiscourseRoute { return this.router.transitionTo(`discovery.${defaultHomepage()}`); } - const INTERCEPTABLE_ROUTES = [ - "chat.channel", - "chat.direct-messages", - "chat.channels", - "chat.threads", - "chat.channel.thread", - "chat.channel.thread.index", - "chat.channel.thread.near-message", - "chat.channel.near-message-with-thread", - "chat.channel.threads", - "chat.channel.index", - "chat.channel.near-message", - "chat.channel-legacy", - "chat.channel.info.settings", - "chat.channel.info.members", - "chat", - "chat.index", - ]; - if ( transition.from && // don't intercept when directly loading chat this.chatStateManager.isDrawerPreferred && - INTERCEPTABLE_ROUTES.includes(transition.targetName) + this.chatDrawerRouter.routeNames.includes(transition.targetName) ) { transition.abort(); diff --git a/plugins/chat/assets/javascripts/discourse/services/chat-drawer-router.js b/plugins/chat/assets/javascripts/discourse/services/chat-drawer-router.js index 1342dee11c9..40693b71420 100644 --- a/plugins/chat/assets/javascripts/discourse/services/chat-drawer-router.js +++ b/plugins/chat/assets/javascripts/discourse/services/chat-drawer-router.js @@ -9,7 +9,9 @@ import ChatDrawerRoutesSettings from "discourse/plugins/chat/discourse/component import ChatDrawerRoutesThreads from "discourse/plugins/chat/discourse/components/chat/drawer-routes/threads"; const ROUTES = { + "chat.index": { name: ChatDrawerRoutesChannels }, "chat.channel": { name: ChatDrawerRoutesChannel }, + "chat.channel.index": { name: ChatDrawerRoutesChannel }, "chat.channel.thread": { name: ChatDrawerRoutesChannelThread, extractParams: (route) => { @@ -103,6 +105,8 @@ export default class ChatDrawerRouter extends Service { @tracked drawerRoute = null; @tracked params = null; + routeNames = Object.keys(ROUTES); + stateFor(route) { this.drawerRoute?.deactivate?.(this.chatHistory.currentRoute);