From 359f6e4d8db32594a4280434538cd3780e2ad21f Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sun, 10 Sep 2023 21:50:07 +0800 Subject: [PATCH] feat: Share Group Admin Rights --- .../org/telegram/messenger/MessageObject.java | 6 +++ .../telegram/ui/Components/AlertsCreator.java | 6 +++ .../NekoExperimentalSettingsActivity.java | 1 + .../kotlin/xyz/nextalone/nagram/NaConfig.kt | 6 +++ .../nextalone/nagram/helper/MessageHelper.kt | 53 ++++++++++++++----- .../src/main/res/values-zh-rCN/strings_na.xml | 1 + .../src/main/res/values/strings_na.xml | 1 + 7 files changed, 62 insertions(+), 12 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessageObject.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessageObject.java index 5eaf28f15e..5bda3e2eef 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessageObject.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessageObject.java @@ -8,6 +8,8 @@ package org.telegram.messenger; +import static xyz.nextalone.nagram.helper.MessageHelper.getHaveRightsAccount; + import android.graphics.Paint; import android.graphics.Typeface; import android.graphics.drawable.BitmapDrawable; @@ -7505,6 +7507,10 @@ public static boolean canDeleteMessage(int currentAccount, boolean inScheduleMod if (chat == null && message.peer_id != null && message.peer_id.channel_id != 0) { chat = MessagesController.getInstance(currentAccount).getChat(message.peer_id.channel_id); } + if (NaConfig.INSTANCE.getShareGroupAdminRights().Bool() && ChatObject.isMegagroup(chat)) { + int newAccount = getHaveRightsAccount(currentAccount, chat); + chat = MessagesController.getInstance(newAccount).getChat(chat.id); + } if (ChatObject.isChannel(chat)) { if (inScheduleMode && !chat.megagroup) { return chat.creator || chat.admin_rights != null && (chat.admin_rights.delete_messages || message.out); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/AlertsCreator.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/AlertsCreator.java index 98f2a7265a..84e0b9e9b6 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/AlertsCreator.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/AlertsCreator.java @@ -137,6 +137,8 @@ import tw.nekomimi.nekogram.utils.AlertUtil; import tw.nekomimi.nekogram.utils.VibrateUtil; import static tw.nekomimi.nekogram.settings.NekoChatSettingsActivity.getDeleteMenuChecks; +import static xyz.nextalone.nagram.helper.MessageHelper.getHaveRightsAccount; + import xyz.nextalone.nagram.NaConfig; public class AlertsCreator { @@ -5456,6 +5458,10 @@ public static void createDeleteMessagesAlert(BaseFragment fragment, TLRPC.User u return; } int currentAccount = fragment.getCurrentAccount(); + if (NaConfig.INSTANCE.getShareGroupAdminRights().Bool() && chat != null && ChatObject.isMegagroup(chat)) { + currentAccount = getHaveRightsAccount(fragment.getCurrentAccount(), chat); + chat = MessagesController.getInstance(currentAccount).getChat(chat.id); + } AlertDialog.Builder builder = new AlertDialog.Builder(activity, resourcesProvider); builder.setDimAlpha(hideDim != null ? .5f : .6f); diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java index e3d8abf8d9..d9a4809841 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java @@ -101,6 +101,7 @@ public class NekoExperimentalSettingsActivity extends BaseNekoXSettingsActivity private final AbstractConfigCell customArtworkApiRow = cellGroup.appendCell(new ConfigCellTextInput(null, NaConfig.INSTANCE.getCustomArtworkApi(), "", null)); private final AbstractConfigCell fakeHighPerformanceDeviceRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getFakeHighPerformanceDevice())); private final AbstractConfigCell disableEmojiDrawLimitRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getDisableEmojiDrawLimit())); + private final AbstractConfigCell shareGroupAdminRightsRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getShareGroupAdminRights())); private final AbstractConfigCell divider1 = cellGroup.appendCell(new ConfigCellDivider()); private UndoView tooltip; diff --git a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt index c117ab606c..f15fcd05ca 100644 --- a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt +++ b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt @@ -436,6 +436,12 @@ object NaConfig { ConfigItem.configTypeBool, false ) + val shareGroupAdminRights = + addConfig( + "ShareGroupAdminRights", + ConfigItem.configTypeBool, + false + ) private fun addConfig( k: String, diff --git a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/MessageHelper.kt b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/MessageHelper.kt index eafee6fa1d..1abdc0a797 100644 --- a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/MessageHelper.kt +++ b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/MessageHelper.kt @@ -6,7 +6,7 @@ import android.content.Context import android.text.TextUtils import androidx.core.content.FileProvider import org.telegram.messenger.* -import org.telegram.tgnet.TLRPC.* +import org.telegram.tgnet.TLRPC import org.telegram.ui.ChatActivity import xyz.nextalone.nagram.NaConfig import java.io.File @@ -154,7 +154,7 @@ object MessageHelper { fun canSendAsDice(text: String, parentFragment: ChatActivity, dialog_id: Long): Boolean { var canSendGames = true if (DialogObject.isChatDialog(dialog_id)) { - val chat: Chat = parentFragment.messagesController.getChat(-dialog_id) + val chat: TLRPC.Chat = parentFragment.messagesController.getChat(-dialog_id) canSendGames = ChatObject.canSendStickers(chat) } return canSendGames && parentFragment.messagesController.diceEmojies.contains( @@ -170,14 +170,14 @@ object MessageHelper { val entities = messageObject.messageOwner.entities if (entities != null) { for (entity in entities) { - if (entity is TL_messageEntityBotCommand || - entity is TL_messageEntityEmail || - entity is TL_messageEntityUrl || - entity is TL_messageEntityMention || - entity is TL_messageEntityCashtag || - entity is TL_messageEntityHashtag || - entity is TL_messageEntityBankCard || - entity is TL_messageEntityPhone + if (entity is TLRPC.TL_messageEntityBotCommand || + entity is TLRPC.TL_messageEntityEmail || + entity is TLRPC.TL_messageEntityUrl || + entity is TLRPC.TL_messageEntityMention || + entity is TLRPC.TL_messageEntityCashtag || + entity is TLRPC.TL_messageEntityHashtag || + entity is TLRPC.TL_messageEntityBankCard || + entity is TLRPC.TL_messageEntityPhone ) { if (entity.offset == 0 && entity.length == messageObject.messageOwner.message.length) { return true @@ -203,7 +203,7 @@ object MessageHelper { @JvmStatic fun getMessagePlainText(messageObject: MessageObject): String { val message: String = if (messageObject.isPoll) { - val poll = (messageObject.messageOwner.media as TL_messageMediaPoll).poll + val poll = (messageObject.messageOwner.media as TLRPC.TL_messageMediaPoll).poll val pollText = StringBuilder(poll.question).append("\n") for (answer in poll.answers) { pollText.append("\n\uD83D\uDD18 ") @@ -217,4 +217,33 @@ object MessageHelper { } return message } -} + + @JvmStatic + fun getChatRightsCount(chat: TLRPC.Chat?) : Int { + if (chat == null) return 0 + var currentRight = 0 + if (ChatObject.canBlockUsers(chat)) currentRight++ + if (ChatObject.canUserDoAction(chat, ChatObject.ACTION_DELETE_MESSAGES)) currentRight++ + return currentRight + } + + @JvmStatic + fun getHaveRightsAccount(oldAccount: Int, chat: TLRPC.Chat?) : Int { + if (chat == null || !ChatObject.isMegagroup(chat)) { + return oldAccount + } + var currentAccount = oldAccount + var currentRights = getChatRightsCount(chat) + for (a in SharedConfig.activeAccounts) { + if (currentRights == 2) break + val newChat = MessagesController.getInstance(a).getChat(chat.id) + val newRights = getChatRightsCount(newChat) + if (newRights > currentRights) { + currentAccount = a + currentRights = newRights + } + } + return currentAccount + } + +} \ No newline at end of file diff --git a/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml b/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml index 14ba17586a..00928535ee 100644 --- a/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml +++ b/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml @@ -88,4 +88,5 @@ 禁用修改手机号码的建议 禁用动态功能 偷偷看动态 + 共享群组管理员权限 diff --git a/TMessagesProj/src/main/res/values/strings_na.xml b/TMessagesProj/src/main/res/values/strings_na.xml index fee8f8f309..45232e5a05 100644 --- a/TMessagesProj/src/main/res/values/strings_na.xml +++ b/TMessagesProj/src/main/res/values/strings_na.xml @@ -91,4 +91,5 @@ Disable Profile Settings Suggestion Disable Stories Disable Send Read Stories + Share Group Admin Rights