Add configuration to enable/disable web push notifications

This commit is contained in:
Egor Kislitsyn 2018-12-07 15:15:31 +07:00
parent ebe2a95140
commit bbae2e10f3
2 changed files with 5 additions and 1 deletions

View File

@ -23,6 +23,7 @@ const defaultState = {
likes: true,
repeats: true
},
webPushNotifications: true,
muteWords: [],
highlight: {},
interfaceLanguage: browserLocale,

View File

@ -1,4 +1,3 @@
function urlBase64ToUint8Array (base64String) {
const padding = '='.repeat((4 - base64String.length % 4) % 4)
const base64 = (base64String + padding)
@ -46,6 +45,10 @@ function askPermission () {
}
function subscribe (registration, store) {
if (!store.rootState.config.webPushNotifications) {
return Promise.reject(new Error('Web Push is disabled in config'))
}
if (!store.rootState.instance.vapidPublicKey) {
return Promise.reject(new Error('VAPID publick key is not found'))
}