Skip to content

A platform for community discussion. Free, open, simple.

FIX: Ensures multi-like notifs respect `prioritize_full_name_in_ux` setting (#31292)

benj028905412636
diff --git a/app/assets/javascripts/discourse/app/lib/notification-types/liked.js b/app/assets/javascripts/discourse/app/lib/notification-types/liked.js
index aa85c85c1f5..5b805d9f931 100644
--- a/app/assets/javascripts/discourse/app/lib/notification-types/liked.js
+++ b/app/assets/javascripts/discourse/app/lib/notification-types/liked.js
@@ -1,17 +1,24 @@
import NotificationTypeBase from "discourse/lib/notification-types/base";
-import { formatUsername } from "discourse/lib/utilities";
import { i18n } from "discourse-i18n";
export default class extends NotificationTypeBase {
get label() {
+ const nameOrUsername = this.siteSettings.prioritize_full_name_in_ux
+ ? this.notification.data.display_name
+ : this.notification.data.display_username;
+
if (this.count === 2) {
+ const nameOrUsername2 = this.siteSettings.prioritize_full_name_in_ux
+ ? this.notification.data.name2
+ : this.notification.data.username2;
+
return i18n("notifications.liked_by_2_users", {
- username: this.username,
- username2: this.#username2,
+ username: nameOrUsername,
+ username2: nameOrUsername2,
});
} else if (this.count > 2) {
return i18n("notifications.liked_by_multiple_users", {
- username: this.username,
+ username: nameOrUsername,
count: this.count - 1,
});
} else {
@@ -30,8 +37,4 @@ export default class extends NotificationTypeBase {
get count() {
return this.notification.data.count;
}
-
- get #username2() {
- return formatUsername(this.notification.data.username2);
- }
}
diff --git a/app/assets/javascripts/discourse/tests/unit/lib/notification-types/liked-test.js b/app/assets/javascripts/discourse/tests/unit/lib/notification-types/liked-test.js
index fb9d73d18ae..8ff913cf66b 100644
--- a/app/assets/javascripts/discourse/tests/unit/lib/notification-types/liked-test.js
+++ b/app/assets/javascripts/discourse/tests/unit/lib/notification-types/liked-test.js
@@ -1,4 +1,4 @@
-import { getOwner } from "@ember/application";
+import { getOwner } from "@ember/owner";
import { setupTest } from "ember-qunit";
import { module, test } from "qunit";
import { deepMerge } from "discourse/lib/object";
@@ -24,8 +24,10 @@ function getNotification(overrides = {}) {
data: {
topic_title: "this is title before it becomes fancy <a>!",
username: "osama",
+ display_name: "Osama Sayegh",
display_username: "osama",
username2: "shrek",
+ name2: "Shrek McOgre",
count: 2,
},
},
@@ -73,3 +75,41 @@ module("Unit | Notification Types | liked", function (hooks) {
);
});
});
+
+module(
+ "Unit | Notification Types | liked with full name setting enabled",
+ function (hooks) {
+ setupTest(hooks);
+
+ test("label", function (assert) {
+ const siteSettings = this.owner.lookup("service:site-settings");
+ siteSettings.prioritize_full_name_in_ux = true;
+
+ const notification = getNotification();
+ const director = createRenderDirector(
+ notification,
+ "liked",
+ getOwner(this).lookup("service:site-settings")
+ );
+ notification.data.count = 2;
+ assert.strictEqual(
+ director.label,
+ i18n("notifications.liked_by_2_users", {
+ username: "Osama Sayegh",
+ username2: "Shrek McOgre",
+ }),
+ "concatenates both usernames with comma when count is 2"
+ );
+
+ notification.data.count = 3;
+ assert.strictEqual(
+ director.label,
+ i18n("notifications.liked_by_multiple_users", {
+ username: "Osama Sayegh",
+ count: 2,
+ }),
+ "concatenates 2 usernames with comma and displays the remaining count when count larger than 2"
+ );
+ });
+ }
+);