2017-04-05 19:45:18 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class InlineRenderer
|
2017-07-07 04:02:06 +02: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
|
2022-11-04 13:21:06 +01:00
|
|
|
preload_associations_for_status
|
2017-07-07 04:02:06 +02:00
|
|
|
when :notification
|
|
|
|
serializer = REST::NotificationSerializer
|
2018-10-07 23:44:58 +02:00
|
|
|
when :conversation
|
|
|
|
serializer = REST::ConversationSerializer
|
2020-01-23 22:00:13 +01:00
|
|
|
when :announcement
|
|
|
|
serializer = REST::AnnouncementSerializer
|
|
|
|
when :reaction
|
|
|
|
serializer = REST::ReactionSerializer
|
2020-06-02 19:24:53 +02:00
|
|
|
when :encrypted_message
|
|
|
|
serializer = REST::EncryptedMessageSerializer
|
2017-07-07 04:02:06 +02: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
|
|
|
|
|
2022-11-04 13:21:06 +01:00
|
|
|
def preload_associations_for_status
|
2023-07-13 09:36:07 +02:00
|
|
|
ActiveRecord::Associations::Preloader.new(records: @object, associations: {
|
2022-11-04 13:21:06 +01:00
|
|
|
active_mentions: :account,
|
|
|
|
|
|
|
|
reblog: {
|
|
|
|
active_mentions: :account,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2017-07-07 04:02:06 +02:00
|
|
|
def current_user
|
|
|
|
@current_account&.user
|
2017-04-05 19:45:18 +02:00
|
|
|
end
|
|
|
|
end
|