Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions app/controllers/discourse_ai/ai_bot/conversations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,38 @@ class ConversationsController < ::ApplicationController
requires_login

def index
# Step 1: Retrieve all AI bot user IDs
page = params[:page]&.to_i || 0
per_page = params[:per_page]&.to_i || 40

bot_user_ids = EntryPoint.all_bot_ids

# Step 2: Query for PM topics including current_user and any bot ID
pms =
Topic
.private_messages_for_user(current_user)
.joins(:topic_users)
.where(topic_users: { user_id: bot_user_ids })
.distinct
.order(last_posted_at: :desc)
.offset(page * per_page)
.limit(per_page)

# Step 3: Serialize (empty array if no results)
serialized_pms = serialize_data(pms, BasicTopicSerializer)
total =
Topic
.private_messages_for_user(current_user)
.joins(:topic_users)
.where(topic_users: { user_id: bot_user_ids })
.distinct
.count

render json: serialized_pms, status: 200
render json: {
conversations: serialize_data(pms, BasicTopicSerializer),
meta: {
total: total,
page: page,
per_page: per_page,
more: total > (page + 1) * per_page,
},
}
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
import { service } from "@ember/service";
import DiscourseRoute from "discourse/routes/discourse";

export default class DiscourseAiBotConversationsRoute extends DiscourseRoute {
@service aiConversationsSidebarManager;

activate() {
super.activate(...arguments);
this.aiConversationsSidebarManager.forceCustomSidebar();
}

deactivate() {
super.deactivate(...arguments);
this.aiConversationsSidebarManager.stopForcingCustomSidebar();
}
}
export default class DiscourseAiBotConversationsRoute extends DiscourseRoute {}
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,24 @@ export default class AiBotConversationsHiddenSubmit extends Service {
// borrowed from ai-bot-helper.js
const draftKey = "new_private_message_ai_" + new Date().getTime();

const personaWithUsername = this.currentUser.ai_enabled_personas.find(
// For now.. find a persona with a username..
const selectedPersona = this.currentUser.ai_enabled_personas.find(
(persona) => persona.username
);

// this is a total hack, the composer is hidden on the homepage with CSS
await this.composer.open({
action: Composer.PRIVATE_MESSAGE,
draftKey,
recipients: personaWithUsername.username,
recipients: selectedPersona.username,
topicTitle: i18n("discourse_ai.ai_bot.default_pm_prefix"),
topicBody: this.inputValue,
archetypeId: "private_message",
disableDrafts: true,
});

this.composer.model.metaData = { ai_persona_id: selectedPersona.id };

try {
await this.composer.save();
if (this.inputValue.length > 10) {
Expand Down
Loading
Loading