Pull custom notification behaviour into its own class

This commit is contained in:
Daniel Waterworth 2019-06-07 07:27:30 +01:00 committed by Robin Ward
parent 305562bf66
commit 42143a874e
2 changed files with 27 additions and 11 deletions

View File

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

View File

@ -109,28 +109,20 @@ export const DefaultNotificationItem =
text(notificationType, notificationName) {
const { attrs } = this;
const data = attrs.data;
const scope =
notificationName === "custom" ? data.message : `notifications.${notificationName}`;
const username = formatUsername(data.display_username);
const description = this.description();
return I18n.t(scope, { description, username });
return I18n.t(`notifications.${notificationName}`, { description, username });
},
icon(notificationName, data) {
let infoKey =
notificationName === "custom" ? data.message : notificationName;
return iconNode(`notification.${infoKey}`);
return iconNode(`notification.${notificationName}`);
},
title(notificationName, data) {
if (notificationName) {
if (notificationName === "custom") {
return data.title ? I18n.t(data.title) : "";
} else {
return I18n.t(`notifications.titles.${notificationName}`);
}
} else {
return "";
}