2019-08-14 09:48:44 +00:00
|
|
|
class MessageFinder
|
|
|
|
def initialize(conversation, params)
|
|
|
|
@conversation = conversation
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def perform
|
|
|
|
current_messages
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def current_messages
|
|
|
|
if @params[:before].present?
|
2019-10-20 08:47:26 +00:00
|
|
|
@conversation.messages.reorder('created_at desc').where('id < ?', @params[:before]).limit(20).reverse
|
2019-08-14 09:48:44 +00:00
|
|
|
else
|
|
|
|
@conversation.messages.reorder('created_at desc').limit(20).reverse
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|