Improved notifications, added simple login progress indication
This commit is contained in:
parent
f38f15f4a7
commit
8cf1125b78
@ -36,8 +36,8 @@
|
||||
|
||||
<script type="text/javascript" src="js/util.js"></script>
|
||||
<script type="text/javascript" src="js/app.js"></script>
|
||||
<script type="text/javascript" src="js/services.js?2"></script>
|
||||
<script type="text/javascript" src="js/controllers.js?1"></script>
|
||||
<script type="text/javascript" src="js/services.js?3"></script>
|
||||
<script type="text/javascript" src="js/controllers.js?2"></script>
|
||||
<script type="text/javascript" src="js/filters.js?1"></script>
|
||||
<script type="text/javascript" src="js/directives.js?2"></script>
|
||||
|
||||
|
@ -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: '/'});
|
||||
|
||||
|
@ -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'};
|
||||
|
@ -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;
|
||||
|
@ -11,7 +11,9 @@
|
||||
<label class="control-label" for="phone_number" ng-if="error.field == 'phone'">Incorrect phone number</label>
|
||||
<input type="text" class="form-control" name="phone_number" ng-model="credentials.phone_number" placeholder="Enter your phone" required>
|
||||
</div>
|
||||
<button class="btn btn-tg btn-block" type="submit">Next</button>
|
||||
<button class="btn btn-tg btn-block" ng-class="{disabled: progress.enabled}" ng-disabled="progress.enabled" type="submit">
|
||||
{{progress.enabled ? 'Generating keys...' : 'Next'}}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<form name="myLoginForm" ng-if="credentials.phone_code_hash" ng-submit="logIn()">
|
||||
@ -23,6 +25,8 @@
|
||||
<input type="text" class="form-control" name="phone_code" ng-model="credentials.phone_code" placeholder="Enter your code" required>
|
||||
</div>
|
||||
|
||||
<button class="btn btn-tg btn-block" type="submit">Sign in</button>
|
||||
<button class="btn btn-tg btn-block" type="submit" ng-class="{disabled: progress.enabled}" ng-disabled="progress.enabled">
|
||||
{{progress.enabled ? 'Checking code...' : 'Sign in'}}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user