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.

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