From 6ccb87a96e8ae3f6d64d186a64900899c4d474c2 Mon Sep 17 00:00:00 2001 From: luvletter2333 Date: Wed, 27 Jul 2022 14:41:49 +0800 Subject: [PATCH] fix: read channel admin count --- .../org/telegram/ui/ChatEditActivity.java | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatEditActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatEditActivity.java index 437f50fe5..49acef128 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatEditActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatEditActivity.java @@ -1140,6 +1140,23 @@ public class ChatEditActivity extends BaseFragment implements ImageUpdater.Image return count; } + private int getChannelAdminCount() { + if (info == null || info.participants == null || info.participants.participants == null) { + return 1; + } + int count = 0; + for (int a = 0, N = info.participants.participants.size(); a < N; a++) { + TLRPC.ChatParticipant chatParticipant = info.participants.participants.get(a); + TLRPC.ChannelParticipant channelParticipant = ((TLRPC.TL_chatChannelParticipant) chatParticipant).channelParticipant; + if (channelParticipant instanceof TLRPC.TL_channelParticipantAdmin || + channelParticipant instanceof TLRPC.TL_channelParticipantCreator) { + count++; + } + } + return count; + } + + @Deprecated private void getRealChannelAdminCount() { TLRPC.TL_channels_getParticipants req = new TLRPC.TL_channels_getParticipants(); req.channel = getMessagesController().getInputChannel(chatId); @@ -1466,14 +1483,17 @@ public class ChatEditActivity extends BaseFragment implements ImageUpdater.Image memberRequestsCell.setTextAndValue(LocaleController.getString("MemberRequests", R.string.MemberRequests), String.format("%d", info.requests_pending), logCell != null && logCell.getVisibility() == View.VISIBLE); } } - // NekoX: read admins count - String adminCount = "" ; - if (info.participants != null) { - if (ChatObject.isChannel(currentChat) && !ChatObject.hasAdminRights(currentChat) && info.participants.participants.size() != info.participants_count) { - getRealChannelAdminCount(); - } + if (ChatObject.hasAdminRights(currentChat)) { + adminCell.setTextAndValue(LocaleController.getString("ChannelAdministrators", R.string.ChannelAdministrators), String.format("%d", ChatObject.isChannel(currentChat) ? info.admins_count : getAdminCount()), true); + } else { + // NekoX: read admins count + int count; + if (ChatObject.isChannel(currentChat)) + count = getChannelAdminCount(); + else + count = getAdminCount(); + adminCell.setTextAndValue(LocaleController.getString("ChannelAdministrators", R.string.ChannelAdministrators), String.format("%d", count), true); } - adminCell.setTextAndValue(LocaleController.getString("ChannelAdministrators", R.string.ChannelAdministrators), String.format("%d", ChatObject.isChannel(currentChat) ? info.admins_count : getAdminCount()), true); } else { if (isChannel) { membersCell.setText(LocaleController.getString("ChannelSubscribers", R.string.ChannelSubscribers), true);