announcement_serializer.rb 1.2 KB

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