From 7958990292cb0e0dcc6ffd122fd1e27626ae6f72 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Thu, 12 Feb 2015 17:32:52 +0300 Subject: [PATCH] Improved group, user link and statuses Added my-chat-link directive Fixed self online status Improved templates performance --- app/css/desktop.css | 3 +- app/js/directives.js | 51 +++++++++++++++++++++++- app/js/services.js | 26 ++++++++++-- app/partials/desktop/chat_modal.html | 2 +- app/partials/desktop/confirm_modal.html | 4 +- app/partials/desktop/contacts_modal.html | 2 +- app/partials/desktop/dialog.html | 8 ++-- app/partials/desktop/head.html | 4 +- app/partials/desktop/message.html | 12 +++--- app/partials/desktop/peer_select.html | 2 +- app/partials/desktop/settings_modal.html | 2 +- app/partials/desktop/user_modal.html | 2 +- app/partials/mobile/chat_modal.html | 2 +- app/partials/mobile/contacts_modal.html | 2 +- app/partials/mobile/dialog.html | 6 +-- app/partials/mobile/head.html | 4 +- app/partials/mobile/message.html | 12 +++--- app/partials/mobile/peer_select.html | 2 +- app/partials/mobile/settings_modal.html | 2 +- 19 files changed, 108 insertions(+), 40 deletions(-) diff --git a/app/css/desktop.css b/app/css/desktop.css index ac190f4d..f6369fce 100644 --- a/app/css/desktop.css +++ b/app/css/desktop.css @@ -639,7 +639,8 @@ a.footer_link.active:active { color: #FFF; } .contacts_modal_members_list .active a.contacts_modal_contact .md_modal_list_peer_description, -.contacts_modal_members_list .active a.contacts_modal_contact:hover .md_modal_list_peer_description { +.contacts_modal_members_list .active a.contacts_modal_contact:hover .md_modal_list_peer_description, +.contacts_modal_members_list .active a.contacts_modal_contact .md_modal_list_peer_description .status_online { color: #FFF; } diff --git a/app/js/directives.js b/app/js/directives.js index 1d227353..3ec69b13 100755 --- a/app/js/directives.js +++ b/app/js/directives.js @@ -2090,10 +2090,17 @@ angular.module('myApp.directives', ['myApp.filters']) userID = $scope.$eval(attrs.myUserLink); update(); } + if (!attrs.noWatch) { + $scope.$on('user_update', function (e, updUserID) { + if (userID == updUserID) { + update(); + } + }); + } } }) - .directive('myUserStatus', function ($filter, $rootScope, AppUsersManager) { + .directive('myUserStatus', function ($filter, AppUsersManager) { var statusFilter = $filter('userStatus'), ind = 0, @@ -2125,7 +2132,7 @@ angular.module('myApp.directives', ['myApp.filters']) userID = newUserID; update(); }); - $rootScope.$on('user_update', function (e, updUserID) { + $scope.$on('user_update', function (e, updUserID) { if (userID == updUserID) { update(); } @@ -2137,6 +2144,46 @@ angular.module('myApp.directives', ['myApp.filters']) } }) + .directive('myChatLink', function ($timeout, AppChatsManager) { + + return { + link: link + }; + + function link($scope, element, attrs) { + var chatID; + var update = function () { + var chat = AppChatsManager.getChat(chatID); + + element.html( + (chat.rTitle || '').valueOf() + ) + }; + + if (element[0].tagName == 'A') { + element.on('click', function () { + AppChatsManager.openChat(chatID); + }); + } + + if (attrs.chatWatch) { + $scope.$watch(attrs.myChatLink, function (newChatID) { + chatID = newChatID; + update(); + }); + } else { + chatID = $scope.$eval(attrs.myChatLink); + update(); + } + + $scope.$on('chat_update', function (e, updChatID) { + if (chatID == updChatID) { + update(); + } + }); + } + }) + .directive('myChatStatus', function ($rootScope, _, MtpApiManager, AppChatsManager, AppUsersManager) { var ind = 0; diff --git a/app/js/services.js b/app/js/services.js index d92560f8..ea373ab9 100755 --- a/app/js/services.js +++ b/app/js/services.js @@ -243,6 +243,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) expires: tsNow(true) + serverTimeOffset + 60, wasStatus: wasStatus }; + user.sortStatus = getUserStatusForSort(user.status); $rootScope.$broadcast('user_update', id); } } @@ -364,6 +365,23 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) }); }; + function setUserStatus (userID, offline) { + var user = users[userID]; + if (user) { + var status = offline ? { + _: 'userStatusOffline', + was_online: tsNow(true) + serverTimeOffset + } : { + _: 'userStatusOnline', + expires: tsNow(true) + serverTimeOffset + 500 + }; + + user.status = status; + user.sortStatus = getUserStatusForSort(user.status); + $rootScope.$broadcast('user_update', userID); + } + } + $rootScope.$on('apiUpdate', function (e, update) { // console.log('on apiUpdate', update); @@ -373,7 +391,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) user = users[userID]; if (user) { user.status = update.status; - user.sortStatus = getUserStatusForSort(update.status); + user.sortStatus = getUserStatusForSort(user.status); $rootScope.$broadcast('user_update', userID); } break; @@ -407,6 +425,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) saveApiUser: saveApiUser, getUser: getUser, getUserInput: getUserInput, + setUserStatus: setUserStatus, forceUserOnline: forceUserOnline, getUserPhoto: getUserPhoto, getUserString: getUserString, @@ -3751,10 +3770,10 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) }) -.service('StatusManager', function ($timeout, $rootScope, MtpApiManager, IdleManager) { +.service('StatusManager', function ($timeout, $rootScope, MtpApiManager, AppUsersManager, IdleManager) { var toPromise; - var lastOnlineUpdated = 0 + var lastOnlineUpdated = 0; var started = false; var myID = 0; var myOtherDeviceActive = false; @@ -3790,6 +3809,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) return; } lastOnlineUpdated = offline ? 0 : date; + AppUsersManager.setUserStatus(myID, offline); return MtpApiManager.invokeApi('account.updateStatus', { offline: offline }, {noErrorBox: true}); diff --git a/app/partials/desktop/chat_modal.html b/app/partials/desktop/chat_modal.html index 9e7274d3..93e4c41d 100644 --- a/app/partials/desktop/chat_modal.html +++ b/app/partials/desktop/chat_modal.html @@ -17,7 +17,7 @@
-
+
diff --git a/app/partials/desktop/confirm_modal.html b/app/partials/desktop/confirm_modal.html index 49ca89b4..1db20e77 100644 --- a/app/partials/desktop/confirm_modal.html +++ b/app/partials/desktop/confirm_modal.html @@ -34,8 +34,8 @@ - - + + diff --git a/app/partials/desktop/contacts_modal.html b/app/partials/desktop/contacts_modal.html index 9b147d2f..83d5a581 100644 --- a/app/partials/desktop/contacts_modal.html +++ b/app/partials/desktop/contacts_modal.html @@ -44,7 +44,7 @@
-
+
diff --git a/app/partials/desktop/dialog.html b/app/partials/desktop/dialog.html index f80d3fd9..0a334cfc 100644 --- a/app/partials/desktop/dialog.html +++ b/app/partials/desktop/dialog.html @@ -19,7 +19,7 @@
- +
@@ -39,7 +39,7 @@ : + >: @@ -82,14 +82,14 @@ - + - + diff --git a/app/partials/desktop/head.html b/app/partials/desktop/head.html index 5d3d33f3..b3b0e563 100644 --- a/app/partials/desktop/head.html +++ b/app/partials/desktop/head.html @@ -74,11 +74,11 @@
- +
- +
diff --git a/app/partials/desktop/message.html b/app/partials/desktop/message.html index d55d0b97..bf7717f0 100644 --- a/app/partials/desktop/message.html +++ b/app/partials/desktop/message.html @@ -1,11 +1,11 @@
-
+
-
+
- +
@@ -19,7 +19,7 @@
-
+
@@ -39,12 +39,12 @@
- +
- +
diff --git a/app/partials/desktop/peer_select.html b/app/partials/desktop/peer_select.html index 0c1d951c..043301a1 100644 --- a/app/partials/desktop/peer_select.html +++ b/app/partials/desktop/peer_select.html @@ -34,7 +34,7 @@
- +
diff --git a/app/partials/desktop/settings_modal.html b/app/partials/desktop/settings_modal.html index 8aef6440..866c8f49 100644 --- a/app/partials/desktop/settings_modal.html +++ b/app/partials/desktop/settings_modal.html @@ -17,7 +17,7 @@
-
+
diff --git a/app/partials/desktop/user_modal.html b/app/partials/desktop/user_modal.html index 9d8490a7..b7cec632 100644 --- a/app/partials/desktop/user_modal.html +++ b/app/partials/desktop/user_modal.html @@ -14,7 +14,7 @@
-
+
diff --git a/app/partials/mobile/chat_modal.html b/app/partials/mobile/chat_modal.html index 87f1aecb..aac54213 100644 --- a/app/partials/mobile/chat_modal.html +++ b/app/partials/mobile/chat_modal.html @@ -57,7 +57,7 @@ />
-

+

diff --git a/app/partials/mobile/contacts_modal.html b/app/partials/mobile/contacts_modal.html index 35c2d0bf..2189f2cf 100644 --- a/app/partials/mobile/contacts_modal.html +++ b/app/partials/mobile/contacts_modal.html @@ -82,7 +82,7 @@

-
+
diff --git a/app/partials/mobile/dialog.html b/app/partials/mobile/dialog.html index b59b12e0..2ea44d06 100644 --- a/app/partials/mobile/dialog.html +++ b/app/partials/mobile/dialog.html @@ -26,7 +26,7 @@
- +
@@ -89,14 +89,14 @@ - + - + diff --git a/app/partials/mobile/head.html b/app/partials/mobile/head.html index af48c1a7..4cd451b4 100644 --- a/app/partials/mobile/head.html +++ b/app/partials/mobile/head.html @@ -72,7 +72,7 @@