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.

147 lines
2.8 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. :atom_uri, :in_reply_to_atom_uri,
  7. :conversation
  8. has_many :media_attachments, key: :attachment
  9. has_many :virtual_tags, key: :tag
  10. def id
  11. ActivityPub::TagManager.instance.uri_for(object)
  12. end
  13. def type
  14. 'Note'
  15. end
  16. def summary
  17. object.spoiler_text.presence
  18. end
  19. def content
  20. Formatter.instance.format(object)
  21. end
  22. def in_reply_to
  23. return unless object.reply? && !object.thread.nil?
  24. if object.thread.uri.nil? || object.thread.uri.start_with?('http')
  25. ActivityPub::TagManager.instance.uri_for(object.thread)
  26. else
  27. object.thread.url
  28. end
  29. end
  30. def published
  31. object.created_at.iso8601
  32. end
  33. def url
  34. ActivityPub::TagManager.instance.url_for(object)
  35. end
  36. def attributed_to
  37. ActivityPub::TagManager.instance.uri_for(object.account)
  38. end
  39. def to
  40. ActivityPub::TagManager.instance.to(object)
  41. end
  42. def cc
  43. ActivityPub::TagManager.instance.cc(object)
  44. end
  45. def virtual_tags
  46. object.mentions + object.tags + object.emojis
  47. end
  48. def atom_uri
  49. return unless object.local?
  50. OStatus::TagManager.instance.uri_for(object)
  51. end
  52. def in_reply_to_atom_uri
  53. return unless object.reply? && !object.thread.nil?
  54. OStatus::TagManager.instance.uri_for(object.thread)
  55. end
  56. def conversation
  57. return if object.conversation.nil?
  58. if object.conversation.uri?
  59. object.conversation.uri
  60. else
  61. OStatus::TagManager.instance.unique_tag(object.conversation.created_at, object.conversation.id, 'Conversation')
  62. end
  63. end
  64. def local?
  65. object.account.local?
  66. end
  67. class MediaAttachmentSerializer < ActiveModel::Serializer
  68. include RoutingHelper
  69. attributes :type, :media_type, :url, :name
  70. def type
  71. 'Document'
  72. end
  73. def name
  74. object.description
  75. end
  76. def media_type
  77. object.file_content_type
  78. end
  79. def url
  80. object.local? ? full_asset_url(object.file.url(:original, false)) : object.remote_url
  81. end
  82. end
  83. class MentionSerializer < ActiveModel::Serializer
  84. attributes :type, :href, :name
  85. def type
  86. 'Mention'
  87. end
  88. def href
  89. ActivityPub::TagManager.instance.uri_for(object.account)
  90. end
  91. def name
  92. "@#{object.account.acct}"
  93. end
  94. end
  95. class TagSerializer < ActiveModel::Serializer
  96. include RoutingHelper
  97. attributes :type, :href, :name
  98. def type
  99. 'Hashtag'
  100. end
  101. def href
  102. tag_url(object)
  103. end
  104. def name
  105. "##{object.name}"
  106. end
  107. end
  108. class CustomEmojiSerializer < ActivityPub::EmojiSerializer
  109. end
  110. end