diff --git a/app/js/controllers.js b/app/js/controllers.js index 890119b0..ed61d6b9 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -2249,40 +2249,34 @@ angular.module('myApp.controllers', ['myApp.i18n']) .controller('ChatModalController', function ($scope, $timeout, $rootScope, $modal, AppUsersManager, AppChatsManager, AppPhotosManager, MtpApiManager, MtpApiFileManager, NotificationsManager, AppMessagesManager, AppPeersManager, ApiUpdatesManager, ContactsSelectService, ErrorService) { $scope.chatFull = AppChatsManager.wrapForFull($scope.chatID, {}); + $scope.settings = {notifications: true}; - MtpApiManager.invokeApi('messages.getFullChat', { - chat_id: $scope.chatID - }).then(function (result) { - AppChatsManager.saveApiChats(result.chats); - AppUsersManager.saveApiUsers(result.users); - if (result.full_chat && result.full_chat.chat_photo.id) { - AppPhotosManager.savePhoto(result.full_chat.chat_photo); - } - - $scope.chatFull = AppChatsManager.wrapForFull($scope.chatID, result.full_chat); + AppChatsManager.getChatFull($scope.chatID).then(function (chatFull) { + $scope.chatFull = AppChatsManager.wrapForFull($scope.chatID, chatFull); $scope.$broadcast('ui_height'); - }); - $scope.settings = {notifications: true}; + NotificationsManager.savePeerSettings(-$scope.chatID, chatFull.notify_settings); - NotificationsManager.getPeerMuted(-$scope.chatID).then(function (muted) { - $scope.settings.notifications = !muted; + NotificationsManager.getPeerMuted(-$scope.chatID).then(function (muted) { + $scope.settings.notifications = !muted; - $scope.$watch('settings.notifications', function(newValue, oldValue) { - if (newValue === oldValue) { - return false; - } - NotificationsManager.getPeerSettings(-$scope.chatID).then(function (settings) { - if (newValue) { - settings.mute_until = 0; - } else { - settings.mute_until = 2000000000; + $scope.$watch('settings.notifications', function(newValue, oldValue) { + if (newValue === oldValue) { + return false; } - NotificationsManager.updatePeerSettings(-$scope.chatID, settings); + NotificationsManager.getPeerSettings(-$scope.chatID).then(function (settings) { + if (newValue) { + settings.mute_until = 0; + } else { + settings.mute_until = 2000000000; + } + NotificationsManager.updatePeerSettings(-$scope.chatID, settings); + }); }); }); }); + function onStatedMessage (statedMessage) { AppMessagesManager.onStatedMessage(statedMessage); $rootScope.$broadcast('history_focus', {peerString: $scope.chatFull.peerString}); diff --git a/app/js/directives.js b/app/js/directives.js index 6899fc1d..7ebed03c 100755 --- a/app/js/directives.js +++ b/app/js/directives.js @@ -2074,6 +2074,97 @@ angular.module('myApp.directives', ['myApp.filters']) } }) + .directive('myChatStatus', function ($rootScope, _, MtpApiManager, AppChatsManager, AppUsersManager) { + + var ind = 0; + var statuses = {}; + + var allPluralize = _.pluralize('group_modal_pluralize_participants'); + var onlinePluralize = _.pluralize('group_modal_pluralize_online_participants'); + + var myID = 0; + MtpApiManager.getUserID().then(function (newMyID) { + myID = newMyID; + }); + + setInterval(updateAll, 90000); + + return { + link: link + }; + + function updateAll () { + angular.forEach(statuses, function (update) { + update(); + }); + } + + function link($scope, element, attrs) { + var chatID; + var curInd = ind++; + var participantsCount = 0; + var participants = {}; + + var updateParticipants = function () { + participantsCount = 0; + participants = {}; + if (!chatID) { + return; + } + AppChatsManager.getChatFull(chatID).then(function (chatFull) { + var participantsVector = (chatFull.participants || {}).participants || []; + participantsCount = participantsVector.length; + angular.forEach(participantsVector, function (participant) { + participants[participant.user_id] = true; + }); + update(); + }); + }; + + var update = function () { + var html = allPluralize(participantsCount); + var onlineCount = 0; + var wasMe = false; + angular.forEach(participants, function (t, userID) { + var user = AppUsersManager.getUser(userID); + if (user.status && user.status._ == 'userStatusOnline') { + if (user.id == myID) { + wasMe = true; + } + onlineCount++; + } + }); + if (onlineCount > 1 || onlineCount == 1 && !wasMe) { + html = _('group_modal_participants', {total: html, online: onlinePluralize(onlineCount)}); + } + + element.html(html); + }; + + $scope.$watch(attrs.myChatStatus, function (newChatID) { + chatID = newChatID; + updateParticipants(); + }); + + $rootScope.$on('chat_full_update', function (e, updChatID) { + if (chatID == updChatID) { + updateParticipants(); + } + }); + + $rootScope.$on('user_update', function (e, updUserID) { + if (participants[updUserID]) { + update(); + } + }); + + statuses[curInd] = update; + $scope.$on('$destroy', function () { + delete statuses[curInd]; + }); + } + }) + .directive('myUserPhotolink', function (AppUsersManager) { diff --git a/app/js/locales/en-us.json b/app/js/locales/en-us.json index 2145cb64..13669d15 100644 --- a/app/js/locales/en-us.json +++ b/app/js/locales/en-us.json @@ -10,6 +10,8 @@ "group_modal_info": "Group info", "group_modal_pluralize_participants": "{'0': 'No members', 'one': '1 member', 'other': '{} members'}", + "group_modal_pluralize_online_participants": "{'one': '1 online', 'other': '{} online'}", + "group_modal_participants": "{total}, {online}", "group_modal_add_member": "Add member", "group_modal_return": "Return to group", "group_modal_update_photo": "Update photo", diff --git a/app/js/services.js b/app/js/services.js index bb83e414..3650e062 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -556,16 +556,15 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) return chatFullPromises[id] = MtpApiManager.invokeApi('messages.getFullChat', { chat_id: id }).then(function (result) { - AppChatsManager.saveApiChats(result.chats); + saveApiChats(result.chats); AppUsersManager.saveApiUsers(result.users); if (result.full_chat && result.full_chat.chat_photo.id) { AppPhotosManager.savePhoto(result.full_chat.chat_photo); } - // NotificationsManager.savePeerSettings(-id, result.notify_settings); delete chatFullPromises[id]; $rootScope.$broadcast('chat_full_update', id); - return chatsFull[id] = result; + return chatsFull[id] = result.full_chat; }); } @@ -639,8 +638,8 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) var chatFull = chatsFull[participants.id]; if (chatFull !== undefined) { chatFull.participants = update.participants; + $rootScope.$broadcast('chat_full_update', chatID); } - $rootScope.$broadcast('chat_full_update', chatID); break; } }); diff --git a/app/partials/desktop/head.html b/app/partials/desktop/head.html index d3b39b66..5d3d33f3 100644 --- a/app/partials/desktop/head.html +++ b/app/partials/desktop/head.html @@ -79,11 +79,7 @@
- - - - +
diff --git a/app/partials/mobile/head.html b/app/partials/mobile/head.html index 3f1b7e2d..af48c1a7 100644 --- a/app/partials/mobile/head.html +++ b/app/partials/mobile/head.html @@ -88,9 +88,7 @@