From 5ea9c6532820ec3e43db7a3bfb075e989341f9b8 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Thu, 9 May 2024 21:01:58 +0800 Subject: [PATCH] feat: support unblock deleted users --- .../messenger/MessagesController.java | 19 +++++++++++---- .../org/telegram/ui/PrivacyUsersActivity.java | 24 +++++++++++++++---- .../src/main/res/values-zh-rCN/strings_na.xml | 2 ++ .../src/main/res/values/strings_na.xml | 2 ++ 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java index 7ec622dcb6..b90651f740 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java @@ -7751,7 +7751,7 @@ public void getBlockedPeers(boolean reset) { })); } - public void unblockAllUsers() { + public void unblockAllUsers(boolean isDeleted, boolean retry) { if (totalBlockedCount == 0) return; @@ -7762,9 +7762,18 @@ public void unblockAllUsers() { if (blockedCopy.size() == 0) return; for (int index = 0; index < blockedCopy.size(); index++) { - - TLRPC.TL_contacts_unblock req = new TLRPC.TL_contacts_unblock(); long peer_id = blockedCopy.keyAt(index); + if (isDeleted) { + if (peer_id > 0) { + TLRPC.User user = getMessagesController().getUser(peer_id); + if (!UserObject.isDeleted(user)) { + continue; + } + } else { + continue; + } + } + TLRPC.TL_contacts_unblock req = new TLRPC.TL_contacts_unblock(); req.id = getInputPeer(peer_id); getConnectionsManager().sendRequest(req, (response, error) -> { @@ -7779,7 +7788,9 @@ public void unblockAllUsers() { } - unblockAllUsers(); + if (retry) { + unblockAllUsers(isDeleted, isDeleted ? false : retry); + } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/PrivacyUsersActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/PrivacyUsersActivity.java index 9751fd74cd..2b2b07599d 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/PrivacyUsersActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/PrivacyUsersActivity.java @@ -78,7 +78,8 @@ public class PrivacyUsersActivity extends BaseFragment implements NotificationCe public static final int TYPE_BLOCKED = 1; public static final int TYPE_FILTER = 2; - private int unblock_all = 1; + private static final int unblockAll = 100; + private static final int unblockDeleted = 101; public interface PrivacyActivityDelegate { void didUpdateUserList(ArrayList ids, boolean added); @@ -155,13 +156,27 @@ public View createView(Context context) { public void onItemClick(int id) { if (id == -1) { finishFragment(); - } else if (id == unblock_all) { + } else if (id == unblockAll) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("UnblockAll", R.string.UnblockAll)); if (getMessagesController().totalBlockedCount != 0) { builder.setMessage(LocaleController.getString("UnblockAllWarn", R.string.UnblockAllWarn)); builder.setPositiveButton(LocaleController.getString("UnblockAll", R.string.UnblockAll), (dialog, which) -> { - new Thread(() -> getMessagesController().unblockAllUsers()).start(); + new Thread(() -> getMessagesController().unblockAllUsers(false, true)).start(); + }); + builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); + } else { + builder.setMessage(LocaleController.getString("BlockedListEmpty",R.string.BlockedListEmpty)); + builder.setPositiveButton(LocaleController.getString("OK",R.string.OK),null); + } + showDialog(builder.create()); + } else if (id == unblockDeleted) { + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); + builder.setTitle(LocaleController.getString("UnblockDeleted", R.string.UnblockDeleted)); + if (getMessagesController().totalBlockedCount != 0) { + builder.setMessage(LocaleController.getString("UnblockDeletedWarn", R.string.UnblockDeletedWarn)); + builder.setPositiveButton(LocaleController.getString("UnblockDeleted", R.string.UnblockDeleted), (dialog, which) -> { + new Thread(() -> getMessagesController().unblockAllUsers(true, true)).start(); }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); } else { @@ -179,7 +194,8 @@ public void onItemClick(int id) { ActionBarMenuItem otherItem = menu.addItem(0, R.drawable.ic_ab_other); otherItem.setContentDescription(LocaleController.getString("AccDescrMoreOptions", R.string.AccDescrMoreOptions)); - otherItem.addSubItem(unblock_all, LocaleController.getString("UnblockAll", R.string.UnblockAll)); + otherItem.addSubItem(unblockAll, LocaleController.getString("UnblockAll", R.string.UnblockAll)); + otherItem.addSubItem(unblockDeleted, LocaleController.getString("UnblockDeleted", R.string.UnblockDeleted)); } 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 f0073733f0..d8236f643b 100644 --- a/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml +++ b/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml @@ -144,4 +144,6 @@ 发送视频 发送文件 Sentry 崩溃自动上报 + 解禁已删除账号 + 您确定要解除屏蔽**所有已删除账号**吗? diff --git a/TMessagesProj/src/main/res/values/strings_na.xml b/TMessagesProj/src/main/res/values/strings_na.xml index b0d864e9fe..b6d8974f61 100644 --- a/TMessagesProj/src/main/res/values/strings_na.xml +++ b/TMessagesProj/src/main/res/values/strings_na.xml @@ -144,4 +144,6 @@ Send Video Send File Sentry Crash Report + Unblock Deleted Users + Are you sure you want to unblock **all deleted users**?