闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.2 KiB

  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. object.text
  22. #Formatter.instance.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