Skip to content

Commit

Permalink
feat: Share Group Admin Rights
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Sep 10, 2023
1 parent 482e8ec commit 359f6e4
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,12 @@ object NaConfig {
ConfigItem.configTypeBool,
false
)
val shareGroupAdminRights =
addConfig(
"ShareGroupAdminRights",
ConfigItem.configTypeBool,
false
)

private fun addConfig(
k: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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 ")
Expand All @@ -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
}

}
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,5 @@
<string name="DisableSuggestionView">禁用修改手机号码的建议</string>
<string name="DisableStories">禁用动态功能</string>
<string name="DisableSendReadStories">偷偷看动态</string>
<string name="ShareGroupAdminRights">共享群组管理员权限</string>
</resources>
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values/strings_na.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,5 @@
<string name="DisableSuggestionView">Disable Profile Settings Suggestion</string>
<string name="DisableStories">Disable Stories</string>
<string name="DisableSendReadStories">Disable Send Read Stories</string>
<string name="ShareGroupAdminRights">Share Group Admin Rights</string>
</resources>

0 comments on commit 359f6e4

Please sign in to comment.