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.js
Joffrey JAFFEUX 7fca07821b
FIX: simplfies previous route handling (#18895)
This commits makes sure we correctly wait for the end of the transition to reopen the drawer on the correct channel/view. Also fixes a bug when previous URL was `/` and causing a double transition.
2022-11-07 14:48:18 +01:00

44 lines
1.1 KiB
JavaScript

import DiscourseRoute from "discourse/routes/discourse";
import I18n from "I18n";
import { defaultHomepage } from "discourse/lib/utilities";
import { inject as service } from "@ember/service";
import { scrollTop } from "discourse/mixins/scroll-top";
import { schedule } from "@ember/runloop";
export default class ChatRoute extends DiscourseRoute {
@service chat;
@service router;
@service fullPageChat;
titleToken() {
return I18n.t("chat.title_capitalized");
}
beforeModel() {
if (!this.chat.userCanChat) {
return this.transitionTo(`discovery.${defaultHomepage()}`);
}
this.fullPageChat.enter(this.router.currentURL);
}
activate() {
this.chat.updatePresence();
schedule("afterRender", () => {
document.body.classList.add("has-full-page-chat");
document.documentElement.classList.add("has-full-page-chat");
});
}
deactivate() {
this.fullPageChat.exit();
this.chat.setActiveChannel(null);
schedule("afterRender", () => {
document.body.classList.remove("has-full-page-chat");
document.documentElement.classList.remove("has-full-page-chat");
scrollTop();
});
}
}