2020-01-24 06:00:13 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class REST::AnnouncementSerializer < ActiveModel::Serializer
|
2022-03-26 10:53:34 +09:00
|
|
|
include FormattingHelper
|
|
|
|
|
2020-01-27 04:07:26 +09:00
|
|
|
attributes :id, :content, :starts_at, :ends_at, :all_day,
|
|
|
|
:published_at, :updated_at
|
2020-01-24 06:00:13 +09:00
|
|
|
|
2020-02-03 09:53:09 +09:00
|
|
|
attribute :read, if: :current_user?
|
|
|
|
|
2020-01-24 06:00:13 +09:00
|
|
|
has_many :mentions
|
2020-03-09 00:10:48 +09:00
|
|
|
has_many :statuses
|
2020-01-24 06:00:13 +09:00
|
|
|
has_many :tags, serializer: REST::StatusSerializer::TagSerializer
|
|
|
|
has_many :emojis, serializer: REST::CustomEmojiSerializer
|
|
|
|
has_many :reactions, serializer: REST::ReactionSerializer
|
|
|
|
|
2020-02-03 09:53:09 +09:00
|
|
|
def current_user?
|
|
|
|
!current_user.nil?
|
|
|
|
end
|
|
|
|
|
2020-01-24 06:00:13 +09:00
|
|
|
def id
|
|
|
|
object.id.to_s
|
|
|
|
end
|
|
|
|
|
2020-02-03 09:53:09 +09:00
|
|
|
def read
|
2024-01-25 21:37:07 +09:00
|
|
|
object.announcement_mutes.exists?(account: current_user.account)
|
2020-02-03 09:53:09 +09:00
|
|
|
end
|
|
|
|
|
2020-01-24 06:00:13 +09:00
|
|
|
def content
|
2022-03-26 10:53:34 +09:00
|
|
|
linkify(object.text)
|
2020-01-24 06:00:13 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
def reactions
|
|
|
|
object.reactions(current_user&.account)
|
|
|
|
end
|
|
|
|
|
|
|
|
class AccountSerializer < ActiveModel::Serializer
|
|
|
|
attributes :id, :username, :url, :acct
|
|
|
|
|
|
|
|
def id
|
|
|
|
object.id.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
def url
|
|
|
|
ActivityPub::TagManager.instance.url_for(object)
|
|
|
|
end
|
2020-02-04 05:16:37 +09:00
|
|
|
|
|
|
|
def acct
|
|
|
|
object.pretty_acct
|
|
|
|
end
|
2020-01-24 06:00:13 +09:00
|
|
|
end
|
2020-03-09 00:10:48 +09:00
|
|
|
|
|
|
|
class StatusSerializer < ActiveModel::Serializer
|
|
|
|
attributes :id, :url
|
|
|
|
|
|
|
|
def id
|
|
|
|
object.id.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
def url
|
|
|
|
ActivityPub::TagManager.instance.url_for(object)
|
|
|
|
end
|
|
|
|
end
|
2020-01-24 06:00:13 +09:00
|
|
|
end
|