Notifications: More reduxification.

This commit is contained in:
lain 2020-06-25 15:32:37 +02:00
parent 6074f16f9b
commit 70db485a58
3 changed files with 22 additions and 34 deletions

View File

@ -133,7 +133,7 @@
@{{ notification.redux.account.redux.acct }}
</router-link>
<div
v-if="notification.type === 'follow_request'"
v-if="notification.redux.type === 'follow_request'"
style="white-space: nowrap;"
>
<i
@ -149,17 +149,17 @@
</div>
</div>
<div
v-else-if="notification.type === 'move'"
v-else-if="notification.redux.type === 'move'"
class="move-text"
>
<router-link :to="targetUserProfileLink">
@{{ notification.target.redux.acct }}
@{{ notification.redux.target.redux.acct }}
</router-link>
</div>
<template v-else>
<status-content
class="faint"
:status="notification.status"
:status="notification.redux.status"
/>
</template>
</div>

View File

@ -13,7 +13,7 @@ import {
omitBy
} from 'lodash'
import { set } from 'vue'
import { isStatusNotification, prepareNotificationObject } from '../services/notification_utils/notification_utils.js'
import { isStatusNotification, prepareNotificationObject, visibleTypes } from '../services/notification_utils/notification_utils.js'
import apiService from '../services/api/api.service.js'
import { muteWordHits } from '../services/status_parser/status_parser.js'
@ -76,17 +76,6 @@ export const prepareStatus = (status) => {
return status
}
const visibleNotificationTypes = (rootState) => {
return [
rootState.config.notificationVisibility.likes && 'like',
rootState.config.notificationVisibility.mentions && 'mention',
rootState.config.notificationVisibility.repeats && 'repeat',
rootState.config.notificationVisibility.follows && 'follow',
rootState.config.notificationVisibility.moves && 'move',
rootState.config.notificationVisibility.emojiReactions && 'pleroma:emoji_reactions'
].filter(_ => _)
}
const mergeOrAdd = (arr, obj, item) => {
const oldItem = obj[item.id]
@ -323,12 +312,11 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
const addNewNotifications = (state, { dispatch, notifications, older, visibleNotificationTypes, rootGetters }) => {
each(notifications, (notification) => {
if (isStatusNotification(notification.type)) {
notification.action = addStatusToGlobalStorage(state, notification.action).item
notification.status = notification.status && addStatusToGlobalStorage(state, notification.status).item
notification.redux.status = notification.redux.status && addStatusToGlobalStorage(state, notification.redux.status).item
}
if (notification.type === 'pleroma:emoji_reaction') {
dispatch('fetchEmojiReactionsBy', notification.status.id)
if (notification.redux.type === 'pleroma:emoji_reaction') {
dispatch('fetchEmojiReactionsBy', notification.redux.status.id)
}
// Only add a new notification if we don't have one for the same action
@ -347,11 +335,11 @@ const addNewNotifications = (state, { dispatch, notifications, older, visibleNot
const notifObj = prepareNotificationObject(notification, rootGetters.i18n)
const reasonsToMuteNotif = (
notification.seen ||
notification.redux.is_seen ||
state.notifications.desktopNotificationSilence ||
!visibleNotificationTypes.includes(notification.type) ||
!visibleNotificationTypes.includes(notification.redux.type) ||
(
notification.type === 'mention' && status && (
notification.redux.type === 'mention' && status && (
status.muted ||
muteWordHits(status, rootGetters.mergedConfig.muteWords).length === 0
)
@ -364,7 +352,7 @@ const addNewNotifications = (state, { dispatch, notifications, older, visibleNot
setTimeout(desktopNotification.close.bind(desktopNotification), 5000)
}
}
} else if (notification.seen) {
} else if (notification.redux.is_seen) {
state.notifications.idStore[notification.id].seen = true
}
})
@ -589,7 +577,7 @@ const statuses = {
commit('addNewStatuses', { statuses, showImmediately, timeline, noIdUpdate, user: rootState.users.currentUser, userId })
},
addNewNotifications ({ rootState, commit, dispatch, rootGetters }, { notifications, older }) {
commit('addNewNotifications', { visibleNotificationTypes: visibleNotificationTypes(rootState), dispatch, notifications, older, rootGetters })
commit('addNewNotifications', { visibleNotificationTypes: visibleTypes(rootState), dispatch, notifications, older, rootGetters })
},
setError ({ rootState, commit }, { value }) {
commit('setError', { value })

View File

@ -2,14 +2,14 @@ import { filter, sortBy, includes } from 'lodash'
export const notificationsFromStore = store => store.state.statuses.notifications.data
export const visibleTypes = store => ([
store.state.config.notificationVisibility.likes && 'like',
store.state.config.notificationVisibility.mentions && 'mention',
store.state.config.notificationVisibility.repeats && 'repeat',
store.state.config.notificationVisibility.follows && 'follow',
store.state.config.notificationVisibility.followRequest && 'follow_request',
store.state.config.notificationVisibility.moves && 'move',
store.state.config.notificationVisibility.emojiReactions && 'pleroma:emoji_reaction'
export const visibleTypes = state => ([
state.config.notificationVisibility.likes && 'favourite',
state.config.notificationVisibility.mentions && 'mention',
state.config.notificationVisibility.repeats && 'reblog',
state.config.notificationVisibility.follows && 'follow',
state.config.notificationVisibility.followRequest && 'follow_request',
state.config.notificationVisibility.moves && 'move',
state.config.notificationVisibility.emojiReactions && 'pleroma:emoji_reaction'
].filter(_ => _))
const statusNotifications = ['like', 'mention', 'repeat', 'pleroma:emoji_reaction']
@ -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)).includes(notification.type)
(notification) => (types || visibleTypes(store.state)).includes(notification.type)
)
}