Admin badge in supergroups
This commit is contained in:
parent
32e3d204e2
commit
ecc0d459e2
@ -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) {
|
.directive('myDialogs', function ($modalStack, $transition, $window, $timeout) {
|
||||||
return {
|
return {
|
||||||
link: link
|
link: link
|
||||||
|
@ -384,6 +384,8 @@
|
|||||||
"message_service_scored_X": "{'one': 'scored {}', 'other': 'scored {}'}",
|
"message_service_scored_X": "{'one': 'scored {}', 'other': 'scored {}'}",
|
||||||
"message_service_payment_sent": "Payment sent",
|
"message_service_payment_sent": "Payment sent",
|
||||||
|
|
||||||
|
"message_admin_badge": "admin",
|
||||||
|
|
||||||
"message_action_reply": "Reply",
|
"message_action_reply": "Reply",
|
||||||
"message_action_edit": "Edit",
|
"message_action_edit": "Edit",
|
||||||
"message_action_delete": "Delete",
|
"message_action_delete": "Delete",
|
||||||
|
@ -1046,6 +1046,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
|
|||||||
var botInfos = {}
|
var botInfos = {}
|
||||||
var chatsFull = {}
|
var chatsFull = {}
|
||||||
var chatFullPromises = {}
|
var chatFullPromises = {}
|
||||||
|
var chatParticipantsPromises = {}
|
||||||
|
|
||||||
function saveBotInfo (botInfo) {
|
function saveBotInfo (botInfo) {
|
||||||
var botID = botInfo && botInfo.user_id
|
var botID = botInfo && botInfo.user_id
|
||||||
@ -1183,18 +1184,49 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getChannelParticipants (id) {
|
function getChannelParticipants (id, filter, limit, offset) {
|
||||||
return MtpApiManager.invokeApi('channels.getParticipants', {
|
filter = filter || {_: 'channelParticipantsRecent'}
|
||||||
channel: AppChatsManager.getChannelInput(id),
|
limit = limit || 200
|
||||||
filter: {_: 'channelParticipantsRecent'},
|
offset = offset || 0
|
||||||
offset: 0,
|
var promiseKey = [id, filter._, offset, limit].join('_')
|
||||||
limit: AppChatsManager.isMegagroup(id) ? 50 : 200
|
var promiseData = chatParticipantsPromises[promiseKey]
|
||||||
}).then(function (result) {
|
|
||||||
AppUsersManager.saveApiUsers(result.users)
|
|
||||||
var participants = result.participants
|
|
||||||
|
|
||||||
|
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)
|
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 myID = AppUsersManager.getSelf().id
|
||||||
var myIndex = false
|
var myIndex = false
|
||||||
var myParticipant
|
var myParticipant
|
||||||
@ -1212,9 +1244,25 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
|
|||||||
}
|
}
|
||||||
participants.unshift(myParticipant)
|
participants.unshift(myParticipant)
|
||||||
}
|
}
|
||||||
|
|
||||||
return participants
|
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) {
|
function getChannelFull (id, force) {
|
||||||
@ -1355,7 +1403,8 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
|
|||||||
getProfile: getProfile,
|
getProfile: getProfile,
|
||||||
getChatInviteLink: getChatInviteLink,
|
getChatInviteLink: getChatInviteLink,
|
||||||
getChatFull: getChatFull,
|
getChatFull: getChatFull,
|
||||||
getChannelFull: getChannelFull
|
getChannelFull: getChannelFull,
|
||||||
|
getChannelParticipants: getChannelParticipants
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1538,6 +1538,10 @@ a.im_dialog_selected {
|
|||||||
.im_message_fwd_via {
|
.im_message_fwd_via {
|
||||||
margin-left: 0;
|
margin-left: 0;
|
||||||
}
|
}
|
||||||
|
.im_message_author_admin {
|
||||||
|
color: #999;
|
||||||
|
margin-left: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
.im_message_from_photo,
|
.im_message_from_photo,
|
||||||
.im_message_contact_photo,
|
.im_message_contact_photo,
|
||||||
|
@ -934,6 +934,9 @@ a.im_message_author_via {
|
|||||||
.im_message_author {
|
.im_message_author {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
.im_message_author_admin {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.im_history_messages_group {
|
.im_history_messages_group {
|
||||||
a.im_message_author {
|
a.im_message_author {
|
||||||
@ -941,6 +944,10 @@ a.im_message_author_via {
|
|||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
}
|
}
|
||||||
|
.im_message_author_admin {
|
||||||
|
display: inline;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
.im_message_sign_link {
|
.im_message_sign_link {
|
||||||
font-size: 12px;
|
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_from_photo,
|
||||||
.im_grouped_short a.im_message_author,
|
.im_grouped_short a.im_message_author,
|
||||||
|
.im_grouped_short .im_message_author_admin,
|
||||||
.im_grouped_short a.im_message_author_via,
|
.im_grouped_short a.im_message_author_via,
|
||||||
.im_grouped a.im_message_from_photo,
|
.im_grouped a.im_message_from_photo,
|
||||||
.im_grouped a.im_message_author,
|
.im_grouped a.im_message_author,
|
||||||
.im_grouped a.im_message_author_via,
|
.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_from_photo,
|
||||||
.im_grouped_fwd a.im_message_author,
|
.im_grouped_fwd a.im_message_author,
|
||||||
.im_grouped_fwd a.im_message_author_via,
|
.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_from_photo,
|
||||||
.im_grouped_fwd_short a.im_message_author,
|
.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_via,
|
||||||
|
.im_grouped_fwd_short a.im_message_author_admin,
|
||||||
.im_message_out a.im_message_from_photo,
|
.im_message_out a.im_message_from_photo,
|
||||||
.im_message_out a.im_message_author,
|
.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;
|
display: none;
|
||||||
}
|
}
|
||||||
.im_message_wrap {
|
.im_message_wrap {
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
<div class="im_message_body" ng-class="::{im_message_body_media: historyMessage._ == 'message' && historyMessage.media ? true : false}">
|
<div class="im_message_body" ng-class="::{im_message_body_media: historyMessage._ == 'message' && historyMessage.media ? true : false}">
|
||||||
|
|
||||||
<span class="im_message_author_wrap">
|
<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"> </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"> </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>
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
@ -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 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>
|
<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>
|
<a class="im_message_reply_wrap" my-reply-message="::historyMessage.reply_to_mid" ng-if="::historyMessage.reply_to_mid"></a>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user