FEATURE: Sort thread list by unread threads first (#22272)

* FEATURE: Sort thread list by unread threads first

This commit changes the thread list to show the threads that
have unread messages at the top of the list sorted by the
last reply date + time, then all other threads sorted by
last reply date + time.

This also fixes some issues by removing the last_reply
relationship on the thread, which did not work for complex
querying scenarios because its order would be discarded.

* FIX: Various fixes for thread list loading

* Use the channel.threadsManager and find the channel first rather
  than use activeChannel in the threads manager, otherwise we may
  be looking at differenct channels.
* Look at threadsManager directly instead of storing result for threads
  list otherwise it can get out of sync because of replace: true in
  other places we are loading threads into the store.
* Fix sorting for thread.last_reply, needed a resort.
This commit is contained in:
Martin Brennan
2023-06-28 13:14:01 +10:00
committed by GitHub
parent 78bc42be2e
commit 1526d1f97d
15 changed files with 243 additions and 84 deletions

View File

@ -49,10 +49,16 @@ RSpec.describe Chat::LookupChannelThreads do
expect(result).to be_a_success
end
it "returns the threads ordered by the last thread the current user posted in" do
it "returns the threads ordered by the last reply created_at date and time for the thread" do
expect(result.threads.map(&:id)).to eq([thread_3.id, thread_1.id, thread_2.id])
end
it "orders threads with unread messages at the top even if their last reply created_at date and time is older" do
unread_message = Fabricate(:chat_message, chat_channel: channel, thread: thread_2)
unread_message.update!(created_at: 2.days.ago)
expect(result.threads.map(&:id)).to eq([thread_2.id, thread_3.id, thread_1.id])
end
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])