From 7d5c3e5db0f69599fa8ce4024f24143274db4ece Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 25 Jun 2020 15:55:12 +0200 Subject: [PATCH] Notification: Even more reducing. --- .../follow_request_card.js | 2 +- src/components/notification/notification.js | 8 +++--- src/components/notification/notification.vue | 2 +- .../notifications/notifications.vue | 4 +-- src/modules/statuses.js | 24 ++++++++--------- src/modules/users.js | 4 +-- .../entity_normalizer.service.js | 3 ++- .../notification_utils/notification_utils.js | 26 +++++++++---------- 8 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/components/follow_request_card/follow_request_card.js b/src/components/follow_request_card/follow_request_card.js index cbd75311..365e765a 100644 --- a/src/components/follow_request_card/follow_request_card.js +++ b/src/components/follow_request_card/follow_request_card.js @@ -22,7 +22,7 @@ const FollowRequestCard = { this.$store.dispatch('updateNotification', { id: notifId, updater: notification => { - notification.type = 'follow' + notification.redux.type = 'follow' } }) }, diff --git a/src/components/notification/notification.js b/src/components/notification/notification.js index 6a0872b8..6bbf9a6e 100644 --- a/src/components/notification/notification.js +++ b/src/components/notification/notification.js @@ -39,18 +39,18 @@ const Notification = { approveUser () { this.$store.state.api.backendInteractor.approveUser({ id: this.user.id }) this.$store.dispatch('removeFollowRequest', this.user) - this.$store.dispatch('markSingleNotificationAsSeen', { id: this.notification.id }) + this.$store.dispatch('markSingleNotificationAsSeen', { id: this.notification.redux.id }) this.$store.dispatch('updateNotification', { - id: this.notification.id, + id: this.notification.redux.id, updater: notification => { - notification.type = 'follow' + notification.redux.type = 'follow' } }) }, denyUser () { this.$store.state.api.backendInteractor.denyUser({ id: this.user.id }) .then(() => { - this.$store.dispatch('dismissNotificationLocal', { id: this.notification.id }) + this.$store.dispatch('dismissNotificationLocal', { id: this.notification.redux.id }) this.$store.dispatch('removeFollowRequest', this.user) }) } diff --git a/src/components/notification/notification.vue b/src/components/notification/notification.vue index 46b3b62b..93cda80c 100644 --- a/src/components/notification/notification.vue +++ b/src/components/notification/notification.vue @@ -95,7 +95,7 @@ class="timeago" > diff --git a/src/components/notifications/notifications.vue b/src/components/notifications/notifications.vue index d477a41b..18479ebb 100644 --- a/src/components/notifications/notifications.vue +++ b/src/components/notifications/notifications.vue @@ -33,9 +33,9 @@
diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 7f8d05cd..25252fcf 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -311,7 +311,7 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us const addNewNotifications = (state, { dispatch, notifications, older, visibleNotificationTypes, rootGetters }) => { each(notifications, (notification) => { - if (isStatusNotification(notification.type)) { + if (isStatusNotification(notification.redux.type)) { notification.redux.status = notification.redux.status && addStatusToGlobalStorage(state, notification.redux.status).item } @@ -320,22 +320,22 @@ const addNewNotifications = (state, { dispatch, notifications, older, visibleNot } // Only add a new notification if we don't have one for the same action - if (!state.notifications.idStore.hasOwnProperty(notification.id)) { - state.notifications.maxId = notification.id > state.notifications.maxId - ? notification.id + if (!state.notifications.idStore.hasOwnProperty(notification.redux.id)) { + state.notifications.maxId = notification.redux.id > state.notifications.maxId + ? notification.redux.id : state.notifications.maxId - state.notifications.minId = notification.id < state.notifications.minId - ? notification.id + state.notifications.minId = notification.redux.id < state.notifications.minId + ? notification.redux.id : state.notifications.minId state.notifications.data.push(notification) - state.notifications.idStore[notification.id] = notification + state.notifications.idStore[notification.redux.id] = notification if ('Notification' in window && window.Notification.permission === 'granted') { const notifObj = prepareNotificationObject(notification, rootGetters.i18n) const reasonsToMuteNotif = ( - notification.redux.is_seen || + notification.redux.pleroma.is_seen || state.notifications.desktopNotificationSilence || !visibleNotificationTypes.includes(notification.redux.type) || ( @@ -352,8 +352,8 @@ const addNewNotifications = (state, { dispatch, notifications, older, visibleNot setTimeout(desktopNotification.close.bind(desktopNotification), 5000) } } - } else if (notification.redux.is_seen) { - state.notifications.idStore[notification.id].seen = true + } else if (notification.redux.pleroma.is_seen) { + state.notifications.idStore[notification.redux.id].pleroma.is_seen = true } }) } @@ -486,12 +486,12 @@ export const mutations = { }, markNotificationsAsSeen (state) { each(state.notifications.data, (notification) => { - notification.seen = true + notification.redux.pleroma.is_seen = true }) }, markSingleNotificationAsSeen (state, { id }) { const notification = find(state.notifications.data, n => n.id === id) - if (notification) notification.seen = true + if (notification) notification.redux.pleroma.is_seen = true }, dismissNotification (state, { id }) { state.notifications.data = state.notifications.data.filter(n => n.id !== id) diff --git a/src/modules/users.js b/src/modules/users.js index 5e32bb49..0f05113f 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -206,10 +206,8 @@ export const mutations = { status.user = state.usersObject[status.user.id] }, setUserForNotification (state, notification) { - if (notification.type !== 'follow') { - notification.action.user = state.usersObject[notification.action.user.id] - } notification.from_profile = state.usersObject[notification.from_profile.id] + notification.redux.account = state.usersObject[notification.redux.account.id] }, setColor (state, { user: { id }, highlighted }) { const user = state.usersObject[id] diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js index 794c9b37..c67bb026 100644 --- a/src/services/entity_normalizer/entity_normalizer.service.js +++ b/src/services/entity_normalizer/entity_normalizer.service.js @@ -362,8 +362,9 @@ export const parseNotification = (data) => { output.redux = data output.redux.account = parseUser(data.account) - output.redux.status = isStatusNotification(output.type) ? parseStatus(data.status) : null + output.redux.status = isStatusNotification(data.type) ? parseStatus(data.status) : null output.redux.target = output.type !== 'move' ? null : parseUser(data.target) + console.log(output.redux.pleroma.is_seen) return output } diff --git a/src/services/notification_utils/notification_utils.js b/src/services/notification_utils/notification_utils.js index efd21087..23f82ba1 100644 --- a/src/services/notification_utils/notification_utils.js +++ b/src/services/notification_utils/notification_utils.js @@ -12,7 +12,7 @@ export const visibleTypes = state => ([ state.config.notificationVisibility.emojiReactions && 'pleroma:emoji_reaction' ].filter(_ => _)) -const statusNotifications = ['like', 'mention', 'repeat', 'pleroma:emoji_reaction'] +const statusNotifications = ['favourite', 'mention', 'reblog', 'pleroma:emoji_reaction'] export const isStatusNotification = (type) => includes(statusNotifications, type) @@ -37,7 +37,7 @@ export const filteredNotificationsFromStore = (store, types) => { let sortedNotifications = notificationsFromStore(store).map(_ => _).sort(sortById) sortedNotifications = sortBy(sortedNotifications, 'seen') return sortedNotifications.filter( - (notification) => (types || visibleTypes(store.state)).includes(notification.type) + (notification) => (types || visibleTypes(store.state)).includes(notification.redux.type) ) } @@ -46,18 +46,18 @@ export const unseenNotificationsFromStore = store => export const prepareNotificationObject = (notification, i18n) => { const notifObj = { - tag: notification.id + tag: notification.redux.id } - const status = notification.status - const title = notification.from_profile.name + const status = notification.redux.status + const title = notification.redux.account.name notifObj.title = title - notifObj.icon = notification.from_profile.profile_image_url + notifObj.icon = notification.redux.account.profile_image_url let i18nString - switch (notification.type) { - case 'like': + switch (notification.redux.type) { + case 'favourite': i18nString = 'favorited_you' break - case 'repeat': + case 'reblog': i18nString = 'repeated_you' break case 'follow': @@ -71,12 +71,12 @@ export const prepareNotificationObject = (notification, i18n) => { break } - if (notification.type === 'pleroma:emoji_reaction') { - notifObj.body = i18n.t('notifications.reacted_with', [notification.emoji]) + if (notification.redux.type === 'pleroma:emoji_reaction') { + notifObj.body = i18n.t('notifications.reacted_with', [notification.redux.emoji]) } else if (i18nString) { notifObj.body = i18n.t('notifications.' + i18nString) - } else if (isStatusNotification(notification.type)) { - notifObj.body = notification.status.text + } else if (isStatusNotification(notification.redux.type)) { + notifObj.body = notification.redux.status.text } // Shows first attached non-nsfw image, if any. Should add configuration for this somehow...