Revert "add subscribe module and fix race condition"
This reverts commit 07f1b8523e
.
This commit is contained in:
parent
07f1b8523e
commit
a85d128d37
|
@ -10,7 +10,6 @@ import apiModule from './modules/api.js'
|
||||||
import configModule from './modules/config.js'
|
import configModule from './modules/config.js'
|
||||||
import chatModule from './modules/chat.js'
|
import chatModule from './modules/chat.js'
|
||||||
import oauthModule from './modules/oauth.js'
|
import oauthModule from './modules/oauth.js'
|
||||||
import subscribeModule from './modules/subscribe.js'
|
|
||||||
|
|
||||||
import VueTimeago from 'vue-timeago'
|
import VueTimeago from 'vue-timeago'
|
||||||
import VueI18n from 'vue-i18n'
|
import VueI18n from 'vue-i18n'
|
||||||
|
@ -61,8 +60,7 @@ createPersistedState(persistedStateOptions).then((persistedState) => {
|
||||||
api: apiModule,
|
api: apiModule,
|
||||||
config: configModule,
|
config: configModule,
|
||||||
chat: chatModule,
|
chat: chatModule,
|
||||||
oauth: oauthModule,
|
oauth: oauthModule
|
||||||
subscribe: subscribeModule
|
|
||||||
},
|
},
|
||||||
plugins: [persistedState],
|
plugins: [persistedState],
|
||||||
strict: false // Socket modifies itself, let's ignore this for now.
|
strict: false // Socket modifies itself, let's ignore this for now.
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
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,4 +1,5 @@
|
||||||
import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js'
|
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 { compact, map, each, merge } from 'lodash'
|
||||||
import { set } from 'vue'
|
import { set } from 'vue'
|
||||||
|
|
||||||
|
@ -121,6 +122,8 @@ const users = {
|
||||||
// Fetch our friends
|
// Fetch our friends
|
||||||
store.rootState.api.backendInteractor.fetchFriends({id: user.id})
|
store.rootState.api.backendInteractor.fetchFriends({id: user.id})
|
||||||
.then((friends) => commit('addNewUsers', friends))
|
.then((friends) => commit('addNewUsers', friends))
|
||||||
|
|
||||||
|
registerPushNotifications(store)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// Authentication failed
|
// Authentication failed
|
||||||
|
|
|
@ -45,17 +45,17 @@ function askPermission () {
|
||||||
}
|
}
|
||||||
|
|
||||||
function subscribe (registration, store) {
|
function subscribe (registration, store) {
|
||||||
if (!store.state.config.webPushNotifications) {
|
if (!store.rootState.config.webPushNotifications) {
|
||||||
return Promise.reject(new Error('Web Push is disabled in config'))
|
return Promise.reject(new Error('Web Push is disabled in config'))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!store.state.subscribe.vapidPublicKey) {
|
if (!store.rootState.instance.vapidPublicKey) {
|
||||||
return Promise.reject(new Error('VAPID public key is not found'))
|
return Promise.reject(new Error('VAPID public key is not found'))
|
||||||
}
|
}
|
||||||
|
|
||||||
const subscribeOptions = {
|
const subscribeOptions = {
|
||||||
userVisibleOnly: true,
|
userVisibleOnly: true,
|
||||||
applicationServerKey: urlBase64ToUint8Array(store.state.subscribe.vapidPublicKey)
|
applicationServerKey: urlBase64ToUint8Array(store.rootState.instance.vapidPublicKey)
|
||||||
}
|
}
|
||||||
return registration.pushManager.subscribe(subscribeOptions)
|
return registration.pushManager.subscribe(subscribeOptions)
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ function sendSubscriptionToBackEnd (subscription, store) {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': `Bearer ${store.state.subscribe.token}`
|
'Authorization': `Bearer ${store.rootState.oauth.token}`
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
subscription,
|
subscription,
|
||||||
|
|
Loading…
Reference in New Issue