Skip to content

A platform for community discussion. Free, open, simple.

FIX: Use optionalRequire for chat imports in calendar livestream code (#40670)

Martin Brennan3acd366269f7
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/livestream/embeddable-chat-channel.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/livestream/embeddable-chat-channel.gjs
index 5d3e5dd3e7d..8c724e3b420 100644
--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/livestream/embeddable-chat-channel.gjs
+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/livestream/embeddable-chat-channel.gjs
@@ -4,9 +4,10 @@ import { array } from "@ember/helper";
import { service } from "@ember/service";
import { modifier } from "ember-modifier";
import { bind } from "discourse/lib/decorators";
+import { optionalRequire } from "discourse/lib/utilities";
+import { and } from "discourse/truth-helpers";
import DButton from "discourse/ui-kit/d-button";
import dConcatClass from "discourse/ui-kit/helpers/d-concat-class";
-import ChatChannel from "discourse/plugins/chat/discourse/components/chat-channel";
export default class EmbedableChatChannel extends Component {
@service chatChannelsManager;
@@ -16,6 +17,13 @@ export default class EmbedableChatChannel extends Component {
@tracked activeChannel;
+ // Resolved at runtime rather than statically imported: cross-plugin static
+ // imports aren't resolvable in the compiled plugin bundle and break the whole
+ // bundle load.
+ chatChannelComponent = optionalRequire(
+ "discourse/plugins/chat/discourse/components/chat-channel"
+ );
+
updateChannel = modifier(async () => {
if (this.args.chatChannelId === this.activeChannel?.id) {
return;
@@ -72,9 +80,9 @@ export default class EmbedableChatChannel extends Component {
</div>
{{/unless}}
<div class="chat-drawer">
- {{#if this.activeChannel}}
+ {{#if (and this.activeChannel this.chatChannelComponent)}}
{{#each (array this.activeChannel) as |channel|}}
- <ChatChannel @channel={{channel}} />
+ <this.chatChannelComponent @channel={{channel}} />
{{/each}}
{{/if}}
</div>
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/services/embeddable-chat.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/services/embeddable-chat.gjs
index 90c8b3136e2..ef1d7e7bfe3 100644
--- a/plugins/discourse-calendar/assets/javascripts/discourse/services/embeddable-chat.gjs
+++ b/plugins/discourse-calendar/assets/javascripts/discourse/services/embeddable-chat.gjs
@@ -1,18 +1,22 @@
import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
-import { service } from "@ember/service";
-import Chat from "discourse/plugins/chat/discourse/services/chat";
+import Service, { service } from "@ember/service";
export const LIVESTREAM_TAG_NAME = "livestream";
-export default class EmbeddableChat extends Chat {
+export default class EmbeddableChat extends Service {
@service siteSettings;
@service router;
@service currentUser;
@service capabilities;
+ @service chat;
@tracked isMobileChatVisible = false;
+ get userCanChat() {
+ return this.chat.userCanChat;
+ }
+
canRenderChatChannel(topicController, mobileViewAllowed = false) {
this.topicController = topicController;
if (