From 179d15d90edb76322cc65929913f834763fda976 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Tue, 6 Dec 2022 19:33:39 +0100 Subject: [PATCH] =?UTF-8?q?FIX:=20webhook=20should=20touch=20channel?= =?UTF-8?q?=E2=80=99s=20last=5Fmessage=5Fsent=5Fat=20(#19342)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/chat/app/controllers/chat_controller.rb | 1 - plugins/chat/lib/chat_message_creator.rb | 1 + .../spec/components/chat_message_creator_spec.rb | 12 ++++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/chat/app/controllers/chat_controller.rb b/plugins/chat/app/controllers/chat_controller.rb index 3f78f15b8ef..57fc55e6da6 100644 --- a/plugins/chat/app/controllers/chat_controller.rb +++ b/plugins/chat/app/controllers/chat_controller.rb @@ -110,7 +110,6 @@ class Chat::ChatController < Chat::ChatBaseController return render_json_error(chat_message_creator.error) if chat_message_creator.failed? - @chat_channel.touch(:last_message_sent_at) @user_chat_channel_membership.update(last_read_message_id: chat_message_creator.chat_message.id) if @chat_channel.direct_message_channel? diff --git a/plugins/chat/lib/chat_message_creator.rb b/plugins/chat/lib/chat_message_creator.rb index 629c07e390c..fe7fed04599 100644 --- a/plugins/chat/lib/chat_message_creator.rb +++ b/plugins/chat/lib/chat_message_creator.rb @@ -53,6 +53,7 @@ class Chat::ChatMessageCreator chat_message: @chat_message, timestamp: @chat_message.created_at, ) + @chat_channel.touch(:last_message_sent_at) DiscourseEvent.trigger(:chat_message_created, @chat_message, @chat_channel, @user) rescue => error @error = error diff --git a/plugins/chat/spec/components/chat_message_creator_spec.rb b/plugins/chat/spec/components/chat_message_creator_spec.rb index 0520ce31d8b..6f87534fa29 100644 --- a/plugins/chat/spec/components/chat_message_creator_spec.rb +++ b/plugins/chat/spec/components/chat_message_creator_spec.rb @@ -112,6 +112,18 @@ describe Chat::ChatMessageCreator do }.to change { ChatMessage.count }.by(1) end + it "updates the channel’s last message date" do + previous_last_message_sent_at = public_chat_channel.last_message_sent_at + + Chat::ChatMessageCreator.create( + chat_channel: public_chat_channel, + user: user1, + content: "this is a message", + ) + + expect(previous_last_message_sent_at).to be < public_chat_channel.reload.last_message_sent_at + end + it "sets the last_editor_id to the user who created the message" do message = Chat::ChatMessageCreator.create(