diff --git a/plugins/chat/lib/chat_message_creator.rb b/plugins/chat/lib/chat_message_creator.rb index 6d4667cbe6d..49b9f58b9f9 100644 --- a/plugins/chat/lib/chat_message_creator.rb +++ b/plugins/chat/lib/chat_message_creator.rb @@ -52,6 +52,7 @@ class Chat::ChatMessageCreator chat_message: @chat_message, timestamp: @chat_message.created_at, ) + DiscourseEvent.trigger(:chat_message_created, @chat_message, @chat_channel, @user) rescue => error @error = error end diff --git a/plugins/chat/lib/chat_message_updater.rb b/plugins/chat/lib/chat_message_updater.rb index 39636cbcd07..2ae108a22e7 100644 --- a/plugins/chat/lib/chat_message_updater.rb +++ b/plugins/chat/lib/chat_message_updater.rb @@ -36,6 +36,7 @@ class Chat::ChatMessageUpdater ChatPublisher.publish_edit!(@chat_channel, @chat_message) Jobs.enqueue(:process_chat_message, { chat_message_id: @chat_message.id }) Chat::ChatNotifier.notify_edit(chat_message: @chat_message, timestamp: revision.created_at) + DiscourseEvent.trigger(:chat_message_edited, @chat_message, @chat_channel, @user) rescue => error @error = error end diff --git a/plugins/chat/spec/components/chat_message_creator_spec.rb b/plugins/chat/spec/components/chat_message_creator_spec.rb index 1ead27d5b20..bebdd302966 100644 --- a/plugins/chat/spec/components/chat_message_creator_spec.rb +++ b/plugins/chat/spec/components/chat_message_creator_spec.rb @@ -105,6 +105,17 @@ describe Chat::ChatMessageCreator do expect(message.last_editor_id).to eq(user1.id) end + it "publishes a DiscourseEvent for new messages" do + events = DiscourseEvent.track_events { + Chat::ChatMessageCreator.create( + chat_channel: public_chat_channel, + user: user1, + content: "this is a message", + ) + } + expect(events.map { _1[:event_name] }).to include(:chat_message_created) + end + it "creates mention notifications for public chat" do expect { Chat::ChatMessageCreator.create( diff --git a/plugins/chat/spec/components/chat_message_updater_spec.rb b/plugins/chat/spec/components/chat_message_updater_spec.rb index 37aea837328..1b6c9989658 100644 --- a/plugins/chat/spec/components/chat_message_updater_spec.rb +++ b/plugins/chat/spec/components/chat_message_updater_spec.rb @@ -83,6 +83,18 @@ describe Chat::ChatMessageUpdater do expect(chat_message.reload.message).to eq(new_message) end + it "publishes a DiscourseEvent for updated messages" do + chat_message = create_chat_message(user1, "This will be changed", public_chat_channel) + events = DiscourseEvent.track_events { + Chat::ChatMessageUpdater.update( + guardian: guardian, + chat_message: chat_message, + new_content: "Change to this!", + ) + } + expect(events.map { _1[:event_name] }).to include(:chat_message_edited) + end + it "creates mention notifications for unmentioned users" do chat_message = create_chat_message(user1, "This will be changed", public_chat_channel) expect {