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

Commit f4708d4

Browse files
authored
DEV: Ai summary utilizing name instead of username (#1180)
* DEV: Ai summary utilizing name instead of username * utilize username if name not available * test added * test added 2
1 parent 833f914 commit f4708d4

File tree

2 files changed

+48
-10
lines changed

2 files changed

+48
-10
lines changed

lib/summarization/strategies/topic_summary.rb

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,28 @@ def highest_target_number
1313
end
1414

1515
def targets_data
16-
posts_data =
17-
(target.has_summary? ? best_replies : pick_selection).pluck(
18-
:post_number,
19-
:raw,
20-
:username,
21-
:last_version_at,
22-
)
23-
24-
posts_data.reduce([]) do |memo, (pn, raw, username, last_version_at)|
16+
post_attributes = %i[post_number raw username last_version_at]
17+
if SiteSetting.enable_names && !SiteSetting.prioritize_username_in_ux
18+
post_attributes.push(:name)
19+
end
20+
21+
posts_data = (target.has_summary? ? best_replies : pick_selection).pluck(post_attributes)
22+
23+
posts_data.reduce([]) do |memo, (pn, raw, username, last_version_at, name)|
2524
raw_text = raw
2625

2726
if pn == 1 && target.topic_embed&.embed_content_cache.present?
2827
raw_text = target.topic_embed&.embed_content_cache
2928
end
3029

31-
memo << { poster: username, id: pn, text: raw_text, last_version_at: last_version_at }
30+
display_name = name.presence || username
31+
32+
memo << {
33+
poster: display_name,
34+
id: pn,
35+
text: raw_text,
36+
last_version_at: last_version_at,
37+
}
3238
end
3339
end
3440

spec/lib/modules/summarization/strategies/topic_summary_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,37 @@
6161
expect(op_content).to include(topic_embed.embed_content_cache)
6262
end
6363
end
64+
65+
context "when enable_names enabled and prioritize_username_in_ux disabled" do
66+
fab!(:user) { Fabricate(:user, name: "test") }
67+
68+
it "includes the name" do
69+
SiteSetting.enable_names = true
70+
SiteSetting.prioritize_username_in_ux = false
71+
72+
post_1.update!(user: user)
73+
74+
content = topic_summary.targets_data
75+
poster_name = content.first[:poster]
76+
77+
expect(poster_name).to eq("test")
78+
end
79+
end
80+
81+
context "when enable_names enabled and prioritize_username_in_ux enabled" do
82+
fab!(:user) { Fabricate(:user, username: "test") }
83+
84+
it "includes the username" do
85+
SiteSetting.enable_names = true
86+
SiteSetting.prioritize_username_in_ux = true
87+
88+
post_1.update!(user: user)
89+
90+
content = topic_summary.targets_data
91+
poster_name = content.first[:poster]
92+
93+
expect(poster_name).to eq("test")
94+
end
95+
end
6496
end
6597
end

0 commit comments

Comments
 (0)