diff options
| author | Maxim Filippov <colixer@gmail.com> | 2018-12-17 02:39:37 +0300 |
|---|---|---|
| committer | Maxim Filippov <colixer@gmail.com> | 2018-12-17 02:39:37 +0300 |
| commit | 2211c533ddf7a05723afb2e2a8664b9b49c9648d (patch) | |
| tree | d5bcfbdb55536db01bc0bfda38991db8f159a3e9 /src/main.js | |
| parent | 5fc0fe28e45882da0fab635e839a2977104d2f46 (diff) | |
| parent | ada4bd0d9874d98213cf79ccd9f7cddda36d1b6c (diff) | |
Merge branch 'develop' into feature/new-user-routes
Diffstat (limited to 'src/main.js')
| -rw-r--r-- | src/main.js | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/main.js b/src/main.js index 378fe95c..bf92e78e 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,16 @@ 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 }) }) + +// These are inlined by webpack's DefinePlugin +/* eslint-disable */ +window.___pleromafe_mode = process.env +window.___pleromafe_commit_hash = COMMIT_HASH +window.___pleromafe_dev_overrides = DEV_OVERRIDES |
