A platform for community discussion. Free, open, simple.
FEATURE: livestreams as a persistent event option (#41096)
Kris9cd9ba64db8f
diff --git a/db/structure.sql b/db/structure.sqlindex bb7612cd72b..0bd5a0ed42b 100644--- a/db/structure.sql+++ b/db/structure.sql@@ -3924,7 +3924,8 @@ CREATE TABLE public.discourse_post_event_events (description character varying(1000),max_attendees integer,all_day boolean DEFAULT false NOT NULL,- image_upload_id bigint+ image_upload_id bigint,+ livestream boolean DEFAULT false NOT NULL);@@ -22202,7 +22203,10 @@ INSERT INTO "schema_migrations" (version) VALUES('20260626055145'),('20260624140945'),('20260623090824'),+('20260622201006'),+('20260622201005'),('20260622140747'),+('20260617180115'),('20260617053237'),('20260615084100'),('20260615082047'),diff --git a/plugins/discourse-calendar/app/models/discourse_post_event/event.rb b/plugins/discourse-calendar/app/models/discourse_post_event/event.rbindex 3726f666cb7..fdb31fc412a 100644--- a/plugins/discourse-calendar/app/models/discourse_post_event/event.rb+++ b/plugins/discourse-calendar/app/models/discourse_post_event/event.rb@@ -22,9 +22,12 @@ module DiscoursePostEventscope :visible, -> { where(deleted_at: nil) }scope :open, -> { where(closed: false) }+ before_validation :reset_invalid_livestreambefore_save :chat_channel_sync# prepend so it runs before `dependent: :delete_all` wipes the inviteesbefore_destroy :reset_invitees_topic_tracking, prepend: true+ after_commit :create_livestream_chat_channel, on: %i[create update]+ after_commit :warm_livestream_onebox, on: %i[create update]after_commit :destroy_topic_custom_field, on: %i[destroy]after_commit :create_or_update_event_date, on: %i[create update]after_save do@@ -51,6 +54,32 @@ module DiscoursePostEventsuper - %w[id]end+ def reset_invalid_livestream+ return unless livestream?++ self.livestream = false unless livestream_location? && post&.is_first_post?+ end++ def livestream_location?+ location.to_s.match?(%r{\Ahttps?://}i)+ end++ def create_livestream_chat_channel+ return unless livestream? && SiteSetting.chat_enabled+ return unless post&.is_first_post?+ return if post.topic.blank?++ DiscourseCalendar::Livestream.handle_topic_chat_channel_creation(post.topic)+ end++ def warm_livestream_onebox+ return if !livestream? || location.blank?+ return if !saved_change_to_livestream? && !saved_change_to_location?+ return if Oneboxer.cached_onebox(location).present?++ Jobs.enqueue(:warm_livestream_onebox, event_id: id, url: location)+ end+def destroy_topic_custom_fieldif post && post.is_first_post?TopicCustomField.where(topic_id: post.topic_id, name: TOPIC_POST_EVENT_STARTS_AT).delete_all@@ -313,6 +342,27 @@ module DiscoursePostEventpruned_user_ids = pruned.pluck(:user_id)pruned.delete_allInvitee.reset_topic_tracking!(user_ids: pruned_user_ids, topic_id: post.topic_id)+ unfollow_livestream_chat(pruned_user_ids)+ end++ # Unfollow users from the livestream chat channel once they are no longer+ # attending (e.g. pruned when a private event's invited groups change). Chat+ # following tracks attendance, so removed attendees should not keep the+ # channel in their chat list.+ def unfollow_livestream_chat(user_ids)+ return if user_ids.blank?++ channel = post.topic.topic_chat_channel&.chat_channel+ return if channel.nil?++ manager = Chat::ChannelMembershipManager.new(channel)+ User+ .where(id: user_ids)+ .find_each do |user|+ membership = manager.unfollow(user)+ next if membership.nil?+ DiscourseCalendar::Livestream.publish_livestream_chat_status(membership, user:)+ endenddef can_user_update_attendance?(user)@@ -562,6 +612,7 @@ end# custom_fields :jsonb not null# deleted_at :datetime# description :string(1000)+# livestream :boolean default(FALSE), not null# location :string(1000)# max_attendees :integer# minimal :booleandiff --git a/plugins/discourse-calendar/app/serializers/discourse_post_event/event_serializer.rb b/plugins/discourse-calendar/app/serializers/discourse_post_event/event_serializer.rbindex ac6081e8c61..de2e8b0b0de 100644--- a/plugins/discourse-calendar/app/serializers/discourse_post_event/event_serializer.rb+++ b/plugins/discourse-calendar/app/serializers/discourse_post_event/event_serializer.rb@@ -29,6 +29,8 @@ module DiscoursePostEventattributes :locationattributes :watching_inviteeattributes :chat_enabled+ attributes :livestream+ attributes :livestream_oneboxattributes :channelattributes :rruleattributes :max_attendees@@ -36,6 +38,14 @@ module DiscoursePostEventhas_one :image_upload, embed: :object, serializer: UploadSerializer+ def include_livestream_onebox?+ object.livestream? && object.location.present?+ end++ def livestream_onebox+ Oneboxer.cached_onebox(object.location).presence+ end+def channel::Chat::ChannelSerializer.new(object.chat_channel,diff --git a/plugins/discourse-calendar/app/services/discourse_post_event/event/action/attributes_from_raw.rb b/plugins/discourse-calendar/app/services/discourse_post_event/event/action/attributes_from_raw.rbindex 2da91d7bcd7..c33fefb6cd4 100644--- a/plugins/discourse-calendar/app/services/discourse_post_event/event/action/attributes_from_raw.rb+++ b/plugins/discourse-calendar/app/services/discourse_post_event/event/action/attributes_from_raw.rb@@ -24,6 +24,7 @@ module DiscoursePostEventminimal: raw_event[:minimal],closed: raw_event[:closed] || false,chat_enabled: raw_event[:"chat-enabled"]&.downcase == "true",+ livestream: raw_event[:livestream]&.downcase == "true",max_attendees: raw_event[:"max-attendees"]&.to_i,all_day: all_day?,custom_fields: custom_fields,diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/compact-event-editor.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/compact-event-editor.gjsindex f7e08630342..69a43485faf 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/compact-event-editor.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/compact-event-editor.gjs@@ -16,6 +16,7 @@ import { i18n } from "discourse-i18n";import PostEventBuilder from "discourse/plugins/discourse-calendar/discourse/components/modal/post-event-builder";import {defaultEventState,+ isLivestreamUrl,reconcileDefaultReminder,} from "discourse/plugins/discourse-calendar/discourse/lib/raw-event-helper";import DiscoursePostEventEvent from "discourse/plugins/discourse-calendar/discourse/models/discourse-post-event-event";@@ -25,6 +26,7 @@ export default class CompactEventEditor extends Component {@service composer;@service currentUser;@service modal;+ @service siteSettings;@tracked name;@tracked location;@@ -40,6 +42,7 @@ export default class CompactEventEditor extends Component {@tracked recurrenceUntil;@tracked showLocalTime;@tracked chatEnabled;+ @tracked livestream;@tracked minimal;@tracked url;@tracked image;@@ -78,6 +81,7 @@ export default class CompactEventEditor extends Component {this.recurrenceUntil = s.recurrenceUntil;this.showLocalTime = s.showLocalTime;this.chatEnabled = s.chatEnabled;+ this.livestream = s.livestream;this.minimal = s.minimal;this.url = s.url;this.image = s.image;@@ -107,6 +111,7 @@ export default class CompactEventEditor extends Component {recurrenceUntil: this.recurrenceUntil,showLocalTime: this.showLocalTime,chatEnabled: this.chatEnabled,+ livestream: this.livestream,minimal: this.minimal,url: this.url,image: this.image,@@ -197,6 +202,10 @@ export default class CompactEventEditor extends Component {return this.args.urlTester?.(this.location) ?? false;}+ get isLivestreamUrl() {+ return this.hasLocation && isLivestreamUrl(this.location);+ }+get locationIcon() {return this.isLocationUrl ? "link" : "location-pin";}@@ -297,6 +306,22 @@ export default class CompactEventEditor extends Component {onLocationInput(event) {const value = event.target.value;this.location = value === "" ? null : value;+ if (!this.isLivestreamUrl) {+ this.livestream = false;+ }+ this.#emitChange();+ }++ get livestreamDisabled() {+ return !this.siteSettings.chat_enabled;+ }++ @action+ toggleLivestream() {+ if (this.livestreamDisabled) {+ return;+ }+ this.livestream = !this.livestream;this.#emitChange();}@@ -568,6 +593,7 @@ export default class CompactEventEditor extends Component {max_attendees: this.maxAttendees,show_local_time: this.showLocalTime,chat_enabled: this.chatEnabled,+ livestream: this.livestream,minimal: this.minimal,all_day: this.allDay,reminders: this.reminders,@@ -600,6 +626,7 @@ export default class CompactEventEditor extends Component {this.maxAttendees = updatedEvent.maxAttendees ?? null;this.showLocalTime = !!updatedEvent.showLocalTime;this.chatEnabled = !!updatedEvent.chatEnabled;+ this.livestream = !!updatedEvent.livestream;this.minimal = !!updatedEvent.minimal;this.allDay = !!updatedEvent.allDay;this.reminders = updatedEvent.reminders || [];@@ -785,6 +812,38 @@ export default class CompactEventEditor extends Component {</div></section>+ {{#if this.isLivestreamUrl}}+ <section class="composer-event__livestream">+ {{#if this.livestreamDisabled}}+ <DTooltip+ @placement="top-start"+ class="composer-event__livestream-toggle"+ >+ <:trigger>+ <DToggleSwitch+ class="composer-event__livestream-switch"+ @state={{this.livestream}}+ @label="discourse_post_event.composer.livestream"+ disabled+ />+ </:trigger>+ <:content>+ {{i18n "discourse_post_event.composer.livestream_chat_disabled"}}+ </:content>+ </DTooltip>+ {{else}}+ <div class="composer-event__livestream-toggle">+ <DToggleSwitch+ class="composer-event__livestream-switch"+ @state={{this.livestream}}+ @label="discourse_post_event.composer.livestream"+ {{on "click" this.toggleLivestream}}+ />+ </div>+ {{/if}}+ </section>+ {{/if}}+<section class="composer-event__attendees">{{dIcon "users"}}<inputdiff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/index.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/index.gjsindex c505ddd7cde..7ee49a22fdf 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/index.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/index.gjs@@ -4,6 +4,7 @@ import { service } from "@ember/service";import { modifier } from "ember-modifier";import moment from "moment";import PluginOutlet from "discourse/components/plugin-outlet";+import bodyClass from "discourse/helpers/body-class";import lazyHash from "discourse/helpers/lazy-hash";import routeAction from "discourse/helpers/route-action";import { popupAjaxError } from "discourse/lib/ajax-error";@@ -22,6 +23,7 @@ import Description from "./description";import EventStatus from "./event-status";import Image from "./image";import Invitees from "./invitees";+import Livestream from "./livestream";import Location from "./location";import MoreMenu from "./more-menu";import Status from "./status";@@ -308,7 +310,10 @@ export default class DiscoursePostEvent extends Component {{{this.recurrenceLabel}}</InfoSection>{{/if}}- <Location @location={{event.location}} />+ <Location+ @location={{event.location}}+ @livestream={{event.livestream}}+ /><Url @url={{event.url}} /><ChatChannel @event={{event}} /><Invitees @event={{event}} />@@ -323,6 +328,11 @@ export default class DiscoursePostEvent extends Component {{{#if this.showStatus}}<Status @event={{event}} />{{/if}}++ {{#if event.livestream}}+ {{bodyClass "livestream-topic"}}+ {{/if}}+ <Livestream @event={{event}} /></PluginOutlet>{{/if}}</div>diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/livestream.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/livestream.gjsnew file mode 100644index 00000000000..4ca6f9804e6--- /dev/null+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/livestream.gjs@@ -0,0 +1,69 @@+import Component from "@glimmer/component";+import { service } from "@ember/service";+import { trustHTML } from "@ember/template";+import { optionalRequire } from "discourse/lib/utilities";++// Renders the event's livestream as a playable video at the bottom of the event+// card, from the cooked onebox served on the event (EventSerializer#livestream_+// onebox). For supported providers we hand the resolved attributes to lazy-+// videos' LazyVideo component (the post-stream decorator that normally does this+// doesn't reach our card); otherwise we render the onebox as-is.+export default class Livestream extends Component {+ @service siteSettings;++ get show() {+ return (+ this.args.event?.livestream &&+ this.args.event?.location &&+ this.args.event?.livestreamOnebox+ );+ }++ // Resolved at runtime: lazy-videos may not be installed, and resolving at+ // module load can return false before the plugin's modules are registered.+ get lazyVideo() {+ return optionalRequire(+ "discourse/plugins/discourse-lazy-videos/discourse/components/lazy-video"+ );+ }++ get videoAttributes() {+ const html = this.args.event?.livestreamOnebox;+ const getVideoAttributes = optionalRequire(+ "discourse/plugins/discourse-lazy-videos/lib/lazy-video-attributes"+ );+ if (!html || !getVideoAttributes || !this.lazyVideo) {+ return null;+ }++ const container = new DOMParser()+ .parseFromString(html, "text/html")+ .querySelector(".lazy-video-container");+ if (!container) {+ return null;+ }++ const attributes = getVideoAttributes(container);+ return this.siteSettings[`lazy_${attributes.providerName}_enabled`]+ ? attributes+ : null;+ }++ get oneboxHtml() {+ return this.videoAttributes+ ? null+ : trustHTML(this.args.event?.livestreamOnebox ?? "");+ }++ <template>+ {{#if this.show}}+ <section class="event__section event-livestream">+ {{#if this.videoAttributes}}+ <this.lazyVideo @videoAttributes={{this.videoAttributes}} />+ {{else}}+ {{this.oneboxHtml}}+ {{/if}}+ </section>+ {{/if}}+ </template>+}diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/location.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/location.gjsindex ed355f45f99..256b5133c77 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/location.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/location.gjs@@ -1,14 +1,29 @@+import Component from "@glimmer/component";import DCookText from "discourse/ui-kit/d-cook-text";import dIcon from "discourse/ui-kit/helpers/d-icon";+import { isLivestreamUrl } from "discourse/plugins/discourse-calendar/discourse/lib/raw-event-helper";-const DiscoursePostEventLocation = <template>- {{#if @location}}- <section class="event__section event-location">- {{dIcon "location-pin"}}+// For livestream events the location is the stream URL: show it as a plain link+// (the playable video renders separately at the bottom of the card) rather than+// letting DCookText onebox it into a thumbnail here.+export default class DiscoursePostEventLocation extends Component {+ get showAsLink() {+ return this.args.livestream && isLivestreamUrl(this.args.location);+ }- <DCookText @rawText={{@location}} />- </section>- {{/if}}-</template>;+ <template>+ {{#if @location}}+ <section class="event__section event-location">+ {{dIcon "location-pin"}}-export default DiscoursePostEventLocation;+ {{#if this.showAsLink}}+ <a href={{@location}} target="_blank" rel="noopener noreferrer">+ {{@location}}+ </a>+ {{else}}+ <DCookText @rawText={{@location}} />+ {{/if}}+ </section>+ {{/if}}+ </template>+}diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/event-node-view.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/event-node-view.gjsindex 75ef3b3b11c..f46de890e84 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/event-node-view.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/event-node-view.gjs@@ -24,6 +24,7 @@ const CLEARABLE_ATTRS = ["showLocalTime","minimal","chatEnabled",+ "livestream","allDay","allowedGroups","reminders",diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/livestream/responsive-livestream-chat-icon.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/livestream/responsive-livestream-chat-icon.gjsindex f30321c82d3..1102409e82f 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/livestream/responsive-livestream-chat-icon.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/livestream/responsive-livestream-chat-icon.gjs@@ -5,12 +5,10 @@ import MobileLivestreamChatIcon from "./mobile-livestream-chat-icon";export default class ResponsiveLivestreamChatIcon extends Component {@service capabilities;- @service siteSettings;@controller("topic") topicController;get shouldShow() {return (- this.siteSettings.livestream_enabled &&!this.capabilities.viewport.lg &&this.topicController?.model?.chat_channel_id);diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/modal/post-event-builder.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/modal/post-event-builder.gjsindex 0e1ba372c40..39bbfdb79c0 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/modal/post-event-builder.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/modal/post-event-builder.gjs@@ -26,6 +26,7 @@ import {defaultEventState,defaultReminderFor,getCustomFieldNames,+ isLivestreamUrl,reconcileDefaultReminder,} from "../../lib/raw-event-helper";import CompactEventEditor from "../compact-event-editor";@@ -109,6 +110,7 @@ export default class PostEventBuilder extends Component {allDay: !!this.event.allDay,showLocalTime: !!this.event.showLocalTime,chatEnabled: !!this.event.chatEnabled,+ livestream: !!this.event.livestream,attendanceMode: this.attendanceMode,maxAttendees: this.event.maxAttendees ?? null,eventType:@@ -144,6 +146,17 @@ export default class PostEventBuilder extends Component {this.event[field] = value;}+ @action+ syncLocationToEvent(value, { set }) {+ set("location", value);+ this.event.location = value;++ if (!isLivestreamUrl(value)) {+ set("livestream", false);+ this.event.livestream = false;+ }+ }+@actionhandleAllDayChange(value, { set }) {set("allDay", value);@@ -310,8 +323,10 @@ export default class PostEventBuilder extends Component {];}- get shouldRenderUrl() {- return this.args.model.event.url !== undefined;+ get showLivestream() {+ return (+ isLivestreamUrl(this.event.location) && this.siteSettings.chat_enabled+ );}get availableRecurrences() {@@ -419,6 +434,7 @@ export default class PostEventBuilder extends Component {recurrenceUntil: this.event.recurrenceUntil ?? null,showLocalTime: !!this.event.showLocalTime,chatEnabled: !!this.event.chatEnabled,+ livestream: !!this.event.livestream,minimal: !!this.event.minimal,url: this.event.url ?? null,image:@@ -446,6 +462,7 @@ export default class PostEventBuilder extends Component {this.event.maxAttendees = state.maxAttendees;this.event.showLocalTime = state.showLocalTime;this.event.chatEnabled = state.chatEnabled;+ this.event.livestream = state.livestream;this.event.minimal = state.minimal;this.event.url = state.url;this.event.recurrence = state.recurrence;@@ -855,7 +872,7 @@ export default class PostEventBuilder extends Component {}}@type="input"@format="full"- @onSet={{fn this.syncFieldToEvent "location"}}+ @onSet={{this.syncLocationToEvent}}as |field|><field.Control@@ -865,22 +882,22 @@ export default class PostEventBuilder extends Component {/></form.Field>- {{#if this.shouldRenderUrl}}+ {{#if this.showLivestream}}<form.Field- @name="url"+ @name="livestream"@title={{i18n- "discourse_post_event.builder_modal.url.label"+ "discourse_post_event.builder_modal.livestream.label"}}- @type="input-url"+ @type="checkbox"@format="full"- @onSet={{fn this.syncFieldToEvent "url"}}+ @onSet={{fn this.syncFieldToEvent "livestream"}}as |field|>- <field.Control- placeholder={{i18n- "discourse_post_event.builder_modal.url.placeholder"+ <field.Control>+ {{i18n+ "discourse_post_event.builder_modal.livestream.checkbox_label"}}- />+ </field.Control></form.Field>{{/if}}diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/connectors/before-main-outlet/embeddable-chat-channel-connector.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/connectors/before-main-outlet/embeddable-chat-channel-connector.gjsindex 6f3cbc0b72f..fca2e82b0d1 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/connectors/before-main-outlet/embeddable-chat-channel-connector.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/connectors/before-main-outlet/embeddable-chat-channel-connector.gjs@@ -14,7 +14,7 @@ export default class EmbedableChatChannelConnector extends Component {!this.siteSettings.livestream_enable_modal_chat_on_mobile &&!this.capabilities.viewport.lg;- if (!this.siteSettings.livestream_enabled) {+ if (!this.siteSettings.chat_enabled) {return false;}diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/connectors/chat-join-channel-button/join-channel-message.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/connectors/chat-join-channel-button/join-channel-message.gjsindex 1f2b286b6ab..b33a58f1401 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/connectors/chat-join-channel-button/join-channel-message.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/connectors/chat-join-channel-button/join-channel-message.gjs@@ -1,19 +1,14 @@import Component from "@glimmer/component";-import { inject as controller } from "@ember/controller";import { service } from "@ember/service";import { i18n } from "discourse-i18n";export default class JoinChannelMessage extends Component {@service embeddableChat;- @service siteSettings;- @controller("topic") topicController;get shouldRenderJoinText() {- const topic = this.topicController?.model;return (- this.siteSettings.livestream_enabled &&- topic?.chat_channel_id &&- this.embeddableChat.topicHasLivestreamTag(topic)+ this.embeddableChat.topicHasLivestream &&+ this.embeddableChat.chatChannelId);}diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/initializers/livestream-chat-overrides.js b/plugins/discourse-calendar/assets/javascripts/discourse/initializers/livestream-chat-overrides.jsindex b5ec88f9e67..4341038b840 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/initializers/livestream-chat-overrides.js+++ b/plugins/discourse-calendar/assets/javascripts/discourse/initializers/livestream-chat-overrides.js@@ -29,12 +29,7 @@ function overrideChat(api, container) {const chatService = container.lookup("service:chat");const appEvents = container.lookup("service:appEvents");- if (- !siteSettings.livestream_enabled ||- !currentUser ||- !siteSettings.chat_enabled ||- !chatService.userCanChat- ) {+ if (!currentUser || !siteSettings.chat_enabled || !chatService?.userCanChat) {return;}diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/lib/discourse-markdown/livestream-preview.js b/plugins/discourse-calendar/assets/javascripts/discourse/lib/discourse-markdown/livestream-preview.jsindex bf6bba8d5c5..d2f70d89daa 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/lib/discourse-markdown/livestream-preview.js+++ b/plugins/discourse-calendar/assets/javascripts/discourse/lib/discourse-markdown/livestream-preview.js@@ -1,12 +1,9 @@function setupMarkdownIt(helper) {- helper.registerOptions((opts, siteSettings) => {- opts.features["livestream-preview"] = !!siteSettings.livestream_enabled;+ helper.registerOptions((opts) => {+ opts.features["livestream-preview"] = true;});helper.registerPlugin((md) => {- // Gated on livestream_enabled so that when it is disabled the standalone- // discourse-livestream plugin (if installed) owns these bbcode tags- // instead, avoiding duplicate registration.if (!md.options.discourse.features["livestream-preview"]) {return;}diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/lib/raw-event-helper.js b/plugins/discourse-calendar/assets/javascripts/discourse/lib/raw-event-helper.jsindex 16361c07783..6ae205c991d 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/lib/raw-event-helper.js+++ b/plugins/discourse-calendar/assets/javascripts/discourse/lib/raw-event-helper.js@@ -1,3 +1,8 @@+// must be an https link to livestream+export function isLivestreamUrl(location) {+ return /^https?:\/\//i.test(location ?? "");+}+export function defaultReminderFor({ startsAt, endsAt, allDay } = {}) {const start = startsAt ? moment(startsAt) : null;const end = endsAt ? moment(endsAt) : null;@@ -161,6 +166,10 @@ export function buildParams(startsAt, endsAt, event, siteSettings) {params.chatEnabled = "true";}+ if (event.livestream) {+ params.livestream = "true";+ }+if (event.maxAttendees) {params.maxAttendees = `${event.maxAttendees}`;}@@ -278,6 +287,7 @@ export function defaultEventState() {recurrenceUntil: null,showLocalTime: false,chatEnabled: false,+ livestream: false,minimal: false,url: null,image: null,@@ -315,6 +325,7 @@ export function parseEventAttrs(recurrenceUntil: attrs.recurrenceUntil || null,showLocalTime: attrs.showLocalTime === "true",chatEnabled: attrs.chatEnabled === "true",+ livestream: attrs.livestream === "true",minimal: attrs.minimal === "true",url: attrs.url || null,image: attrs.image || null,@@ -338,6 +349,7 @@ export function stateToEventInput(state) {showLocalTime: state.showLocalTime,minimal: state.minimal,chatEnabled: state.chatEnabled,+ livestream: state.livestream,maxAttendees: state.maxAttendees,rawInvitees: state.allowedGroups ? state.allowedGroups.split(",") : [],reminders: state.reminders,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.jsindex 90f64103a77..6b41e08ed43 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@@ -38,6 +38,8 @@ export default class DiscoursePostEventEvent {@tracked post;@tracked minimal;@tracked chatEnabled;+ @tracked livestream;+ @tracked livestreamOnebox;@tracked canUpdateAttendance;@tracked canActOnDiscoursePostEvent;@tracked shouldDisplayInvitees;@@ -87,6 +89,8 @@ export default class DiscoursePostEventEvent {this.isStandalone = args.is_standalone;this.minimal = args.minimal;this.chatEnabled = args.chat_enabled;+ this.livestream = args.livestream;+ this.livestreamOnebox = args.livestream_onebox;this.maxAttendees = args.max_attendees;this.atCapacity = args.at_capacity;this.recurrence = args.recurrence;@@ -179,6 +183,8 @@ export default class DiscoursePostEventEvent {this.isStandalone = event.isStandalone;this.minimal = event.minimal;this.chatEnabled = event.chatEnabled;+ this.livestream = event.livestream;+ this.livestreamOnebox = event.livestreamOnebox;this.rrule = event.rrule;this.maxAttendees = event.maxAttendees;this.atCapacity = event.atCapacity;diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/pre-initializers/rich-editor-extension.js b/plugins/discourse-calendar/assets/javascripts/discourse/pre-initializers/rich-editor-extension.jsindex afd8c57ecb0..a0c93ab10e4 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/pre-initializers/rich-editor-extension.js+++ b/plugins/discourse-calendar/assets/javascripts/discourse/pre-initializers/rich-editor-extension.js@@ -24,6 +24,7 @@ export const EVENT_ATTRIBUTES = {recurrence: { default: null },recurrenceUntil: { default: null },chatEnabled: { default: null },+ livestream: { default: null },allDay: { default: null },image: { default: null },};diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/services/embeddable-chat.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/services/embeddable-chat.gjsindex ef1d7e7bfe3..6ad35f0b731 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/services/embeddable-chat.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/services/embeddable-chat.gjs@@ -1,26 +1,24 @@import { tracked } from "@glimmer/tracking";import { action } from "@ember/object";import Service, { service } from "@ember/service";--export const LIVESTREAM_TAG_NAME = "livestream";+import optionalService from "discourse/lib/optional-service";export default class EmbeddableChat extends Service {@service siteSettings;@service router;@service currentUser;@service capabilities;- @service chat;+ @optionalService chat;@tracked isMobileChatVisible = false;get userCanChat() {- return this.chat.userCanChat;+ return this.chat?.userCanChat ?? false;}canRenderChatChannel(topicController, mobileViewAllowed = false) {this.topicController = topicController;if (- this.siteSettings.livestream_enabled &&this.isMobileViewport === mobileViewAllowed &&this.siteSettings.chat_enabled &&this.currentUser &&@@ -47,17 +45,6 @@ export default class EmbeddableChat extends Service {this.isMobileChatVisible = !this.isMobileChatVisible;}- topicHasLivestreamTag(topic) {- return (- // TODO(https://github.com/discourse/discourse/pull/36678): The string check can be- // removed using .discourse-compatibility once the PR is merged.- topic?.tags?.some?.((tag) => {- const tagName = typeof tag === "string" ? tag : tag.name;- return tagName === LIVESTREAM_TAG_NAME;- }) || false- );- }-get isMobileModal() {return (this.siteSettings.livestream_enable_modal_chat_on_mobile &&@@ -69,7 +56,15 @@ export default class EmbeddableChat extends Service {return !this.capabilities.viewport.lg;}+ get topic() {+ return this.topicController?.model;+ }+get chatChannelId() {- return this.topicController?.model?.chat_channel_id;+ return this.topic?.chat_channel_id;+ }++ get topicHasLivestream() {+ return this.topic?.has_livestream;}}diff --git a/plugins/discourse-calendar/assets/stylesheets/common/composer-event-node-view.scss b/plugins/discourse-calendar/assets/stylesheets/common/composer-event-node-view.scssindex 7d36559a81b..51937218eb5 100644--- a/plugins/discourse-calendar/assets/stylesheets/common/composer-event-node-view.scss+++ b/plugins/discourse-calendar/assets/stylesheets/common/composer-event-node-view.scss@@ -128,7 +128,8 @@.composer-event__dates,.composer-event__location,.composer-event__attendees,- .composer-event__reminder {+ .composer-event__reminder,+ .composer-event__livestream {position: relative;display: grid;grid-template-columns: 3em 1fr;@@ -202,6 +203,7 @@}}+ .composer-event__livestream-toggle,.composer-event__all-day-toggle {display: flex;margin-bottom: var(--space-1);@@ -212,6 +214,17 @@}}+ .composer-event__livestream-toggle {+ grid-column-start: 2;+ justify-self: start;+ }++ .d-toggle-switch:has(.composer-event__livestream-switch:disabled) {+ cursor: not-allowed;+ opacity: 0.5;+ pointer-events: none;+ }+.composer-event__date-row {display: flex;align-items: center;diff --git a/plugins/discourse-calendar/assets/stylesheets/common/livestream.scss b/plugins/discourse-calendar/assets/stylesheets/common/livestream.scssindex 24e8126897b..2166c6601db 100644--- a/plugins/discourse-calendar/assets/stylesheets/common/livestream.scss+++ b/plugins/discourse-calendar/assets/stylesheets/common/livestream.scss@@ -1,4 +1,4 @@-body.chat-enabled.tag-livestream.confirmed-event-assistance {+body.chat-enabled.livestream-topic.confirmed-event-assistance {#post_1 {.topic-avatar {display: none;@@ -23,7 +23,7 @@ body.chat-enabled.tag-livestream.confirmed-event-assistance {}}-body.chat-enabled.tag-livestream .chat-channel-preview-card {+body.chat-enabled.livestream-topic .chat-channel-preview-card {.chat-channel-preview-card__browse-all {display: none;}diff --git a/plugins/discourse-calendar/assets/stylesheets/desktop/livestream.scss b/plugins/discourse-calendar/assets/stylesheets/desktop/livestream.scssindex d38d91a9199..64431ab1d06 100644--- a/plugins/discourse-calendar/assets/stylesheets/desktop/livestream.scss+++ b/plugins/discourse-calendar/assets/stylesheets/desktop/livestream.scss@@ -1,4 +1,4 @@-.tag-livestream.chat-enabled.archetype-regular {+.livestream-topic.chat-enabled.archetype-regular {// we need to fullscreen the header icons to match the chat panel// being on the right side of the screen.d-header-wrap .wrap {diff --git a/plugins/discourse-calendar/assets/stylesheets/mobile/livestream.scss b/plugins/discourse-calendar/assets/stylesheets/mobile/livestream.scssindex 9a695817cf7..27b2c834eda 100644--- a/plugins/discourse-calendar/assets/stylesheets/mobile/livestream.scss+++ b/plugins/discourse-calendar/assets/stylesheets/mobile/livestream.scss@@ -1,4 +1,4 @@-body.tag-livestream.chat-enabled {+body.livestream-topic.chat-enabled {.d-header-icons {.livestream-header-icon {position: relative;@@ -163,6 +163,6 @@ body.tag-livestream.chat-enabled {}}-body:not(.tag-livestream) .d-header-icons .livestream-header-icon {+body:not(.livestream-topic) .d-header-icons .livestream-header-icon {display: none;}diff --git a/plugins/discourse-calendar/config/locales/client.en.yml b/plugins/discourse-calendar/config/locales/client.en.ymlindex 761c5d2257e..58ba6583ca2 100644--- a/plugins/discourse-calendar/config/locales/client.en.yml+++ b/plugins/discourse-calendar/config/locales/client.en.yml@@ -459,6 +459,8 @@ en:create_event_button: "Create event"action_title: "Create a new event"all_day: "All day"+ livestream: "Livestream"+ livestream_chat_disabled: "Enable chat to create livestream channels."reminder:units:minutes:@@ -555,11 +557,11 @@ en:allow_chat:label: "Chat integration"checkbox_label: "Create and manage event specific chat channel"- url:- label: "URL"- placeholder: "Optional"+ livestream:+ label: "Livestream"+ checkbox_label: "Embed the URL as a video and open livestream chat for attendees"location:- label: "Location"+ label: "Location or URL"placeholder: "Add a location, link or something."description:label: "Description"diff --git a/plugins/discourse-calendar/config/locales/server.en.yml b/plugins/discourse-calendar/config/locales/server.en.ymlindex e7b12b1f488..e1e45cc8d0c 100644--- a/plugins/discourse-calendar/config/locales/server.en.yml+++ b/plugins/discourse-calendar/config/locales/server.en.yml@@ -73,8 +73,6 @@ en:sidebar_show_upcoming_events: "Show upcoming events link in the sidebar under 'More'."calendar_first_day_of_week: "Set the first day of the week for calendar display. Options are Saturday, Sunday, or Monday."enable_events_category_type_setup: "Enables the Events category type option during category creation setup."- livestream_enabled: "Enable livestream chat for topics tagged 'livestream'."- livestream_chat_allowed_groups: "Only allowlisted groups can chat in the livestream channel."livestream_embeddable_chat_allowed_paths: "Allowed paths for the embeddable livestream chat."livestream_enable_modal_chat_on_mobile: "Show livestream chat in a modal on mobile."diff --git a/plugins/discourse-calendar/config/settings.yml b/plugins/discourse-calendar/config/settings.ymlindex a59018108b9..0f05a7bed7b 100644--- a/plugins/discourse-calendar/config/settings.yml+++ b/plugins/discourse-calendar/config/settings.yml@@ -140,9 +140,6 @@ discourse_calendar:status: "stable"impact: "feature,staff"learn_more_url: "https://meta.discourse.org/t/-/401309"- livestream_enabled:- default: false- client: truelivestream_embeddable_chat_allowed_paths:type: listdefault: "/t"@@ -150,8 +147,4 @@ discourse_calendar:hidden: truelivestream_enable_modal_chat_on_mobile:default: true- client: true- livestream_chat_allowed_groups:- default: "11" # default group trust_level_1- client: true- type: group_list\ No newline at end of file+ client: true\ No newline at end of filediff --git a/plugins/discourse-calendar/db/migrate/20260617180115_add_livestream_to_discourse_post_event.rb b/plugins/discourse-calendar/db/migrate/20260617180115_add_livestream_to_discourse_post_event.rbnew file mode 100644index 00000000000..e8232a4ebfd--- /dev/null+++ b/plugins/discourse-calendar/db/migrate/20260617180115_add_livestream_to_discourse_post_event.rb@@ -0,0 +1,7 @@+# frozen_string_literal: true++class AddLivestreamToDiscoursePostEvent < ActiveRecord::Migration[8.0]+ def change+ add_column :discourse_post_event_events, :livestream, :boolean, null: false, default: false+ end+enddiff --git a/plugins/discourse-calendar/db/post_migrate/20260622201005_backfill_livestream_from_tag.rb b/plugins/discourse-calendar/db/post_migrate/20260622201005_backfill_livestream_from_tag.rbnew file mode 100644index 00000000000..f5d6f81989f--- /dev/null+++ b/plugins/discourse-calendar/db/post_migrate/20260622201005_backfill_livestream_from_tag.rb@@ -0,0 +1,37 @@+# frozen_string_literal: true++class BackfillLivestreamFromTag < ActiveRecord::Migration[8.0]+ # Before livestreams became a boolean on the event+ # (`discourse_post_event_events.livestream`), a topic behaved as a livestream+ # when `livestream_enabled` was on and the topic was tagged "livestream".+ # Backfill the new column for those existing topics so they keep livestreaming after upgrade.+ # Livestream is now read from the topic's first-post event (topic.first_post.event.livestream?)+ # so only first-post events are updated.+ #+ # This must run BEFORE 20260622201006_cleanup_removed_livestream_site_settings, which deletes+ # the `livestream_enabled` row we read below. The timestamp is intentionally one tick earlier+ # so the ordering holds within the post-deploy phase.+ def up+ livestream_enabled =+ DB.query_single(+ "SELECT value FROM site_settings WHERE name = 'livestream_enabled' AND value = 't'",+ )+ return if livestream_enabled.blank?++ execute <<~SQL+ UPDATE discourse_post_event_events e+ SET livestream = true+ FROM posts p+ JOIN topic_tags tt ON tt.topic_id = p.topic_id+ JOIN tags t ON t.id = tt.tag_id+ WHERE e.id = p.id+ AND p.post_number = 1+ AND e.livestream = false+ AND t.name = 'livestream'+ SQL+ end++ def down+ raise ActiveRecord::IrreversibleMigration+ end+enddiff --git a/plugins/discourse-calendar/db/post_migrate/20260622201006_cleanup_removed_livestream_site_settings.rb b/plugins/discourse-calendar/db/post_migrate/20260622201006_cleanup_removed_livestream_site_settings.rbnew file mode 100644index 00000000000..cefb7fc2896--- /dev/null+++ b/plugins/discourse-calendar/db/post_migrate/20260622201006_cleanup_removed_livestream_site_settings.rb@@ -0,0 +1,14 @@+# frozen_string_literal: true++class CleanupRemovedLivestreamSiteSettings < ActiveRecord::Migration[8.0]+ def up+ execute <<~SQL+ DELETE FROM site_settings+ WHERE name IN ('livestream_enabled', 'livestream_chat_allowed_groups')+ SQL+ end++ def down+ raise ActiveRecord::IrreversibleMigration+ end+enddiff --git a/plugins/discourse-calendar/jobs/regular/discourse_post_event/warm_livestream_onebox.rb b/plugins/discourse-calendar/jobs/regular/discourse_post_event/warm_livestream_onebox.rbnew file mode 100644index 00000000000..37d71dfa8bd--- /dev/null+++ b/plugins/discourse-calendar/jobs/regular/discourse_post_event/warm_livestream_onebox.rb@@ -0,0 +1,19 @@+# frozen_string_literal: true++module Jobs+ # Warms the cached onebox for a livestream event's URL so the event card can+ # render the embedded (lazy) video from EventSerializer#livestream_onebox.+ class WarmLivestreamOnebox < ::Jobs::Base+ def execute(args)+ url = args[:url]+ return if url.blank?++ Oneboxer.onebox(url)++ event = DiscoursePostEvent::Event.find_by(id: args[:event_id])+ return if event.blank? || !event.livestream? || event.location != url++ event.post&.publish_change_to_clients!(:revised)+ end+ end+enddiff --git a/plugins/discourse-calendar/jobs/regular/livestream/recalculate_user_channel_memberships.rb b/plugins/discourse-calendar/jobs/regular/livestream/recalculate_user_channel_memberships.rbdeleted file mode 100644index 26768fbb0ed..00000000000--- a/plugins/discourse-calendar/jobs/regular/livestream/recalculate_user_channel_memberships.rb+++ /dev/null@@ -1,50 +0,0 @@-# frozen_string_literal: true--module Jobs- class LivestreamRecalculateUserChannelMemberships < ::Jobs::Base- def execute- if !SiteSetting.calendar_enabled || !SiteSetting.discourse_post_event_enabled ||- !SiteSetting.livestream_enabled- return- end-- going = DiscoursePostEvent::Invitee.statuses[:going]- query = <<~SQL- WITH attending_users AS (- SELECT u.*- FROM discourse_post_event_invitees dpei- JOIN users u ON dpei.user_id = u.id- WHERE dpei.status = :going- )- SELECT uccm.*- FROM livestream_topic_chat_channels ltcc- JOIN chat_channels cc ON cc.id = ltcc.chat_channel_id- JOIN user_chat_channel_memberships uccm ON cc.id = uccm.chat_channel_id- JOIN attending_users au ON au.id = uccm.user_id- SQL- memberships = ::Chat::UserChatChannelMembership.find_by_sql([query, { going: going }])-- memberships.each do |membership|- user = membership.user- ActiveRecord::Base.transaction do- is_user_allowed_in_livestream_chat = user_allowed_in_livestream_chat?(user)- if membership.following != is_user_allowed_in_livestream_chat- membership.update!(following: is_user_allowed_in_livestream_chat)- ::Chat::ChannelMembershipManager.new(membership.chat_channel).recalculate_user_count- end- end-- ::DiscourseCalendar::Livestream.publish_livestream_chat_status(- membership.reload,- user: user,- )- end- end-- private-- def user_allowed_in_livestream_chat?(user)- user.in_any_groups?(SiteSetting.livestream_chat_allowed_groups_map)- end- end-enddiff --git a/plugins/discourse-calendar/lib/discourse_post_event/event_parser.rb b/plugins/discourse-calendar/lib/discourse_post_event/event_parser.rbindex 4d6786e216d..83879c93469 100644--- a/plugins/discourse-calendar/lib/discourse_post_event/event_parser.rb+++ b/plugins/discourse-calendar/lib/discourse_post_event/event_parser.rb@@ -18,6 +18,7 @@ module DiscoursePostEvent:minimal,:closed,:"chat-enabled",+ :livestream,:"max-attendees",:"all-day",:image,diff --git a/plugins/discourse-calendar/plugin.rb b/plugins/discourse-calendar/plugin.rbindex 07e9ad48931..6454306d49c 100644--- a/plugins/discourse-calendar/plugin.rb+++ b/plugins/discourse-calendar/plugin.rb@@ -69,7 +69,7 @@ module ::DiscourseCalendardef self.handle_topic_chat_channel_creation(topic)return if topic.category.blank?return if DiscourseCalendar::Livestream::TopicChatChannel.exists?(topic_id: topic.id)- return if topic.tags.blank? || topic.tags.none? { |tag| tag.name == "livestream" }+ return unless topic.first_post&.event&.livestream?channel =Chat::Channel.create!(@@ -174,7 +174,7 @@ after_initialize dorequire_relative "jobs/regular/discourse_post_event/bulk_invite"require_relative "jobs/regular/discourse_post_event/bump_topic"require_relative "jobs/regular/discourse_post_event/send_reminder"- require_relative "jobs/regular/livestream/recalculate_user_channel_memberships"+ require_relative "jobs/regular/discourse_post_event/warm_livestream_onebox"require_relative "lib/discourse_post_event/engine"require_relative "lib/discourse_post_event/event_finder"require_relative "lib/discourse_post_event/event_parser"@@ -855,32 +855,19 @@ after_initialize doadd_to_serializer(:topic_view,:chat_channel_id,- include_condition: -> { SiteSetting.livestream_enabled },- ) do- return nil if object.topic.topic_chat_channel.blank?- object.topic.topic_chat_channel.chat_channel_id- end+ include_condition: -> do+ object.topic.first_post&.event&.livestream? && object.topic.topic_chat_channel.present?+ end,+ ) { object.topic.topic_chat_channel.chat_channel_id }++ add_to_serializer(:topic_view, :has_livestream) { object.topic.first_post&.event&.livestream? }- on(:post_edited) do |post, _, _|- if SiteSetting.livestream_enabled- DiscourseCalendar::Livestream.handle_topic_chat_channel_creation(post.topic)- end- end- on(:topic_created) do |topic, _, _|- if SiteSetting.livestream_enabled- DiscourseCalendar::Livestream.handle_topic_chat_channel_creation(topic)- end- endon(:chat_channel_trashed) do |channel, user|- if SiteSetting.livestream_enabled- # If the chat channel is deleted, delete the related TopicChatChannel record- DiscourseCalendar::Livestream::TopicChatChannel.where(chat_channel_id: channel.id).destroy_all- end+ # If the chat channel is deleted, delete the related TopicChatChannel record+ DiscourseCalendar::Livestream::TopicChatChannel.where(chat_channel_id: channel.id).destroy_allendon(:discourse_calendar_post_event_invitee_status_changed) do |invitee|- next if !SiteSetting.livestream_enabled-topic = invitee.event.post.topictopic_chat_channel = topic.topic_chat_channel@@ -890,21 +877,17 @@ after_initialize dochannel = topic_chat_channel.chat_channelmanager = Chat::ChannelMembershipManager.new(channel)- user_allowed_in_chat = user.in_any_groups?(SiteSetting.livestream_chat_allowed_groups_map)-+ # Attendance is the chat gate: anyone going is auto-followed into the+ # livestream channel, anyone else is unfollowed.membership =if invitee.status == DiscoursePostEvent::Invitee.statuses[:going]- user_allowed_in_chat ? manager.follow(user) : manager.unfollow(user)+ manager.follow(user)elsemanager.unfollow(user)end- DiscourseCalendar::Livestream.publish_livestream_chat_status(membership, user: user)- end-- on(:site_setting_changed) do |name, old_val, new_val|- if name == :livestream_chat_allowed_groups && SiteSetting.livestream_enabled- Jobs::LivestreamRecalculateUserChannelMemberships.new.execute+ if membership+ DiscourseCalendar::Livestream.publish_livestream_chat_status(membership, user: user)endendenddiff --git a/plugins/discourse-calendar/spec/jobs/livestream/recalculate_user_channel_memberships_spec.rb b/plugins/discourse-calendar/spec/jobs/livestream/recalculate_user_channel_memberships_spec.rbdeleted file mode 100644index 1767abb3544..00000000000--- a/plugins/discourse-calendar/spec/jobs/livestream/recalculate_user_channel_memberships_spec.rb+++ /dev/null@@ -1,122 +0,0 @@-# frozen_string_literal: true--RSpec.describe Jobs::LivestreamRecalculateUserChannelMemberships do- def run_job- Jobs::LivestreamRecalculateUserChannelMemberships.new.execute- end-- fab!(:admin)- fab!(:user) { Fabricate(:user, trust_level: TrustLevel[1]) }-- fab!(:livestream_channel1, :category_channel)- fab!(:livestream_channel2, :category_channel)-- fab!(:normal_channel1, :category_channel)- fab!(:normal_channel2, :category_channel)-- fab!(:topic1) { Fabricate(:topic, user: user) }- fab!(:topic2) { Fabricate(:topic, user: user) }-- fab!(:topic_chat_channel1) do- Fabricate(:topic_chat_channel, topic: topic1, chat_channel: livestream_channel1)- end- fab!(:topic_chat_channel2) do- Fabricate(:topic_chat_channel, topic: topic2, chat_channel: livestream_channel2)- end-- fab!(:first_post1) { Fabricate(:post, topic: topic1) }- fab!(:first_post2) { Fabricate(:post, topic: topic2) }-- fab!(:normal_membership1) do- Fabricate(- :user_chat_channel_membership,- user: user,- chat_channel: normal_channel1,- following: true,- )- end-- fab!(:normal_membership2) do- Fabricate(- :user_chat_channel_membership,- user: user,- chat_channel: normal_channel2,- following: false,- )- end-- fab!(:event1) do- Fabricate(- :event,- post: first_post1,- original_starts_at: Time.now + 1.hour,- original_ends_at: Time.now + 2.hours,- )- end-- fab!(:event2) do- Fabricate(- :event,- post: first_post2,- original_starts_at: Time.now + 1.hour,- original_ends_at: Time.now + 2.hours,- )- end-- fab!(:livestream_membership1) do- Fabricate(:user_chat_channel_membership, user: user, chat_channel: livestream_channel1)- end-- fab!(:livestream_membership2) do- Fabricate(:user_chat_channel_membership, user: user, chat_channel: livestream_channel2)- end-- fab!(:post_event_invitee1) do- Fabricate(- :post_event_invitee,- event: event1,- user: user,- status: DiscoursePostEvent::Invitee.statuses[:going],- )- end-- fab!(:post_event_invitee2) do- Fabricate(- :post_event_invitee,- event: event2,- user: user,- status: DiscoursePostEvent::Invitee.statuses[:going],- )- end- before do- SiteSetting.livestream_enabled = true- SiteSetting.calendar_enabled = true- SiteSetting.discourse_post_event_enabled = true- end-- describe "when user is not in the allow list" do- before { SiteSetting.livestream_chat_allowed_groups = Group::AUTO_GROUPS[:trust_level_4].to_s }-- it "unfollows all livestream channels" do- run_job-- expect(livestream_membership1.following).to eq(false)- expect(livestream_membership2.following).to eq(false)- expect(normal_membership1.following).to eq(true)- expect(normal_membership2.following).to eq(false)- expect(Chat::UserChatChannelMembership.count).to eq(4)- end-- it "publishes membership changes only to the affected user's message bus channel" do- messages = MessageBus.track_publish { run_job }-- expect(messages).not_to be_empty- expect(messages).to all(- have_attributes(- channel: "/discourse-calendar/livestream/chat-status/#{user.id}",- user_ids: [user.id],- ),- )- end- end-enddiff --git a/plugins/discourse-calendar/spec/jobs/regular/discourse_post_event/warm_livestream_onebox_spec.rb b/plugins/discourse-calendar/spec/jobs/regular/discourse_post_event/warm_livestream_onebox_spec.rbnew file mode 100644index 00000000000..40dda37e7ca--- /dev/null+++ b/plugins/discourse-calendar/spec/jobs/regular/discourse_post_event/warm_livestream_onebox_spec.rb@@ -0,0 +1,37 @@+# frozen_string_literal: true++describe Jobs::WarmLivestreamOnebox do+ let(:livestream_url) { "https://example.com/live" }++ fab!(:topic)+ fab!(:post) { Fabricate(:post, topic: topic) }++ let(:event) { Fabricate(:event, post: post, livestream: true, location: livestream_url) }++ before { Jobs.run_later! }++ it "publishes a changed post after warming the onebox" do+ event+ Oneboxer.expects(:onebox).with(livestream_url).returns("<aside>cached</aside>")++ messages =+ MessageBus.track_publish("/topic/#{post.topic_id}") do+ described_class.new.execute(event_id: event.id, url: livestream_url)+ end++ expect(messages.first.data).to include(id: post.id, type: :revised)+ end++ it "does not publish when the event URL has changed" do+ stale_url = "https://example.com/old-live"+ event+ Oneboxer.expects(:onebox).with(stale_url).returns("<aside>cached</aside>")++ messages =+ MessageBus.track_publish("/topic/#{post.topic_id}") do+ described_class.new.execute(event_id: event.id, url: stale_url)+ end++ expect(messages).to be_empty+ end+enddiff --git a/plugins/discourse-calendar/spec/lib/discourse_calendar/livestream/handle_topic_chat_channel_creation_spec.rb b/plugins/discourse-calendar/spec/lib/discourse_calendar/livestream/handle_topic_chat_channel_creation_spec.rbindex 22e777de35d..c6d9b721579 100644--- a/plugins/discourse-calendar/spec/lib/discourse_calendar/livestream/handle_topic_chat_channel_creation_spec.rb+++ b/plugins/discourse-calendar/spec/lib/discourse_calendar/livestream/handle_topic_chat_channel_creation_spec.rb@@ -17,7 +17,13 @@ RSpec.describe DiscourseCalendar::Livestream dobefore { topic.update!(category: category) }- context "when the topic has no 'livestream' tag" do+ context "when the first post is not a livestream event" do+ before do+ SiteSetting.calendar_enabled = true+ post = Fabricate(:post, topic: topic)+ Fabricate(:event, post: post, livestream: false)+ end+it "does not create a chat channel" dodescribed_class.handle_topic_chat_channel_creation(topic)@@ -25,13 +31,11 @@ RSpec.describe DiscourseCalendar::Livestream doendend- context "when the topic has a 'livestream' tag" do- let(:tag) { Fabricate(:tag, name: "livestream") }-+ context "when the first post is a livestream event" dobefore doSiteSetting.calendar_enabled = true- SiteSetting.livestream_enabled = true- topic.tags << tag+ post = Fabricate(:post, topic: topic)+ Fabricate(:event, post: post, livestream: true, location: "https://example.com/live")endit "creates a chat channel" dodiff --git a/plugins/discourse-calendar/spec/migrations/backfill_livestream_from_tag_spec.rb b/plugins/discourse-calendar/spec/migrations/backfill_livestream_from_tag_spec.rbnew file mode 100644index 00000000000..62defd60b6f--- /dev/null+++ b/plugins/discourse-calendar/spec/migrations/backfill_livestream_from_tag_spec.rb@@ -0,0 +1,67 @@+# frozen_string_literal: true++require Rails.root.join(+ "plugins/discourse-calendar/db/post_migrate/20260622201005_backfill_livestream_from_tag.rb",+ )++RSpec.describe BackfillLivestreamFromTag do+ subject(:migrate) { described_class.new.up }++ fab!(:livestream_tag) { Fabricate(:tag, name: "livestream") }+ fab!(:other_tag) { Fabricate(:tag, name: "webinar") }++ fab!(:tagged_topic) { Fabricate(:topic, tags: [livestream_tag]) }+ fab!(:tagged_event) { Fabricate(:event, post: Fabricate(:post, topic: tagged_topic)) }++ fab!(:untagged_topic) { Fabricate(:topic, tags: [other_tag]) }+ fab!(:untagged_event) { Fabricate(:event, post: Fabricate(:post, topic: untagged_topic)) }++ # A livestream-tagged topic whose event sits on a reply, not the first post.+ fab!(:reply_event_topic) { Fabricate(:topic, tags: [livestream_tag]) }+ fab!(:reply_event) do+ Fabricate(:post, topic: reply_event_topic) # first post, no event+ Fabricate(:event, post: Fabricate(:post, topic: reply_event_topic)) # event on a reply+ end++ before do+ @original_verbose = ActiveRecord::Migration.verbose+ ActiveRecord::Migration.verbose = false+ end++ after { ActiveRecord::Migration.verbose = @original_verbose }++ context "when livestream_enabled is true" do+ before do+ # livestream_enabled is no longer a registered setting; insert the row the+ # way an upgraded site carries it (see CopyLivestreamSettingsToCalendar).+ DB.exec(<<~SQL)+ INSERT INTO site_settings (name, data_type, value, created_at, updated_at)+ VALUES ('livestream_enabled', 5, 't', NOW(), NOW())+ SQL+ end++ it "enables livestream on events whose topic has the livestream tag" do+ migrate++ expect(tagged_event.reload.livestream).to eq(true)+ end++ it "leaves events whose topic lacks the livestream tag unchanged" do+ migrate++ expect(untagged_event.reload.livestream).to eq(false)+ end++ it "leaves events that are not on the first post unchanged" do+ migrate++ expect(reply_event.reload.livestream).to eq(false)+ end+ end++ it "does nothing when livestream_enabled is not set" do+ migrate++ expect(tagged_event.reload.livestream).to eq(false)+ end+enddiff --git a/plugins/discourse-calendar/spec/models/discourse_post_event/event_spec.rb b/plugins/discourse-calendar/spec/models/discourse_post_event/event_spec.rbindex 32f0ce5fba1..6e47b7fcace 100644--- a/plugins/discourse-calendar/spec/models/discourse_post_event/event_spec.rb+++ b/plugins/discourse-calendar/spec/models/discourse_post_event/event_spec.rb@@ -20,6 +20,112 @@ describe DiscoursePostEvent::Event do).is_at_most(DiscoursePostEvent::Event::MAX_NAME_LENGTH)end+ describe "#warm_livestream_onebox" do+ let(:livestream_url) { "https://example.com/live" }++ fab!(:topic) { Fabricate(:topic, category: nil) }+ fab!(:post) { Fabricate(:post, topic: topic) }++ before { Jobs.run_later! }++ it "enqueues onebox warming for a livestream URL" do+ expect_enqueued_with(+ job: :warm_livestream_onebox,+ args: {+ event_id: post.id,+ url: livestream_url,+ },+ ) { Fabricate(:event, post: post, livestream: true, location: livestream_url) }+ end++ it "skips onebox warming when the onebox is cached" do+ Discourse.cache.write(+ Oneboxer.onebox_cache_key(livestream_url),+ { onebox: "<aside>cached</aside>" },+ )++ expect_not_enqueued_with(job: :warm_livestream_onebox) do+ Fabricate(:event, post: post, livestream: true, location: livestream_url)+ end+ end+ end++ describe "#create_livestream_chat_channel" do+ fab!(:category)+ fab!(:topic) { Fabricate(:topic, category: category) }+ fab!(:post) { Fabricate(:post, topic: topic) }++ before do+ SiteSetting.chat_enabled = true+ Jobs.run_later!+ end++ it "creates the chat channel after the livestream event is committed" do+ expect {+ Fabricate(:event, post: post, livestream: true, location: "https://example.com/live")+ }.to change(DiscourseCalendar::Livestream::TopicChatChannel, :count).by(1)++ expect(post.topic.topic_chat_channel.chat_channel.chatable).to eq(category)+ end++ it "does not create a chat channel when chat is disabled" do+ SiteSetting.chat_enabled = false++ expect {+ Fabricate(:event, post: post, livestream: true, location: "https://example.com/live")+ }.not_to change(DiscourseCalendar::Livestream::TopicChatChannel, :count)+ end++ it "does not create a chat channel for a livestream event on a reply" do+ reply = Fabricate(:post, topic: topic)++ expect {+ Fabricate(:event, post: reply, livestream: true, location: "https://example.com/live")+ }.not_to change(DiscourseCalendar::Livestream::TopicChatChannel, :count)+ end+ end++ describe "#reset_invalid_livestream" do+ fab!(:post)++ # enqueue (don't run) the onebox-warming job so it doesn't make a real request+ before { Jobs.run_later! }++ it "keeps livestream enabled for an http(s) location" do+ event = Fabricate(:event, post: post, livestream: true, location: "https://example.com/live")++ expect(event.reload.livestream).to eq(true)+ end++ it "resets livestream when the location is not an http(s) URL" do+ event = Fabricate(:event, post: post, livestream: true, location: "Room 5")++ expect(event.reload.livestream).to eq(false)+ end++ it "resets livestream when there is no location" do+ event = Fabricate(:event, post: post, livestream: true)++ expect(event.reload.livestream).to eq(false)+ end++ it "resets livestream when the location is edited away from a URL" do+ event = Fabricate(:event, post: post, livestream: true, location: "https://example.com/live")+ event.update!(location: "Room 5")++ expect(event.reload.livestream).to eq(false)+ end++ it "resets livestream when the event is not on the first post" do+ reply = Fabricate(:post, topic: post.topic)+ expect(reply.is_first_post?).to be(false)++ event = Fabricate(:event, post: reply, livestream: true, location: "https://example.com/live")++ expect(event.reload.livestream).to eq(false)+ end+ end+describe "#raw_invitees_are_groups" dofab!(:user) { Fabricate(:user, admin: true) }fab!(:topic) { Fabricate(:topic, user: user) }@@ -656,6 +762,23 @@ describe DiscoursePostEvent::Event doTopicUser.notification_levels[:regular],)end++ it "unfollows the pruned invitee from the livestream chat channel" do+ channel = Fabricate(:category_channel)+ Fabricate(:topic_chat_channel, topic: post_1.topic, chat_channel: channel)+ membership =+ Fabricate(+ :user_chat_channel_membership,+ user: user_1,+ chat_channel: channel,+ following: true,+ )++ event_1.update_with_params!(raw_invitees: [group_2.name])++ expect(event_1.invitees.find_by(user_id: user_1.id)).to be_nil+ expect(membership.reload.following).to eq(false)+ endendendend@@ -858,6 +981,40 @@ describe DiscoursePostEvent::Event dofab!(:post) { Fabricate(:post, topic: topic, user: user) }fab!(:upload)+ it "sets livestream from the bbcode attribute" do+ Jobs.run_later!++ post.update!(+ raw:+ "[event start=\"2020-04-24 14:15\" livestream=\"true\" location=\"https://example.com/live\"]\n[/event]",+ )+ post.rebake!+ DiscoursePostEvent::Event::SyncFromPost.call(params: { post_id: post.id })+ post.reload++ expect(post.event.livestream).to eq(true)+ end++ it "defaults livestream to false when the attribute is absent" do+ post.update!(raw: "[event start=\"2020-04-24 14:15\"]\n[/event]")+ post.rebake!+ DiscoursePostEvent::Event::SyncFromPost.call(params: { post_id: post.id })+ post.reload++ expect(post.event.livestream).to eq(false)+ end++ it "ignores livestream=true when the location is not an http(s) URL" do+ post.update!(+ raw: "[event start=\"2020-04-24 14:15\" livestream=\"true\" location=\"Room 5\"]\n[/event]",+ )+ post.rebake!+ DiscoursePostEvent::Event::SyncFromPost.call(params: { post_id: post.id })+ post.reload++ expect(post.event.livestream).to eq(false)+ end+context "with image" dobefore dopost.update!(diff --git a/plugins/discourse-calendar/spec/requests/api/schemas/json/events_index_detailed_response.json b/plugins/discourse-calendar/spec/requests/api/schemas/json/events_index_detailed_response.jsonindex 3eaf3265a51..eebdca5d396 100644--- a/plugins/discourse-calendar/spec/requests/api/schemas/json/events_index_detailed_response.json+++ b/plugins/discourse-calendar/spec/requests/api/schemas/json/events_index_detailed_response.json@@ -232,6 +232,15 @@"channel": {"type": "object"},+ "livestream": {+ "type": "boolean"+ },+ "livestream_onebox": {+ "type": [+ "string",+ "null"+ ]+ },"max_attendees": {"type": ["integer",diff --git a/plugins/discourse-calendar/spec/serializers/discourse_post_event/event_serializer_spec.rb b/plugins/discourse-calendar/spec/serializers/discourse_post_event/event_serializer_spec.rbindex f82b55e3785..a040ed2004e 100644--- a/plugins/discourse-calendar/spec/serializers/discourse_post_event/event_serializer_spec.rb+++ b/plugins/discourse-calendar/spec/serializers/discourse_post_event/event_serializer_spec.rb@@ -101,6 +101,27 @@ describe DiscoursePostEvent::EventSerializer doendend+ context "when event is a livestream" do+ let(:livestream_url) { "https://example.com/live" }+ let(:livestream_post) { Fabricate(:post, topic: topic) }+ let(:livestream_event) do+ Fabricate(:event, post: livestream_post, livestream: true, location: livestream_url)+ end++ before { Jobs.run_later! }++ it "does not enqueue onebox warming while serializing" do+ livestream_event++ expect_not_enqueued_with(job: :warm_livestream_onebox) do+ json =+ DiscoursePostEvent::EventSerializer.new(livestream_event, scope: Guardian.new).as_json++ expect(json[:event][:livestream_onebox]).to be_nil+ end+ end+ end+context "when event has duration" dofab!(:post_with_duration) { Fabricate(:post, topic: topic) }fab!(:event_with_duration) dodiff --git a/plugins/discourse-calendar/spec/serializers/topic_view_serializer_spec.rb b/plugins/discourse-calendar/spec/serializers/topic_view_serializer_spec.rbindex 715fcd77104..1f0ad9f4173 100644--- a/plugins/discourse-calendar/spec/serializers/topic_view_serializer_spec.rb+++ b/plugins/discourse-calendar/spec/serializers/topic_view_serializer_spec.rb@@ -131,4 +131,41 @@ RSpec.describe TopicViewSerializer doendendend++ describe "#chat_channel_id" do+ fab!(:category)+ let(:topic) { Fabricate(:topic, category:) }++ before do+ SiteSetting.chat_enabled = true+ # enqueue (don't run) the onebox-warming job so it doesn't make a real request+ Jobs.run_later!+ first_post+ end++ def create_event(livestream:)+ DiscoursePostEvent::Event.create!(+ id: first_post.id,+ original_starts_at: 1.hour.from_now,+ original_ends_at: 2.hours.from_now,+ location: "https://example.com/live",+ livestream:,+ )+ end++ it "is included while the event is a livestream" do+ create_event(livestream: true)++ expect(topic.topic_chat_channel).to be_present+ expect(parsed_json["chat_channel_id"]).to eq(topic.topic_chat_channel.chat_channel_id)+ end++ it "is not included once livestream is disabled, even if the channel row remains" do+ event = create_event(livestream: true)+ event.update!(livestream: false)++ expect(topic.reload.topic_chat_channel).to be_present+ expect(parsed_json).not_to have_key("chat_channel_id")+ end+ endenddiff --git a/plugins/discourse-calendar/spec/system/desktop_topic_livestream_authenticated_spec.rb b/plugins/discourse-calendar/spec/system/desktop_topic_livestream_authenticated_spec.rbindex 53590c5fcda..7977a3150f0 100644--- a/plugins/discourse-calendar/spec/system/desktop_topic_livestream_authenticated_spec.rb+++ b/plugins/discourse-calendar/spec/system/desktop_topic_livestream_authenticated_spec.rb@@ -11,7 +11,8 @@ describe "Discourse Livestream - Topic Livestream - Desktop - Authenticated" dobefore doSiteSetting.calendar_enabled = trueSiteSetting.chat_enabled = true- SiteSetting.livestream_enabled = true+ SiteSetting.discourse_post_event_enabled = true+ SiteSetting.discourse_post_event_allowed_on_groups = Group::AUTO_GROUPS[:everyone].to_ssign_in(current_user)enddiff --git a/plugins/discourse-calendar/spec/system/livestream_calendar_event_spec.rb b/plugins/discourse-calendar/spec/system/livestream_calendar_event_spec.rbindex d14a7d4eb64..9be56c1629a 100644--- a/plugins/discourse-calendar/spec/system/livestream_calendar_event_spec.rb+++ b/plugins/discourse-calendar/spec/system/livestream_calendar_event_spec.rb@@ -12,10 +12,8 @@ describe "Discourse Livestream - Topic Livestream with events - Authenticated" dbefore doSiteSetting.calendar_enabled = trueSiteSetting.chat_enabled = true- SiteSetting.livestream_enabled = trueSiteSetting.discourse_post_event_enabled = trueSiteSetting.discourse_post_event_allowed_on_groups = group.id.to_s- SiteSetting.livestream_chat_allowed_groups = group.id.to_ssign_in(current_user)enddiff --git a/plugins/discourse-calendar/spec/system/mobile_topic_livestream_authenticated_spec.rb b/plugins/discourse-calendar/spec/system/mobile_topic_livestream_authenticated_spec.rbindex b8cc4f7e87a..e377f4a42db 100644--- a/plugins/discourse-calendar/spec/system/mobile_topic_livestream_authenticated_spec.rb+++ b/plugins/discourse-calendar/spec/system/mobile_topic_livestream_authenticated_spec.rb@@ -12,7 +12,6 @@ describe "Discourse Livestream - Topic Livestream - Mobile - Authenticated", mobbefore doSiteSetting.calendar_enabled = trueSiteSetting.chat_enabled = true- SiteSetting.livestream_enabled = trueSiteSetting.discourse_post_event_enabled = truesign_in(admin)end@@ -39,9 +38,8 @@ describe "Discourse Livestream - Topic Livestream - Mobile - Authenticated", mobexpect(topic_page).to have_css(".chat-channel-preview-card")end- context "when user in allowlisted group" do- it "opens the chat channel and allows to chat after clicking the header icon" do- SiteSetting.livestream_chat_allowed_groups = Group::AUTO_GROUPS[:admins].to_s+ context "when the user is going to the event" do+ it "opens the chat channel and allows chatting after clicking the header icon" dotopic_livestream.create_livestream_event_topic(composer, topic_page, livestream_tag)find(".going-button").click@@ -52,21 +50,5 @@ describe "Discourse Livestream - Topic Livestream - Mobile - Authenticated", mobexpect(topic_page).to have_css(".chat-composer")endend-- context "when user not in allowlisted group" do- fab!(:group)-- it "opens the chat channel and allows to chat after clicking the header icon" do- SiteSetting.livestream_chat_allowed_groups = group.id.to_s- topic_livestream.create_livestream_event_topic(composer, topic_page, livestream_tag)-- find(".going-button").click- find(".livestream-header-icon").click- expect(topic_page).to have_css("#custom-chat-container")- expect(topic_page).to have_css(".chat-drawer")-- expect(topic_page).not_to have_css(".chat-composer")- end- endendenddiff --git a/plugins/discourse-calendar/spec/system/page_objects/discourse_calendar/livestream/topic_livestream.rb b/plugins/discourse-calendar/spec/system/page_objects/discourse_calendar/livestream/topic_livestream.rbindex 4b56875fdb5..4ed8a6a2008 100644--- a/plugins/discourse-calendar/spec/system/page_objects/discourse_calendar/livestream/topic_livestream.rb+++ b/plugins/discourse-calendar/spec/system/page_objects/discourse_calendar/livestream/topic_livestream.rb@@ -13,7 +13,11 @@ module PageObjectstag_chooser.select_row_by_name(tag.name)tag_chooser.collapse- composer.fill_content("The content for my livestream topic")+ tomorrow = 1.day.from_now.strftime("%Y-%m-%d")+ composer.fill_content <<~MD+ [event start="#{tomorrow} 13:37" status="public" livestream="true" location="https://example.com/live"]+ [/event]+ MDcomposer.createend@@ -38,7 +42,7 @@ module PageObjectstomorrow = 1.day.from_now.strftime("%Y-%m-%d")composer.fill_content <<~MD- [event start="#{tomorrow} 13:37" status="public"]+ [event start="#{tomorrow} 13:37" status="public" livestream="true" location="https://example.com/live"][/event]MDcomposer.creatediff --git a/plugins/discourse-calendar/test/javascripts/integration/components/post-event-builder-test.gjs b/plugins/discourse-calendar/test/javascripts/integration/components/post-event-builder-test.gjsindex 4e41eb70635..74c99950c82 100644--- a/plugins/discourse-calendar/test/javascripts/integration/components/post-event-builder-test.gjs+++ b/plugins/discourse-calendar/test/javascripts/integration/components/post-event-builder-test.gjs@@ -1,5 +1,5 @@import { getOwner } from "@ember/owner";-import { render } from "@ember/test-helpers";+import { fillIn, render } from "@ember/test-helpers";import { module, test } from "qunit";import { setupRenderingTest } from "discourse/tests/helpers/component-test";import PostEventBuilder from "../../discourse/components/modal/post-event-builder";@@ -104,4 +104,53 @@ module("Integration | Component | Modal | PostEventBuilder", function (hooks) {.dom(`[data-name="customFields.field_aa"] input`).exists("renders the dashed custom field without crashing");});++ test("clears livestream when the location stops being a URL", async function (assert) {+ this.siteSettings.chat_enabled = true;++ const event = DiscoursePostEventEvent.create({+ name: "My event",+ starts_at: "2022-07-01T10:00:00Z",+ ends_at: "2022-07-01T11:00:00Z",+ timezone: "UTC",+ status: "public",+ reminders: [],+ raw_invitees: [],+ custom_fields: {},+ location: "https://example.com/live",+ livestream: true,+ });++ const model = {+ event,+ initialScreen: "advanced",+ onUpdate: () => {},+ toolbarEvent: {},+ };+ const closeModal = () => {};++ await render(+ <template>+ <PostEventBuilder+ @inline={{true}}+ @model={{model}}+ @closeModal={{closeModal}}+ />+ </template>+ );++ assert+ .dom(`[data-name="livestream"]`)+ .exists("the livestream field shows while the location is a URL");++ await fillIn(`[data-name="location"] input`, "Room 5");++ assert+ .dom(`[data-name="livestream"]`)+ .doesNotExist("the livestream field is hidden for a non-URL location");+ assert.false(+ event.livestream,+ "livestream is reset so it is not submitted for a non-URL location"+ );+ });});diff --git a/plugins/discourse-calendar/test/javascripts/lib/raw-event-helper-test.js b/plugins/discourse-calendar/test/javascripts/lib/raw-event-helper-test.jsindex ab05dc1c0dc..729853414db 100644--- a/plugins/discourse-calendar/test/javascripts/lib/raw-event-helper-test.js+++ b/plugins/discourse-calendar/test/javascripts/lib/raw-event-helper-test.js@@ -4,12 +4,15 @@ import {buildEventBlock,buildParams,defaultReminderFor,+ isLivestreamUrl,+ parseEventAttrs,parseEventBlock,parseReminders,reconcileDefaultReminder,reminderToBBCode,removeEvent,replaceRaw,+ stateToEventInput,} from "discourse/plugins/discourse-calendar/discourse/lib/raw-event-helper";const SAME_DAY_CONFIG = {@@ -445,4 +448,50 @@ module("Unit | Lib | raw-event-helper", function () {"omits image when imageUpload is not set");});++ test("livestream round-trips through state, params and parsing", function (assert) {+ const startsAt = "2024-06-15T10:00:00Z";+ const siteSettings = { discourse_post_event_allowed_custom_fields: "" };++ assert.strictEqual(+ buildParams(startsAt, null, { livestream: true }, siteSettings)+ .livestream,+ "true",+ "buildParams emits livestream when enabled"+ );++ assert.strictEqual(+ buildParams(startsAt, null, { livestream: false }, siteSettings)+ .livestream,+ undefined,+ "buildParams omits livestream when disabled"+ );++ assert.true(+ stateToEventInput({ livestream: true }).livestream,+ "stateToEventInput carries livestream through"+ );++ assert.true(+ parseEventAttrs({ livestream: "true" }).livestream,+ "parseEventAttrs reads livestream=true"+ );++ assert.false(+ parseEventAttrs({}).livestream,+ "parseEventAttrs defaults livestream to false"+ );+ });++ test("isLivestreamUrl only accepts http(s) URLs", function (assert) {+ assert.true(isLivestreamUrl("https://example.com/live"), "accepts https");+ assert.true(isLivestreamUrl("http://example.com/live"), "accepts http");+ assert.true(isLivestreamUrl("HTTPS://EXAMPLE.COM"), "case-insensitive");++ assert.false(isLivestreamUrl("www.example.com"), "rejects schemeless www");+ assert.false(isLivestreamUrl("mailto:[email protected]"), "rejects mailto");+ assert.false(isLivestreamUrl("Room 5"), "rejects plain text");+ assert.false(isLivestreamUrl(null), "handles null");+ assert.false(isLivestreamUrl(undefined), "handles undefined");+ });});diff --git a/themes/horizon/scss/compatibility.scss b/themes/horizon/scss/compatibility.scssindex 105af54d651..ed454c993c2 100644--- a/themes/horizon/scss/compatibility.scss+++ b/themes/horizon/scss/compatibility.scss@@ -53,11 +53,12 @@}// livestream plugin: https://github.com/discourse/discourse-livestream-.tag-livestream.chat-enabled.archetype-regular {+.livestream-topic.chat-enabled.archetype-regular {#custom-chat-container {margin-left: 0;border-top-left-radius: var(--d-border-radius-large);border-top-right-radius: var(--d-border-radius-large);+ border: 0;}.container.posts {