Joffrey JAFFEUX f12724b5a5
DEV: routable chat part 2 (#20232)
This commit is expanding on previous work making everything chat working through an URL.

Improves drawer templates to be all URLs
Implements some kind of router for the drawer
Removes few remaining actions for opening channels
2023-02-14 11:27:07 +01:00

42 lines
1.3 KiB
JavaScript

import Service, { inject as service } from "@ember/service";
import { tracked } from "@glimmer/tracking";
import ChatDrawerDraftChannel from "discourse/plugins/chat/discourse/components/chat-drawer/draft-channel";
import ChatDrawerChannel from "discourse/plugins/chat/discourse/components/chat-drawer/channel";
import ChatDrawerIndex from "discourse/plugins/chat/discourse/components/chat-drawer/index";
const COMPONENTS_MAP = {
"chat.draft-channel": { name: ChatDrawerDraftChannel },
"chat.channel": { name: ChatDrawerChannel },
chat: { name: ChatDrawerIndex },
"chat.channel.near-message": {
name: ChatDrawerChannel,
extractParams: (route) => {
return {
channelId: route.parent.params.channelId,
messageId: route.params.messageId,
};
},
},
"chat.channel-legacy": {
name: ChatDrawerChannel,
extractParams: (route) => {
return {
channelId: route.params.channelId,
messageId: route.queryParams.messageId,
};
},
},
};
export default class ChatDrawerRouter extends Service {
@service router;
@tracked component = null;
@tracked params = null;
stateFor(route) {
const component = COMPONENTS_MAP[route.name];
this.params = component?.extractParams?.(route) || route.params;
this.component = component?.name || ChatDrawerIndex;
}
}