mirror of
https://github.com/discourse/discourse.git
synced 2026-08-06 13:08:40 +08:00
This does a handful of things to improve the livestream chat experience: 1. RSVP prompt replaces the default join button. A new chat-channel-preview-card-content plugin outlet in core chat lets the calendar plugin's livestream-rsvp connector fill the redesigned preview card's content slots. For users who can RSVP, it swaps the default join button for a going button for the event. 2. Pinned reference message linking back to the event topic. When a livestream channel is created, a system message is posted and pinned, and its id is stored in a new `reference_message_id` column. It's hidden via CSS when the chat is embedded in that same topic because it would be redundant. 3. Access control for private events. `chat_channel_id` is only serialized to users who can access the event's chat (invitees/invited groups, or admins) 4. If the channel is already open and expanded in the chat drawer, the embedded chat (and the livestream page layout) are suppressed. 5. Livestream channels are created with the spiral calendar emoji 🗓️ as their icon. I also converted core chat's preview card from viewport media queries to container queries so its layout responds to the width of the chat column it's rendered in rather than the viewport. With livestream sidebar <img width="2962" height="1726" alt="image" src="https://github.com/user-attachments/assets/71dc3d3f-35e5-4a0d-9103-92a03d4bb08e" /> Isolated chat when you're not in the livestream topic <img width="2560" height="1726" alt="image" src="https://github.com/user-attachments/assets/51cef0b8-85b4-4be8-a4f3-bf669f4be4fb" /> --------- Co-authored-by: Martin Brennan <martin@discourse.org>
87 lines
2.7 KiB
Ruby
Vendored
87 lines
2.7 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
RSpec.describe Chat::ChannelSerializer do
|
|
fab!(:category)
|
|
fab!(:viewer, :user)
|
|
let(:topic) { Fabricate(:topic, category:) }
|
|
let(:first_post) { Fabricate(:post, topic:) }
|
|
|
|
before do
|
|
SiteSetting.calendar_enabled = true
|
|
SiteSetting.discourse_post_event_enabled = true
|
|
SiteSetting.chat_enabled = true
|
|
# avoid the onebox-warming job making a real request
|
|
Jobs.run_later!
|
|
first_post
|
|
end
|
|
|
|
def create_event(livestream: true, status: :public, raw_invitees: nil)
|
|
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",
|
|
status: DiscoursePostEvent::Event.statuses[status],
|
|
raw_invitees:,
|
|
livestream:,
|
|
)
|
|
end
|
|
|
|
def livestream_channel
|
|
topic.reload.topic_chat_channel.chat_channel
|
|
end
|
|
|
|
def serialize(channel, user)
|
|
described_class.new(channel, scope: Guardian.new(user), root: nil).as_json
|
|
end
|
|
|
|
describe "#livestream_topic" do
|
|
it "references the linked topic for accessible livestream channels" do
|
|
create_event(livestream: true)
|
|
|
|
expect(serialize(livestream_channel, viewer)[:livestream_topic]).to include(
|
|
id: topic.id,
|
|
title: topic.title,
|
|
slug: topic.slug,
|
|
url: topic.relative_url,
|
|
event_id: first_post.id,
|
|
)
|
|
end
|
|
|
|
it "is omitted for channels without a linked livestream topic" do
|
|
channel = Fabricate(:chat_channel, chatable: category)
|
|
|
|
expect(serialize(channel, viewer)).not_to have_key(:livestream_topic)
|
|
end
|
|
|
|
it "is omitted for users who cannot access a private event" do
|
|
create_event(livestream: true, status: :private, raw_invitees: ["some_group"])
|
|
|
|
expect(serialize(livestream_channel, viewer)).not_to have_key(:livestream_topic)
|
|
end
|
|
|
|
it "is included for users in an invited group" do
|
|
group = Fabricate(:group)
|
|
group.add(viewer)
|
|
create_event(livestream: true, status: :private, raw_invitees: [group.name])
|
|
|
|
expect(serialize(livestream_channel, viewer)[:livestream_topic]).to include(id: topic.id)
|
|
end
|
|
|
|
it "is included for admins even when they cannot access the event" do
|
|
create_event(livestream: true, status: :private, raw_invitees: ["some_group"])
|
|
|
|
expect(serialize(livestream_channel, Fabricate(:admin))[:livestream_topic]).to include(
|
|
id: topic.id,
|
|
)
|
|
end
|
|
|
|
it "is omitted once livestream is disabled, even if the channel row remains" do
|
|
event = create_event(livestream: true)
|
|
channel = livestream_channel
|
|
event.update!(livestream: false)
|
|
|
|
expect(serialize(channel.reload, viewer)).not_to have_key(:livestream_topic)
|
|
end
|
|
end
|
|
end
|