relationship_serializer.rb 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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,
  5. :requested, :requested_by, :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 requested_by
  45. instance_options[:relationships].requested_by[object.id] ? true : false
  46. end
  47. def domain_blocking
  48. instance_options[:relationships].domain_blocking[object.id] || false
  49. end
  50. def endorsed
  51. instance_options[:relationships].endorsed[object.id] || false
  52. end
  53. def note
  54. (instance_options[:relationships].account_note[object.id] || {})[:comment] || ''
  55. end
  56. end