Browse Source

Added global search to contacts modal

Closes #539
master
Igor Zhukov 10 years ago
parent
commit
c15ef061b5
  1. 33
      app/js/controllers.js
  2. 5
      app/partials/desktop/contacts_modal.html
  3. 6
      app/partials/mobile/contacts_modal.html

33
app/js/controllers.js

@ -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.contacts = [];
$scope.foundUsers = [];
$scope.search = {}; $scope.search = {};
$scope.slice = {limit: 20, limitDelta: 20}; $scope.slice = {limit: 20, limitDelta: 20};
var jump = 0;
resetSelected(); resetSelected();
$scope.disabledContacts = {}; $scope.disabledContacts = {};
@ -2421,7 +2424,10 @@ angular.module('myApp.controllers', ['myApp.i18n'])
}; };
function updateContacts (query) { function updateContacts (query) {
var curJump = ++jump;
var doneIDs = [];
AppUsersManager.getContacts(query).then(function (contactsList) { AppUsersManager.getContacts(query).then(function (contactsList) {
if (curJump != jump) return;
$scope.contacts = []; $scope.contacts = [];
$scope.slice.limit = 20; $scope.slice.limit = 20;
@ -2431,11 +2437,36 @@ angular.module('myApp.controllers', ['myApp.i18n'])
user: AppUsersManager.getUser(userID), user: AppUsersManager.getUser(userID),
userPhoto: AppUsersManager.getUserPhoto(userID, 'User') userPhoto: AppUsersManager.getUserPhoto(userID, 'User')
} }
doneIDs.push(userID);
$scope.contacts.push(contact); $scope.contacts.push(contact);
}); });
$scope.contactsEmpty = query ? false : !$scope.contacts.length; $scope.contactsEmpty = query ? false : !$scope.contacts.length;
$scope.$broadcast('contacts_change'); $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); $scope.$watch('search.query', updateContacts);

5
app/partials/desktop/contacts_modal.html

@ -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_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_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> </a>
</li> </li>

6
app/partials/mobile/contacts_modal.html

@ -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_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_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> </a>
</li> </li>

Loading…
Cancel
Save