relationship_serializer.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # frozen_string_literal: true
  2. class REST::RelationshipSerializer < ActiveModel::Serializer
  3. attributes :id, :following, :showing_reblogs, :followed_by, :blocking, :blocked_by,
  4. :muting, :muting_notifications, :requested, :domain_blocking,
  5. :endorsed
  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 followed_by
  18. instance_options[:relationships].followed_by[object.id] || false
  19. end
  20. def blocking
  21. instance_options[:relationships].blocking[object.id] || false
  22. end
  23. def blocked_by
  24. instance_options[:relationships].blocked_by[object.id] || false
  25. end
  26. def muting
  27. instance_options[:relationships].muting[object.id] ? true : false
  28. end
  29. def muting_notifications
  30. (instance_options[:relationships].muting[object.id] || {})[:notifications] || false
  31. end
  32. def requested
  33. instance_options[:relationships].requested[object.id] ? true : false
  34. end
  35. def domain_blocking
  36. instance_options[:relationships].domain_blocking[object.id] || false
  37. end
  38. def endorsed
  39. instance_options[:relationships].endorsed[object.id] || false
  40. end
  41. end