This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/plugins/chat/assets/javascripts/discourse/routes/chat-index.js
Joffrey JAFFEUX 21570410ab
FIX: makes sidebar links respect drawer mode (#18918)
Clicking a link of the sidebar will now open the drawer and load the correct channel.

This solution should correctly solve these cases:

closing drawer, clicking sidebar channel, should open the drawer on correct channel
visiting /chat then visiting / and clicking sidebar channel, should open full page chat on correct channel
2022-11-08 16:23:13 +01:00

39 lines
1.0 KiB
JavaScript

import DiscourseRoute from "discourse/routes/discourse";
import { inject as service } from "@ember/service";
export default class ChatIndexRoute extends DiscourseRoute {
@service chat;
@service router;
redirect() {
if (this.site.mobileView) {
return; // Always want the channel index on mobile.
}
// We are on desktop. Check for a channel to enter and transition if so.
// Otherwise, `setupController` will fetch all available
return this.chat.getIdealFirstChannelIdAndTitle().then((channelInfo) => {
if (channelInfo) {
return this.chat.getChannelBy("id", channelInfo.id).then((c) => {
return this.chat.openChannel(c);
});
} else {
return this.router.transitionTo("chat.browse");
}
});
}
model() {
if (this.site.mobileView) {
return this.chat.getChannels().then((channels) => {
if (
channels.publicChannels.length ||
channels.directMessageChannels.length
) {
return channels;
}
});
}
}
}