Skip to content

Open-source live-chat, email support, omni-channel desk. An alternative to Intercom, Zendesk, Salesforce Service Cloud etc. 🔥💬

797 B
Raw Blame
class Api::V1::Accounts::Contacts::AttachmentsController < Api::V1::Accounts::Contacts::BaseController
  RESULTS_PER_PAGE = 100

  def index
    conversations = Conversations::PermissionFilterService.new(
      Current.account.conversations.where(contact_id: @contact.id),
      Current.user,
      Current.account
    ).perform

    @attachments = Attachment.where(message_id: Message.where(conversation_id: conversations).select(:id))
                             .includes({ file_attachment: :blob }, message: [:conversation, :inbox, { sender: { avatar_attachment: :blob } }])
                             .order(created_at: :desc)
                             .page(params[:page])
                             .per(RESULTS_PER_PAGE)
    @attachments_count = @attachments.total_count
  end
end