36 lines
1.0 KiB
Ruby
36 lines
1.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseAi
|
|
module AiBot
|
|
class ConversationsController < ::ApplicationController
|
|
requires_plugin ::DiscourseAi::PLUGIN_NAME
|
|
requires_login
|
|
|
|
def index
|
|
page = params[:page].to_i
|
|
per_page = params[:per_page]&.to_i || 40
|
|
|
|
bot_user_ids = EntryPoint.all_bot_ids
|
|
base_query =
|
|
Topic
|
|
.private_messages_for_user(current_user)
|
|
.joins(:topic_users)
|
|
.where(topic_users: { user_id: bot_user_ids })
|
|
.distinct
|
|
total = base_query.count
|
|
pms = base_query.order(last_posted_at: :desc).offset(page * per_page).limit(per_page)
|
|
|
|
render json: {
|
|
conversations: serialize_data(pms, BasicTopicSerializer),
|
|
meta: {
|
|
total: total,
|
|
page: page,
|
|
per_page: per_page,
|
|
has_more: total > (page + 1) * per_page,
|
|
},
|
|
}
|
|
end
|
|
end
|
|
end
|
|
end
|