mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 01:31:35 +08:00
FIX: Show same username or name for post notices. (#7862)
This commit is contained in:
@ -8,6 +8,7 @@ import { durationTiny } from "discourse/lib/formatter";
|
|||||||
import CanCheckEmails from "discourse/mixins/can-check-emails";
|
import CanCheckEmails from "discourse/mixins/can-check-emails";
|
||||||
import CardContentsBase from "discourse/mixins/card-contents-base";
|
import CardContentsBase from "discourse/mixins/card-contents-base";
|
||||||
import CleansUp from "discourse/mixins/cleans-up";
|
import CleansUp from "discourse/mixins/cleans-up";
|
||||||
|
import { prioritizeNameInUx } from "discourse/lib/settings";
|
||||||
|
|
||||||
export default Ember.Component.extend(
|
export default Ember.Component.extend(
|
||||||
CardContentsBase,
|
CardContentsBase,
|
||||||
@ -65,11 +66,7 @@ export default Ember.Component.extend(
|
|||||||
|
|
||||||
@computed("user.name")
|
@computed("user.name")
|
||||||
nameFirst(name) {
|
nameFirst(name) {
|
||||||
return (
|
return prioritizeNameInUx(name, this.siteSettings);
|
||||||
!this.siteSettings.prioritize_username_in_ux &&
|
|
||||||
name &&
|
|
||||||
name.trim().length > 0
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed("username")
|
@computed("username")
|
||||||
|
@ -2,6 +2,7 @@ import CanCheckEmails from "discourse/mixins/can-check-emails";
|
|||||||
import computed from "ember-addons/ember-computed-decorators";
|
import computed from "ember-addons/ember-computed-decorators";
|
||||||
import User from "discourse/models/user";
|
import User from "discourse/models/user";
|
||||||
import optionalService from "discourse/lib/optional-service";
|
import optionalService from "discourse/lib/optional-service";
|
||||||
|
import { prioritizeNameInUx } from "discourse/lib/settings";
|
||||||
|
|
||||||
export default Ember.Controller.extend(CanCheckEmails, {
|
export default Ember.Controller.extend(CanCheckEmails, {
|
||||||
indexStream: false,
|
indexStream: false,
|
||||||
@ -87,11 +88,7 @@ export default Ember.Controller.extend(CanCheckEmails, {
|
|||||||
|
|
||||||
@computed("model.name")
|
@computed("model.name")
|
||||||
nameFirst(name) {
|
nameFirst(name) {
|
||||||
return (
|
return prioritizeNameInUx(name, this.siteSettings);
|
||||||
!this.get("siteSettings.prioritize_username_in_ux") &&
|
|
||||||
name &&
|
|
||||||
name.trim().length > 0
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed("model.badge_count")
|
@computed("model.badge_count")
|
||||||
|
7
app/assets/javascripts/discourse/lib/settings.js.es6
Normal file
7
app/assets/javascripts/discourse/lib/settings.js.es6
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
export function prioritizeNameInUx(name, siteSettings) {
|
||||||
|
siteSettings = siteSettings || Discourse.SiteSettings;
|
||||||
|
|
||||||
|
return (
|
||||||
|
!siteSettings.prioritize_username_in_ux && name && name.trim().length > 0
|
||||||
|
);
|
||||||
|
}
|
@ -15,6 +15,7 @@ import {
|
|||||||
} from "discourse/lib/utilities";
|
} from "discourse/lib/utilities";
|
||||||
import hbs from "discourse/widgets/hbs-compiler";
|
import hbs from "discourse/widgets/hbs-compiler";
|
||||||
import { durationTiny } from "discourse/lib/formatter";
|
import { durationTiny } from "discourse/lib/formatter";
|
||||||
|
import { prioritizeNameInUx } from "discourse/lib/settings";
|
||||||
|
|
||||||
function transformWithCallbacks(post) {
|
function transformWithCallbacks(post) {
|
||||||
let transformed = transformBasicPost(post);
|
let transformed = transformBasicPost(post);
|
||||||
@ -454,9 +455,9 @@ createWidget("post-notice", {
|
|||||||
|
|
||||||
html(attrs) {
|
html(attrs) {
|
||||||
const user =
|
const user =
|
||||||
this.siteSettings.prioritize_username_in_ux || !attrs.name
|
this.siteSettings.display_name_on_posts && prioritizeNameInUx(attrs.name)
|
||||||
? attrs.username
|
? attrs.name
|
||||||
: attrs.name;
|
: attrs.username;
|
||||||
let text, icon;
|
let text, icon;
|
||||||
if (attrs.noticeType === "custom") {
|
if (attrs.noticeType === "custom") {
|
||||||
icon = "user-shield";
|
icon = "user-shield";
|
||||||
|
@ -2,6 +2,7 @@ import { iconNode } from "discourse-common/lib/icon-library";
|
|||||||
import { createWidget, applyDecorators } from "discourse/widgets/widget";
|
import { createWidget, applyDecorators } from "discourse/widgets/widget";
|
||||||
import { h } from "virtual-dom";
|
import { h } from "virtual-dom";
|
||||||
import { formatUsername } from "discourse/lib/utilities";
|
import { formatUsername } from "discourse/lib/utilities";
|
||||||
|
import { prioritizeNameInUx } from "discourse/lib/settings";
|
||||||
|
|
||||||
let sanitizeName = function(name) {
|
let sanitizeName = function(name) {
|
||||||
return name.toLowerCase().replace(/[\s\._-]/g, "");
|
return name.toLowerCase().replace(/[\s\._-]/g, "");
|
||||||
@ -66,9 +67,7 @@ export default createWidget("poster-name", {
|
|||||||
const name = attrs.name;
|
const name = attrs.name;
|
||||||
const nameFirst =
|
const nameFirst =
|
||||||
this.siteSettings.display_name_on_posts &&
|
this.siteSettings.display_name_on_posts &&
|
||||||
!this.siteSettings.prioritize_username_in_ux &&
|
prioritizeNameInUx(name, this.siteSettings);
|
||||||
name &&
|
|
||||||
name.trim().length > 0;
|
|
||||||
const classNames = nameFirst
|
const classNames = nameFirst
|
||||||
? ["first", "full-name"]
|
? ["first", "full-name"]
|
||||||
: ["first", "username"];
|
: ["first", "username"];
|
||||||
|
@ -875,6 +875,7 @@ widgetTest("post notice - with username", {
|
|||||||
beforeEach() {
|
beforeEach() {
|
||||||
const twoDaysAgo = new Date();
|
const twoDaysAgo = new Date();
|
||||||
twoDaysAgo.setDate(twoDaysAgo.getDate() - 2);
|
twoDaysAgo.setDate(twoDaysAgo.getDate() - 2);
|
||||||
|
this.siteSettings.display_name_on_posts = false;
|
||||||
this.siteSettings.prioritize_username_in_ux = true;
|
this.siteSettings.prioritize_username_in_ux = true;
|
||||||
this.siteSettings.old_post_notice_days = 14;
|
this.siteSettings.old_post_notice_days = 14;
|
||||||
this.set("args", {
|
this.set("args", {
|
||||||
@ -901,6 +902,7 @@ widgetTest("post notice - with username", {
|
|||||||
widgetTest("post notice - with name", {
|
widgetTest("post notice - with name", {
|
||||||
template: '{{mount-widget widget="post" args=args}}',
|
template: '{{mount-widget widget="post" args=args}}',
|
||||||
beforeEach() {
|
beforeEach() {
|
||||||
|
this.siteSettings.display_name_on_posts = true;
|
||||||
this.siteSettings.prioritize_username_in_ux = false;
|
this.siteSettings.prioritize_username_in_ux = false;
|
||||||
this.siteSettings.old_post_notice_days = 14;
|
this.siteSettings.old_post_notice_days = 14;
|
||||||
this.set("args", {
|
this.set("args", {
|
||||||
|
Reference in New Issue
Block a user