Browse Source

Admin badge in supergroups

master
Igor Zhukov 7 years ago
parent
commit
ecc0d459e2
  1. 40
      app/js/directives.js
  2. 2
      app/js/locales/en-us.json
  3. 75
      app/js/services.js
  4. 4
      app/less/app.less
  5. 15
      app/less/mobile.less
  6. 2
      app/partials/desktop/message.html
  7. 1
      app/partials/mobile/message.html

40
app/js/directives.js

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

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

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

75
app/js/services.js

@ -1046,6 +1046,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -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']) @@ -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']) @@ -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']) @@ -1355,7 +1403,8 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
getProfile: getProfile,
getChatInviteLink: getChatInviteLink,
getChatFull: getChatFull,
getChannelFull: getChannelFull
getChannelFull: getChannelFull,
getChannelParticipants: getChannelParticipants
}
})

4
app/less/app.less

@ -1538,6 +1538,10 @@ a.im_dialog_selected { @@ -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,

15
app/less/mobile.less

@ -934,6 +934,9 @@ a.im_message_author_via { @@ -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 { @@ -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 { @@ -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 {

2
app/partials/desktop/message.html

@ -47,7 +47,7 @@ @@ -47,7 +47,7 @@
<div class="im_message_body" ng-class="::{im_message_body_media: historyMessage._ == 'message' &amp;&amp; historyMessage.media ? true : false}">
<span class="im_message_author_wrap">
<span class="copyonly">[<span ng-bind="::historyMessage.date | time"></span>] </span><a class="im_message_author" my-peer-link="historyMessage.fromID" short="historyMessage.peerID > 0" color="historyMessage.peerID < 0" no-watch="true"></a><a ng-if="::historyMessage.viaBotID && !historyMessage.fwdFromID" class="im_message_author_via" ng-click="selectInlineBot(historyMessage.viaBotID, $event)"><span class="copyonly">&nbsp;</span><span my-i18n="message_via_bot"><my-i18n-param name="bot"><span class="im_message_fwd_author" my-peer-link="historyMessage.viaBotID" username="true" no-watch="true"></span></my-i18n-param></span></a><span class="copyonly">:</span>
<span class="copyonly">[<span ng-bind="::historyMessage.date | time"></span>] </span><a class="im_message_author" my-peer-link="historyMessage.fromID" short="historyMessage.peerID > 0" color="historyMessage.peerID < 0" no-watch="true"></a><a ng-if="::historyMessage.viaBotID && !historyMessage.fwdFromID" class="im_message_author_via" ng-click="selectInlineBot(historyMessage.viaBotID, $event)"><span class="copyonly">&nbsp;</span><span my-i18n="message_via_bot"><my-i18n-param name="bot"><span class="im_message_fwd_author" my-peer-link="historyMessage.viaBotID" username="true" no-watch="true"></span></my-i18n-param></span></a><span class="copyonly">:</span><span class="im_message_author_admin" my-message-admin-badge="historyMessage"></span>
</span>

1
app/partials/mobile/message.html

@ -48,6 +48,7 @@ @@ -48,6 +48,7 @@
<a class="im_message_author" my-peer-link="historyMessage.fromID" short="historyMessage.peerID > 0" color="historyMessage.peerID < 0" no-watch="true"></a>
<a ng-if="::historyMessage.viaBotID && !historyMessage.fwdFromID" class="im_message_author_via" my-i18n="message_via_bot" ng-click="selectInlineBot(historyMessage.viaBotID, $event)"><my-i18n-param name="bot"><span class="im_message_fwd_author" my-peer-link="historyMessage.viaBotID" username="true" no-watch="true"></span></my-i18n-param></a>
<span class="im_message_author_admin" my-message-admin-badge="historyMessage"></span>
<a class="im_message_reply_wrap" my-reply-message="::historyMessage.reply_to_mid" ng-if="::historyMessage.reply_to_mid"></a>

Loading…
Cancel
Save