mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 18:30:26 -06:00
FIX: Handle deleted original message for thread index (#21470)
Since we have channel message retention which deletes messages, we can end up with cases where the thread is still around but the message is deleted. We will handle the cascade delete in a different commit -- for now we will ensure the thread list lookup handles this case and doesn't error.
This commit is contained in:
parent
cbbaeb55b5
commit
91c5658e9b
@ -10,7 +10,9 @@ module Chat
|
||||
def initialize(object, opts)
|
||||
super(object, opts)
|
||||
@opts = opts
|
||||
original_message.thread = object
|
||||
|
||||
# Avoids an N1 to re-load the thread in the serializer for original_message.
|
||||
object.original_message.thread = object
|
||||
end
|
||||
|
||||
def meta
|
||||
|
@ -64,7 +64,9 @@ module Chat
|
||||
)
|
||||
.where("chat_messages.user_id = ? OR chat_messages.user_id IS NULL", guardian.user.id)
|
||||
.where(channel_id: channel.id)
|
||||
.where("original_messages.deleted_at IS NULL AND chat_messages.deleted_at IS NULL")
|
||||
.where(
|
||||
"original_messages.deleted_at IS NULL AND chat_messages.deleted_at IS NULL AND original_messages.id IS NOT NULL",
|
||||
)
|
||||
.group("chat_threads.id")
|
||||
.order("last_posted_at DESC NULLS LAST")
|
||||
.limit(50)
|
||||
|
@ -24,5 +24,6 @@
|
||||
|
||||
&__no-threads {
|
||||
@include thread-list-item;
|
||||
margin: 0.5rem 0rem 0.5rem 0.5rem;
|
||||
}
|
||||
}
|
||||
|
@ -3,5 +3,9 @@
|
||||
.chat-thread-list-item {
|
||||
margin: 0.5rem;
|
||||
}
|
||||
|
||||
&__no-threads {
|
||||
margin: 0.5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,11 +59,16 @@ RSpec.describe Chat::LookupChannelThreads do
|
||||
expect(result.threads.map(&:id)).to eq([thread_3.id, thread_1.id, thread_2.id])
|
||||
end
|
||||
|
||||
it "does not return threads where the original message is deleted" do
|
||||
it "does not return threads where the original message is trashed" do
|
||||
thread_1.original_message.trash!
|
||||
expect(result.threads.map(&:id)).to eq([thread_3.id, thread_2.id])
|
||||
end
|
||||
|
||||
it "does not return threads where the original message is deleted" do
|
||||
thread_1.original_message.destroy
|
||||
expect(result.threads.map(&:id)).to eq([thread_3.id, thread_2.id])
|
||||
end
|
||||
|
||||
it "does not count deleted messages for sort order" do
|
||||
Chat::Message.find_by(user: current_user, thread: thread_3).trash!
|
||||
expect(result.threads.map(&:id)).to eq([thread_1.id, thread_2.id])
|
||||
|
Loading…
Reference in New Issue
Block a user