#436: integrate mastoAPI notifications

This commit is contained in:
dave 2019-03-12 17:16:57 -04:00
parent f397537642
commit cd9a7dd488
8 changed files with 135 additions and 42 deletions

View file

@ -1,4 +1,4 @@
import { remove, slice, each, find, maxBy, minBy, merge, first, last, isArray } from 'lodash'
import { remove, slice, each, find, findIndex, maxBy, minBy, merge, first, last, isArray } from 'lodash'
import apiService from '../services/api/api.service.js'
// import parse from '../services/status_parser/status_parser.js'
@ -390,6 +390,27 @@ export const mutations = {
notification.seen = true
})
},
clearNotifications (state) {
state.notifications.data = []
state.notifications.idStore = {}
state.notifications.maxId = 0
state.notifications.minId = 0
},
dismissNotifications (state, { id }) {
const { data } = state.notifications
const idx = findIndex(data, { id })
if (idx !== -1) {
const notification = data[idx]
data.splice(idx, 1)
delete state.notifications.idStore[id]
if (state.notifications.maxId === notification.id) {
state.notifications.maxId = data.length ? maxBy(data, 'id').id : 0
} else if (state.notifications.minId === notification.id) {
state.notifications.minId = data.length ? minBy(data, 'id').id : 0
}
}
},
queueFlush (state, { timeline, id }) {
state.timelines[timeline].flushMarker = id
}
@ -474,6 +495,19 @@ const statuses = {
id: rootState.statuses.notifications.maxId,
credentials: rootState.users.currentUser.credentials
})
},
clearNotifications ({ rootState, commit }) {
commit('clearNotifications')
apiService.clearNotifications({
credentials: rootState.users.currentUser.credentials
})
},
dismissNotifications ({ rootState, commit }, { id }) {
commit('dismissNotifications', { id })
apiService.dismissNotifications({
id,
credentials: rootState.users.currentUser.credentials
})
}
},
mutations