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-channel.js
Roman Rizzi d07b472b79
DEV: /channel -> /c chat route rename (#19782)
* 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>
2023-01-27 09:58:12 -03:00

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;
}
}