From 94433b1f765a81e01b02d287c8bb5dc425122cd6 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Fri, 21 Mar 2014 12:13:04 +0400 Subject: [PATCH] Suggesting contacts in dialogs --- app/css/app.css | 7 +++++++ app/js/controllers.js | 35 +++++++++++++++++++++++++++++++++-- app/js/directives.js | 10 +++++++++- app/partials/im.html | 24 ++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 3 deletions(-) diff --git a/app/css/app.css b/app/css/app.css index 6e2d068f..0bfe8904 100644 --- a/app/css/app.css +++ b/app/css/app.css @@ -2518,3 +2518,10 @@ ce671b orange .user_color_7:hover {color: #2996ad;} .user_color_8, .user_color_8:hover {color: #ce671b;} + + +.im_dialogs_contacts_wrap h5 { + color: #999; + font-size: 13px; + margin-left: 8px; +} \ No newline at end of file diff --git a/app/js/controllers.js b/app/js/controllers.js index 37f99e73..9b89d4b0 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -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)); }); diff --git a/app/js/directives.js b/app/js/directives.js index e95e8f9c..8f19a8ac 100644 --- a/app/js/directives.js +++ b/app/js/directives.js @@ -60,6 +60,10 @@ angular.module('myApp.directives', ['myApp.filters']) onContentLoaded(function () { updateScroller(); moreNotified = false; + + $timeout(function () { + $(scrollableWrap).trigger('scroll'); + }); }); }); @@ -67,6 +71,10 @@ angular.module('myApp.directives', ['myApp.filters']) onContentLoaded(function () { updateScroller(); moreNotified = false; + + $timeout(function () { + $(scrollableWrap).trigger('scroll'); + }); }); }); @@ -176,7 +184,7 @@ angular.module('myApp.directives', ['myApp.filters']) var transform = false, trs = ['transform', 'webkitTransform', 'MozTransform', 'msTransform', 'OTransform'], - i = 0; + i; for (i = 0; i < trs.length; i++) { if (trs[i] in historyMessagesEl.style) { transform = trs[i]; diff --git a/app/partials/im.html b/app/partials/im.html index 644322f8..492b7f0b 100644 --- a/app/partials/im.html +++ b/app/partials/im.html @@ -15,6 +15,30 @@ +
+
Contacts
+ +