FIX: Doubled up or not tracked threads in thread list (#22631)

This commit fixes two issues with the thread list:

1. All threads were being shown regardless of whether the user had
   a membership in the thread. This was happening because the list
   and the channel share the same thread store, so if the channel
   had OMs with threads we would load them and they showed in the list.
2. Threads created by the user from a staged thread would double up.
   This is because the _cache in the channel threadsManager would use
   the staged thread ID even after we'd replaced the object's ID with
   the actual thread from the DB. The answer to this is to remove and
   re-add the thread to the local cache with the actual ID.
This commit is contained in:
Martin Brennan
2023-07-19 10:09:22 +10:00
committed by GitHub
parent bf799fb1e7
commit 6efae69c61
4 changed files with 62 additions and 1 deletions
@@ -26,6 +26,50 @@ describe "Thread list in side panel | full page", type: :system do
end
end
context "for threads the user is not a participant in" do
fab!(:thread_om) { Fabricate(:chat_message, chat_channel: channel) }
before { chat_system_user_bootstrap(user: other_user, channel: channel) }
it "does not show existing threads in the channel if the user is not tracking them" do
Fabricate(:chat_thread, original_message: thread_om, channel: channel)
chat_page.visit_channel(channel)
channel_page.open_thread_list
expect(page).to have_content(I18n.t("js.chat.threads.none"))
end
it "does not show new threads in the channel in the thread list if the user is not tracking them" do
chat_page.visit_channel(channel)
using_session(:other_user) do |session|
sign_in(other_user)
chat_page.visit_channel(channel)
channel_page.reply_to(thread_om)
thread_page.send_message("hey everyone!")
expect(channel_page).to have_thread_indicator(thread_om)
session.quit
end
channel_page.open_thread_list
expect(page).to have_content(I18n.t("js.chat.threads.none"))
end
describe "when the user creates a new thread" do
it "does not double up the staged thread and the actual thread in the list" do
chat_page.visit_channel(channel)
channel_page.reply_to(thread_om)
thread_page.send_message("hey everyone!")
expect(channel_page).to have_thread_indicator(thread_om)
thread_page.close
channel_page.open_thread_list
expect(page).to have_css(
thread_list_page.item_by_id_selector(thread_om.reload.thread_id),
count: 1,
)
end
end
end
context "when there are threads that the user is participating in" do
fab!(:thread_1) do
chat_thread_chain_bootstrap(channel: channel, users: [current_user, other_user])