diff options
| author | lain <lain@soykaf.club> | 2020-06-19 13:34:04 +0000 |
|---|---|---|
| committer | lain <lain@soykaf.club> | 2020-06-19 13:34:04 +0000 |
| commit | 1afa0f004455175e5bc1770cae5c7833a1a0e84f (patch) | |
| tree | 48725152f1e0099e84bb02fe33a947c5e96f5eed /src/services/notification_utils/notification_utils.js | |
| parent | 267102809d3e866d510c42bd4cf0dbfa36094703 (diff) | |
| parent | ed908e0195db26ec9c51d124315bc084c5576a29 (diff) | |
Merge branch 'notification-unification-experiments' into 'develop'
Notification unification / WebPush i18n.
See merge request pleroma/pleroma-fe!1142
Diffstat (limited to 'src/services/notification_utils/notification_utils.js')
| -rw-r--r-- | src/services/notification_utils/notification_utils.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/services/notification_utils/notification_utils.js b/src/services/notification_utils/notification_utils.js index eb479227..5cc19215 100644 --- a/src/services/notification_utils/notification_utils.js +++ b/src/services/notification_utils/notification_utils.js @@ -43,3 +43,47 @@ export const filteredNotificationsFromStore = (store, types) => { export const unseenNotificationsFromStore = store => filter(filteredNotificationsFromStore(store), ({ seen }) => !seen) + +export const prepareNotificationObject = (notification, i18n) => { + const notifObj = { + tag: notification.id + } + const status = notification.status + const title = notification.from_profile.name + notifObj.title = title + notifObj.icon = notification.from_profile.profile_image_url + let i18nString + switch (notification.type) { + case 'like': + i18nString = 'favorited_you' + break + case 'repeat': + i18nString = 'repeated_you' + break + case 'follow': + i18nString = 'followed_you' + break + case 'move': + i18nString = 'migrated_to' + break + case 'follow_request': + i18nString = 'follow_request' + break + } + + if (notification.type === 'pleroma:emoji_reaction') { + notifObj.body = i18n.t('notifications.reacted_with', [notification.emoji]) + } else if (i18nString) { + notifObj.body = i18n.t('notifications.' + i18nString) + } else if (isStatusNotification(notification.type)) { + notifObj.body = notification.status.text + } + + // Shows first attached non-nsfw image, if any. Should add configuration for this somehow... + if (status && status.attachments && status.attachments.length > 0 && !status.nsfw && + status.attachments[0].mimetype.startsWith('image/')) { + notifObj.image = status.attachments[0].url + } + + return notifObj +} |
