2017-04-05 17:45:18 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class InlineRenderer
|
2017-07-07 02:02:06 +00:00
|
|
|
def initialize(object, current_account, template)
|
|
|
|
@object = object
|
|
|
|
@current_account = current_account
|
|
|
|
@template = template
|
|
|
|
end
|
|
|
|
|
|
|
|
def render
|
|
|
|
case @template
|
|
|
|
when :status
|
|
|
|
serializer = REST::StatusSerializer
|
|
|
|
when :notification
|
|
|
|
serializer = REST::NotificationSerializer
|
2018-10-07 21:44:58 +00:00
|
|
|
when :conversation
|
|
|
|
serializer = REST::ConversationSerializer
|
2020-01-23 21:00:13 +00:00
|
|
|
when :announcement
|
|
|
|
serializer = REST::AnnouncementSerializer
|
|
|
|
when :reaction
|
|
|
|
serializer = REST::ReactionSerializer
|
2021-05-19 05:58:27 +00:00
|
|
|
when :emoji_reaction
|
2021-09-17 06:20:32 +00:00
|
|
|
serializer = REST::GroupedEmojiReactionSerializer
|
2020-06-02 17:24:53 +00:00
|
|
|
when :encrypted_message
|
|
|
|
serializer = REST::EncryptedMessageSerializer
|
2017-07-07 02:02:06 +00:00
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
serializable_resource = ActiveModelSerializers::SerializableResource.new(@object, serializer: serializer, scope: current_user, scope_name: :current_user)
|
|
|
|
serializable_resource.as_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.render(object, current_account, template)
|
|
|
|
new(object, current_account, template).render
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def current_user
|
|
|
|
@current_account&.user
|
2017-04-05 17:45:18 +00:00
|
|
|
end
|
|
|
|
end
|