logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

note_serializer.rb (3089B)


  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.to_a.sort_by(&:id) + 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. attribute :focal_point, if: :focal_point?
  71. def type
  72. 'Document'
  73. end
  74. def name
  75. object.description
  76. end
  77. def media_type
  78. object.file_content_type
  79. end
  80. def url
  81. object.local? ? full_asset_url(object.file.url(:original, false)) : object.remote_url
  82. end
  83. def focal_point?
  84. object.file.meta.is_a?(Hash) && object.file.meta['focus'].is_a?(Hash)
  85. end
  86. def focal_point
  87. [object.file.meta['focus']['x'], object.file.meta['focus']['y']]
  88. end
  89. end
  90. class MentionSerializer < ActiveModel::Serializer
  91. attributes :type, :href, :name
  92. def type
  93. 'Mention'
  94. end
  95. def href
  96. ActivityPub::TagManager.instance.uri_for(object.account)
  97. end
  98. def name
  99. "@#{object.account.acct}"
  100. end
  101. end
  102. class TagSerializer < ActiveModel::Serializer
  103. include RoutingHelper
  104. attributes :type, :href, :name
  105. def type
  106. 'Hashtag'
  107. end
  108. def href
  109. tag_url(object)
  110. end
  111. def name
  112. "##{object.name}"
  113. end
  114. end
  115. class CustomEmojiSerializer < ActivityPub::EmojiSerializer
  116. end
  117. end