2022-11-02 21:41:30 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class StructuredChannelSerializer < ApplicationSerializer
|
2022-12-02 08:57:53 +08:00
|
|
|
attributes :public_channels, :direct_message_channels, :message_bus_last_ids
|
2022-11-02 21:41:30 +08:00
|
|
|
|
|
|
|
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
|
2022-12-02 08:57:53 +08:00
|
|
|
|
|
|
|
def message_bus_last_ids
|
|
|
|
last_ids = {
|
|
|
|
channel_metadata: MessageBus.last_id("/chat/channel-metadata"),
|
|
|
|
channel_edits: MessageBus.last_id("/chat/channel-edits"),
|
|
|
|
channel_status: MessageBus.last_id("/chat/channel-status"),
|
|
|
|
new_channel: MessageBus.last_id("/chat/new-channel"),
|
|
|
|
}
|
|
|
|
if !scope.anonymous?
|
|
|
|
last_ids[:user_tracking_state] = MessageBus.last_id(
|
|
|
|
"/chat/user-tracking-state/#{scope.user.id}",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
last_ids
|
|
|
|
end
|
2022-11-02 21:41:30 +08:00
|
|
|
end
|