Browse Source

Added group onlines to head

master
Igor Zhukov 10 years ago
parent
commit
1f7217724a
  1. 18
      app/js/controllers.js
  2. 91
      app/js/directives.js
  3. 2
      app/js/locales/en-us.json
  4. 7
      app/js/services.js
  5. 6
      app/partials/desktop/head.html
  6. 4
      app/partials/mobile/head.html

18
app/js/controllers.js

@ -2249,21 +2249,13 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -2249,21 +2249,13 @@ 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;
@ -2282,6 +2274,8 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -2282,6 +2274,8 @@ angular.module('myApp.controllers', ['myApp.i18n'])
});
});
});
});
function onStatedMessage (statedMessage) {
AppMessagesManager.onStatedMessage(statedMessage);

91
app/js/directives.js

@ -2074,6 +2074,97 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -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) {

2
app/js/locales/en-us.json

@ -10,6 +10,8 @@ @@ -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",

7
app/js/services.js

@ -556,16 +556,15 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -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']) @@ -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);
}
break;
}
});

6
app/partials/desktop/head.html

@ -79,11 +79,7 @@ @@ -79,11 +79,7 @@
</div>
<div class="tg_head_peer_info" ng-switch-default>
<span class="tg_head_peer_title" ng-bind-html="historyPeer.data.rTitle" dir="auto"></span>
<span class="tg_head_peer_status">
<ng-pluralize count="historyPeer.data.participants_count"
when="im_pluralize_participants">
</ng-pluralize>
</span>
<span class="tg_head_peer_status" my-chat-status="-historyPeer.id"></span>
</div>
</a>

4
app/partials/mobile/head.html

@ -88,9 +88,7 @@ @@ -88,9 +88,7 @@
<div class="navbar-quick-back-title">
<h4 ng-bind-html="historyPeer.data.rTitle"></h4>
<small ng-switch="historyState.typing.length">
<ng-pluralize ng-switch-when="0" count="historyPeer.data.participants_count"
when="head_pluralize_participants">
</ng-pluralize>
<span ng-switch-when="0" class="tg_head_peer_status" my-chat-status="-historyPeer.id"></span>
<my-i18n>
<span ng-switch-when="1" class="status_online" my-i18n-format="head_one_typing"></span>
<span ng-switch-when="2" class="status_online" my-i18n-format="head_two_typing"></span>

Loading…
Cancel
Save