discourse/plugins/chat/app/serializers/chat/chatable_group_serializer.rb
Jan Cernik f4e51e0789
FEATURE: Allow users to DM groups in chat (#25189)
Allows users to create DMs by selecting groups as a target. It also allows adding user groups to an existing chat

- When creating the channel, it expands the user group and adds all its members with chat enabled to the channel.
- After creation, there's no difference between adding a group or adding its members individually.
- Users can add multiple groups and users simultaneously.
- There are UI validations; the member count preview updates according to the member count of added groups, and it does not allow users to add more members than SiteSetting.chat_max_direct_message_users."
2024-01-19 11:09:47 -03:00

21 lines
493 B
Ruby

# frozen_string_literal: true
module Chat
class ChatableGroupSerializer < BasicGroupSerializer
attributes :chat_enabled, :chat_enabled_user_count, :can_chat
def chat_enabled
SiteSetting.chat_enabled
end
def chat_enabled_user_count
object.users.count { |user| user.user_option&.chat_enabled }
end
def can_chat
# + 1 for current user
chat_enabled && chat_enabled_user_count + 1 <= SiteSetting.chat_max_direct_message_users
end
end
end