relationship_serializer.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # frozen_string_literal: true
  2. class REST::RelationshipSerializer < ActiveModel::Serializer
  3. attributes :id, :following, :showing_reblogs, :notifying, :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 followed_by
  23. instance_options[:relationships].followed_by[object.id] || false
  24. end
  25. def blocking
  26. instance_options[:relationships].blocking[object.id] || false
  27. end
  28. def blocked_by
  29. instance_options[:relationships].blocked_by[object.id] || false
  30. end
  31. def muting
  32. instance_options[:relationships].muting[object.id] ? true : false
  33. end
  34. def muting_notifications
  35. (instance_options[:relationships].muting[object.id] || {})[:notifications] || false
  36. end
  37. def requested
  38. instance_options[:relationships].requested[object.id] ? true : false
  39. end
  40. def domain_blocking
  41. instance_options[:relationships].domain_blocking[object.id] || false
  42. end
  43. def endorsed
  44. instance_options[:relationships].endorsed[object.id] || false
  45. end
  46. def note
  47. (instance_options[:relationships].account_note[object.id] || {})[:comment] || ''
  48. end
  49. end