diff --git a/plugin.rb b/plugin.rb index 7b571ec..5d0682c 100755 --- a/plugin.rb +++ b/plugin.rb @@ -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| diff --git a/spec/lib/discourse_livestream/handle_topic_chat_channel_creation_spec.rb b/spec/lib/discourse_livestream/handle_topic_chat_channel_creation_spec.rb index 8e487cc..665fdc4 100644 --- a/spec/lib/discourse_livestream/handle_topic_chat_channel_creation_spec.rb +++ b/spec/lib/discourse_livestream/handle_topic_chat_channel_creation_spec.rb @@ -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) @@ -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)