1
0

relationship_serializer.rb 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # frozen_string_literal: true
  2. class REST::RelationshipSerializer < ActiveModel::Serializer
  3. # Please update `app/javascript/mastodon/api_types/relationships.ts` when making changes to the attributes
  4. attributes :id, :following, :showing_reblogs, :notifying, :languages, :followed_by,
  5. :blocking, :blocked_by, :muting, :muting_notifications,
  6. :requested, :requested_by, :domain_blocking, :endorsed, :note
  7. def id
  8. object.id.to_s
  9. end
  10. def following
  11. instance_options[:relationships].following[object.id] ? true : false
  12. end
  13. def showing_reblogs
  14. (instance_options[:relationships].following[object.id] || {})[:reblogs] ||
  15. (instance_options[:relationships].requested[object.id] || {})[:reblogs] ||
  16. false
  17. end
  18. def notifying
  19. (instance_options[:relationships].following[object.id] || {})[:notify] ||
  20. (instance_options[:relationships].requested[object.id] || {})[:notify] ||
  21. false
  22. end
  23. def languages
  24. (instance_options[:relationships].following[object.id] || {})[:languages] ||
  25. (instance_options[:relationships].requested[object.id] || {})[:languages]
  26. end
  27. def followed_by
  28. instance_options[:relationships].followed_by[object.id] || false
  29. end
  30. def blocking
  31. instance_options[:relationships].blocking[object.id] || false
  32. end
  33. def blocked_by
  34. instance_options[:relationships].blocked_by[object.id] || false
  35. end
  36. def muting
  37. instance_options[:relationships].muting[object.id] ? true : false
  38. end
  39. def muting_notifications
  40. (instance_options[:relationships].muting[object.id] || {})[:notifications] || false
  41. end
  42. def requested
  43. instance_options[:relationships].requested[object.id] ? true : false
  44. end
  45. def requested_by
  46. instance_options[:relationships].requested_by[object.id] ? true : false
  47. end
  48. def domain_blocking
  49. instance_options[:relationships].domain_blocking[object.id] || false
  50. end
  51. def endorsed
  52. instance_options[:relationships].endorsed[object.id] || false
  53. end
  54. def note
  55. (instance_options[:relationships].account_note[object.id] || {})[:comment] || ''
  56. end
  57. end