FIX: webhook should touch channel’s last_message_sent_at (#19342)

This commit is contained in:
Joffrey JAFFEUX 2022-12-06 19:33:39 +01:00 committed by GitHub
parent 9c8043a4d2
commit 179d15d90e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View File

@ -110,7 +110,6 @@ class Chat::ChatController < Chat::ChatBaseController
return render_json_error(chat_message_creator.error) if chat_message_creator.failed? 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) @user_chat_channel_membership.update(last_read_message_id: chat_message_creator.chat_message.id)
if @chat_channel.direct_message_channel? if @chat_channel.direct_message_channel?

View File

@ -53,6 +53,7 @@ class Chat::ChatMessageCreator
chat_message: @chat_message, chat_message: @chat_message,
timestamp: @chat_message.created_at, timestamp: @chat_message.created_at,
) )
@chat_channel.touch(:last_message_sent_at)
DiscourseEvent.trigger(:chat_message_created, @chat_message, @chat_channel, @user) DiscourseEvent.trigger(:chat_message_created, @chat_message, @chat_channel, @user)
rescue => error rescue => error
@error = error @error = error

View File

@ -112,6 +112,18 @@ describe Chat::ChatMessageCreator do
}.to change { ChatMessage.count }.by(1) }.to change { ChatMessage.count }.by(1)
end end
it "updates the channels 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 it "sets the last_editor_id to the user who created the message" do
message = message =
Chat::ChatMessageCreator.create( Chat::ChatMessageCreator.create(