mirror of
https://github.com/discourse/discourse.git
synced 2025-02-14 18:22:44 +08:00
c8fff19b99
While very fast and powerful staged threads forces a lot of gymnastic and edge cases. This patch adds a new service `Chat::CreateThread` and uses it to create a thread unconditionally when a user replies to a message in a threading enabled channel. If the user actually doesn’t send a message we will have a thread with no messages which has no important impact and could even be periodically cleaned if necessary. Note that this commit also moves message actions to .gjs as it was the original goal of this PR to correctly check for staged thread to show the menu or not.
59 lines
1.6 KiB
JavaScript
59 lines
1.6 KiB
JavaScript
import DiscourseRoute from "discourse/routes/discourse";
|
|
import { inject as service } from "@ember/service";
|
|
import { action } from "@ember/object";
|
|
|
|
export default class ChatChannelThread extends DiscourseRoute {
|
|
@service router;
|
|
@service chatStateManager;
|
|
@service chat;
|
|
@service chatThreadPane;
|
|
|
|
model(params, transition) {
|
|
const channel = this.modelFor("chat.channel");
|
|
return channel.threadsManager
|
|
.find(channel.id, params.threadId)
|
|
.catch(() => {
|
|
transition.abort();
|
|
this.chatStateManager.closeSidePanel();
|
|
this.router.transitionTo("chat.channel", ...channel.routeModels);
|
|
return;
|
|
});
|
|
}
|
|
|
|
afterModel(model) {
|
|
this.chat.activeChannel.activeThread = model;
|
|
}
|
|
|
|
@action
|
|
willTransition(transition) {
|
|
if (
|
|
transition.targetName === "chat.channel.index" ||
|
|
transition.targetName === "chat.channel.near-message" ||
|
|
transition.targetName === "chat.index" ||
|
|
!transition.targetName.startsWith("chat")
|
|
) {
|
|
this.chatStateManager.closeSidePanel();
|
|
}
|
|
}
|
|
|
|
beforeModel(transition) {
|
|
const channel = this.modelFor("chat.channel");
|
|
|
|
if (!channel.threadingEnabled) {
|
|
transition.abort();
|
|
this.router.transitionTo("chat.channel", ...channel.routeModels);
|
|
return;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
this.chatStateManager.openSidePanel();
|
|
}
|
|
}
|