|
|
@ -840,6 +840,11 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
midnightOffseted = new Date(), |
|
|
|
midnightOffseted = new Date(), |
|
|
|
midnightOffset; |
|
|
|
midnightOffset; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Storage.get('server_time_offset').then(function (to) { |
|
|
|
|
|
|
|
if (to) { |
|
|
|
|
|
|
|
serverTimeOffset = to; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
var maxSeenID = false; |
|
|
|
var maxSeenID = false; |
|
|
|
if (Config.Modes.packed) { |
|
|
|
if (Config.Modes.packed) { |
|
|
@ -848,13 +853,9 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Storage.get('server_time_offset').then(function (to) { |
|
|
|
|
|
|
|
if (to) { |
|
|
|
|
|
|
|
serverTimeOffset = to; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var dateOrTimeFilter = $filter('dateOrTime'); |
|
|
|
var dateOrTimeFilter = $filter('dateOrTime'); |
|
|
|
|
|
|
|
var fwdMessagesPluralize = _.pluralize('conversation_forwarded_X_messages'); |
|
|
|
|
|
|
|
|
|
|
|
midnightOffseted.setHours(0); |
|
|
|
midnightOffseted.setHours(0); |
|
|
|
midnightOffseted.setMinutes(0); |
|
|
|
midnightOffseted.setMinutes(0); |
|
|
@ -966,9 +967,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
if (message.unread && !message.out) { |
|
|
|
if (message.unread && !message.out) { |
|
|
|
NotificationsManager.getPeerMuted(notifyPeer).then(function (muted) { |
|
|
|
NotificationsManager.getPeerMuted(notifyPeer).then(function (muted) { |
|
|
|
if (!muted) { |
|
|
|
if (!muted) { |
|
|
|
Storage.get('notify_nopreview').then(function (no_preview) { |
|
|
|
notifyAboutMessage(message); |
|
|
|
notifyAboutMessage(message, no_preview); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -1375,6 +1374,8 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NotificationsManager.soundReset(AppPeersManager.getPeerString(peerID)) |
|
|
|
|
|
|
|
|
|
|
|
return historyStorage.readPromise; |
|
|
|
return historyStorage.readPromise; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2255,7 +2256,9 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function notifyAboutMessage (message, no_preview) { |
|
|
|
function notifyAboutMessage (message, options) { |
|
|
|
|
|
|
|
options = options || {}; |
|
|
|
|
|
|
|
|
|
|
|
var peerID = getMessagePeer(message); |
|
|
|
var peerID = getMessagePeer(message); |
|
|
|
var fromUser = AppUsersManager.getUser(message.from_id); |
|
|
|
var fromUser = AppUsersManager.getUser(message.from_id); |
|
|
|
var fromPhoto = AppUsersManager.getUserPhoto(message.from_id, 'User'); |
|
|
|
var fromPhoto = AppUsersManager.getUserPhoto(message.from_id, 'User'); |
|
|
@ -2264,8 +2267,12 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
notificationMessage = false, |
|
|
|
notificationMessage = false, |
|
|
|
notificationPhoto; |
|
|
|
notificationPhoto; |
|
|
|
|
|
|
|
|
|
|
|
if (message.message) { |
|
|
|
var notifySettings = NotificationsManager.getNotifySettings(); |
|
|
|
if (no_preview) { |
|
|
|
|
|
|
|
|
|
|
|
if (message.fwd_from_id && options.fwd_count) { |
|
|
|
|
|
|
|
notificationMessage = fwdMessagesPluralize(options.fwd_count); |
|
|
|
|
|
|
|
} else if (message.message) { |
|
|
|
|
|
|
|
if (notifySettings.nopreview) { |
|
|
|
notificationMessage = _('conversation_message_sent'); |
|
|
|
notificationMessage = _('conversation_message_sent'); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
notificationMessage = RichTextProcessor.wrapPlainText(message.message); |
|
|
|
notificationMessage = RichTextProcessor.wrapPlainText(message.message); |
|
|
@ -2303,6 +2310,9 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
case 'messageActionChatDeleteUser': |
|
|
|
case 'messageActionChatDeleteUser': |
|
|
|
notificationMessage = message.action.user_id == message.from_id ? _('conversation_left_group') : _('conversation_kicked_user_message_raw'); |
|
|
|
notificationMessage = message.action.user_id == message.from_id ? _('conversation_left_group') : _('conversation_kicked_user_message_raw'); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
case 'messageActionChatJoinedByLink': |
|
|
|
|
|
|
|
notificationMessage = _('conversation_joined_by_link'); |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2380,6 +2390,8 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
var newMessagesToHandle = {}; |
|
|
|
var newMessagesToHandle = {}; |
|
|
|
var newDialogsHandlePromise = false; |
|
|
|
var newDialogsHandlePromise = false; |
|
|
|
var newDialogsToHandle = {}; |
|
|
|
var newDialogsToHandle = {}; |
|
|
|
|
|
|
|
var notificationsHandlePromise = false; |
|
|
|
|
|
|
|
var notificationsToHandle = {}; |
|
|
|
|
|
|
|
|
|
|
|
function handleNewMessages () { |
|
|
|
function handleNewMessages () { |
|
|
|
$timeout.cancel(newMessagesHandlePromise); |
|
|
|
$timeout.cancel(newMessagesHandlePromise); |
|
|
@ -2395,6 +2407,31 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
newDialogsToHandle = {}; |
|
|
|
newDialogsToHandle = {}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function handleNotifications () { |
|
|
|
|
|
|
|
$timeout.cancel(notificationsHandlePromise); |
|
|
|
|
|
|
|
notificationsHandlePromise = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var timeout = $rootScope.idle.isIDLE && StatusManager.isOtherDeviceActive() ? 30000 : 1000; |
|
|
|
|
|
|
|
angular.forEach(notificationsToHandle, function (notifyPeerToHandle) { |
|
|
|
|
|
|
|
notifyPeerToHandle.isMutedPromise.then(function (muted) { |
|
|
|
|
|
|
|
var topMessage = notifyPeerToHandle.top_message; |
|
|
|
|
|
|
|
if (muted || |
|
|
|
|
|
|
|
!topMessage.unread) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
setTimeout(function () { |
|
|
|
|
|
|
|
if (topMessage.unread) { |
|
|
|
|
|
|
|
notifyAboutMessage(topMessage, { |
|
|
|
|
|
|
|
fwd_count: notifyPeerToHandle.fwd_count |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, timeout); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
notificationsToHandle = {}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$rootScope.$on('apiUpdate', function (e, update) { |
|
|
|
$rootScope.$on('apiUpdate', function (e, update) { |
|
|
|
// if (update._ != 'updateUserStatus') {
|
|
|
|
// if (update._ != 'updateUserStatus') {
|
|
|
|
// console.log('on apiUpdate', update);
|
|
|
|
// console.log('on apiUpdate', update);
|
|
|
@ -2490,17 +2527,28 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
if (inboxUnread && ($rootScope.selectedPeerID != peerID || $rootScope.idle.isIDLE)) { |
|
|
|
if (inboxUnread && ($rootScope.selectedPeerID != peerID || $rootScope.idle.isIDLE)) { |
|
|
|
|
|
|
|
|
|
|
|
var notifyPeer = message.flags & 16 ? message.from_id : peerID; |
|
|
|
var notifyPeer = message.flags & 16 ? message.from_id : peerID; |
|
|
|
var isMutedPromise = NotificationsManager.getPeerMuted(notifyPeer); |
|
|
|
var notifyPeerToHandle = notificationsToHandle[notifyPeer]; |
|
|
|
var timeout = $rootScope.idle.isIDLE && StatusManager.isOtherDeviceActive() ? 30000 : 1000; |
|
|
|
if (notifyPeerToHandle === undefined) { |
|
|
|
setTimeout(function () { |
|
|
|
notifyPeerToHandle = notificationsToHandle[notifyPeer] = { |
|
|
|
isMutedPromise.then(function (muted) { |
|
|
|
isMutedPromise: NotificationsManager.getPeerMuted(notifyPeer), |
|
|
|
if (message.unread && !muted) { |
|
|
|
fwd_count: 0, |
|
|
|
Storage.get('notify_nopreview').then(function (no_preview) { |
|
|
|
from_id: 0 |
|
|
|
notifyAboutMessage(message, no_preview); |
|
|
|
}; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (notifyPeerToHandle.from_id != message.from_id) { |
|
|
|
|
|
|
|
notifyPeerToHandle.from_id = message.from_id; |
|
|
|
|
|
|
|
notifyPeerToHandle.fwd_count = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (message.fwd_from_id) { |
|
|
|
|
|
|
|
notifyPeerToHandle.fwd_count++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
notifyPeerToHandle.top_message = message; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!notificationsHandlePromise) { |
|
|
|
|
|
|
|
notificationsHandlePromise = $timeout(handleNotifications, 1000); |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
}, timeout); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
incrementMaxSeenID(message.id); |
|
|
|
incrementMaxSeenID(message.id); |
|
|
@ -4522,6 +4570,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
var notificationsShown = {}; |
|
|
|
var notificationsShown = {}; |
|
|
|
var notificationIndex = 0; |
|
|
|
var notificationIndex = 0; |
|
|
|
var notificationsCount = 0; |
|
|
|
var notificationsCount = 0; |
|
|
|
|
|
|
|
var soundsPlayed = {}; |
|
|
|
var vibrateSupport = !!navigator.vibrate; |
|
|
|
var vibrateSupport = !!navigator.vibrate; |
|
|
|
var nextSoundAt = false; |
|
|
|
var nextSoundAt = false; |
|
|
|
var prevSoundVolume = false; |
|
|
|
var prevSoundVolume = false; |
|
|
@ -4534,6 +4583,8 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
titlePromise; |
|
|
|
titlePromise; |
|
|
|
var prevFavicon; |
|
|
|
var prevFavicon; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var settings = {}; |
|
|
|
|
|
|
|
|
|
|
|
$rootScope.$watch('idle.isIDLE', function (newVal) { |
|
|
|
$rootScope.$watch('idle.isIDLE', function (newVal) { |
|
|
|
if (!newVal) { |
|
|
|
if (!newVal) { |
|
|
|
notificationsClear(); |
|
|
|
notificationsClear(); |
|
|
@ -4596,14 +4647,34 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
notify: notify, |
|
|
|
notify: notify, |
|
|
|
cancel: notificationCancel, |
|
|
|
cancel: notificationCancel, |
|
|
|
clear: notificationsClear, |
|
|
|
clear: notificationsClear, |
|
|
|
|
|
|
|
soundReset: notificationSoundReset, |
|
|
|
getPeerSettings: getPeerSettings, |
|
|
|
getPeerSettings: getPeerSettings, |
|
|
|
getPeerMuted: getPeerMuted, |
|
|
|
getPeerMuted: getPeerMuted, |
|
|
|
savePeerSettings: savePeerSettings, |
|
|
|
savePeerSettings: savePeerSettings, |
|
|
|
updatePeerSettings: updatePeerSettings, |
|
|
|
updatePeerSettings: updatePeerSettings, |
|
|
|
|
|
|
|
updateNotifySettings: updateNotifySettings, |
|
|
|
|
|
|
|
getNotifySettings: getNotifySettings, |
|
|
|
getVibrateSupport: getVibrateSupport, |
|
|
|
getVibrateSupport: getVibrateSupport, |
|
|
|
testSound: playSound |
|
|
|
testSound: playSound |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function updateNotifySettings () { |
|
|
|
|
|
|
|
Storage.get('notify_nodesktop', 'notify_volume', 'notify_novibrate', 'notify_nopreview').then(function (updSettings) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
settings.nodesktop = updSettings[0]; |
|
|
|
|
|
|
|
settings.volume = updSettings[1] === false |
|
|
|
|
|
|
|
? 0.5 |
|
|
|
|
|
|
|
: updSettings[1]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
settings.novibrate = updSettings[2]; |
|
|
|
|
|
|
|
settings.nopreview = updSettings[3]; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getNotifySettings () { |
|
|
|
|
|
|
|
return settings; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getPeerSettings (peerID) { |
|
|
|
function getPeerSettings (peerID) { |
|
|
|
if (peerSettings[peerID] !== undefined) { |
|
|
|
if (peerSettings[peerID] !== undefined) { |
|
|
|
return peerSettings[peerID]; |
|
|
|
return peerSettings[peerID]; |
|
|
@ -4660,7 +4731,10 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function start () { |
|
|
|
function start () { |
|
|
|
|
|
|
|
updateNotifySettings(); |
|
|
|
|
|
|
|
$rootScope.$on('settings_changed', updateNotifySettings); |
|
|
|
registerDevice(); |
|
|
|
registerDevice(); |
|
|
|
|
|
|
|
|
|
|
|
if (!notificationsUiSupport) { |
|
|
|
if (!notificationsUiSupport) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
@ -4695,25 +4769,31 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
|
|
|
|
|
|
|
|
notificationsCount++; |
|
|
|
notificationsCount++; |
|
|
|
|
|
|
|
|
|
|
|
Storage.get('notify_nosound', 'notify_volume').then(function (settings) { |
|
|
|
var now = tsNow(); |
|
|
|
if (!settings[0] && settings[1] === false || settings[1] > 0) { |
|
|
|
if (settings.volume > 0 && |
|
|
|
playSound(settings[1] || 0.5); |
|
|
|
( |
|
|
|
|
|
|
|
!data.tag || |
|
|
|
|
|
|
|
!soundsPlayed[data.tag] || |
|
|
|
|
|
|
|
now > soundsPlayed[data.tag] + 60000 |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
playSound(settings.volume); |
|
|
|
|
|
|
|
soundsPlayed[data.tag] = now; |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!notificationsUiSupport || |
|
|
|
if (!notificationsUiSupport || |
|
|
|
'Notification' in window && Notification.permission !== 'granted') { |
|
|
|
'Notification' in window && Notification.permission !== 'granted') { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Storage.get('notify_nodesktop', 'notify_novibrate').then(function (settings) { |
|
|
|
if (settings.nodesktop) { |
|
|
|
if (settings[0]) { |
|
|
|
if (vibrateSupport && !settings.novibrate) { |
|
|
|
if (vibrateSupport && !settings[1]) { |
|
|
|
|
|
|
|
navigator.vibrate([200, 100, 200]); |
|
|
|
navigator.vibrate([200, 100, 200]); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var idx = ++notificationIndex, |
|
|
|
var idx = ++notificationIndex, |
|
|
|
key = data.key || 'k' + idx, |
|
|
|
key = data.key || 'k' + idx, |
|
|
|
notification; |
|
|
|
notification; |
|
|
@ -4758,7 +4838,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
notification.show(); |
|
|
|
notification.show(); |
|
|
|
} |
|
|
|
} |
|
|
|
notificationsShown[key] = notification; |
|
|
|
notificationsShown[key] = notification; |
|
|
|
}); |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
function playSound (volume) { |
|
|
|
function playSound (volume) { |
|
|
@ -4795,6 +4874,10 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function notificationSoundReset (tag) { |
|
|
|
|
|
|
|
delete soundsPlayed[tag]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function notificationsClear() { |
|
|
|
function notificationsClear() { |
|
|
|
if (notificationsMsSiteMode) { |
|
|
|
if (notificationsMsSiteMode) { |
|
|
|
window.external.msSiteModeClearIconOverlay(); |
|
|
|
window.external.msSiteModeClearIconOverlay(); |
|
|
|