DEV: Prioritize full name when setting active (#15820)

Prioritize full name in these places (when setting active):
See: https://meta.discourse.org/t/display-full-name-not-username-when-attributing-quote-or-reply/203533/6 for context

- Reply to post
- Composer reply to post
- Quoting
This commit is contained in:
janzenisaac 2022-02-08 08:37:20 -06:00 committed by GitHub
parent fa9b2b4f42
commit 5a93ce421d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 90 additions and 6 deletions

View File

@ -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 (

View File

@ -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}`,
];

View File

@ -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;
}

View File

@ -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,
};
}

View File

@ -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)),
];
},

View File

@ -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]'
);
});
});

View File

@ -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) {

View File

@ -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",

View File

@ -256,6 +256,7 @@ class PostSerializer < BasicPostSerializer
def reply_to_user
{
username: object.reply_to_user.username,
name: object.reply_to_user.name,
avatar_template: object.reply_to_user.avatar_template
}
end