FEATURE: Chat side panel with threads initial skeleton (#20209)

This commit introduces the skeleton of the chat thread UI. The
structure of the components looks like this. Its done this way
so the side panel can be used for other things as well if we wish,
not just for threads:

```
.main-chat-outlet
   <ChatLivePane />
   <ChatSidePanel>
     <-- rendered with {{outlet}} -->
     <ChatThread />
   </ChatSidePanel>
```

Later on the `ChatThreadList` will be rendered here as well.
Now, when you go to a channel you can open a thread by clicking
on either the Open Thread message action button or by clicking on
the reply indicator. This will take you to a route like `chat/c/:slug/:channelId/t/:threadId`.
This works on mobile as well.

This commit includes basic serializers and routes for threads,
as well as a new `ChatThreadsManager` service in JS that caches
threads for a channel the same way the channel threads manager does.

The chat messages inside the thread are intentionally left out
until a later PR.

**NOTE: These changes are gated behind the site setting enable_experimental_chat_threaded_discussions
and the threading_enabled boolean on a ChatChannel**
This commit is contained in:
Martin Brennan
2023-02-14 11:38:41 +10:00
committed by GitHub
parent cf5fa23cd3
commit 07ab20131a
48 changed files with 721 additions and 38 deletions

View File

@ -0,0 +1,75 @@
# frozen_string_literal: true
require "rails_helper"
RSpec.describe Chat::Api::ChatChannelThreadsController do
fab!(:current_user) { Fabricate(:user) }
before do
SiteSetting.chat_enabled = true
SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:everyone]
SiteSetting.enable_experimental_chat_threaded_discussions = true
Group.refresh_automatic_groups!
sign_in(current_user)
end
describe "show" do
context "when thread does not exist" do
fab!(:thread) { Fabricate(:chat_thread, original_message: Fabricate(:chat_message)) }
it "returns 404" do
thread.destroy!
get "/chat/api/channels/#{thread.channel_id}/threads/#{thread.id}"
expect(response.status).to eq(404)
end
end
context "when thread exists" do
fab!(:thread) { Fabricate(:chat_thread, original_message: Fabricate(:chat_message)) }
it "works" do
get "/chat/api/channels/#{thread.channel_id}/threads/#{thread.id}"
expect(response.status).to eq(200)
expect(response.parsed_body["thread"]["id"]).to eq(thread.id)
end
context "when the channel_id does not match the thread id" do
fab!(:other_channel) { Fabricate(:chat_channel) }
it "returns 404" do
get "/chat/api/channels/#{other_channel.id}/threads/#{thread.id}"
expect(response.status).to eq(404)
end
end
context "when enable_experimental_chat_threaded_discussions is disabled" do
before { SiteSetting.enable_experimental_chat_threaded_discussions = false }
it "returns 404" do
get "/chat/api/channels/#{thread.channel_id}/threads/#{thread.id}"
expect(response.status).to eq(404)
end
end
context "when user cannot access the channel" do
before do
thread.channel.update!(chatable: Fabricate(:private_category, group: Fabricate(:group)))
end
it "returns 403" do
get "/chat/api/channels/#{thread.channel_id}/threads/#{thread.id}"
expect(response.status).to eq(403)
end
end
context "when user cannot chat" do
before { SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:trust_level_4] }
it "returns 403" do
get "/chat/api/channels/#{thread.channel_id}/threads/#{thread.id}"
expect(response.status).to eq(403)
end
end
end
end
end