Added check for other active device before notify

Closes #644
This commit is contained in:
Igor Zhukov 2015-01-16 15:36:51 +03:00
parent fbf87d499a
commit 4012135f26

View File

@ -687,7 +687,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
} }
}) })
.service('AppMessagesManager', function ($q, $rootScope, $location, $filter, ApiUpdatesManager, AppUsersManager, AppChatsManager, AppPeersManager, AppPhotosManager, AppVideoManager, AppDocsManager, AppAudioManager, MtpApiManager, MtpApiFileManager, RichTextProcessor, NotificationsManager, SearchIndexManager, PeersSelectService, Storage, FileManager, TelegramMeWebService, _) { .service('AppMessagesManager', function ($q, $rootScope, $location, $filter, ApiUpdatesManager, AppUsersManager, AppChatsManager, AppPeersManager, AppPhotosManager, AppVideoManager, AppDocsManager, AppAudioManager, MtpApiManager, MtpApiFileManager, RichTextProcessor, NotificationsManager, SearchIndexManager, PeersSelectService, Storage, FileManager, TelegramMeWebService, StatusManager, _) {
var messagesStorage = {}; var messagesStorage = {};
var messagesForHistory = {}; var messagesForHistory = {};
@ -2100,16 +2100,18 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
dialogsStorage.dialogs.unshift(dialog); dialogsStorage.dialogs.unshift(dialog);
$rootScope.$broadcast('dialogs_update', dialog); $rootScope.$broadcast('dialogs_update', dialog);
if (($rootScope.selectedPeerID != peerID || $rootScope.idle.isIDLE) &&
if ((Config.Mobile && $rootScope.selectedPeerID != peerID || $rootScope.idle.isIDLE) &&
!message.out && !message.out &&
message.unread) { message.unread) {
NotificationsManager.getPeerMuted(peerID).then(function (muted) {
if (!message.unread || muted) { var isMutedPromise = NotificationsManager.getPeerMuted(peerID);
return; var timeout = $rootScope.idle.isIDLE && StatusManager.isOtherDeviceActive() ? 30000 : 1000;
setTimeout(function () {
isMutedPromise.then(function (muted) {
if (message.unread && !muted) {
notifyAboutMessage(message);
} }
notifyAboutMessage(message); }, timeout);
});
} }
break; break;
@ -2252,7 +2254,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
} }
}) })
.service('AppPhotosManager', function ($modal, $window, $timeout, $rootScope, MtpApiManager, MtpApiFileManager, AppUsersManager, FileManager) { .service('AppPhotosManager', function ($modal, $window, $rootScope, MtpApiManager, MtpApiFileManager, AppUsersManager, FileManager) {
var photos = {}, var photos = {},
windowW = $(window).width(), windowW = $(window).width(),
windowH = $(window).height(); windowH = $(window).height();
@ -2489,7 +2491,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}) })
.service('AppVideoManager', function ($sce, $rootScope, $modal, $window, $timeout, MtpApiFileManager, AppUsersManager, FileManager) { .service('AppVideoManager', function ($sce, $rootScope, $modal, $window, MtpApiFileManager, AppUsersManager, FileManager) {
var videos = {}, var videos = {},
videosForHistory = {}, videosForHistory = {},
windowW = $(window).width(), windowW = $(window).width(),
@ -2675,7 +2677,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
} }
}) })
.service('AppDocsManager', function ($sce, $rootScope, $modal, $window, $timeout, $q, MtpApiFileManager, FileManager) { .service('AppDocsManager', function ($sce, $rootScope, $modal, $window, $q, MtpApiFileManager, FileManager) {
var docs = {}, var docs = {},
docsForHistory = {}, docsForHistory = {},
windowW = $(window).width(), windowW = $(window).width(),
@ -2877,7 +2879,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
} }
}) })
.service('AppAudioManager', function ($sce, $rootScope, $modal, $window, $timeout, MtpApiFileManager, FileManager) { .service('AppAudioManager', function ($sce, $rootScope, $modal, $window, MtpApiFileManager, FileManager) {
var audios = {}; var audios = {};
var audiosForHistory = {}; var audiosForHistory = {};
@ -3508,10 +3510,25 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
.service('StatusManager', function ($timeout, $rootScope, MtpApiManager, IdleManager) { .service('StatusManager', function ($timeout, $rootScope, MtpApiManager, IdleManager) {
var toPromise, lastOnlineUpdated = 0, started = false; var toPromise;
var lastOnlineUpdated = 0
var started = false;
var myID = 0;
var myOtherDeviceActive = false;
MtpApiManager.getUserID().then(function (id) {
myID = id;
});
$rootScope.$on('apiUpdate', function (e, update) {
if (update._ == 'updateUserStatus' && update.user_id == myID) {
myOtherDeviceActive = tsNow() + (update.status._ == 'userStatusOnline' ? 300000 : 0);
}
});
return { return {
start: start start: start,
isOtherDeviceActive: isOtherDeviceActive
}; };
function start() { function start() {
@ -3547,9 +3564,20 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
} }
} }
function isOtherDeviceActive() {
if (!myOtherDeviceActive) {
return false;
}
if (tsNow() > myOtherDeviceActive) {
myOtherDeviceActive = false;
return false;
}
return true;
}
}) })
.service('NotificationsManager', function ($rootScope, $window, $timeout, $interval, $q, _, MtpApiManager, AppPeersManager, IdleManager, Storage, AppRuntimeManager) { .service('NotificationsManager', function ($rootScope, $window, $interval, $q, _, MtpApiManager, AppPeersManager, IdleManager, Storage, AppRuntimeManager) {
navigator.vibrate = navigator.vibrate || navigator.mozVibrate || navigator.webkitVibrate; navigator.vibrate = navigator.vibrate || navigator.mozVibrate || navigator.webkitVibrate;