Notification: Even more reducing.
This commit is contained in:
parent
70db485a58
commit
7d5c3e5db0
8 changed files with 36 additions and 37 deletions
|
@ -22,7 +22,7 @@ const FollowRequestCard = {
|
|||
this.$store.dispatch('updateNotification', {
|
||||
id: notifId,
|
||||
updater: notification => {
|
||||
notification.type = 'follow'
|
||||
notification.redux.type = 'follow'
|
||||
}
|
||||
})
|
||||
},
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@
|
|||
class="timeago"
|
||||
>
|
||||
<router-link
|
||||
v-if="notification.status"
|
||||
v-if="notification.redux.status"
|
||||
:to="{ name: 'conversation', params: { id: notification.redux.status.id } }"
|
||||
class="faint-link"
|
||||
>
|
||||
|
|
|
@ -33,9 +33,9 @@
|
|||
<div class="panel-body">
|
||||
<div
|
||||
v-for="notification in notificationsToDisplay"
|
||||
:key="notification.id"
|
||||
:key="notification.redux.id"
|
||||
class="notification"
|
||||
:class="{"unseen": !minimalMode && !notification.seen}"
|
||||
:class="{"unseen": !minimalMode && !notification.redux.pleroma.is_seen}"
|
||||
>
|
||||
<div class="notification-overlay" />
|
||||
<notification :notification="notification" />
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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...
|
||||
|
|
Loading…
Reference in a new issue