Browse Source

Improved pushes in Chrome

master
Igor Zhukov 7 years ago
parent
commit
f4fe5941f7
  1. 2
      app/js/lib/mtproto_wrapper.js
  2. 40
      app/js/lib/push_worker.js

2
app/js/lib/mtproto_wrapper.js

@ -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 ||

40
app/js/lib/push_worker.js

@ -21,32 +21,28 @@ 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() && return clients.matchAll({type: 'window'}).then(function(clientList) {
muteUntil && console.log('matched clients', clientList)
nowTime < muteUntil) { hasActiveWindows = clientList.length > 0
console.log('Supress notification because mute for ', Math.ceil((muteUntil - nowTime) / 60000), 'min') if (hasActiveWindows) {
return reject() console.log('Supress notification because some instance is alive')
} return reject()
if (lastAliveTime && }
nowTime - lastAliveTime < 60000) { if (userInvisibleIsSupported() &&
return clients.matchAll({type: 'window'}).then(function(clientList) { muteUntil &&
console.log('matched clients', clientList) nowTime < muteUntil) {
hasActiveWindows = clientList.length > 0 console.log('Supress notification because mute for ', Math.ceil((muteUntil - nowTime) / 60000), 'min')
if (hasActiveWindows) { return reject()
console.log('Supress notification because some instance is alive') }
return reject() if (!obj.badge) {
} return reject()
return resolve() }
}) return resolve()
} })
return resolve()
}) })
}) })

Loading…
Cancel
Save