Chatwoot/app/finders/message_finder.rb
Sojan Jose 8d2b719dc1
chore: Sentry issues (#4623)
Fixes various issues reported on sentry

- Twilio channel creation validation errors
- Room Channel error with nil class
- Webhook Uri exception
2022-05-06 14:50:55 +05:30

30 lines
730 B
Ruby

class MessageFinder
def initialize(conversation, params)
@conversation = conversation
@params = params
end
def perform
current_messages
end
private
def conversation_messages
@conversation.messages.includes(:attachments, :sender, sender: { avatar_attachment: [:blob] })
end
def messages
return conversation_messages if @params[:filter_internal_messages].blank?
conversation_messages.where.not('private = ? OR message_type = ?', true, 2)
end
def current_messages
if @params[:before].present?
messages.reorder('created_at desc').where('id < ?', @params[:before].to_i).limit(20).reverse
else
messages.reorder('created_at desc').limit(20).reverse
end
end
end