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
|
|
|
|
|
2019-10-29 07:20:54 +00:00
|
|
|
def messages
|
|
|
|
return @conversation.messages if @params[:filter_internal_messages].blank?
|
|
|
|
|
|
|
|
@conversation.messages.where.not('private = ? OR message_type = ?', true, 2)
|
|
|
|
end
|
|
|
|
|
2019-08-14 09:48:44 +00:00
|
|
|
def current_messages
|
|
|
|
if @params[:before].present?
|
2019-10-29 07:20:54 +00:00
|
|
|
messages.reorder('created_at desc').where('id < ?', @params[:before]).limit(20).reverse
|
2019-08-14 09:48:44 +00:00
|
|
|
else
|
2019-10-29 07:20:54 +00:00
|
|
|
messages.reorder('created_at desc').limit(20).reverse
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|