mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 03:03:45 +08: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) {
|
||||
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}`);
|
||||
}
|
||||
return I18n.t(`notifications.titles.${notificationName}`);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user