mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-07-01 12:02:16 +00:00
38 lines
1.1 KiB
Ruby
38 lines
1.1 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)
|
||
|
.where(user: current_user) # Only show PMs where the current user is the author
|
||
|
.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
|