logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

push_notifications_plugin.js (1214B)


  1. export default (store) => {
  2. store.subscribe((mutation, state) => {
  3. const vapidPublicKey = state.instance.vapidPublicKey
  4. const webPushNotification = state.config.webPushNotifications
  5. const permission = state.interface.notificationPermission === 'granted'
  6. const user = state.users.currentUser
  7. const isUserMutation = mutation.type === 'setCurrentUser'
  8. const isVapidMutation = mutation.type === 'setInstanceOption' && mutation.payload.name === 'vapidPublicKey'
  9. const isPermMutation = mutation.type === 'setNotificationPermission' && mutation.payload === 'granted'
  10. const isUserConfigMutation = mutation.type === 'setOption' && mutation.payload.name === 'webPushNotifications'
  11. const isVisibilityMutation = mutation.type === 'setOption' && mutation.payload.name === 'notificationVisibility'
  12. if (isUserMutation || isVapidMutation || isPermMutation || isUserConfigMutation || isVisibilityMutation) {
  13. if (user && vapidPublicKey && permission && webPushNotification) {
  14. return store.dispatch('registerPushNotifications')
  15. } else if (isUserConfigMutation && !webPushNotification) {
  16. return store.dispatch('unregisterPushNotifications')
  17. }
  18. }
  19. })
  20. }