闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
986 B

  1. # frozen_string_literal: true
  2. class InlineRenderer
  3. def initialize(object, current_account, template)
  4. @object = object
  5. @current_account = current_account
  6. @template = template
  7. end
  8. def render
  9. case @template
  10. when :status
  11. serializer = REST::StatusSerializer
  12. when :notification
  13. serializer = REST::NotificationSerializer
  14. when :conversation
  15. serializer = REST::ConversationSerializer
  16. when :announcement
  17. serializer = REST::AnnouncementSerializer
  18. when :reaction
  19. serializer = REST::ReactionSerializer
  20. else
  21. return
  22. end
  23. serializable_resource = ActiveModelSerializers::SerializableResource.new(@object, serializer: serializer, scope: current_user, scope_name: :current_user)
  24. serializable_resource.as_json
  25. end
  26. def self.render(object, current_account, template)
  27. new(object, current_account, template).render
  28. end
  29. private
  30. def current_user
  31. @current_account&.user
  32. end
  33. end