Ciao ![]()
Abbiamo riscontrato un piccolo bug nella funzione di chat del plugin discourse-calendar, in cui il link
al canale di chat è improvvisamente scomparso dal widget dell’evento nel post.
È molto probabile che si sia rotto a causa del recente cambiamento nel core di Discourse che ha spostato il sistema di build su Rollup:
- af3385baba — Introduzione del compilatore Rollup (disabilitato di default)
- 74d532c559 — Abilitazione del compilatore Rollup come default
Posso risolverlo e fornire una PR a riguardo
.
Comportamento atteso
Quando si aggiunge un evento a un argomento e si abilita l’Integrazione Chat (“Crea e gestisci un canale di chat specifico per l’evento”), il widget dell’evento nel post dovrebbe includere un’icona
con un link al canale di chat associato all’evento:
Comportamento attuale
Al momento, sulla versione corrente di main, questa sezione del widget dell’evento nel post non viene affatto visualizzata:
Correzione/Soluzione
Il problema sembra essere che l’helper lazy optionalRequire non funziona più come inizialmente previsto con Rollup. Dal mio punto di vista, Rollup chiama optionalRequire troppo presto, quando altri moduli non sono ancora registrati, quindi restituisce sempre false.
Ciò che risolve il problema è spostare le chiamate a optionalRequire nel costruttore del componente, in modo che vengano effettivamente valutate in modo lazy.
Per il file del modello, ad esempio, apparirebbe così:
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/models/discourse-post-event-event.js b/plugins/discourse-calendar/assets/javascripts/discourse/models/discourse-post-event-event.js
index 742cc35a84..f687b956aa 100644
--- a/plugins/discourse-calendar/assets/javascripts/discourse/models/discourse-post-event-event.js
+++ b/plugins/discourse-calendar/assets/javascripts/discourse/models/discourse-post-event-event.js
@@ -7,10 +7,6 @@ import User from "discourse/models/user";
import DiscoursePostEventEventStats from "./discourse-post-event-event-stats";
import DiscoursePostEventInvitee from "./discourse-post-event-invitee";
-const ChatChannel = optionalRequire(
- "discourse/plugins/chat/discourse/models/chat-channel"
-);
-
const DEFAULT_REMINDER = {
type: "notification",
value: 15,
@@ -62,6 +58,8 @@ export default class DiscoursePostEventEvent {
@tracked _reminders;
constructor(args = {}) {
+ const ChatChannel = optionalRequire( "discourse/plugins/chat/discourse/models/chat-channel");
+
this.id = args.id;
this.rrule = args.rrule;
this.name = args.name;
E rispettivamente per il componente che renderizza il link effettivo:
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/chat-channel.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/chat-channel.gjs
index f673ee8a9f..a988b341e6 100644
--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/chat-channel.gjs
+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/chat-channel.gjs
@@ -1,24 +1,27 @@
+import Component from "@glimmer/component";
import { LinkTo } from "@ember/routing";
import { optionalRequire } from "discourse/lib/utilities";
import { and } from "discourse/truth-helpers";
-const ChannelTitle = optionalRequire(
- "discourse/plugins/chat/discourse/components/channel-title"
-);
+export default class DiscoursePostEventChatChannel extends Component {
+ get channelTitle() {
+ return optionalRequire(
+ "discourse/plugins/chat/discourse/components/channel-title"
+ );
+ }
-const DiscoursePostEventChatChannel = <template>
- {{#if (and @event.channel ChannelTitle)}}
- <section class="event__section event-chat-channel">
- <span></span>
- <LinkTo
- @route="chat.channel"
- @models={{@event.channel.routeModels}}
- class="chat-channel-link"
- >
- <ChannelTitle @channel={{@event.channel}} />
- </LinkTo>
- </section>
- {{/if}}
-</template>;
-
-export default DiscoursePostEventChatChannel;
+ <template>
+ {{#if (and @event.channel this.channelTitle)}}
+ <section class="event__section event-chat-channel">
+ <span></span>
+ <LinkTo
+ @route="chat.channel"
+ @models={{@event.channel.routeModels}}
+ class="chat-channel-link"
+ >
+ <this.channelTitle @channel={{@event.channel}} />
+ </LinkTo>
+ </section>
+ {{/if}}
+ </template>
+}
(Nota: devo convertirlo in un componente di classe, ecco perché il diff è più ampio)
Fornirò una PR con la mia correzione su GitHub, in modo che le persone possano provarla e esprimere le proprie opinioni al riguardo.

