Fixed legacy GCM subscriptions handling

Closes #1294
This commit is contained in:
Igor Zhukov 2016-12-16 16:52:11 +03:00
parent a6cf0a7772
commit 80c3927192

View File

@ -2140,10 +2140,21 @@ angular.module('izhukov.utils', [])
function pushSubscriptionNotify(event, subscription) {
if (subscription) {
console.warn(dT(), 'Push', event, subscription.toJSON())
var subscriptionObj = subscription.toJSON()
if (!subscriptionObj ||
!subscriptionObj.endpoint ||
!subscriptionObj.keys ||
!subscriptionObj.keys.p256dh ||
!subscriptionObj.keys.auth) {
console.warn(dT(), 'Invalid push subscription', subscriptionObj)
unsubscribe()
isAvailable = false
return pushSubscriptionNotify(event, false)
}
console.warn(dT(), 'Push', event, subscriptionObj)
$rootScope.$emit('push_' + event, {
tokenType: 10,
tokenValue: JSON.stringify(subscription.toJSON())
tokenValue: JSON.stringify(subscriptionObj)
})
} else {
console.warn(dT(), 'Push', event, false)