aboutsummaryrefslogtreecommitdiff
path: root/src/main.js
diff options
context:
space:
mode:
authorRinpatch <rinpatch@sdf.org>2018-12-13 17:22:19 +0300
committerRinpatch <rinpatch@sdf.org>2018-12-13 17:22:19 +0300
commit6de4dcc7c99e14552303e5eee7dac31dd5e58e2e (patch)
tree668904f3dba16ab39f683345b2e979e57696db94 /src/main.js
parent48edc0c8fcc6c63e432c9b6d78f14af086b56900 (diff)
parent8e4777ccc6bf72b56a0905ca491c8e0e97fb73cf (diff)
Resolve merge conflict
Diffstat (limited to 'src/main.js')
-rw-r--r--src/main.js30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/main.js b/src/main.js
index 378fe95c..23ea854b 100644
--- a/src/main.js
+++ b/src/main.js
@@ -50,6 +50,32 @@ const persistedStateOptions = {
'oauth'
]
}
+
+const registerPushNotifications = store => {
+ store.subscribe((mutation, state) => {
+ const vapidPublicKey = state.instance.vapidPublicKey
+ const permission = state.interface.notificationPermission === 'granted'
+ const isUserMutation = mutation.type === 'setCurrentUser'
+
+ if (isUserMutation && vapidPublicKey && permission) {
+ return store.dispatch('registerPushNotifications')
+ }
+
+ const user = state.users.currentUser
+ const isVapidMutation = mutation.type === 'setInstanceOption' && mutation.payload.name === 'vapidPublicKey'
+
+ if (isVapidMutation && user && permission) {
+ return store.dispatch('registerPushNotifications')
+ }
+
+ const isPermMutation = mutation.type === 'setNotificationPermission' && mutation.payload === 'granted'
+
+ if (isPermMutation && user && vapidPublicKey) {
+ return store.dispatch('registerPushNotifications')
+ }
+ })
+}
+
createPersistedState(persistedStateOptions).then((persistedState) => {
const store = new Vuex.Store({
modules: {
@@ -62,10 +88,10 @@ createPersistedState(persistedStateOptions).then((persistedState) => {
chat: chatModule,
oauth: oauthModule
},
- plugins: [persistedState],
+ plugins: [persistedState, registerPushNotifications],
strict: false // Socket modifies itself, let's ignore this for now.
// strict: process.env.NODE_ENV !== 'production'
})
- afterStoreSetup({store, i18n})
+ afterStoreSetup({ store, i18n })
})