@ -113,19 +113,6 @@ angular.module('myApp.controllers', [])
country _code : $scope . credentials . phone _country ,
phone _number : $scope . credentials . phone _number
} ) . then ( function ( ) {
$scope . progress . enabled = true ;
MtpApiManager . invokeApi ( 'auth.checkPhone' , {
phone _number : $scope . credentials . phone _full
} , options ) . then ( function ( result ) {
$scope . progress . enabled = false ;
if ( ! result . phone _registered ) {
ErrorService . show ( {
error : { code : 400 , type : 'ACCOUNT_REQUIRED' } ,
phone : $scope . credentials . phone _full
} ) ;
return false ;
}
$scope . progress . enabled = true ;
MtpApiManager . invokeApi ( 'auth.sendCode' , {
phone _number : $scope . credentials . phone _full ,
@ -145,15 +132,6 @@ angular.module('myApp.controllers', [])
} , function ( error ) {
$scope . progress . enabled = false ;
console . log ( 'sendCode error' , error ) ;
switch ( error . type ) {
case 'PHONE_NUMBER_INVALID' :
$scope . error = { field : 'phone' } ;
error . handled = true ;
break ;
}
} ) ;
} , function ( error ) {
$scope . progress . enabled = false ;
switch ( error . type ) {
case 'NETWORK_BAD_REQUEST' :
if ( location . protocol == 'https:' ) {
@ -178,7 +156,8 @@ angular.module('myApp.controllers', [])
$timeout . cancel ( callTimeout ) ;
delete $scope . credentials . phone _code _hash ;
delete $scope . credentials . phone _occupied ;
delete $scope . credentials . phone _unoccupied ;
delete $scope . credentials . phone _code _valid ;
delete $scope . callPending . remaining ;
delete $scope . callPending . success ;
}
@ -202,7 +181,9 @@ angular.module('myApp.controllers', [])
$scope . progress . enabled = false ;
if ( error . code == 400 && error . type == 'PHONE_NUMBER_UNOCCUPIED' ) {
error . handled = true ;
return $scope . logIn ( true ) ;
$scope . credentials . phone _code _valid = true ;
$scope . credentials . phone _unoccupied = true ;
return ;
} else if ( error . code == 400 && error . type == 'PHONE_NUMBER_OCCUPIED' ) {
error . handled = true ;
return $scope . logIn ( false ) ;
@ -220,6 +201,7 @@ angular.module('myApp.controllers', [])
break ;
case 'PHONE_CODE_INVALID' :
$scope . error = { field : 'phone_code' } ;
delete $scope . credentials . phone _code _valid ;
error . handled = true ;
break ;
}
@ -243,6 +225,8 @@ angular.module('myApp.controllers', [])
$scope . isLoggedIn = true ;
$scope . isEmpty = { } ;
$scope . openSettings = function ( ) {
$modal . open ( {
templateUrl : 'partials/settings_modal.html' ,
@ -308,6 +292,7 @@ angular.module('myApp.controllers', [])
$scope . dialogs = [ ] ;
$scope . contacts = [ ] ;
$scope . search = { } ;
$scope . contactsLoaded = false ;
var offset = 0 ,
maxID = 0 ,
@ -361,6 +346,14 @@ angular.module('myApp.controllers', [])
$scope . $watch ( 'search.query' , loadDialogs ) ;
$scope . importContact = function ( ) {
AppUsersManager . openImportContact ( ) . then ( function ( ) {
if ( contactsShown ) {
loadDialogs ( ) ;
}
} ) ;
} ;
function loadDialogs ( ) {
offset = 0 ;
maxID = 0 ;
@ -382,12 +375,16 @@ angular.module('myApp.controllers', [])
peersInDialogs [ dialog . peerID ] = true ;
$scope . dialogs . push ( AppMessagesManager . wrapForDialog ( dialog . top _message , dialog . unread _count ) ) ;
} ) ;
delete $scope . isEmpty . dialogs ;
}
$scope . $broadcast ( 'ui_dialogs_change' ) ;
if ( ! $scope . search . query ) {
AppMessagesManager . getDialogs ( '' , maxID , 100 ) ;
if ( ! dialogsResult . dialogs . length ) {
$scope . isEmpty . dialogs = true ;
}
} else {
showMoreDialogs ( ) ;
}
@ -416,7 +413,7 @@ angular.module('myApp.controllers', [])
return ;
}
if ( ! hasMore && $scope . search . query ) {
if ( ! hasMore && ( $scope . search . query || ! $scope . dialogs . length ) ) {
contactsShown = true ;
AppUsersManager . getContacts ( $scope . search . query ) . then ( function ( contactsList ) {
@ -431,6 +428,12 @@ angular.module('myApp.controllers', [])
} ) ;
}
} ) ;
if ( contactsList . length ) {
delete $scope . isEmpty . contacts ;
} else if ( ! $scope . search . query ) {
$scope . isEmpty . contacts = true ;
}
} ) ;
$scope . $broadcast ( 'ui_dialogs_append' ) ;
return ;
@ -1815,18 +1818,8 @@ angular.module('myApp.controllers', [])
}
$scope . importContact = function ( ) {
$modal . open ( {
templateUrl : 'partials/import_contact_modal.html' ,
controller : 'ImportContactModalController' ,
windowClass : 'import_contact_modal_window'
} ) . result . then ( function ( foundUserID ) {
if ( foundUserID ) {
AppUsersManager . openImportContact ( ) . then ( function ( ) {
updateContacts ( $scope . search && $scope . search . query || '' ) ;
} else {
ErrorService . show ( {
error : { code : 404 , type : 'USER_NOT_USING_TELEGRAM' }
} ) ;
}
} ) ;
} ;
@ -1937,8 +1930,8 @@ angular.module('myApp.controllers', [])
$scope . progress = { enabled : true } ;
AppUsersManager . importContact (
$scope . importContact . phone ,
$scope . importContact . first _name ,
$scope . importContact . last _name
$scope . importContact . first _name || '' ,
$scope . importContact . last _name || ''
) . then ( function ( foundUserID ) {
$modalInstance . close ( foundUserID ) ;
} ) [ 'finally' ] ( function ( ) {