forked from AkkomaGang/akkoma-fe
Merge branch 'fix/dont-crash-on-invalid-notificaiton' into 'develop'
close #1043 - add basic validation for statusless status notifications Closes #1043 See merge request pleroma/pleroma-fe!1360
This commit is contained in:
commit
a83fdbbd59
3 changed files with 30 additions and 7 deletions
|
@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
- Fixed missing highlighted border in expanded conversations again
|
||||
- Fixed some UI jumpiness when opening images particularly in chat view
|
||||
- Fixed chat unread badge looking weird
|
||||
- Fixed notifications crashing on an invalid notification
|
||||
|
||||
### Changed
|
||||
- Display 'people voted' instead of 'votes' for multi-choice polls
|
||||
|
|
|
@ -13,7 +13,11 @@ import {
|
|||
omitBy
|
||||
} from 'lodash'
|
||||
import { set } from 'vue'
|
||||
import { isStatusNotification, maybeShowNotification } from '../services/notification_utils/notification_utils.js'
|
||||
import {
|
||||
isStatusNotification,
|
||||
isValidNotification,
|
||||
maybeShowNotification
|
||||
} from '../services/notification_utils/notification_utils.js'
|
||||
import apiService from '../services/api/api.service.js'
|
||||
|
||||
const emptyTl = (userId = 0) => ({
|
||||
|
@ -310,8 +314,24 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
|||
}
|
||||
}
|
||||
|
||||
const updateNotificationsMinMaxId = (state, notification) => {
|
||||
state.notifications.maxId = notification.id > state.notifications.maxId
|
||||
? notification.id
|
||||
: state.notifications.maxId
|
||||
state.notifications.minId = notification.id < state.notifications.minId
|
||||
? notification.id
|
||||
: state.notifications.minId
|
||||
}
|
||||
|
||||
const addNewNotifications = (state, { dispatch, notifications, older, visibleNotificationTypes, rootGetters, newNotificationSideEffects }) => {
|
||||
each(notifications, (notification) => {
|
||||
// If invalid notification, update ids but don't add it to store
|
||||
if (!isValidNotification(notification)) {
|
||||
console.error('Invalid notification:', notification)
|
||||
updateNotificationsMinMaxId(state, notification)
|
||||
return
|
||||
}
|
||||
|
||||
if (isStatusNotification(notification.type)) {
|
||||
notification.action = addStatusToGlobalStorage(state, notification.action).item
|
||||
notification.status = notification.status && addStatusToGlobalStorage(state, notification.status).item
|
||||
|
@ -323,12 +343,7 @@ 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
|
||||
: state.notifications.maxId
|
||||
state.notifications.minId = notification.id < state.notifications.minId
|
||||
? notification.id
|
||||
: state.notifications.minId
|
||||
updateNotificationsMinMaxId(state, notification)
|
||||
|
||||
state.notifications.data.push(notification)
|
||||
state.notifications.idStore[notification.id] = notification
|
||||
|
|
|
@ -22,6 +22,13 @@ const statusNotifications = ['like', 'mention', 'repeat', 'pleroma:emoji_reactio
|
|||
|
||||
export const isStatusNotification = (type) => includes(statusNotifications, type)
|
||||
|
||||
export const isValidNotification = (notification) => {
|
||||
if (isStatusNotification(notification.type) && !notification.status) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
const sortById = (a, b) => {
|
||||
const seqA = Number(a.id)
|
||||
const seqB = Number(b.id)
|
||||
|
|
Loading…
Reference in a new issue