Files
discourse/plugins/chat/assets/javascripts/discourse/routes/chat-channel-thread.js
Joffrey JAFFEUX a52a8f4663 FIX: correctly closes panels in threads (#31013)
The following case was bugged:

- visit a thread in full page chat
- click channel title
- click back button in channel navbar
- 💥 you would have a channel with limited width as if there was
still the thread showing next to it, but it was empty
2025-01-27 16:34:56 +01:00

58 lines
1.4 KiB
JavaScript

import { action } from "@ember/object";
import { service } from "@ember/service";
import DiscourseRoute from "discourse/routes/discourse";
export default class ChatChannelThread extends DiscourseRoute {
@service router;
@service chatStateManager;
@service chat;
redirectToChannel(channel, transition) {
transition.abort();
this.chatStateManager.closeSidePanel();
this.router.transitionTo("chat.channel", ...channel.routeModels);
}
model(params, transition) {
const channel = this.modelFor("chat.channel");
return channel.threadsManager
.find(channel.id, params.threadId)
.catch(() => {
this.redirectToChannel(channel, transition);
return;
});
}
afterModel(thread, transition) {
const channel = this.modelFor("chat.channel");
if (!channel.threadingEnabled && !thread.force) {
this.redirectToChannel(channel, transition);
return;
}
channel.activeThread = thread;
}
@action
activate() {
this.chat.activeMessage = null;
this.chatStateManager.openSidePanel();
}
@action
deactivate() {
this.chatStateManager.closeSidePanel();
}
beforeModel() {
const { messageId } = this.paramsFor(this.routeName + ".near-message");
if (
!messageId &&
this.controllerFor("chat-channel-thread").get("targetMessageId")
) {
this.controllerFor("chat-channel-thread").set("targetMessageId", null);
}
}
}