Added global search to contacts modal

Closes #539
This commit is contained in:
Igor Zhukov 2014-11-13 20:12:11 +03:00
parent 09d176282e
commit c15ef061b5
3 changed files with 40 additions and 4 deletions

View File

@ -2391,12 +2391,15 @@ angular.module('myApp.controllers', ['myApp.i18n'])
})
})
.controller('ContactsModalController', function ($scope, $modal, $modalInstance, AppUsersManager, ErrorService) {
.controller('ContactsModalController', function ($scope, $timeout, $modal, $modalInstance, MtpApiManager, AppUsersManager, ErrorService) {
$scope.contacts = [];
$scope.foundUsers = [];
$scope.search = {};
$scope.slice = {limit: 20, limitDelta: 20};
var jump = 0;
resetSelected();
$scope.disabledContacts = {};
@ -2421,7 +2424,10 @@ angular.module('myApp.controllers', ['myApp.i18n'])
};
function updateContacts (query) {
var curJump = ++jump;
var doneIDs = [];
AppUsersManager.getContacts(query).then(function (contactsList) {
if (curJump != jump) return;
$scope.contacts = [];
$scope.slice.limit = 20;
@ -2431,11 +2437,36 @@ angular.module('myApp.controllers', ['myApp.i18n'])
user: AppUsersManager.getUser(userID),
userPhoto: AppUsersManager.getUserPhoto(userID, 'User')
}
doneIDs.push(userID);
$scope.contacts.push(contact);
});
$scope.contactsEmpty = query ? false : !$scope.contacts.length;
$scope.$broadcast('contacts_change');
});
if (query && query.length >= 5) {
$timeout(function() {
if (curJump != jump) return;
MtpApiManager.invokeApi('contacts.search', {q: query, limit: 10}).then(function (result) {
AppUsersManager.saveApiUsers(result.users);
if (curJump != jump) return;
angular.forEach(result.results, function(contactFound) {
var userID = contactFound.user_id;
if (doneIDs.indexOf(userID) != -1) return;
$scope.contacts.push({
userID: userID,
user: AppUsersManager.getUser(userID),
peerString: AppUsersManager.getUserString(userID),
found: true
});
});
}, function (error) {
if (error.code == 400) {
error.handled = true;
}
});
}, 500);
}
};
$scope.$watch('search.query', updateContacts);

View File

@ -46,7 +46,10 @@
<div class="contacts_modal_contact_photo pull-left" my-user-photolink="contact.userID" status="true" img-class="contacts_modal_contact_photo"></div>
<div class="contacts_modal_contact_name" ng-bind-html="contact.user.rFullName"></div>
<div class="contacts_modal_contact_status" my-user-status="::contact.userID"></div>
<div class="contacts_modal_contact_status" ng-switch="contact.found">
<span ng-switch-when="true" ng-bind="'@' + contact.user.username"></span>
<span ng-switch-default my-user-status="::contact.userID"></span>
</div>
</a>
</li>

View File

@ -81,8 +81,10 @@
<div class="contacts_modal_contact_photo pull-left" my-user-photolink="contact.userID" status="true" img-class="contacts_modal_contact_photo"></div>
<div class="contacts_modal_contact_name" ng-bind-html="contact.user.rFullName"></div>
<div class="contacts_modal_contact_status" my-user-status="::contact.userID"></div>
<div class="contacts_modal_contact_status" ng-switch="contact.found">
<span ng-switch-when="true" ng-bind="'@' + contact.user.username"></span>
<span ng-switch-default my-user-status="::contact.userID"></span>
</div>
</a>
</li>