Skip to content

FIX: delete "TopicChatChannel" record when chat channel is trashed #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class Engine < ::Rails::Engine
on(:topic_created) do |topic, _, _|
DiscourseLivestream.handle_topic_chat_channel_creation(topic)
end
on(:chat_channel_trashed) do |channel, user|
# If the chat channel is deleted, delete the related TopicChatChannel record
DiscourseLivestream::TopicChatChannel.where(chat_channel_id: channel.id).destroy_all
end
end

on(:discourse_calendar_post_event_invitee_status_changed) do |invitee|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
context "when the topic has a 'livestream' tag" do
let(:tag) { Fabricate(:tag, name: "livestream") }

before { topic.tags << tag }
before do
SiteSetting.discourse_livestream_enabled = true
topic.tags << tag
end

it "creates a chat channel" do
described_class.handle_topic_chat_channel_creation(topic)
Expand Down Expand Up @@ -72,6 +75,22 @@
expect(DiscourseLivestream::TopicChatChannel.count).to eq(0)
end

it "deletes the topic chat channel when the chat channel is soft deleted" do
described_class.handle_topic_chat_channel_creation(topic)
expect(DiscourseLivestream::TopicChatChannel.count).to eq(1)
expect(Chat::Channel.count).to eq(1)

chat_channel = Chat::Channel.first
Chat::TrashChannel.call(
guardian: Guardian.new(Fabricate(:admin)),
params: {
channel_id: chat_channel.id,
},
)
expect(chat_channel.reload).to be_trashed
expect(DiscourseLivestream::TopicChatChannel.count).to eq(0)
end

it "deletes the chat channel when topic chat channel is destroyed" do
described_class.handle_topic_chat_channel_creation(topic)

Expand Down
Loading