diff --git a/app/js/directives.js b/app/js/directives.js index 9b2e6930..91e759a5 100755 --- a/app/js/directives.js +++ b/app/js/directives.js @@ -757,6 +757,46 @@ angular.module('myApp.directives', ['myApp.filters']) } }) + .directive('myMessageAdminBadge', function (_, AppPeersManager, AppMessagesManager, AppProfileManager) { + + var adminBadgeText = _('message_admin_badge') + + return { + scope: {}, + link: link + } + + function link($scope, element, attrs) { + var message = $scope.$parent.$eval(attrs.myMessageAdminBadge) + var fromID = message && message.fromID + var peerID = message && AppMessagesManager.getMessagePeer(message) + console.warn(dT(), 'admin', message, fromID, peerID) + if (!fromID || !AppPeersManager.isMegagroup(peerID)) { + element.hide() + return + } + + var channelID = -peerID + + AppProfileManager.getChannelParticipants(channelID, {_: 'channelParticipantsAdmins'}).then(function (participants) { + var isAdmin = false + for (var i = 0, len = participants.length; i < len; i++) { + if (participants[i].user_id == fromID) { + isAdmin = true + break + } + } + if (isAdmin) { + element.text(adminBadgeText).show() + } else { + element.hide() + } + }, function () { + element.hide() + }) + } + }) + .directive('myDialogs', function ($modalStack, $transition, $window, $timeout) { return { link: link diff --git a/app/js/locales/en-us.json b/app/js/locales/en-us.json index fb917f70..85547ac1 100644 --- a/app/js/locales/en-us.json +++ b/app/js/locales/en-us.json @@ -384,6 +384,8 @@ "message_service_scored_X": "{'one': 'scored {}', 'other': 'scored {}'}", "message_service_payment_sent": "Payment sent", + "message_admin_badge": "admin", + "message_action_reply": "Reply", "message_action_edit": "Edit", "message_action_delete": "Delete", diff --git a/app/js/services.js b/app/js/services.js index 2ab0d0bb..116bdcbc 100755 --- a/app/js/services.js +++ b/app/js/services.js @@ -1046,6 +1046,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) var botInfos = {} var chatsFull = {} var chatFullPromises = {} + var chatParticipantsPromises = {} function saveBotInfo (botInfo) { var botID = botInfo && botInfo.user_id @@ -1183,18 +1184,49 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) }) } - function getChannelParticipants (id) { - return MtpApiManager.invokeApi('channels.getParticipants', { - channel: AppChatsManager.getChannelInput(id), - filter: {_: 'channelParticipantsRecent'}, - offset: 0, - limit: AppChatsManager.isMegagroup(id) ? 50 : 200 - }).then(function (result) { - AppUsersManager.saveApiUsers(result.users) - var participants = result.participants + function getChannelParticipants (id, filter, limit, offset) { + filter = filter || {_: 'channelParticipantsRecent'} + limit = limit || 200 + offset = offset || 0 + var promiseKey = [id, filter._, offset, limit].join('_') + var promiseData = chatParticipantsPromises[promiseKey] + + var fetchParticipants = function (cachedParticipants) { + var hash = 0 + if (cachedParticipants) { + var userIDs = [] + angular.forEach(cachedParticipants, function (participant) { + userIDs.push(participant.user_id) + }) + userIDs.sort() + angular.forEach(userIDs, function (userID) { + hash = ((hash * 20261) + 0x80000000 + userID) % 0x80000000 + }) + } + return MtpApiManager.invokeApi('channels.getParticipants', { + channel: AppChatsManager.getChannelInput(id), + filter: filter, + offset: offset, + limit: limit, + hash: hash + }).then(function (result) { + if (result._ == 'channels.channelParticipantsNotModified') { + return cachedParticipants + } + AppUsersManager.saveApiUsers(result.users) + return result.participants + }) + } + var maybeAddSelf = function (participants) { var chat = AppChatsManager.getChat(id) - if (!chat.pFlags.kicked && !chat.pFlags.left) { + var selfMustBeFirst = filter._ == 'channelParticipantsRecent' && + !offset && + !chat.pFlags.kicked && + !chat.pFlags.left + + if (selfMustBeFirst) { + participants = angular.copy(participants) var myID = AppUsersManager.getSelf().id var myIndex = false var myParticipant @@ -1212,9 +1244,25 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) } participants.unshift(myParticipant) } - return participants - }) + } + + var timeNow = tsNow() + if (promiseData !== undefined) { + var promise = promiseData[1] + if (promiseData[0] > timeNow - 60000) { + return promise + } + var newPromise = promise.then(function (cachedParticipants) { + return fetchParticipants(cachedParticipants).then(maybeAddSelf) + }) + chatParticipantsPromises[promiseKey] = [timeNow, newPromise] + return newPromise + } + + var newPromise = fetchParticipants().then(maybeAddSelf) + chatParticipantsPromises[promiseKey] = [timeNow, newPromise] + return newPromise } function getChannelFull (id, force) { @@ -1355,7 +1403,8 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) getProfile: getProfile, getChatInviteLink: getChatInviteLink, getChatFull: getChatFull, - getChannelFull: getChannelFull + getChannelFull: getChannelFull, + getChannelParticipants: getChannelParticipants } }) diff --git a/app/less/app.less b/app/less/app.less index 37c9bb8b..f992ab35 100644 --- a/app/less/app.less +++ b/app/less/app.less @@ -1538,6 +1538,10 @@ a.im_dialog_selected { .im_message_fwd_via { margin-left: 0; } +.im_message_author_admin { + color: #999; + margin-left: 6px; +} .im_message_from_photo, .im_message_contact_photo, diff --git a/app/less/mobile.less b/app/less/mobile.less index 0ad3b770..68eee22e 100644 --- a/app/less/mobile.less +++ b/app/less/mobile.less @@ -934,6 +934,9 @@ a.im_message_author_via { .im_message_author { display: none; } +.im_message_author_admin { + display: none; +} .im_history_messages_group { a.im_message_author { @@ -941,6 +944,10 @@ a.im_message_author_via { font-size: 13px; font-weight: normal; } + .im_message_author_admin { + display: inline; + font-size: 13px; + } .im_message_sign_link { font-size: 12px; } @@ -953,19 +960,25 @@ a.im_message_author_via { .im_grouped_short a.im_message_from_photo, .im_grouped_short a.im_message_author, +.im_grouped_short .im_message_author_admin, .im_grouped_short a.im_message_author_via, .im_grouped a.im_message_from_photo, .im_grouped a.im_message_author, .im_grouped a.im_message_author_via, +.im_grouped a.im_message_author_admin, .im_grouped_fwd a.im_message_from_photo, .im_grouped_fwd a.im_message_author, .im_grouped_fwd a.im_message_author_via, +.im_grouped_fwd a.im_message_author_admin, .im_grouped_fwd_short a.im_message_from_photo, .im_grouped_fwd_short a.im_message_author, .im_grouped_fwd_short a.im_message_author_via, +.im_grouped_fwd_short a.im_message_author_admin, .im_message_out a.im_message_from_photo, .im_message_out a.im_message_author, -.im_message_body_media a.im_message_author { +.im_message_out a.im_message_author_admin, +.im_message_body_media a.im_message_author, +.im_message_body_media a.im_message_author_admin { display: none; } .im_message_wrap { diff --git a/app/partials/desktop/message.html b/app/partials/desktop/message.html index b9265382..f4af6ae1 100644 --- a/app/partials/desktop/message.html +++ b/app/partials/desktop/message.html @@ -47,7 +47,7 @@
- []  : + []  : diff --git a/app/partials/mobile/message.html b/app/partials/mobile/message.html index f6b7eddb..a4c305d7 100644 --- a/app/partials/mobile/message.html +++ b/app/partials/mobile/message.html @@ -48,6 +48,7 @@ +