* DEV: Rnemae channel path to just c Also swap the channel id and channel slug params to be consistent with core. * linting * channel_path * params in wrong order * Drop slugify helper and channel route without slug * Request slug and route models through the channel model if possible * Add client side redirection for backwards-compatibility Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
import DiscourseRoute from "discourse/routes/discourse";
|
|
import { inject as service } from "@ember/service";
|
|
import { action } from "@ember/object";
|
|
import { schedule } from "@ember/runloop";
|
|
|
|
export default class ChatChannelRoute extends DiscourseRoute {
|
|
@service chat;
|
|
@service router;
|
|
@service chatChannelsManager;
|
|
|
|
async model(params) {
|
|
return this.chatChannelsManager.find(params.channelId);
|
|
}
|
|
|
|
afterModel(model) {
|
|
this.chat.setActiveChannel(model);
|
|
|
|
const { channelTitle, messageId } = this.paramsFor(this.routeName);
|
|
if (channelTitle !== model.slugifiedTitle) {
|
|
this.router.replaceWith("chat.channel.index", ...model.routeModels, {
|
|
queryParams: { messageId },
|
|
});
|
|
}
|
|
}
|
|
|
|
@action
|
|
didTransition() {
|
|
const { channelId, messageId } = this.paramsFor(this.routeName);
|
|
if (channelId && messageId) {
|
|
schedule("afterRender", () => {
|
|
this.chat.openChannelAtMessage(channelId, messageId);
|
|
this.controller.set("messageId", null); // clear the query param
|
|
});
|
|
}
|
|
return true;
|
|
}
|
|
}
|