闭社主体 forked from https://github.com/tootsuite/mastodon
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.

93 lines
2.1 KiB

  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. belongs_to :reblog, serializer: REST::StatusSerializer
  10. belongs_to :application
  11. belongs_to :account, serializer: REST::AccountSerializer
  12. has_many :media_attachments, serializer: REST::MediaAttachmentSerializer
  13. has_many :mentions
  14. has_many :tags
  15. def current_user?
  16. !current_user.nil?
  17. end
  18. def uri
  19. TagManager.instance.uri_for(object)
  20. end
  21. def content
  22. Formatter.instance.format(object)
  23. end
  24. def url
  25. TagManager.instance.url_for(object)
  26. end
  27. def favourited
  28. if instance_options && instance_options[:relationships]
  29. instance_options[:relationships].favourites_map[object.id] || false
  30. else
  31. current_user.account.favourited?(object)
  32. end
  33. end
  34. def reblogged
  35. if instance_options && instance_options[:relationships]
  36. instance_options[:relationships].reblogs_map[object.id] || false
  37. else
  38. current_user.account.reblogged?(object)
  39. end
  40. end
  41. def muted
  42. if instance_options && instance_options[:relationships]
  43. instance_options[:relationships].mutes_map[object.conversation_id] || false
  44. else
  45. current_user.account.muting_conversation?(object.conversation)
  46. end
  47. end
  48. class ApplicationSerializer < ActiveModel::Serializer
  49. attributes :name, :website
  50. end
  51. class MentionSerializer < ActiveModel::Serializer
  52. attributes :id, :username, :url, :acct
  53. def id
  54. object.account_id
  55. end
  56. def username
  57. object.account_username
  58. end
  59. def url
  60. TagManager.instance.url_for(object.account)
  61. end
  62. def acct
  63. object.account_acct
  64. end
  65. end
  66. class TagSerializer < ActiveModel::Serializer
  67. include RoutingHelper
  68. attributes :name, :url
  69. def url
  70. tag_url(object)
  71. end
  72. end
  73. end