logo

mastofe

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

status_serializer.rb (2915B)


  1. # frozen_string_literal: true
  2. class REST::StatusSerializer < ActiveModel::Serializer
  3. attributes :id, :created_at, :in_reply_to_id, :in_reply_to_account_id,
  4. :sensitive, :spoiler_text, :visibility, :language,
  5. :uri, :content, :url, :reblogs_count, :favourites_count
  6. attribute :favourited, if: :current_user?
  7. attribute :reblogged, if: :current_user?
  8. attribute :muted, if: :current_user?
  9. attribute :pinned, if: :pinnable?
  10. belongs_to :reblog, serializer: REST::StatusSerializer
  11. belongs_to :application
  12. belongs_to :account, serializer: REST::AccountSerializer
  13. has_many :media_attachments, serializer: REST::MediaAttachmentSerializer
  14. has_many :ordered_mentions, key: :mentions
  15. has_many :tags
  16. has_many :emojis, serializer: REST::CustomEmojiSerializer
  17. def id
  18. object.id.to_s
  19. end
  20. def in_reply_to_id
  21. object.in_reply_to_id&.to_s
  22. end
  23. def in_reply_to_account_id
  24. object.in_reply_to_account_id&.to_s
  25. end
  26. def current_user?
  27. !current_user.nil?
  28. end
  29. def uri
  30. OStatus::TagManager.instance.uri_for(object)
  31. end
  32. def content
  33. Formatter.instance.format(object)
  34. end
  35. def url
  36. TagManager.instance.url_for(object)
  37. end
  38. def favourited
  39. if instance_options && instance_options[:relationships]
  40. instance_options[:relationships].favourites_map[object.id] || false
  41. else
  42. current_user.account.favourited?(object)
  43. end
  44. end
  45. def reblogged
  46. if instance_options && instance_options[:relationships]
  47. instance_options[:relationships].reblogs_map[object.id] || false
  48. else
  49. current_user.account.reblogged?(object)
  50. end
  51. end
  52. def muted
  53. if instance_options && instance_options[:relationships]
  54. instance_options[:relationships].mutes_map[object.conversation_id] || false
  55. else
  56. current_user.account.muting_conversation?(object.conversation)
  57. end
  58. end
  59. def pinned
  60. if instance_options && instance_options[:relationships]
  61. instance_options[:relationships].pins_map[object.id] || false
  62. else
  63. current_user.account.pinned?(object)
  64. end
  65. end
  66. def pinnable?
  67. current_user? &&
  68. current_user.account_id == object.account_id &&
  69. !object.reblog? &&
  70. %w(public unlisted).include?(object.visibility)
  71. end
  72. def ordered_mentions
  73. object.mentions.to_a.sort_by(&:id)
  74. end
  75. class ApplicationSerializer < ActiveModel::Serializer
  76. attributes :name, :website
  77. end
  78. class MentionSerializer < ActiveModel::Serializer
  79. attributes :id, :username, :url, :acct
  80. def id
  81. object.account_id.to_s
  82. end
  83. def username
  84. object.account_username
  85. end
  86. def url
  87. TagManager.instance.url_for(object.account)
  88. end
  89. def acct
  90. object.account_acct
  91. end
  92. end
  93. class TagSerializer < ActiveModel::Serializer
  94. include RoutingHelper
  95. attributes :name, :url
  96. def url
  97. tag_url(object)
  98. end
  99. end
  100. end