diff --git a/app/controllers/api/v1/accounts/conversations_controller.rb b/app/controllers/api/v1/accounts/conversations_controller.rb index 2cd5281ff..138c2bd68 100644 --- a/app/controllers/api/v1/accounts/conversations_controller.rb +++ b/app/controllers/api/v1/accounts/conversations_controller.rb @@ -6,6 +6,8 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro before_action :conversation, except: [:index, :meta, :search, :create, :filter] before_action :inbox, :contact, :contact_inbox, only: [:create] + ATTACHMENT_RESULTS_PER_PAGE = 100 + def index result = conversation_finder.perform @conversations = result[:conversations] @@ -24,7 +26,12 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro end def attachments + @attachments_count = @conversation.attachments.count @attachments = @conversation.attachments + .includes(:message) + .order(created_at: :desc) + .page(attachment_params[:page]) + .per(ATTACHMENT_RESULTS_PER_PAGE) end def show; end @@ -124,6 +131,10 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro params.permit(:priority) end + def attachment_params + params.permit(:page) + end + def update_last_seen_on_conversation(last_seen_at, update_assignee) # rubocop:disable Rails/SkipsModelValidations @conversation.update_column(:agent_last_seen_at, last_seen_at) diff --git a/app/views/api/v1/accounts/conversations/attachments.json.jbuilder b/app/views/api/v1/accounts/conversations/attachments.json.jbuilder index 068462d54..167b18390 100644 --- a/app/views/api/v1/accounts/conversations/attachments.json.jbuilder +++ b/app/views/api/v1/accounts/conversations/attachments.json.jbuilder @@ -1,3 +1,7 @@ +json.meta do + json.total_count @attachments_count +end + json.payload @attachments do |attachment| json.message_id attachment.push_event_data[:message_id] json.thumb_url attachment.push_event_data[:thumb_url]