2020-01-23 21:00:13 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class REST::AnnouncementSerializer < ActiveModel::Serializer
|
2020-01-26 19:07:26 +00:00
|
|
|
attributes :id, :content, :starts_at, :ends_at, :all_day,
|
|
|
|
:published_at, :updated_at
|
2020-01-23 21:00:13 +00:00
|
|
|
|
2020-02-03 00:53:09 +00:00
|
|
|
attribute :read, if: :current_user?
|
|
|
|
|
2020-01-23 21:00:13 +00:00
|
|
|
has_many :mentions
|
|
|
|
has_many :tags, serializer: REST::StatusSerializer::TagSerializer
|
|
|
|
has_many :emojis, serializer: REST::CustomEmojiSerializer
|
|
|
|
has_many :reactions, serializer: REST::ReactionSerializer
|
|
|
|
|
2020-02-03 00:53:09 +00:00
|
|
|
def current_user?
|
|
|
|
!current_user.nil?
|
|
|
|
end
|
|
|
|
|
2020-01-23 21:00:13 +00:00
|
|
|
def id
|
|
|
|
object.id.to_s
|
|
|
|
end
|
|
|
|
|
2020-02-03 00:53:09 +00:00
|
|
|
def read
|
|
|
|
object.announcement_mutes.where(account: current_user.account).exists?
|
|
|
|
end
|
|
|
|
|
2020-01-23 21:00:13 +00:00
|
|
|
def content
|
|
|
|
Formatter.instance.linkify(object.text)
|
|
|
|
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-03 20:16:37 +00:00
|
|
|
|
|
|
|
def acct
|
|
|
|
object.pretty_acct
|
|
|
|
end
|
2020-01-23 21:00:13 +00:00
|
|
|
end
|
|
|
|
end
|