A platform for community discussion. Free, open, simple.
FIX: make the check better for drawer router (#28212)
Gabriel Grubba2b577950af5b
diff --git a/plugins/chat/assets/javascripts/discourse/services/chat-drawer-router.js b/plugins/chat/assets/javascripts/discourse/services/chat-drawer-router.jsindex cbd0b5e460c..083b8892747 100644--- a/plugins/chat/assets/javascripts/discourse/services/chat-drawer-router.js+++ b/plugins/chat/assets/javascripts/discourse/services/chat-drawer-router.js@@ -11,7 +11,28 @@ import ChatDrawerRoutesDirectMessages from "discourse/plugins/chat/discourse/comimport ChatDrawerRoutesThreads from "discourse/plugins/chat/discourse/components/chat/drawer-routes/threads";const ROUTES = {- chat: { name: ChatDrawerRoutesChannels },+ chat: {+ name: ChatDrawerRoutesChannels,+ redirect: (context) => {+ if (+ context.siteSettings.chat_preferred_index === "my_threads" &&+ context.hasThreads+ ) {+ return "/chat/threads";+ }++ if (+ context.siteSettings.chat_preferred_index === "direct_messages" &&+ context.hasDirectMessages+ ) {+ return "/chat/direct-messages";+ }++ if (!context.siteSettings.enable_public_channels) {+ return "/chat/direct-messages";+ }+ },+ },"chat.index": { name: ChatDrawerRoutesChannels },// order matters, non index before index"chat.browse": {@@ -154,36 +175,6 @@ export default class ChatDrawerRouter extends Service {return this.chat.userCanAccessDirectMessages;}- #routeFromURL(url) {- let route = this.router.recognize(url);-- // ember might recognize the index subroute- if (route.localName === "index") {- route = route.parent;- }-- return route;- }-- #redirect() {- if (- this.siteSettings.chat_preferred_index === "my_threads" &&- this.hasThreads- ) {- return this.stateFor(this.#routeFromURL("/chat/threads"));- }- if (- this.siteSettings.chat_preferred_index === "direct_messages" &&- this.hasDirectMessages- ) {- return this.stateFor(this.#routeFromURL("/chat/direct-messages"));- }-- if (!this.siteSettings.enable_public_channels) {- return this.stateFor(this.#routeFromURL("/chat/direct-messages"));- }- }-stateFor(route) {this.drawerRoute?.deactivate?.(this.chatHistory.currentRoute);@@ -191,15 +182,23 @@ export default class ChatDrawerRouter extends Service {this.drawerRoute = ROUTES[route.name];this.params = this.drawerRoute?.extractParams?.(route) || route.params;this.component = this.drawerRoute?.name || ChatDrawerRoutesChannels;+ this.currentRouteName = route.name;+ this.drawerRoute.activate?.(route);- if (- !this.chatStateManager.isDrawerActive && // only when opening the drawer- this.component.name === "ChatDrawerRoutesChannels" // we should check if redirect to channels- ) {- this.#redirect();+ const redirectedRoute = this.drawerRoute.redirect?.(this);+ if (redirectedRoute) {+ this.stateFor(this.#routeFromURL(redirectedRoute));}+ }- this.currentRouteName = route.name;- this.drawerRoute.activate?.(route);+ #routeFromURL(url) {+ let route = this.router.recognize(url);++ // ember might recognize the index subroute+ if (route.localName === "index") {+ route = route.parent;+ }++ return route;}}