Improved pushes in Chrome

This commit is contained in:
Igor Zhukov 2017-05-11 20:16:40 +03:00
parent c9723f5723
commit f4fe5941f7
2 changed files with 19 additions and 23 deletions

View File

@ -803,7 +803,7 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto'])
var newInstance = {id: instanceID, idle: idle, time: time} var newInstance = {id: instanceID, idle: idle, time: time}
Storage.get('xt_instance').then(function (curInstance) { Storage.get('xt_instance').then(function (curInstance) {
console.log(dT(), 'check instance', newInstance, curInstance) // console.log(dT(), 'check instance', newInstance, curInstance)
if (!idle || if (!idle ||
!curInstance || !curInstance ||
curInstance.id == instanceID || curInstance.id == instanceID ||

View File

@ -21,21 +21,10 @@ self.addEventListener('push', function(event) {
var hasActiveWindows = false var hasActiveWindows = false
var checksPromise = new Promise(function (resolve, reject) { var checksPromise = new Promise(function (resolve, reject) {
if (!obj.badge) {
return reject()
}
var nowTime = +(new Date()) var nowTime = +(new Date())
Promise.all([getMuteUntil(), getLastAliveTime()]).then(function (result) { Promise.all([getMuteUntil(), getLastAliveTime()]).then(function (result) {
var muteUntil = result[0] var muteUntil = result[0]
var lastAliveTime = result[1] var lastAliveTime = result[1]
if (userInvisibleIsSupported() &&
muteUntil &&
nowTime < muteUntil) {
console.log('Supress notification because mute for ', Math.ceil((muteUntil - nowTime) / 60000), 'min')
return reject()
}
if (lastAliveTime &&
nowTime - lastAliveTime < 60000) {
return clients.matchAll({type: 'window'}).then(function(clientList) { return clients.matchAll({type: 'window'}).then(function(clientList) {
console.log('matched clients', clientList) console.log('matched clients', clientList)
hasActiveWindows = clientList.length > 0 hasActiveWindows = clientList.length > 0
@ -43,12 +32,19 @@ self.addEventListener('push', function(event) {
console.log('Supress notification because some instance is alive') console.log('Supress notification because some instance is alive')
return reject() return reject()
} }
return resolve() if (userInvisibleIsSupported() &&
}) muteUntil &&
nowTime < muteUntil) {
console.log('Supress notification because mute for ', Math.ceil((muteUntil - nowTime) / 60000), 'min')
return reject()
}
if (!obj.badge) {
return reject()
} }
return resolve() return resolve()
}) })
}) })
})
var notificationPromise = checksPromise.then(function () { var notificationPromise = checksPromise.then(function () {
return Promise.all([getSettings(), getLang()]).then(function (result) { return Promise.all([getSettings(), getLang()]).then(function (result) {