Notification: Even more reducing.

This commit is contained in:
lain 2020-06-25 15:55:12 +02:00
parent 70db485a58
commit 7d5c3e5db0
8 changed files with 36 additions and 37 deletions

View File

@ -22,7 +22,7 @@ const FollowRequestCard = {
this.$store.dispatch('updateNotification', { this.$store.dispatch('updateNotification', {
id: notifId, id: notifId,
updater: notification => { updater: notification => {
notification.type = 'follow' notification.redux.type = 'follow'
} }
}) })
}, },

View File

@ -39,18 +39,18 @@ const Notification = {
approveUser () { approveUser () {
this.$store.state.api.backendInteractor.approveUser({ id: this.user.id }) this.$store.state.api.backendInteractor.approveUser({ id: this.user.id })
this.$store.dispatch('removeFollowRequest', this.user) 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', { this.$store.dispatch('updateNotification', {
id: this.notification.id, id: this.notification.redux.id,
updater: notification => { updater: notification => {
notification.type = 'follow' notification.redux.type = 'follow'
} }
}) })
}, },
denyUser () { denyUser () {
this.$store.state.api.backendInteractor.denyUser({ id: this.user.id }) this.$store.state.api.backendInteractor.denyUser({ id: this.user.id })
.then(() => { .then(() => {
this.$store.dispatch('dismissNotificationLocal', { id: this.notification.id }) this.$store.dispatch('dismissNotificationLocal', { id: this.notification.redux.id })
this.$store.dispatch('removeFollowRequest', this.user) this.$store.dispatch('removeFollowRequest', this.user)
}) })
} }

View File

@ -95,7 +95,7 @@
class="timeago" class="timeago"
> >
<router-link <router-link
v-if="notification.status" v-if="notification.redux.status"
:to="{ name: 'conversation', params: { id: notification.redux.status.id } }" :to="{ name: 'conversation', params: { id: notification.redux.status.id } }"
class="faint-link" class="faint-link"
> >

View File

@ -33,9 +33,9 @@
<div class="panel-body"> <div class="panel-body">
<div <div
v-for="notification in notificationsToDisplay" v-for="notification in notificationsToDisplay"
:key="notification.id" :key="notification.redux.id"
class="notification" class="notification"
:class="{&quot;unseen&quot;: !minimalMode && !notification.seen}" :class="{&quot;unseen&quot;: !minimalMode && !notification.redux.pleroma.is_seen}"
> >
<div class="notification-overlay" /> <div class="notification-overlay" />
<notification :notification="notification" /> <notification :notification="notification" />

View File

@ -311,7 +311,7 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
const addNewNotifications = (state, { dispatch, notifications, older, visibleNotificationTypes, rootGetters }) => { const addNewNotifications = (state, { dispatch, notifications, older, visibleNotificationTypes, rootGetters }) => {
each(notifications, (notification) => { each(notifications, (notification) => {
if (isStatusNotification(notification.type)) { if (isStatusNotification(notification.redux.type)) {
notification.redux.status = notification.redux.status && addStatusToGlobalStorage(state, notification.redux.status).item 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 // Only add a new notification if we don't have one for the same action
if (!state.notifications.idStore.hasOwnProperty(notification.id)) { if (!state.notifications.idStore.hasOwnProperty(notification.redux.id)) {
state.notifications.maxId = notification.id > state.notifications.maxId state.notifications.maxId = notification.redux.id > state.notifications.maxId
? notification.id ? notification.redux.id
: state.notifications.maxId : state.notifications.maxId
state.notifications.minId = notification.id < state.notifications.minId state.notifications.minId = notification.redux.id < state.notifications.minId
? notification.id ? notification.redux.id
: state.notifications.minId : state.notifications.minId
state.notifications.data.push(notification) 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') { if ('Notification' in window && window.Notification.permission === 'granted') {
const notifObj = prepareNotificationObject(notification, rootGetters.i18n) const notifObj = prepareNotificationObject(notification, rootGetters.i18n)
const reasonsToMuteNotif = ( const reasonsToMuteNotif = (
notification.redux.is_seen || notification.redux.pleroma.is_seen ||
state.notifications.desktopNotificationSilence || state.notifications.desktopNotificationSilence ||
!visibleNotificationTypes.includes(notification.redux.type) || !visibleNotificationTypes.includes(notification.redux.type) ||
( (
@ -352,8 +352,8 @@ const addNewNotifications = (state, { dispatch, notifications, older, visibleNot
setTimeout(desktopNotification.close.bind(desktopNotification), 5000) setTimeout(desktopNotification.close.bind(desktopNotification), 5000)
} }
} }
} else if (notification.redux.is_seen) { } else if (notification.redux.pleroma.is_seen) {
state.notifications.idStore[notification.id].seen = true state.notifications.idStore[notification.redux.id].pleroma.is_seen = true
} }
}) })
} }
@ -486,12 +486,12 @@ export const mutations = {
}, },
markNotificationsAsSeen (state) { markNotificationsAsSeen (state) {
each(state.notifications.data, (notification) => { each(state.notifications.data, (notification) => {
notification.seen = true notification.redux.pleroma.is_seen = true
}) })
}, },
markSingleNotificationAsSeen (state, { id }) { markSingleNotificationAsSeen (state, { id }) {
const notification = find(state.notifications.data, n => n.id === 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 }) { dismissNotification (state, { id }) {
state.notifications.data = state.notifications.data.filter(n => n.id !== id) state.notifications.data = state.notifications.data.filter(n => n.id !== id)

View File

@ -206,10 +206,8 @@ export const mutations = {
status.user = state.usersObject[status.user.id] status.user = state.usersObject[status.user.id]
}, },
setUserForNotification (state, notification) { 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.from_profile = state.usersObject[notification.from_profile.id]
notification.redux.account = state.usersObject[notification.redux.account.id]
}, },
setColor (state, { user: { id }, highlighted }) { setColor (state, { user: { id }, highlighted }) {
const user = state.usersObject[id] const user = state.usersObject[id]

View File

@ -362,8 +362,9 @@ export const parseNotification = (data) => {
output.redux = data output.redux = data
output.redux.account = parseUser(data.account) 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) output.redux.target = output.type !== 'move' ? null : parseUser(data.target)
console.log(output.redux.pleroma.is_seen)
return output return output
} }

View File

@ -12,7 +12,7 @@ export const visibleTypes = state => ([
state.config.notificationVisibility.emojiReactions && 'pleroma:emoji_reaction' state.config.notificationVisibility.emojiReactions && 'pleroma:emoji_reaction'
].filter(_ => _)) ].filter(_ => _))
const statusNotifications = ['like', 'mention', 'repeat', 'pleroma:emoji_reaction'] const statusNotifications = ['favourite', 'mention', 'reblog', 'pleroma:emoji_reaction']
export const isStatusNotification = (type) => includes(statusNotifications, type) export const isStatusNotification = (type) => includes(statusNotifications, type)
@ -37,7 +37,7 @@ export const filteredNotificationsFromStore = (store, types) => {
let sortedNotifications = notificationsFromStore(store).map(_ => _).sort(sortById) let sortedNotifications = notificationsFromStore(store).map(_ => _).sort(sortById)
sortedNotifications = sortBy(sortedNotifications, 'seen') sortedNotifications = sortBy(sortedNotifications, 'seen')
return sortedNotifications.filter( 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) => { export const prepareNotificationObject = (notification, i18n) => {
const notifObj = { const notifObj = {
tag: notification.id tag: notification.redux.id
} }
const status = notification.status const status = notification.redux.status
const title = notification.from_profile.name const title = notification.redux.account.name
notifObj.title = title notifObj.title = title
notifObj.icon = notification.from_profile.profile_image_url notifObj.icon = notification.redux.account.profile_image_url
let i18nString let i18nString
switch (notification.type) { switch (notification.redux.type) {
case 'like': case 'favourite':
i18nString = 'favorited_you' i18nString = 'favorited_you'
break break
case 'repeat': case 'reblog':
i18nString = 'repeated_you' i18nString = 'repeated_you'
break break
case 'follow': case 'follow':
@ -71,12 +71,12 @@ export const prepareNotificationObject = (notification, i18n) => {
break break
} }
if (notification.type === 'pleroma:emoji_reaction') { if (notification.redux.type === 'pleroma:emoji_reaction') {
notifObj.body = i18n.t('notifications.reacted_with', [notification.emoji]) notifObj.body = i18n.t('notifications.reacted_with', [notification.redux.emoji])
} else if (i18nString) { } else if (i18nString) {
notifObj.body = i18n.t('notifications.' + i18nString) notifObj.body = i18n.t('notifications.' + i18nString)
} else if (isStatusNotification(notification.type)) { } else if (isStatusNotification(notification.redux.type)) {
notifObj.body = notification.status.text notifObj.body = notification.redux.status.text
} }
// Shows first attached non-nsfw image, if any. Should add configuration for this somehow... // Shows first attached non-nsfw image, if any. Should add configuration for this somehow...