FIX: prevents exception when last reply has deleted user (#25852)

Prior to this fix, if the last message of a thread had been made by a deleted user it would cause an exception as we would have no user to display, this commit uses a solution we have been using at other places: the null pattern, through the use of `Chat::NullUser.new`.
This commit is contained in:
Joffrey JAFFEUX 2024-02-26 03:44:54 +01:00 committed by GitHub
parent 1bd9ca11e7
commit a1d7548869
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -32,7 +32,7 @@ module Chat
end
def last_reply_user
object.last_message.user
object.last_message.user || Chat::NullUser.new
end
def include_participant_data?

View File

@ -46,6 +46,17 @@ describe "Thread preview", type: :system do
expect(channel_page.messages).to have_message(id: message_1.id)
expect(channel_page).to have_thread_indicator(message_1)
end
context "when the user of the preview has been deleted" do
before { thread_1_message_1.user.destroy! }
it "shows a deleted user" do
chat_page.visit_channel(channel_1)
expect(channel_page).to have_thread_indicator(message_1)
expect(channel_page).to have_css(".chat-user-avatar[data-username='deleted']")
end
end
end
context "when message has thread with deleted original message" do