announcement_serializer.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # frozen_string_literal: true
  2. class REST::AnnouncementSerializer < ActiveModel::Serializer
  3. attributes :id, :content, :starts_at, :ends_at, :all_day,
  4. :published_at, :updated_at
  5. attribute :read, if: :current_user?
  6. has_many :mentions
  7. has_many :statuses
  8. has_many :tags, serializer: REST::StatusSerializer::TagSerializer
  9. has_many :emojis, serializer: REST::CustomEmojiSerializer
  10. has_many :reactions, serializer: REST::ReactionSerializer
  11. def current_user?
  12. !current_user.nil?
  13. end
  14. def id
  15. object.id.to_s
  16. end
  17. def read
  18. object.announcement_mutes.where(account: current_user.account).exists?
  19. end
  20. def content
  21. Formatter.instance.linkify(object.text)
  22. end
  23. def reactions
  24. object.reactions(current_user&.account)
  25. end
  26. class AccountSerializer < ActiveModel::Serializer
  27. attributes :id, :username, :url, :acct
  28. def id
  29. object.id.to_s
  30. end
  31. def url
  32. ActivityPub::TagManager.instance.url_for(object)
  33. end
  34. def acct
  35. object.pretty_acct
  36. end
  37. end
  38. class StatusSerializer < ActiveModel::Serializer
  39. attributes :id, :url
  40. def id
  41. object.id.to_s
  42. end
  43. def url
  44. ActivityPub::TagManager.instance.url_for(object)
  45. end
  46. end
  47. end