relationship_serializer.rb 1.9 KB

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