Added group onlines to head
This commit is contained in:
parent
24e230d7c7
commit
1f7217724a
@ -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, {});
|
||||
|
||||
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);
|
||||
$scope.$broadcast('ui_height');
|
||||
});
|
||||
|
||||
$scope.settings = {notifications: true};
|
||||
|
||||
NotificationsManager.getPeerMuted(-$scope.chatID).then(function (muted) {
|
||||
$scope.settings.notifications = !muted;
|
||||
AppChatsManager.getChatFull($scope.chatID).then(function (chatFull) {
|
||||
$scope.chatFull = AppChatsManager.wrapForFull($scope.chatID, chatFull);
|
||||
$scope.$broadcast('ui_height');
|
||||
|
||||
$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;
|
||||
NotificationsManager.savePeerSettings(-$scope.chatID, chatFull.notify_settings);
|
||||
|
||||
NotificationsManager.getPeerMuted(-$scope.chatID).then(function (muted) {
|
||||
$scope.settings.notifications = !muted;
|
||||
|
||||
$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});
|
||||
|
@ -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) {
|
||||
|
||||
|
@ -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",
|
||||
|
@ -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;
|
||||
}
|
||||
});
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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…
x
Reference in New Issue
Block a user