FIX: handle thread participants limit on the frontend (#23839)

Workaround for an issue we are experiencing on thread index frontend where thread loads participants correctly (up to 10), then refreshes the threads and then limits to 3 participants.

There is an issue with storing threads for the main channel view and the thread list in the same store so handling the max participants on the frontend is a workaround until channel.threadsManager is updated.

I've adjusted the tests to handle the additional data being returned from ThreadParticipantQuery.
This commit is contained in:
David Battersby
2023-10-09 14:04:59 +08:00
committed by GitHub
parent c468110929
commit 79ececd976
4 changed files with 21 additions and 17 deletions

View File

@ -35,16 +35,15 @@ RSpec.describe Chat::ThreadParticipantQuery do
)
end
it "does not return more than 3 thread participants by default" do
thread_1.add(Fabricate(:user))
it "returns up to 10 thread participants" do
result = described_class.call(thread_ids: [thread_1.id])
expect(result[thread_1.id][:users].length).to eq(3)
expect(result[thread_1.id][:users].length).to eq(4)
end
it "calculates the top messagers in a thread as well as the last messager" do
result = described_class.call(thread_ids: [thread_1.id, thread_2.id])
expect(result[thread_1.id][:users].map { |u| u[:id] }).to eq(
[user_1.id, user_2.id, user_3.id],
expect(result[thread_1.id][:users].map { |u| u[:id] }).to match_array(
[thread_1.original_message_user_id, user_1.id, user_2.id, user_3.id],
)
end
@ -82,8 +81,8 @@ RSpec.describe Chat::ThreadParticipantQuery do
Fabricate(:chat_message, thread: thread_2, user: user_2)
Fabricate(:chat_message, thread: thread_2, user: user_2)
result = described_class.call(thread_ids: [thread_1.id, thread_2.id])
expect(result[thread_1.id][:users].map { |u| u[:id] }).to eq(
[user_1.id, user_2.id, user_3.id],
expect(result[thread_1.id][:users].map { |u| u[:id] }).to match_array(
[thread_1.original_message_user_id, user_1.id, user_2.id, user_3.id],
)
expect(result[thread_2.id][:users].map { |u| u[:id] }).to eq(
[thread_2.original_message_user_id, user_2.id],
@ -119,11 +118,11 @@ RSpec.describe Chat::ThreadParticipantQuery do
end
end
it "does not return more than 10 thread participants when preview is false" do
it "does not return more than 10 thread participants" do
other_user = Fabricate(:user)
thread_3.add(other_user)
Fabricate(:chat_message, thread: thread_3, user: other_user)
result = described_class.call(thread_ids: [thread_3.id], preview: false)
result = described_class.call(thread_ids: [thread_3.id])
expect(result[thread_3.id][:users].length).to eq(10)
end
end