Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 8896745

Browse files
committed
DEV: Load authored pms with any bot id
1 parent c9df623 commit 8896745

File tree

3 files changed

+62
-10
lines changed

3 files changed

+62
-10
lines changed

app/controllers/discourse_ai/ai_bot/conversations_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ def index
1414
base_query =
1515
Topic
1616
.private_messages_for_user(current_user)
17+
.where(user: current_user) # Only show PMs where the current user is the author
1718
.joins(:topic_users)
1819
.where(topic_users: { user_id: bot_user_ids })
1920
.distinct
21+
2022
total = base_query.count
2123
pms = base_query.order(last_posted_at: :desc).offset(page * per_page).limit(per_page)
2224

assets/javascripts/initializers/ai-conversations-sidebar.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,11 @@ export default {
232232
}
233233

234234
const topic = api.container.lookup("controller:topic").model;
235+
// if the topic is not a private message, not created by the current user,
236+
// or doesn't have a bot response, we don't need to override sidebar
235237
if (
236238
topic?.archetype === "private_message" &&
239+
topic.user_id === currentUser.id &&
237240
topic.postStream.posts.some((post) =>
238241
isPostFromAiBot(post, currentUser)
239242
)

spec/system/ai_bot/personal_message_spec.rb renamed to spec/system/ai_bot/homepage_spec.rb

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
RSpec.describe "AI Bot - Personal Message", type: :system do
3+
RSpec.describe "AI Bot - Homepage", type: :system do
44
let(:topic_page) { PageObjects::Pages::Topic.new }
55
let(:composer) { PageObjects::Components::Composer.new }
66
let(:ai_pm_homepage) { PageObjects::Components::AiPmHomepage.new }
@@ -9,6 +9,7 @@
99
let(:dialog) { PageObjects::Components::Dialog.new }
1010

1111
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
12+
fab!(:user_2) { Fabricate(:user, refresh_auto_groups: true) }
1213

1314
fab!(:claude_2) do
1415
Fabricate(
@@ -88,15 +89,6 @@
8889
sign_in(user)
8990
end
9091

91-
it "has normal bot interaction when `ai_enable_experimental_bot_ux` is disabled" do
92-
SiteSetting.ai_enable_experimental_bot_ux = false
93-
visit "/"
94-
find(".ai-bot-button").click
95-
96-
expect(ai_pm_homepage).to have_no_homepage
97-
expect(composer).to be_opened
98-
end
99-
10092
context "when `ai_enable_experimental_bot_ux` is enabled" do
10193
it "renders landing page on bot click" do
10294
visit "/"
@@ -181,5 +173,60 @@
181173
composer.submit
182174
expect(page).to have_content("Hello bot replying to you")
183175
end
176+
177+
it "does not render custom sidebar on non-authored bot pms" do
178+
# Include user_2 in the PM by creating a new post and topic_allowed_user association
179+
Fabricate(:post, topic: pm, user: user_2, post_number: 4)
180+
Fabricate(:topic_allowed_user, topic: pm, user: user_2)
181+
sign_in(user_2)
182+
topic_page.visit_topic(pm)
183+
184+
expect(sidebar).to be_visible
185+
expect(sidebar).to have_no_section("ai-conversations-history")
186+
expect(sidebar).to have_no_css("button.ai-new-question-button")
187+
end
188+
189+
it "does not include non-authored bot pms in sidebar" do
190+
# Include user_2 in the PM by creating a new post and topic_allowed_user association
191+
Fabricate(:post, topic: pm, user: user_2, post_number: 4)
192+
Fabricate(:topic_allowed_user, topic: pm, user: user_2)
193+
sign_in(user_2)
194+
195+
visit "/"
196+
find(".ai-bot-button").click
197+
expect(ai_pm_homepage).to have_homepage
198+
expect(sidebar).to have_no_section_link(pm.title)
199+
end
200+
end
201+
202+
context "when `ai_enable_experimental_bot_ux` is disabled" do
203+
before { SiteSetting.ai_enable_experimental_bot_ux = false }
204+
205+
it "opens composer on bot click" do
206+
visit "/"
207+
find(".ai-bot-button").click
208+
209+
expect(ai_pm_homepage).to have_no_homepage
210+
expect(composer).to be_opened
211+
end
212+
213+
it "does not render sidebar when navigation menu is set to header on pm" do
214+
SiteSetting.navigation_menu = "header dropdown"
215+
topic_page.visit_topic(pm)
216+
217+
expect(ai_pm_homepage).to have_no_homepage
218+
expect(sidebar).to be_not_visible
219+
expect(header_dropdown).to be_visible
220+
end
221+
222+
it "shows default content in the sidebar" do
223+
topic_page.visit_topic(pm)
224+
225+
expect(sidebar).to have_section("categories")
226+
expect(sidebar).to have_section("messages")
227+
expect(sidebar).to have_section("chat-dms")
228+
expect(sidebar).to have_section("user-threads")
229+
expect(sidebar).to have_no_css("button.ai-new-question-button")
230+
end
184231
end
185232
end

0 commit comments

Comments
 (0)