diff --git a/lib/summarization/strategies/topic_summary.rb b/lib/summarization/strategies/topic_summary.rb index 4dfca68c5..36a304963 100644 --- a/lib/summarization/strategies/topic_summary.rb +++ b/lib/summarization/strategies/topic_summary.rb @@ -13,22 +13,28 @@ def highest_target_number end def targets_data - posts_data = - (target.has_summary? ? best_replies : pick_selection).pluck( - :post_number, - :raw, - :username, - :last_version_at, - ) - - posts_data.reduce([]) do |memo, (pn, raw, username, last_version_at)| + post_attributes = %i[post_number raw username last_version_at] + if SiteSetting.enable_names && !SiteSetting.prioritize_username_in_ux + post_attributes.push(:name) + end + + posts_data = (target.has_summary? ? best_replies : pick_selection).pluck(post_attributes) + + posts_data.reduce([]) do |memo, (pn, raw, username, last_version_at, name)| raw_text = raw if pn == 1 && target.topic_embed&.embed_content_cache.present? raw_text = target.topic_embed&.embed_content_cache end - memo << { poster: username, id: pn, text: raw_text, last_version_at: last_version_at } + display_name = name.presence || username + + memo << { + poster: display_name, + id: pn, + text: raw_text, + last_version_at: last_version_at, + } end end diff --git a/spec/lib/modules/summarization/strategies/topic_summary_spec.rb b/spec/lib/modules/summarization/strategies/topic_summary_spec.rb index 93f2c4c2c..561c6270a 100644 --- a/spec/lib/modules/summarization/strategies/topic_summary_spec.rb +++ b/spec/lib/modules/summarization/strategies/topic_summary_spec.rb @@ -61,5 +61,37 @@ expect(op_content).to include(topic_embed.embed_content_cache) end end + + context "when enable_names enabled and prioritize_username_in_ux disabled" do + fab!(:user) { Fabricate(:user, name: "test") } + + it "includes the name" do + SiteSetting.enable_names = true + SiteSetting.prioritize_username_in_ux = false + + post_1.update!(user: user) + + content = topic_summary.targets_data + poster_name = content.first[:poster] + + expect(poster_name).to eq("test") + end + end + + context "when enable_names enabled and prioritize_username_in_ux enabled" do + fab!(:user) { Fabricate(:user, username: "test") } + + it "includes the username" do + SiteSetting.enable_names = true + SiteSetting.prioritize_username_in_ux = true + + post_1.update!(user: user) + + content = topic_summary.targets_data + poster_name = content.first[:poster] + + expect(poster_name).to eq("test") + end + end end end