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:
Martin Brennan
2023-07-13 10:28:11 +10:00
committed by GitHub
parent 4ae26bcaac
commit b1978e7ad8
53 changed files with 554 additions and 212 deletions

View File

@ -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]