mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 05:01:14 +08:00
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:
@ -1,31 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "discourse_dev/record"
|
||||
require "faker"
|
||||
|
||||
module DiscourseDev
|
||||
class DirectChannel < Record
|
||||
def initialize
|
||||
super(::DirectMessage, 5)
|
||||
end
|
||||
|
||||
def data
|
||||
if Faker::Boolean.boolean(true_ratio: 0.5)
|
||||
admin_username =
|
||||
begin
|
||||
DiscourseDev::Config.new.config[:admin][:username]
|
||||
rescue StandardError
|
||||
nil
|
||||
end
|
||||
admin_user = ::User.find_by(username: admin_username) if admin_username
|
||||
end
|
||||
|
||||
[User.new.create!, admin_user || User.new.create!]
|
||||
end
|
||||
|
||||
def create!
|
||||
users = data
|
||||
Chat::DirectMessageChannelCreator.create!(acting_user: users[0], target_users: users)
|
||||
end
|
||||
end
|
||||
end
|
@ -1,30 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "discourse_dev/record"
|
||||
require "faker"
|
||||
|
||||
module DiscourseDev
|
||||
class Message < Record
|
||||
def initialize
|
||||
super(::ChatMessage, 200)
|
||||
end
|
||||
|
||||
def data
|
||||
if Faker::Boolean.boolean(true_ratio: 0.5)
|
||||
channel = ::ChatChannel.where(chatable_type: "DirectMessage").order("RANDOM()").first
|
||||
channel.user_chat_channel_memberships.update_all(following: true)
|
||||
user = channel.chatable.users.order("RANDOM()").first
|
||||
else
|
||||
membership = ::UserChatChannelMembership.order("RANDOM()").first
|
||||
channel = membership.chat_channel
|
||||
user = membership.user
|
||||
end
|
||||
|
||||
{ user: user, content: Faker::Lorem.paragraph, chat_channel: channel }
|
||||
end
|
||||
|
||||
def create!
|
||||
Chat::ChatMessageCreator.create(data)
|
||||
end
|
||||
end
|
||||
end
|
@ -1,44 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "discourse_dev/record"
|
||||
require "faker"
|
||||
|
||||
module DiscourseDev
|
||||
class PublicChannel < Record
|
||||
def initialize
|
||||
super(::CategoryChannel, 5)
|
||||
end
|
||||
|
||||
def data
|
||||
chatable = Category.random
|
||||
|
||||
{
|
||||
chatable: chatable,
|
||||
description: Faker::Lorem.paragraph,
|
||||
user_count: 1,
|
||||
name: Faker::Company.name,
|
||||
created_at: Faker::Time.between(from: DiscourseDev.config.start_date, to: DateTime.now),
|
||||
}
|
||||
end
|
||||
|
||||
def create!
|
||||
super do |channel|
|
||||
Faker::Number
|
||||
.between(from: 5, to: 10)
|
||||
.times do
|
||||
if Faker::Boolean.boolean(true_ratio: 0.5)
|
||||
admin_username =
|
||||
begin
|
||||
DiscourseDev::Config.new.config[:admin][:username]
|
||||
rescue StandardError
|
||||
nil
|
||||
end
|
||||
admin_user = ::User.find_by(username: admin_username) if admin_username
|
||||
end
|
||||
|
||||
Chat::ChatChannelMembershipManager.new(channel).follow(admin_user || User.new.create!)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user