diff --git a/app/index.html b/app/index.html index 5f69ec50..1bb283d4 100644 --- a/app/index.html +++ b/app/index.html @@ -36,8 +36,8 @@ - - + + diff --git a/app/js/app.js b/app/js/app.js index 828de512..385303fb 100644 --- a/app/js/app.js +++ b/app/js/app.js @@ -48,7 +48,7 @@ config(['$locationProvider', '$routeProvider', '$compileProvider', function($loc // $locationProvider.html5Mode(true); $routeProvider.when('/', {templateUrl: 'partials/welcome.html', controller: 'AppWelcomeController'}); - $routeProvider.when('/login', {templateUrl: 'partials/login.html', controller: 'AppLoginController'}); + $routeProvider.when('/login', {templateUrl: 'partials/login.html?1', controller: 'AppLoginController'}); $routeProvider.when('/im', {templateUrl: 'partials/im.html', controller: 'AppIMController', reloadOnSearch: false}); $routeProvider.otherwise({redirectTo: '/'}); diff --git a/app/js/controllers.js b/app/js/controllers.js index 38595c1c..acd0fc38 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -25,6 +25,7 @@ angular.module('myApp.controllers', []) var dcID = 1; $scope.credentials = {}; + $scope.progress = {}; function saveAuth (result) { MtpApiManager.setUserAuth(dcID, { @@ -36,18 +37,21 @@ angular.module('myApp.controllers', []) }; $scope.sendCode = function () { + $scope.progress.enabled = true; MtpApiManager.invokeApi('auth.sendCode', { phone_number: $scope.credentials.phone_number, sms_type: 0, api_id: 2496, api_hash: '8da85b0d5bfe62527e5b244c209159c3' }, {dcID: dcID}).then(function (sentCode) { + $scope.progress.enabled = false; $scope.credentials.phone_code_hash = sentCode.phone_code_hash; $scope.credentials.phone_occupied = sentCode.phone_registered; $scope.error = {}; }, function (error) { + $scope.progress.enabled = false; dLog('sendCode', error); if (error.code == 303) { var newDcID = error.type.match(/^(PHONE_MIGRATE_|NETWORK_MIGRATE_)(\d+)/)[2]; @@ -79,13 +83,16 @@ angular.module('myApp.controllers', []) }); } + $scope.progress.enabled = true; MtpApiManager.invokeApi(method, params, {dcID: dcID}).then(saveAuth, function (error) { + $scope.progress.enabled = false; if (error.code == 400 && error.type == 'PHONE_NUMBER_UNOCCUPIED') { return $scope.logIn(true); } else if (error.code == 400 && error.type == 'PHONE_NUMBER_UNOCCUPIED') { return $scope.logIn(false); } + switch (error.type) { case 'FIRSTNAME_INVALID': $scope.error = {field: 'first_name'}; diff --git a/app/js/services.js b/app/js/services.js index 0eaee69c..8fbf48eb 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -927,6 +927,76 @@ angular.module('myApp.services', []) return []; } + function notifyAboutMessage (message) { + var peerID = getMessagePeer(message); + var fromUser = AppUsersManager.getUser(message.from_id); + var fromPhoto = AppUsersManager.getUserPhoto(message.from_id, 'User'); + var peerString; + var notification = {}, + notificationMessage = false, + notificationPhoto; + + if (message.message) { + notificationMessage = message.message; + } else if (message.media && message.media._ != 'messageMediaEmpty') { + switch (message.media._) { + case 'messageMediaPhoto': notificationMessage = 'Photo'; break; + case 'messageMediaVideo': notificationMessage = 'Video'; break; + case 'messageMediaDocument': notificationMessage = 'Document'; break; + case 'messageMediaGeo': notificationMessage = 'Location'; break; + case 'messageMediaContact': notificationMessage = 'Contact'; break; + default: notificationMessage = 'Attachment'; break; + } + } else if (message._ == 'messageService') { + switch (message.action._) { + case 'messageActionChatCreate': notificationMessage = 'created the group'; break; + case 'messageActionChatEditTitle': notificationMessage = 'changed group name'; break; + case 'messageActionChatEditPhoto': notificationMessage = 'changed group photo'; break; + case 'messageActionChatDeletePhoto': notificationMessage = 'removed group photo'; break; + case 'messageActionChatAddUser': notificationMessage = 'invited user'; break; + case 'messageActionChatDeleteUser': notificationMessage = 'kicked user'; break; + } + } + + if (peerID > 0) { + notification.title = (fromUser.first_name || '') + + (fromUser.first_name && fromUser.last_name ? ' ' : '') + + (fromUser.last_name || ''); + + notificationPhoto = fromPhoto; + + peerString = AppUsersManager.getUserString(peerID); + + } else { + notification.title = (fromUser.first_name || fromUser.last_name || 'Somebody') + + ' @ ' + + (AppChatsManager.getChat(-peerID).title || 'Unknown chat'); + + notificationPhoto = AppChatsManager.getChatPhoto(-peerID, 'Chat'); + + peerString = AppChatsManager.getChatString(-peerID); + } + + notification.onclick = function () { + $location.url('/im?p=' + peerString); + }; + + notification.message = notificationMessage; + notification.image = notificationPhoto.placeholder; + + if (notificationPhoto.location) { + MtpApiFileManager.downloadSmallFile(notificationPhoto.location, notificationPhoto.size).then(function (url) { + notification.image = url; + + if (message.unread) { + NotificationsManager.notify(notification); + } + }); + } else { + NotificationsManager.notify(notification); + } + } + $rootScope.$on('apiUpdate', function (e, update) { dLog('on apiUpdate', update); switch (update._) { @@ -989,54 +1059,12 @@ angular.module('myApp.services', []) if ($rootScope.idle.isIDLE && !message.out && message.unread) { - var fromUser = AppUsersManager.getUser(message.from_id); - var fromPhoto = AppUsersManager.getUserPhoto(message.from_id, 'User'); - var peerString; - var notification = {}, - notificationPhoto; - - if (peerID > 0) { - notification.title = (fromUser.first_name || '') + - (fromUser.first_name && fromUser.last_name ? ' ' : '') + - (fromUser.last_name || ''); - - notification.message = message.message; - - notificationPhoto = fromPhoto; - - peerString = AppUsersManager.getUserString(peerID); - - } else { - notification.title = fromUser.first_name || fromUser.last_name || 'Somebody' + - ' @ ' + - AppChatsManager.getChat(-peerID).title || 'Unknown chat'; - - notification.message = message.message; - - notificationPhoto = AppChatsManager.getChatPhoto(-peerID, 'Chat'); - - peerString = AppChatsManager.getChatString(-peerID); - } - - notification.onclick = function () { - $location.url('/im?p=' + peerString); - }; - - notification.image = notificationPhoto.placeholder; - - if (notificationPhoto.location) { - MtpApiFileManager.downloadSmallFile(notificationPhoto.location, notificationPhoto.size).then(function (url) { - notification.image = url; - - if (message.unread) { - // dLog(111, notification); - NotificationsManager.notify(notification); - } - }); - } else { - // dLog(222, notification); - NotificationsManager.notify(notification); - } + NotificationsManager.getPeerSettings(peerID).then(function (muted) { + if (!message.unread || muted) { + return; + } + notifyAboutMessage(message); + }); } break; @@ -1787,11 +1815,12 @@ angular.module('myApp.services', []) }) -.service('NotificationsManager', function ($rootScope, $window, $timeout, $interval, IdleManager) { +.service('NotificationsManager', function ($rootScope, $window, $timeout, $interval, MtpApiManager, AppPeersManager, IdleManager) { var notificationsUiSupport = window.webkitNotifications !== undefined; var notificationsShown = []; var notificationsCount = 0; + var peerSettings = {}; var titleBackup = document.title, titlePromise; @@ -1820,9 +1849,27 @@ angular.module('myApp.services', []) return { start: start, - notify: notify + notify: notify, + getPeerSettings: getPeerSettings }; + function getPeerSettings (peerID) { + if (peerSettings[peerID] !== undefined) { + return peerSettings[peerID]; + } + + return peerSettings[peerID] = MtpApiManager.invokeApi('account.getNotifySettings', { + peer: { + _: 'inputNotifyPeer', + peer: AppPeersManager.getInputPeerByID(peerID) + } + }).then(function (peerNotifySettings) { + // dLog('got settings', peerID, peerNotifySettings); + return peerNotifySettings._ == 'peerNotifySettings' && + peerNotifySettings.mute_until * 1000 > (+new Date()); + }); + } + function start () { if (!notificationsUiSupport) { return false; diff --git a/app/partials/login.html b/app/partials/login.html index 0b616d4c..974e0e89 100644 --- a/app/partials/login.html +++ b/app/partials/login.html @@ -11,7 +11,9 @@ - +
@@ -23,6 +25,8 @@ - +
\ No newline at end of file