@ -219,11 +219,14 @@ angular.module('myApp.controllers', [])
// console.log('init controller');
$scope . dialogs = [ ] ;
$scope . contacts = [ ] ;
$scope . search = { } ;
var offset = 0 ,
maxID = 0 ,
hasMore = false ;
hasMore = false ,
peersInDialogs = { } ,
contactsShown ;
MtpApiManager . invokeApi ( 'account.updateStatus' , { offline : false } ) ;
$scope . $on ( 'dialogs_need_more' , function ( ) {
@ -275,10 +278,16 @@ angular.module('myApp.controllers', [])
offset = 0 ;
maxID = 0 ;
hasMore = false ;
peersInDialogs = { } ;
contactsShown = false ;
AppMessagesManager . getDialogs ( $scope . search . query , maxID ) . then ( function ( dialogsResult ) {
$scope . dialogs = [ ] ;
if ( ! $scope . search . query ) {
$scope . contacts = [ ] ;
}
if ( dialogsResult . dialogs . length ) {
offset += dialogsResult . dialogs . length ;
@ -286,6 +295,7 @@ angular.module('myApp.controllers', [])
hasMore = dialogsResult . count === null || offset < dialogsResult . count ;
angular . forEach ( dialogsResult . dialogs , function ( dialog ) {
peersInDialogs [ dialog . peerID ] = true ;
$scope . dialogs . push ( AppMessagesManager . wrapForDialog ( dialog . top _message , dialog . unread _count ) ) ;
} ) ;
}
@ -306,7 +316,27 @@ angular.module('myApp.controllers', [])
}
function showMoreDialogs ( ) {
if ( ! hasMore || ! offset ) {
if ( ! hasMore && contactsShown || ! offset ) {
return ;
}
if ( ! hasMore ) {
contactsShown = true ;
AppUsersManager . getContacts ( $scope . search . query ) . then ( function ( contactsList ) {
$scope . contacts = [ ] ;
angular . forEach ( contactsList , function ( userID ) {
if ( peersInDialogs [ userID ] === undefined ) {
$scope . contacts . push ( {
userID : userID ,
user : AppUsersManager . getUser ( userID ) ,
userPhoto : AppUsersManager . getUserPhoto ( userID , 'User' ) ,
peerString : AppUsersManager . getUserString ( userID )
} ) ;
}
} ) ;
} ) ;
$scope . $broadcast ( 'ui_dialogs_append' ) ;
return ;
}
@ -316,6 +346,7 @@ angular.module('myApp.controllers', [])
hasMore = dialogsResult . count === null || offset < dialogsResult . count ;
angular . forEach ( dialogsResult . dialogs , function ( dialog ) {
peersInDialogs [ dialog . peerID ] = true ;
$scope . dialogs . push ( AppMessagesManager . wrapForDialog ( dialog . top _message , dialog . unread _count ) ) ;
} ) ;