Skip to content

A platform for community discussion. Free, open, simple.

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

Joffrey JAFFEUXa1d7548869a3
diff --git a/plugins/chat/app/serializers/chat/thread_preview_serializer.rb b/plugins/chat/app/serializers/chat/thread_preview_serializer.rb
index 1ec04c3504f..e7fb373d11c 100644
--- a/plugins/chat/app/serializers/chat/thread_preview_serializer.rb
+++ b/plugins/chat/app/serializers/chat/thread_preview_serializer.rb
@@ -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?
diff --git a/plugins/chat/spec/system/thread_preview_spec.rb b/plugins/chat/spec/system/thread_preview_spec.rb
index a4f87233067..77a29f61a91 100644
--- a/plugins/chat/spec/system/thread_preview_spec.rb
+++ b/plugins/chat/spec/system/thread_preview_spec.rb
@@ -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