Files
discourse/plugins/chat/assets/javascripts/discourse/routes/chat-index.js
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

32 lines
825 B
JavaScript

import DiscourseRoute from "discourse/routes/discourse";
import { inject as service } from "@ember/service";
export default class ChatIndexRoute extends DiscourseRoute {
@service chat;
@service chatChannelsManager;
@service router;
redirect() {
// Always want the channel index on mobile.
if (this.site.mobileView) {
return;
}
// We are on desktop. Check for a channel to enter and transition if so
const id = this.chat.getIdealFirstChannelId();
if (id) {
return this.chatChannelsManager.find(id).then((c) => {
return this.router.transitionTo("chat.channel", ...c.routeModels);
});
} else {
return this.router.transitionTo("chat.browse");
}
}
model() {
if (this.site.mobileView) {
return this.chatChannelsManager.channels;
}
}
}