add subscribe module and fix race condition
This commit is contained in:
parent
264da19f69
commit
07f1b8523e
4 changed files with 29 additions and 9 deletions
21
src/modules/subscribe.js
Normal file
21
src/modules/subscribe.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
import registerPushNotifications from '../services/push/push.js'
|
||||
|
||||
const subscribe = {
|
||||
state: {
|
||||
token: null,
|
||||
vapidPublicKey: null
|
||||
},
|
||||
mutations: {
|
||||
setCurrentUser (state, user) {
|
||||
state.token = user.credentials
|
||||
if (state.token && state.vapidPublicKey) registerPushNotifications(this)
|
||||
},
|
||||
setInstanceOption (state, { name, value }) {
|
||||
if (name !== 'vapidPublicKey') return
|
||||
state.vapidPublicKey = value
|
||||
if (state.token && state.vapidPublicKey) registerPushNotifications(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default subscribe
|
|
@ -1,5 +1,4 @@
|
|||
import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js'
|
||||
import registerPushNotifications from '../services/push/push.js'
|
||||
import { compact, map, each, merge } from 'lodash'
|
||||
import { set } from 'vue'
|
||||
|
||||
|
@ -120,10 +119,8 @@ const users = {
|
|||
})
|
||||
|
||||
// Fetch our friends
|
||||
store.rootState.api.backendInteractor.fetchFriends({id: user.id})
|
||||
store.rootState.api.backendInteractor.fetchFriends({ id: user.id })
|
||||
.then((friends) => commit('addNewUsers', friends))
|
||||
|
||||
registerPushNotifications(store)
|
||||
})
|
||||
} else {
|
||||
// Authentication failed
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue