|
|
@ -1013,6 +1013,7 @@ angular.module('myApp.services', []) |
|
|
|
|
|
|
|
|
|
|
|
notification.message = notificationMessage; |
|
|
|
notification.message = notificationMessage; |
|
|
|
notification.image = notificationPhoto.placeholder; |
|
|
|
notification.image = notificationPhoto.placeholder; |
|
|
|
|
|
|
|
notification.key = 'msg' + message.id; |
|
|
|
|
|
|
|
|
|
|
|
if (notificationPhoto.location) { |
|
|
|
if (notificationPhoto.location) { |
|
|
|
MtpApiFileManager.downloadSmallFile(notificationPhoto.location, notificationPhoto.size).then(function (url) { |
|
|
|
MtpApiFileManager.downloadSmallFile(notificationPhoto.location, notificationPhoto.size).then(function (url) { |
|
|
@ -1117,6 +1118,8 @@ angular.module('myApp.services', []) |
|
|
|
if (foundDialog) { |
|
|
|
if (foundDialog) { |
|
|
|
dialogsUpdated[peerID] = --foundDialog[0].unread_count; |
|
|
|
dialogsUpdated[peerID] = --foundDialog[0].unread_count; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NotificationsManager.cancel('msg' + messageID); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1917,8 +1920,10 @@ angular.module('myApp.services', []) |
|
|
|
|
|
|
|
|
|
|
|
.service('NotificationsManager', function ($rootScope, $window, $timeout, $interval, MtpApiManager, AppPeersManager, IdleManager) { |
|
|
|
.service('NotificationsManager', function ($rootScope, $window, $timeout, $interval, MtpApiManager, AppPeersManager, IdleManager) { |
|
|
|
|
|
|
|
|
|
|
|
var notificationsUiSupport = window.webkitNotifications !== undefined; |
|
|
|
var notificationsUiSupport = 'Notification' in window; |
|
|
|
var notificationsShown = []; |
|
|
|
var notificationsShown = {}; |
|
|
|
|
|
|
|
// var lastClosed = [];
|
|
|
|
|
|
|
|
var notificationIndex = 0; |
|
|
|
var notificationsCount = 0; |
|
|
|
var notificationsCount = 0; |
|
|
|
var peerSettings = {}; |
|
|
|
var peerSettings = {}; |
|
|
|
var faviconEl = $('link[rel="icon"]'); |
|
|
|
var faviconEl = $('link[rel="icon"]'); |
|
|
@ -1956,6 +1961,7 @@ angular.module('myApp.services', []) |
|
|
|
return { |
|
|
|
return { |
|
|
|
start: start, |
|
|
|
start: start, |
|
|
|
notify: notify, |
|
|
|
notify: notify, |
|
|
|
|
|
|
|
cancel: notificationCancel, |
|
|
|
getPeerSettings: getPeerSettings |
|
|
|
getPeerSettings: getPeerSettings |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -1981,25 +1987,23 @@ angular.module('myApp.services', []) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var havePermission = window.webkitNotifications.checkPermission(); |
|
|
|
if (Notification.permission !== 'granted' && Notification.permission !== 'denied') { |
|
|
|
// console.log('perm', havePermission);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (havePermission != 0) { // 0 is PERMISSION_ALLOWED
|
|
|
|
|
|
|
|
$($window).on('click', requestPermission); |
|
|
|
$($window).on('click', requestPermission); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
$($window).on('beforeunload', notificationsClear); |
|
|
|
$($window).on('beforeunload', notificationsClear); |
|
|
|
} catch (e) {} |
|
|
|
} catch (e) {} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function requestPermission() { |
|
|
|
function requestPermission() { |
|
|
|
window.webkitNotifications.requestPermission(); |
|
|
|
Notification.requestPermission(); |
|
|
|
$($window).off('click', requestPermission); |
|
|
|
$($window).off('click', requestPermission); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function notify (data) { |
|
|
|
function notify (data) { |
|
|
|
// console.log('notify', $rootScope.idle.isIDLE);
|
|
|
|
// console.log('notify', $rootScope.idle.isIDLE, notificationsUiSupport);
|
|
|
|
if (!$rootScope.idle.isIDLE) { |
|
|
|
if (!$rootScope.idle.isIDLE) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
@ -2007,15 +2011,17 @@ angular.module('myApp.services', []) |
|
|
|
notificationsCount++; |
|
|
|
notificationsCount++; |
|
|
|
|
|
|
|
|
|
|
|
if (!notificationsUiSupport || |
|
|
|
if (!notificationsUiSupport || |
|
|
|
window.webkitNotifications.checkPermission() != 0) { |
|
|
|
Notification.permission !== 'granted') { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var notification = window.webkitNotifications.createNotification( |
|
|
|
var idx = ++notificationIndex, |
|
|
|
data.image || '', |
|
|
|
key = data.key || 'k' + idx; |
|
|
|
data.title || '', |
|
|
|
|
|
|
|
data.message || '' |
|
|
|
var notification = new Notification(data.title, { |
|
|
|
); |
|
|
|
icon: data.image || '', |
|
|
|
|
|
|
|
body: data.message || '' |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
notification.onclick = function () { |
|
|
|
notification.onclick = function () { |
|
|
|
notification.close(); |
|
|
|
notification.close(); |
|
|
@ -2026,24 +2032,39 @@ angular.module('myApp.services', []) |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
notification.onclose = function () { |
|
|
|
|
|
|
|
delete notificationsShown[key]; |
|
|
|
|
|
|
|
// lastClosed.push(+new Date());
|
|
|
|
|
|
|
|
notificationsClear(); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// console.log('notify', notification);
|
|
|
|
// console.log('notify', notification);
|
|
|
|
|
|
|
|
|
|
|
|
notification.show(); |
|
|
|
notification.show(); |
|
|
|
|
|
|
|
|
|
|
|
notificationsShown.push(notification); |
|
|
|
notificationsShown[key] = notification; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function notificationCancel (key) { |
|
|
|
|
|
|
|
var notification = notificationsShown[key]; |
|
|
|
|
|
|
|
if (notification) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
if (notification.close) { |
|
|
|
|
|
|
|
notification.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (e) {} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function notificationsClear() { |
|
|
|
function notificationsClear() { |
|
|
|
angular.forEach(notificationsShown, function (notification) { |
|
|
|
angular.forEach(notificationsShown, function (notification) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (notification.close) { |
|
|
|
if (notification.close) { |
|
|
|
notification.close() |
|
|
|
notification.close() |
|
|
|
} else if (notification.cancel) { |
|
|
|
|
|
|
|
notification.cancel(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e) {} |
|
|
|
} catch (e) {} |
|
|
|
}); |
|
|
|
}); |
|
|
|
notificationsShown = []; |
|
|
|
notificationsShown = {}; |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|