mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 02:48:28 +08:00
DEV: Add last_message_id to channel and thread (#22488)
Initial migration and changes to models as well as changing the following services to update last_message_id: * Chat::MessageCreator * Chat::RestoreMessage * Chat::TrashMessage The data migration will set the `last_message_id` for all existing threads and channels in the database. When we query the thread list as well as the channel, we look at the last message ID for the following: * Channel - Sorting DM channels, and channel metadata for the list of channels * Thread - Last reply details for thread indicators and thread list
This commit is contained in:
@ -160,6 +160,7 @@ Fabricator(:chat_thread, class_name: "Chat::Thread") do
|
||||
transient :with_replies
|
||||
transient :channel
|
||||
transient :original_message_user
|
||||
transient :old_om
|
||||
|
||||
original_message do |attrs|
|
||||
Fabricate(
|
||||
@ -170,7 +171,13 @@ Fabricator(:chat_thread, class_name: "Chat::Thread") do
|
||||
end
|
||||
|
||||
after_create do |thread, transients|
|
||||
thread.original_message.update!(thread_id: thread.id)
|
||||
attrs = { thread_id: thread.id }
|
||||
|
||||
# Sometimes we make this older via created_at so any messages fabricated for this thread
|
||||
# afterwards are not created earlier in time than the OM.
|
||||
attrs[:created_at] = 1.week.ago if transients[:old_om]
|
||||
|
||||
thread.original_message.update!(**attrs)
|
||||
thread.add(thread.original_message_user)
|
||||
|
||||
if transients[:with_replies]
|
||||
|
Reference in New Issue
Block a user