improve push notifications code

This commit is contained in:
Egor Kislitsyn 2018-12-09 19:25:43 +07:00
parent 11716a7a53
commit 73b17d70ec
3 changed files with 48 additions and 65 deletions

View file

@ -12,16 +12,23 @@ const subscribe = {
setVapidPublicKey (state, vapidPublicKey) {
state.vapidPublicKey = vapidPublicKey
}
},
actions: {
setInstanceOption (store, { name, value }) {
store.commit('setVapidPublicKey', value)
if (store.state.token) registerPushNotifications(this)
if (name === 'vapidPublicKey') {
store.commit('setVapidPublicKey', value)
if (store.state.token) {
registerPushNotifications(store.rootState.config.webPushNotifications, value, store.state.token)
}
}
},
setCurrentUser (store, user) {
store.commit('setApiToken', user.credentials)
if (store.state.vapidPublicKey) registerPushNotifications(this)
if (store.state.vapidPublicKey) {
registerPushNotifications(store.rootState.config.webPushNotifications, store.state.vapidPublicKey, user.credentials)
}
}
}
}