A platform for community discussion. Free, open, simple.
DEV: Prioritize full name when setting active (#15820)
janzenisaac5a93ce421da4
diff --git a/app/assets/javascripts/discourse/app/components/quote-button.js b/app/assets/javascripts/discourse/app/components/quote-button.jsindex a8a4de73de5..0f739d3298e 100644--- a/app/assets/javascripts/discourse/app/components/quote-button.js+++ b/app/assets/javascripts/discourse/app/components/quote-button.js@@ -173,6 +173,9 @@ export default Component.extend(KeyEnterEscape, {selectedRange().startOffset > 0? false: _selectedText === toMarkdown(cooked.innerHTML),+ displayName:+ this.siteSettings.display_name_on_posts &&+ !this.siteSettings.prioritize_username_in_ux,};for (diff --git a/app/assets/javascripts/discourse/app/lib/quote.js b/app/assets/javascripts/discourse/app/lib/quote.jsindex d965833a6ee..650223acbde 100644--- a/app/assets/javascripts/discourse/app/lib/quote.js+++ b/app/assets/javascripts/discourse/app/lib/quote.js@@ -6,8 +6,12 @@ export function buildQuote(post, contents, opts = {}) {return "";}+ const name = opts.displayName+ ? opts.name || post.name+ : opts.username || post.username;+const params = [- opts.username || post.username,+ name,`post:${opts.post || post.post_number}`,`topic:${opts.topic || post.topic_id}`,];diff --git a/app/assets/javascripts/discourse/app/lib/transform-post.js b/app/assets/javascripts/discourse/app/lib/transform-post.jsindex 37a1e4940f4..14244853de7 100644--- a/app/assets/javascripts/discourse/app/lib/transform-post.js+++ b/app/assets/javascripts/discourse/app/lib/transform-post.js@@ -74,6 +74,7 @@ export function transformBasicPost(post) {actionsSummary: null,read: post.read,replyToUsername: null,+ replyToName: null,replyToAvatarTemplate: null,reply_to_post_number: post.reply_to_post_number,cooked_hidden: !!post.cooked_hidden,@@ -227,6 +228,7 @@ export default function transformPost(const replyToUser = post.get("reply_to_user");if (replyToUser) {postAtts.replyToUsername = replyToUser.username;+ postAtts.replyToName = replyToUser.name;postAtts.replyToAvatarTemplate = replyToUser.avatar_template;}diff --git a/app/assets/javascripts/discourse/app/models/composer.js b/app/assets/javascripts/discourse/app/models/composer.jsindex 4f9194b414d..259149c11bb 100644--- a/app/assets/javascripts/discourse/app/models/composer.js+++ b/app/assets/javascripts/discourse/app/models/composer.js@@ -23,6 +23,7 @@ import deprecated from "discourse-common/lib/deprecated";import { isEmpty } from "@ember/utils";import { propertyNotEqual } from "discourse/lib/computed";import { throwAjaxError } from "discourse/lib/ajax-error";+import { prioritizeNameInUx } from "discourse/lib/settings";let _customizations = [];export function registerCustomizationCallback(cb) {@@ -356,6 +357,10 @@ const Composer = RestModel.extend({if (topic && post) {const postNumber = post.post_number;+ const name =+ this.siteSettings.display_name_on_posts && prioritizeNameInUx(post.name)+ ? post.name+ : post.username;options.postLink = {href: `${topic.url}/${postNumber}`,@@ -364,7 +369,7 @@ const Composer = RestModel.extend({options.userLink = {href: `${topic.url}/${postNumber}`,- anchor: post.username,+ anchor: name,};}diff --git a/app/assets/javascripts/discourse/app/widgets/post.js b/app/assets/javascripts/discourse/app/widgets/post.jsindex ca41e8eabed..889e66dd905 100644--- a/app/assets/javascripts/discourse/app/widgets/post.js+++ b/app/assets/javascripts/discourse/app/widgets/post.js@@ -134,16 +134,21 @@ createWidget("reply-to-tab", {html(attrs, state) {const icon = state.loading ? h("div.spinner.small") : iconNode("share");+ const name =+ this.siteSettings.display_name_on_posts &&+ prioritizeNameInUx(attrs.replyToName)+ ? attrs.replyToName+ : attrs.replyToUsername;return [icon," ",avatarImg("small", {template: attrs.replyToAvatarTemplate,- username: attrs.replyToUsername,+ username: name,})," ",- h("span", formatUsername(attrs.replyToUsername)),+ h("span", formatUsername(name)),];},diff --git a/app/assets/javascripts/discourse/tests/acceptance/composer-actions-test.js b/app/assets/javascripts/discourse/tests/acceptance/composer-actions-test.jsindex acc54f4a38e..a289708080f 100644--- a/app/assets/javascripts/discourse/tests/acceptance/composer-actions-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/composer-actions-test.js@@ -4,6 +4,7 @@ import {exists,query,queryAll,+ selectText,updateCurrentUser,} from "discourse/tests/helpers/qunit-helpers";import { click, fillIn, visit } from "@ember/test-helpers";@@ -18,7 +19,11 @@ import { toggleCheckDraftPopup } from "discourse/controllers/composer";acceptance("Composer Actions", function (needs) {needs.user();- needs.settings({ enable_whispers: true });+ needs.settings({+ prioritize_username_in_ux: true,+ display_name_on_post: false,+ enable_whispers: true,+ });needs.site({ can_tag_topics: true });test("creating new topic and then reply_as_private_message keeps attributes", async function (assert) {@@ -551,3 +556,59 @@ acceptance("Composer Actions With New Topic Draft", function (needs) {sinon.restore();});});++acceptance("Prioritize Username", function (needs) {+ needs.user();+ needs.settings({+ prioritize_username_in_ux: true,+ display_name_on_post: false,+ });++ test("Reply to post use username", async function (assert) {+ await visit("/t/internationalization-localization/280");+ await click("article#post_3 button.reply");++ assert.strictEqual(+ queryAll(".action-title .user-link").text().trim(),+ "codinghorror"+ );+ });++ test("Quotes use username", async function (assert) {+ await visit("/t/internationalization-localization/280");+ await selectText("#post_3 p");+ await click(".insert-quote");+ assert.strictEqual(+ queryAll(".d-editor-input").val().trim(),+ '[quote="codinghorror, post:3, topic:280"]\nYep, all strings are going through a lookup table.*\n[/quote]'+ );+ });+});++acceptance("Prioritize Full Name", function (needs) {+ needs.user();+ needs.settings({+ prioritize_username_in_ux: false,+ display_name_on_post: true,+ });++ test("Reply to post use full name", async function (assert) {+ await visit("/t/internationalization-localization/280");+ await click("article#post_3 button.reply");++ assert.strictEqual(+ queryAll(".action-title .user-link").text().trim(),+ "Jeff Atwood"+ );+ });++ test("Quotes use full name", async function (assert) {+ await visit("/t/internationalization-localization/280");+ await selectText("#post_3 p");+ await click(".insert-quote");+ assert.strictEqual(+ queryAll(".d-editor-input").val().trim(),+ '[quote="Jeff Atwood, post:3, topic:280"]\nYep, all strings are going through a lookup table.*\n[/quote]'+ );+ });+});diff --git a/app/assets/javascripts/discourse/tests/acceptance/topic-quote-button-test.js b/app/assets/javascripts/discourse/tests/acceptance/topic-quote-button-test.jsindex 6c9c7bb9c25..c156488a3b3 100644--- a/app/assets/javascripts/discourse/tests/acceptance/topic-quote-button-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/topic-quote-button-test.js@@ -13,10 +13,11 @@ import { test } from "qunit";acceptance("Topic - Quote button - logged in", function (needs) {needs.user();needs.settings({+ display_name_on_posts: false,+ prioritize_username_in_ux: true,share_quote_visibility: "anonymous",share_quote_buttons: "twitter|email",});-chromeTest("Does not show the quote share buttons by default",async function (assert) {diff --git a/app/assets/javascripts/discourse/tests/acceptance/topic-test.js b/app/assets/javascripts/discourse/tests/acceptance/topic-test.jsindex da2305ba7d1..db7d8e6ed10 100644--- a/app/assets/javascripts/discourse/tests/acceptance/topic-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/topic-test.js@@ -241,6 +241,8 @@ acceptance("Topic", function (needs) {acceptance("Topic featured links", function (needs) {needs.user();needs.settings({+ display_name_on_posts: false,+ prioritize_username_in_ux: true,topic_featured_link_enabled: true,max_topic_title_length: 80,exclude_rel_nofollow_domains: "example.com",diff --git a/app/serializers/post_serializer.rb b/app/serializers/post_serializer.rbindex 2a2eec117b6..bbab210afde 100644--- a/app/serializers/post_serializer.rb+++ b/app/serializers/post_serializer.rb@@ -256,6 +256,7 @@ class PostSerializer < BasicPostSerializerdef reply_to_user{username: object.reply_to_user.username,+ name: object.reply_to_user.name,avatar_template: object.reply_to_user.avatar_template}end