fedibird-fe/app/serializers/rest/notification_serializer.rb
2023-02-06 16:28:37 +09:00

34 lines
838 B
Ruby

# frozen_string_literal: true
class REST::NotificationSerializer < ActiveModel::Serializer
attributes :id, :type, :created_at
belongs_to :from_account, key: :account, serializer: REST::AccountSerializer
belongs_to :target_status, key: :status, if: :status_type?, serializer: REST::StatusSerializer
belongs_to :emoji_reaction, if: :emoji_reaction?
attribute :reblog_visibility, if: :reblog?
def id
object.id.to_s
end
def status_type?
[:favourite, :reblog, :status, :mention, :poll, :emoji_reaction, :status_reference, :scheduled_status].include?(object.type)
end
def reblog?
object.type == :reblog
end
def emoji_reaction?
object.type == :emoji_reaction
end
class EmojiReactionSerializer < REST::GroupedEmojiReactionSerializer
attributes :me
def me
false
end
end
end