discourse/plugins/chat/app/serializers/structured_channel_serializer.rb
Roman Rizzi 0a5f548635
DEV: Move discourse-chat to the core repo. (#18776)
As part of this move, we are also renaming `discourse-chat` to `chat`.
2022-11-02 10:41:30 -03:00

33 lines
796 B
Ruby

# frozen_string_literal: true
class StructuredChannelSerializer < ApplicationSerializer
attributes :public_channels, :direct_message_channels
def public_channels
object[:public_channels].map do |channel|
ChatChannelSerializer.new(
channel,
root: nil,
scope: scope,
membership: channel_membership(channel.id),
)
end
end
def direct_message_channels
object[:direct_message_channels].map do |channel|
ChatChannelSerializer.new(
channel,
root: nil,
scope: scope,
membership: channel_membership(channel.id),
)
end
end
def channel_membership(channel_id)
return if scope.anonymous?
object[:memberships].find { |membership| membership.chat_channel_id == channel_id }
end
end