mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 18:41:07 +08:00
FEATURE: introduces chat_max_direct_message_users
setting (#18997)
This setting limits the number of users in a direct message. 0 means you can only create a direct message with yourself. Co-authored-by: David McClure <dave@xerotrope.org>
This commit is contained in:
@ -11,6 +11,7 @@ module Chat::DirectMessageChannelCreator
|
||||
if direct_message
|
||||
chat_channel = ChatChannel.find_by!(chatable: direct_message)
|
||||
else
|
||||
enforce_max_direct_message_users!(acting_user, target_users)
|
||||
ensure_actor_can_communicate!(acting_user, target_users)
|
||||
direct_message = DirectMessage.create!(user_ids: target_users.map(&:id))
|
||||
chat_channel = direct_message.create_chat_channel!
|
||||
@ -24,6 +25,20 @@ module Chat::DirectMessageChannelCreator
|
||||
|
||||
private
|
||||
|
||||
def self.enforce_max_direct_message_users!(acting_user, target_users)
|
||||
# We never want to prevent the actor from communicating with themself.
|
||||
target_users = target_users.reject { |user| user.id == acting_user.id }
|
||||
|
||||
if !acting_user.staff? && target_users.size > SiteSetting.chat_max_direct_message_users
|
||||
raise NotAllowed.new(
|
||||
I18n.t(
|
||||
"chat.errors.over_chat_max_direct_message_users",
|
||||
count: SiteSetting.chat_max_direct_message_users + 1, # +1 for the acting_user
|
||||
),
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def self.update_memberships(acting_user, target_users, chat_channel_id)
|
||||
sql_params = {
|
||||
acting_user_id: acting_user.id,
|
||||
|
Reference in New Issue
Block a user