Pull liked notification behaviour in its own class

This commit is contained in:
Daniel Waterworth 2019-06-07 06:48:02 +01:00 committed by Robin Ward
parent bd062fcbef
commit 396e13aaa7
2 changed files with 35 additions and 20 deletions

View File

@ -123,26 +123,6 @@ export const DefaultNotificationItem =
const username = formatUsername(data.display_username); const username = formatUsername(data.display_username);
const description = this.description(); const description = this.description();
if (notificationType === notificationTypes.liked && data.count > 1) {
const count = data.count - 2;
const username2 = formatUsername(data.username2);
if (count === 0) {
return I18n.t("notifications.liked_2", {
description,
username,
username2
});
} else {
return I18n.t("notifications.liked_many", {
description,
username,
username2,
count
});
}
}
return I18n.t(scope, { description, username }); return I18n.t(scope, { description, username });
}, },

View File

@ -0,0 +1,35 @@
import { createWidgetFrom } from "discourse/widgets/widget";
import { DefaultNotificationItem } from "discourse/widgets/default-notification-item";
import { formatUsername } from "discourse/lib/utilities";
createWidgetFrom(DefaultNotificationItem, "liked-notification-item", {
text(notificationType, notificationName) {
const { attrs } = this;
const data = attrs.data;
const username = formatUsername(data.display_username);
const description = this.description();
if (data.count > 1) {
const count = data.count - 2;
const username2 = formatUsername(data.username2);
if (count === 0) {
return I18n.t("notifications.liked_2", {
description,
username,
username2
});
} else {
return I18n.t("notifications.liked_many", {
description,
username,
username2,
count
});
}
}
return I18n.t("notifications.liked", { description, username });
}
});