diff options
| author | HJ <spam@hjkos.com> | 2018-12-25 11:33:00 +0000 |
|---|---|---|
| committer | HJ <spam@hjkos.com> | 2018-12-25 11:33:00 +0000 |
| commit | 0ad837846a3b833203bdae68fc6d3cb37c257c4b (patch) | |
| tree | 0901d0aedde172b1e4a6d89230906424870ee4e0 /src/main.js | |
| parent | 2fe0af2af12c436d25f258eec21c149d773ec0d0 (diff) | |
| parent | 500b4bd37412960c7b2278b930794b2ccf00c971 (diff) | |
Merge branch 'push_fix' into 'develop'
Fixes for push notifications
Closes #235
See merge request pleroma/pleroma-fe!433
Diffstat (limited to 'src/main.js')
| -rw-r--r-- | src/main.js | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/main.js b/src/main.js index bf92e78e..c22a762e 100644 --- a/src/main.js +++ b/src/main.js @@ -54,24 +54,21 @@ const persistedStateOptions = { const registerPushNotifications = store => { store.subscribe((mutation, state) => { const vapidPublicKey = state.instance.vapidPublicKey + const webPushNotification = state.config.webPushNotifications 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 isUserMutation = mutation.type === 'setCurrentUser' + const isVapidMutation = mutation.type === 'setInstanceOption' && mutation.payload.name === 'vapidPublicKey' const isPermMutation = mutation.type === 'setNotificationPermission' && mutation.payload === 'granted' - - if (isPermMutation && user && vapidPublicKey) { - return store.dispatch('registerPushNotifications') + const isUserConfigMutation = mutation.type === 'setOption' && mutation.payload.name === 'webPushNotifications' + + if (isUserMutation || isVapidMutation || isPermMutation || isUserConfigMutation) { + if (user && vapidPublicKey && permission && webPushNotification) { + return store.dispatch('registerPushNotifications') + } else if (isUserConfigMutation && !webPushNotification) { + return store.dispatch('unregisterPushNotifications') + } } }) } |
