DEV: properly namespace chat (#20690)

This commit main goal was to comply with Zeitwerk and properly rely on autoloading. To achieve this, most resources have been namespaced under the `Chat` module.

- Given all models are now namespaced with `Chat::` and would change the stored types in DB when using polymorphism or STI (single table inheritance), this commit uses various Rails methods to ensure proper class is loaded and the stored name in DB is unchanged, eg: `Chat::Message` model will be stored as `"ChatMessage"`, and `"ChatMessage"` will correctly load `Chat::Message` model.
- Jobs are now using constants only, eg: `Jobs::Chat::Foo` and should only be enqueued this way

Notes:
- This commit also used this opportunity to limit the number of registered css files in plugin.rb
- `discourse_dev` support has been removed within this commit and will be reintroduced later

<!-- NOTE: All pull requests should have tests (rspec in Ruby, qunit in JavaScript). If your code does not include test coverage, please include an explanation of why it was omitted. -->
This commit is contained in:
Joffrey JAFFEUX
2023-03-17 14:24:38 +01:00
committed by GitHub
parent 74349e17c9
commit 12a18d4d55
343 changed files with 9077 additions and 8745 deletions

View File

@ -2,7 +2,7 @@
require "rails_helper"
describe ChatChannelMembershipsQuery do
describe Chat::ChannelMembershipsQuery do
fab!(:user_1) { Fabricate(:user, username: "Aline", name: "Boetie") }
fab!(:user_2) { Fabricate(:user, username: "Bertrand", name: "Arlan") }
@ -23,8 +23,16 @@ describe ChatChannelMembershipsQuery do
context "when memberships exist" do
before do
UserChatChannelMembership.create(user: user_1, chat_channel: channel_1, following: true)
UserChatChannelMembership.create(user: user_2, chat_channel: channel_1, following: true)
Chat::UserChatChannelMembership.create(
user: user_1,
chat_channel: channel_1,
following: true,
)
Chat::UserChatChannelMembership.create(
user: user_2,
chat_channel: channel_1,
following: true,
)
end
it "returns the memberships" do
@ -45,7 +53,11 @@ describe ChatChannelMembershipsQuery do
context "when membership exists" do
before do
UserChatChannelMembership.create(user: user_1, chat_channel: channel_1, following: true)
Chat::UserChatChannelMembership.create(
user: user_1,
chat_channel: channel_1,
following: true,
)
end
it "lists the user" do
@ -89,7 +101,11 @@ describe ChatChannelMembershipsQuery do
context "when user is not in group" do
context "when membership exists" do
before do
UserChatChannelMembership.create(user: user_1, chat_channel: channel_1, following: true)
Chat::UserChatChannelMembership.create(
user: user_1,
chat_channel: channel_1,
following: true,
)
end
it "doesn’t list the user" do
@ -135,8 +151,16 @@ describe ChatChannelMembershipsQuery do
fab!(:channel_1) { Fabricate(:category_channel) }
before do
UserChatChannelMembership.create(user: user_1, chat_channel: channel_1, following: true)
UserChatChannelMembership.create(user: user_2, chat_channel: channel_1, following: true)
Chat::UserChatChannelMembership.create(
user: user_1,
chat_channel: channel_1,
following: true,
)
Chat::UserChatChannelMembership.create(
user: user_2,
chat_channel: channel_1,
following: true,
)
end
describe "offset param" do
@ -160,8 +184,16 @@ describe ChatChannelMembershipsQuery do
fab!(:channel_1) { Fabricate(:category_channel) }
before do
UserChatChannelMembership.create(user: user_1, chat_channel: channel_1, following: true)
UserChatChannelMembership.create(user: user_2, chat_channel: channel_1, following: true)
Chat::UserChatChannelMembership.create(
user: user_1,
chat_channel: channel_1,
following: true,
)
Chat::UserChatChannelMembership.create(
user: user_2,
chat_channel: channel_1,
following: true,
)
end
it "filters the results" do
@ -176,8 +208,16 @@ describe ChatChannelMembershipsQuery do
fab!(:channel_1) { Fabricate(:category_channel) }
before do
UserChatChannelMembership.create(user: user_1, chat_channel: channel_1, following: true)
UserChatChannelMembership.create(user: user_2, chat_channel: channel_1, following: true)
Chat::UserChatChannelMembership.create(
user: user_1,
chat_channel: channel_1,
following: true,
)
Chat::UserChatChannelMembership.create(
user: user_2,
chat_channel: channel_1,
following: true,
)
end
context "when prioritizes username in ux is enabled" do
@ -220,7 +260,11 @@ describe ChatChannelMembershipsQuery do
fab!(:staged_user) { Fabricate(:staged) }
before do
UserChatChannelMembership.create(user: staged_user, chat_channel: channel_1, following: true)
Chat::UserChatChannelMembership.create(
user: staged_user,
chat_channel: channel_1,
following: true,
)
end
it "doesn’t list staged users" do
@ -236,7 +280,7 @@ describe ChatChannelMembershipsQuery do
end
before do
UserChatChannelMembership.create(
Chat::UserChatChannelMembership.create(
user: suspended_user,
chat_channel: channel_1,
following: true,
@ -254,7 +298,7 @@ describe ChatChannelMembershipsQuery do
fab!(:inactive_user) { Fabricate(:inactive_user) }
before do
UserChatChannelMembership.create(
Chat::UserChatChannelMembership.create(
user: inactive_user,
chat_channel: channel_1,
following: true,

View File

@ -2,7 +2,7 @@
require "rails_helper"
describe ChatChannelUnreadsQuery do
describe Chat::ChannelUnreadsQuery do
fab!(:channel_1) { Fabricate(:category_channel) }
fab!(:current_user) { Fabricate(:user) }
@ -33,7 +33,7 @@ describe ChatChannelUnreadsQuery do
user_id: current_user.id,
data: { chat_message_id: message.id, chat_channel_id: channel_1.id }.to_json,
)
ChatMention.create!(notification: notification, user: current_user, chat_message: message)
Chat::Mention.create!(notification: notification, user: current_user, chat_message: message)
expect(described_class.call(channel_id: channel_1.id, user_id: current_user.id)).to eq(
{ mention_count: 1, unread_count: 0 },