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.

116 lines
2.0 KiB

  1. # frozen_string_literal: true
  2. class ActivityPub::NoteSerializer < ActiveModel::Serializer
  3. attributes :id, :type, :summary, :content,
  4. :in_reply_to, :published, :url,
  5. :attributed_to, :to, :cc, :sensitive
  6. has_many :media_attachments, key: :attachment
  7. has_many :virtual_tags, key: :tag
  8. attribute :atom_uri, key: '_:atomUri', if: :local?
  9. def id
  10. ActivityPub::TagManager.instance.uri_for(object)
  11. end
  12. def type
  13. 'Note'
  14. end
  15. def summary
  16. object.spoiler_text.presence
  17. end
  18. def content
  19. Formatter.instance.format(object)
  20. end
  21. def in_reply_to
  22. ActivityPub::TagManager.instance.uri_for(object.thread) if object.reply?
  23. end
  24. def published
  25. object.created_at.iso8601
  26. end
  27. def url
  28. ActivityPub::TagManager.instance.url_for(object)
  29. end
  30. def attributed_to
  31. ActivityPub::TagManager.instance.uri_for(object.account)
  32. end
  33. def to
  34. ActivityPub::TagManager.instance.to(object)
  35. end
  36. def cc
  37. ActivityPub::TagManager.instance.cc(object)
  38. end
  39. def virtual_tags
  40. object.mentions + object.tags
  41. end
  42. def atom_uri
  43. ::TagManager.instance.uri_for(object)
  44. end
  45. def local?
  46. object.account.local?
  47. end
  48. class MediaAttachmentSerializer < ActiveModel::Serializer
  49. include RoutingHelper
  50. attributes :type, :media_type, :url
  51. def type
  52. 'Document'
  53. end
  54. def media_type
  55. object.file_content_type
  56. end
  57. def url
  58. object.local? ? full_asset_url(object.file.url(:original, false)) : object.remote_url
  59. end
  60. end
  61. class MentionSerializer < ActiveModel::Serializer
  62. attributes :type, :href, :name
  63. def type
  64. 'Mention'
  65. end
  66. def href
  67. ActivityPub::TagManager.instance.uri_for(object.account)
  68. end
  69. def name
  70. "@#{object.account.acct}"
  71. end
  72. end
  73. class TagSerializer < ActiveModel::Serializer
  74. include RoutingHelper
  75. attributes :type, :href, :name
  76. def type
  77. 'Hashtag'
  78. end
  79. def href
  80. tag_url(object)
  81. end
  82. def name
  83. "##{object.name}"
  84. end
  85. end
  86. end