aboutsummaryrefslogtreecommitdiff
path: root/src/main.js
diff options
context:
space:
mode:
authorEgor Kislitsyn <egor@kislitsyn.com>2018-12-25 20:43:18 +0700
committerEgor Kislitsyn <egor@kislitsyn.com>2018-12-25 20:43:18 +0700
commitc5847349e0afb14702d1746fac142b8aeb2020e7 (patch)
tree752493201f43bc10dd1a3f334401f997171e162d /src/main.js
parent0ad837846a3b833203bdae68fc6d3cb37c257c4b (diff)
improve web push notifications
Diffstat (limited to 'src/main.js')
-rw-r--r--src/main.js25
1 files changed, 2 insertions, 23 deletions
diff --git a/src/main.js b/src/main.js
index c22a762e..f87ef9da 100644
--- a/src/main.js
+++ b/src/main.js
@@ -15,6 +15,7 @@ import VueTimeago from 'vue-timeago'
import VueI18n from 'vue-i18n'
import createPersistedState from './lib/persisted_state.js'
+import pushNotifications from './lib/push_notifications_plugin.js'
import messages from './i18n/messages.js'
@@ -51,28 +52,6 @@ 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 user = state.users.currentUser
-
- const isUserMutation = mutation.type === 'setCurrentUser'
- const isVapidMutation = mutation.type === 'setInstanceOption' && mutation.payload.name === 'vapidPublicKey'
- const isPermMutation = mutation.type === 'setNotificationPermission' && mutation.payload === 'granted'
- 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')
- }
- }
- })
-}
-
createPersistedState(persistedStateOptions).then((persistedState) => {
const store = new Vuex.Store({
modules: {
@@ -85,7 +64,7 @@ createPersistedState(persistedStateOptions).then((persistedState) => {
chat: chatModule,
oauth: oauthModule
},
- plugins: [persistedState, registerPushNotifications],
+ plugins: [persistedState, pushNotifications],
strict: false // Socket modifies itself, let's ignore this for now.
// strict: process.env.NODE_ENV !== 'production'
})