mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Pull custom notification behaviour into its own class
This commit is contained in:
parent
305562bf66
commit
42143a874e
@ -0,0 +1,24 @@
|
|||||||
|
import { createWidgetFrom } from "discourse/widgets/widget";
|
||||||
|
import { DefaultNotificationItem } from "discourse/widgets/default-notification-item";
|
||||||
|
import { formatUsername } from "discourse/lib/utilities";
|
||||||
|
import { iconNode } from "discourse-common/lib/icon-library";
|
||||||
|
|
||||||
|
createWidgetFrom(DefaultNotificationItem, "custom-notification-item", {
|
||||||
|
title(notificationName, data) {
|
||||||
|
return data.title ? I18n.t(data.title) : "";
|
||||||
|
},
|
||||||
|
|
||||||
|
text(notificationType, notificationName) {
|
||||||
|
const { attrs } = this;
|
||||||
|
const data = attrs.data;
|
||||||
|
|
||||||
|
const username = formatUsername(data.display_username);
|
||||||
|
const description = this.description();
|
||||||
|
|
||||||
|
return I18n.t(data.message, { description, username });
|
||||||
|
},
|
||||||
|
|
||||||
|
icon(notificationName, data) {
|
||||||
|
return iconNode(`notification.${data.message}`);
|
||||||
|
}
|
||||||
|
});
|
@ -109,28 +109,20 @@ export const DefaultNotificationItem =
|
|||||||
text(notificationType, notificationName) {
|
text(notificationType, notificationName) {
|
||||||
const { attrs } = this;
|
const { attrs } = this;
|
||||||
const data = attrs.data;
|
const data = attrs.data;
|
||||||
const scope =
|
|
||||||
notificationName === "custom" ? data.message : `notifications.${notificationName}`;
|
|
||||||
|
|
||||||
const username = formatUsername(data.display_username);
|
const username = formatUsername(data.display_username);
|
||||||
const description = this.description();
|
const description = this.description();
|
||||||
|
|
||||||
return I18n.t(scope, { description, username });
|
return I18n.t(`notifications.${notificationName}`, { description, username });
|
||||||
},
|
},
|
||||||
|
|
||||||
icon(notificationName, data) {
|
icon(notificationName, data) {
|
||||||
let infoKey =
|
return iconNode(`notification.${notificationName}`);
|
||||||
notificationName === "custom" ? data.message : notificationName;
|
|
||||||
return iconNode(`notification.${infoKey}`);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
title(notificationName, data) {
|
title(notificationName, data) {
|
||||||
if (notificationName) {
|
if (notificationName) {
|
||||||
if (notificationName === "custom") {
|
|
||||||
return data.title ? I18n.t(data.title) : "";
|
|
||||||
} else {
|
|
||||||
return I18n.t(`notifications.titles.${notificationName}`);
|
return I18n.t(`notifications.titles.${notificationName}`);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user