A platform for community discussion. Free, open, simple.
DEV: Use optionalRequire to import chat in d-ai (#37990)
Jarek Radosz1bda9a7b449d
diff --git a/plugins/discourse-ai/assets/javascripts/discourse/components/reviewable-ai-chat-message.gjs b/plugins/discourse-ai/assets/javascripts/discourse/components/reviewable-ai-chat-message.gjsindex cdef8c29fb4..f2e4a38fa7d 100644--- a/plugins/discourse-ai/assets/javascripts/discourse/components/reviewable-ai-chat-message.gjs+++ b/plugins/discourse-ai/assets/javascripts/discourse/components/reviewable-ai-chat-message.gjs@@ -4,9 +4,8 @@ import { LinkTo } from "@ember/routing";import { htmlSafe } from "@ember/template";import ReviewableCreatedBy from "discourse/components/reviewable-created-by";import ReviewablePostHeader from "discourse/components/reviewable-post-header";+import { optionalRequire } from "discourse/lib/utilities";import { or } from "discourse/truth-helpers";-import ChatChannelTitle from "discourse/plugins/chat/discourse/components/chat-channel-title";-import ChatChannel from "discourse/plugins/chat/discourse/models/chat-channel";import ModelAccuracies from "./model-accuracies";export default class ReviewableAiChatMessage extends Component {@@ -14,9 +13,20 @@ export default class ReviewableAiChatMessage extends Component {if (!this.args.reviewable.chat_channel) {return;}++ const ChatChannel = optionalRequire(+ "discourse/plugins/chat/discourse/models/chat-channel"+ );+return ChatChannel.create(this.args.reviewable.chat_channel);}+ get ChatChannelTitle() {+ return optionalRequire(+ "discourse/plugins/chat/discourse/components/chat-channel-title"+ );+ }+<template>{{#if this.chatChannel}}<div class="flagged-post-header">@@ -28,7 +38,7 @@ export default class ReviewableAiChatMessage extends Component {@reviewable.target_id}}>- <ChatChannelTitle @channel={{this.chatChannel}} />+ <this.ChatChannelTitle @channel={{this.chatChannel}} /></LinkTo></div>{{/if}}diff --git a/plugins/discourse-ai/assets/javascripts/discourse/components/reviewable/ai-chat-message.gjs b/plugins/discourse-ai/assets/javascripts/discourse/components/reviewable/ai-chat-message.gjsindex 8ce1a37a744..35c9bb29d5d 100644--- a/plugins/discourse-ai/assets/javascripts/discourse/components/reviewable/ai-chat-message.gjs+++ b/plugins/discourse-ai/assets/javascripts/discourse/components/reviewable/ai-chat-message.gjs@@ -5,9 +5,8 @@ import { LinkTo } from "@ember/routing";import ReviewableCreatedBy from "discourse/components/reviewable/created-by";import ReviewableTopicLink from "discourse/components/reviewable/topic-link";import highlightWatchedWords from "discourse/lib/highlight-watched-words";+import { optionalRequire } from "discourse/lib/utilities";import { i18n } from "discourse-i18n";-import ChannelTitle from "discourse/plugins/chat/discourse/components/channel-title";-import ChatChannel from "discourse/plugins/chat/discourse/models/chat-channel";import ModelAccuracies from "../model-accuracies";export default class ReviewableRefreshAiChatMessage extends Component {@@ -16,6 +15,11 @@ export default class ReviewableRefreshAiChatMessage extends Component {if (!this.args.reviewable.chat_channel) {return;}++ const ChatChannel = optionalRequire(+ "discourse/plugins/chat/discourse/models/chat-channel"+ );+return ChatChannel.create(this.args.reviewable.chat_channel);}@@ -26,6 +30,12 @@ export default class ReviewableRefreshAiChatMessage extends Component {);}+ get ChannelTitle() {+ return optionalRequire(+ "discourse/plugins/chat/discourse/components/channel-title"+ );+ }+<template><div class="review-item__meta-content"><div class="review-item__meta-label">{{i18n@@ -42,7 +52,7 @@ export default class ReviewableRefreshAiChatMessage extends Component {@reviewable.target_id}}>- <ChannelTitle @channel={{this.channel}} />+ <this.ChannelTitle @channel={{this.channel}} /></LinkTo>{{else}}<ReviewableTopicLink @reviewable={{@reviewable}} />