From f4fe5941f763c9bdc24b2db8ce1bca8ebd0ce9dc Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Thu, 11 May 2017 20:16:40 +0300 Subject: [PATCH] Improved pushes in Chrome --- app/js/lib/mtproto_wrapper.js | 2 +- app/js/lib/push_worker.js | 40 ++++++++++++++++------------------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/app/js/lib/mtproto_wrapper.js b/app/js/lib/mtproto_wrapper.js index a3c77d72..85ef5943 100644 --- a/app/js/lib/mtproto_wrapper.js +++ b/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} Storage.get('xt_instance').then(function (curInstance) { - console.log(dT(), 'check instance', newInstance, curInstance) + // console.log(dT(), 'check instance', newInstance, curInstance) if (!idle || !curInstance || curInstance.id == instanceID || diff --git a/app/js/lib/push_worker.js b/app/js/lib/push_worker.js index acaf6882..517093b7 100644 --- a/app/js/lib/push_worker.js +++ b/app/js/lib/push_worker.js @@ -21,32 +21,28 @@ self.addEventListener('push', function(event) { var hasActiveWindows = false var checksPromise = new Promise(function (resolve, reject) { - if (!obj.badge) { - return reject() - } var nowTime = +(new Date()) Promise.all([getMuteUntil(), getLastAliveTime()]).then(function (result) { var muteUntil = result[0] 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) { - console.log('matched clients', clientList) - hasActiveWindows = clientList.length > 0 - if (hasActiveWindows) { - console.log('Supress notification because some instance is alive') - return reject() - } - return resolve() - }) - } - return resolve() + return clients.matchAll({type: 'window'}).then(function(clientList) { + console.log('matched clients', clientList) + hasActiveWindows = clientList.length > 0 + if (hasActiveWindows) { + console.log('Supress notification because some instance is alive') + return reject() + } + 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() + }) }) })