reaction_serializer.rb 591 B

12345678910111213141516171819202122232425262728293031
  1. # frozen_string_literal: true
  2. class REST::ReactionSerializer < ActiveModel::Serializer
  3. include RoutingHelper
  4. attributes :name, :count
  5. attribute :me, if: :current_user?
  6. attribute :url, if: :custom_emoji?
  7. attribute :static_url, if: :custom_emoji?
  8. def count
  9. object.respond_to?(:count) ? object.count : 0
  10. end
  11. def current_user?
  12. !current_user.nil?
  13. end
  14. def custom_emoji?
  15. object.custom_emoji.present?
  16. end
  17. def url
  18. full_asset_url(object.custom_emoji.image.url)
  19. end
  20. def static_url
  21. full_asset_url(object.custom_emoji.image.url(:static))
  22. end
  23. end