Browse Source

merge with master

gh-pages
Igor Zhukov 11 years ago
parent
commit
cdc8a335ed
  1. 8
      index.html
  2. 2
      js/app.js
  3. 7
      js/controllers.js
  4. 3
      js/directives.js
  5. 25
      js/lib/mtproto.js
  6. 147
      js/services.js
  7. 2
      partials/dialog.html
  8. 8
      partials/login.html

8
index.html

@ -32,14 +32,14 @@
<script type="text/javascript" src="js/lib/config.js"></script> <script type="text/javascript" src="js/lib/config.js"></script>
<script type="text/javascript" src="js/lib/mtproto.js"></script> <script type="text/javascript" src="js/lib/mtproto.js?1"></script>
<script type="text/javascript" src="js/util.js"></script> <script type="text/javascript" src="js/util.js"></script>
<script type="text/javascript" src="js/app.js"></script> <script type="text/javascript" src="js/app.js"></script>
<script type="text/javascript" src="js/services.js?1"></script> <script type="text/javascript" src="js/services.js?3"></script>
<script type="text/javascript" src="js/controllers.js?1"></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/filters.js?1"></script>
<script type="text/javascript" src="js/directives.js?1"></script> <script type="text/javascript" src="js/directives.js?2"></script>
</body> </body>
</html> </html>

2
js/app.js

@ -48,7 +48,7 @@ config(['$locationProvider', '$routeProvider', '$compileProvider', function($loc
// $locationProvider.html5Mode(true); // $locationProvider.html5Mode(true);
$routeProvider.when('/', {templateUrl: 'partials/welcome.html', controller: 'AppWelcomeController'}); $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.when('/im', {templateUrl: 'partials/im.html', controller: 'AppIMController', reloadOnSearch: false});
$routeProvider.otherwise({redirectTo: '/'}); $routeProvider.otherwise({redirectTo: '/'});

7
js/controllers.js

@ -25,6 +25,7 @@ angular.module('myApp.controllers', [])
var dcID = 1; var dcID = 1;
$scope.credentials = {}; $scope.credentials = {};
$scope.progress = {};
function saveAuth (result) { function saveAuth (result) {
MtpApiManager.setUserAuth(dcID, { MtpApiManager.setUserAuth(dcID, {
@ -36,18 +37,21 @@ angular.module('myApp.controllers', [])
}; };
$scope.sendCode = function () { $scope.sendCode = function () {
$scope.progress.enabled = true;
MtpApiManager.invokeApi('auth.sendCode', { MtpApiManager.invokeApi('auth.sendCode', {
phone_number: $scope.credentials.phone_number, phone_number: $scope.credentials.phone_number,
sms_type: 0, sms_type: 0,
api_id: 2496, api_id: 2496,
api_hash: '8da85b0d5bfe62527e5b244c209159c3' api_hash: '8da85b0d5bfe62527e5b244c209159c3'
}, {dcID: dcID}).then(function (sentCode) { }, {dcID: dcID}).then(function (sentCode) {
$scope.progress.enabled = false;
$scope.credentials.phone_code_hash = sentCode.phone_code_hash; $scope.credentials.phone_code_hash = sentCode.phone_code_hash;
$scope.credentials.phone_occupied = sentCode.phone_registered; $scope.credentials.phone_occupied = sentCode.phone_registered;
$scope.error = {}; $scope.error = {};
}, function (error) { }, function (error) {
$scope.progress.enabled = false;
dLog('sendCode', error); dLog('sendCode', error);
if (error.code == 303) { if (error.code == 303) {
var newDcID = error.type.match(/^(PHONE_MIGRATE_|NETWORK_MIGRATE_)(\d+)/)[2]; 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) { MtpApiManager.invokeApi(method, params, {dcID: dcID}).then(saveAuth, function (error) {
$scope.progress.enabled = false;
if (error.code == 400 && error.type == 'PHONE_NUMBER_UNOCCUPIED') { if (error.code == 400 && error.type == 'PHONE_NUMBER_UNOCCUPIED') {
return $scope.logIn(true); return $scope.logIn(true);
} else if (error.code == 400 && error.type == 'PHONE_NUMBER_UNOCCUPIED') { } else if (error.code == 400 && error.type == 'PHONE_NUMBER_UNOCCUPIED') {
return $scope.logIn(false); return $scope.logIn(false);
} }
switch (error.type) { switch (error.type) {
case 'FIRSTNAME_INVALID': case 'FIRSTNAME_INVALID':
$scope.error = {field: 'first_name'}; $scope.error = {field: 'first_name'};

3
js/directives.js

@ -331,8 +331,7 @@ angular.module('myApp.directives', ['myApp.filters'])
function link (scope, element, attrs) { function link (scope, element, attrs) {
scope.$watch('thumb.location', function (newVal) { scope.$watch('thumb.location', function (newVal) {
if (!scope.thumb) dLog(222, scope); if (!scope.thumb || !scope.thumb.location) {
if (!scope.thumb.location) {
element.attr('src', scope.thumb.placeholder || ''); element.attr('src', scope.thumb.placeholder || '');
return; return;
} }

25
js/lib/mtproto.js

@ -2117,14 +2117,23 @@ factory('MtpApiManager', function (AppConfigManager, MtpAuthorizer, MtpNetworker
}; };
function mtpInvokeApi (method, params, options) { function mtpInvokeApi (method, params, options) {
var deferred = $q.defer();
options = options || {}; options = options || {};
var dcID = options.dcID || baseDcID || 1;
var deferred = $q.defer(),
dcID,
networkerPromise;
if (dcID = options.dcID) {
networkerPromise = mtpGetNetworker(dcID);
} else {
networkerPromise = AppConfigManager.get('dc').then(function (baseDcID) {
return mtpGetNetworker(dcID = baseDcID || 1);
});
}
var cachedNetworker; var cachedNetworker;
mtpGetNetworker(dcID).then(function (networker) { networkerPromise.then(function (networker) {
return (cachedNetworker = networker).wrapApiCall(method, params, options).then( return (cachedNetworker = networker).wrapApiCall(method, params, options).then(
function (result) { function (result) {
deferred.resolve(result); deferred.resolve(result);
@ -2175,13 +2184,9 @@ factory('MtpApiManager', function (AppConfigManager, MtpAuthorizer, MtpNetworker
}; };
function mtpGetUserID () { function mtpGetUserID () {
var deferred = $q.defer(); return AppConfigManager.get('user_auth').then(function (auth) {
return auth.id || 0;
AppConfigManager.get('user_auth').then(function (auth) {
deferred.resolve(auth.id || 0);
}); });
return deferred.promise;
} }
return { return {

147
js/services.js

@ -927,6 +927,76 @@ angular.module('myApp.services', [])
return []; 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) { $rootScope.$on('apiUpdate', function (e, update) {
dLog('on apiUpdate', update); dLog('on apiUpdate', update);
switch (update._) { switch (update._) {
@ -989,54 +1059,12 @@ angular.module('myApp.services', [])
if ($rootScope.idle.isIDLE && !message.out && message.unread) { if ($rootScope.idle.isIDLE && !message.out && message.unread) {
var fromUser = AppUsersManager.getUser(message.from_id); NotificationsManager.getPeerSettings(peerID).then(function (muted) {
var fromPhoto = AppUsersManager.getUserPhoto(message.from_id, 'User'); if (!message.unread || muted) {
var peerString; return;
var notification = {}, }
notificationPhoto; notifyAboutMessage(message);
});
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);
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);
}
} }
break; 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 notificationsUiSupport = window.webkitNotifications !== undefined;
var notificationsShown = []; var notificationsShown = [];
var notificationsCount = 0; var notificationsCount = 0;
var peerSettings = {};
var titleBackup = document.title, var titleBackup = document.title,
titlePromise; titlePromise;
@ -1820,9 +1849,27 @@ angular.module('myApp.services', [])
return { return {
start: start, 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 () { function start () {
if (!notificationsUiSupport) { if (!notificationsUiSupport) {
return false; return false;

2
partials/dialog.html

@ -32,7 +32,7 @@
<span class="glyphicon glyphicon-camera"></span> Photo <span class="glyphicon glyphicon-camera"></span> Photo
</span> </span>
<span ng-switch-when="messageMediaVideo"> <span ng-switch-when="messageMediaVideo">
<span class="glyphicon glyphicon-facetime-video"></span> Video <span class="glyphicon glyphicon-facetime-video"></span> Video
</span> </span>
<span ng-switch-when="messageMediaDocument"> <span ng-switch-when="messageMediaDocument">
<span class="glyphicon glyphicon-document"></span> Document <span class="glyphicon glyphicon-document"></span> Document

8
partials/login.html

@ -11,7 +11,9 @@
<label class="control-label" for="phone_number" ng-if="error.field == 'phone'">Incorrect phone number</label> <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> <input type="text" class="form-control" name="phone_number" ng-model="credentials.phone_number" placeholder="Enter your phone" required>
</div> </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>
<form name="myLoginForm" ng-if="credentials.phone_code_hash" ng-submit="logIn()"> <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> <input type="text" class="form-control" name="phone_code" ng-model="credentials.phone_code" placeholder="Enter your code" required>
</div> </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> </form>
</div> </div>
Loading…
Cancel
Save