feat: support unblock deleted users

This commit is contained in:
xtaodada 2024-05-09 21:01:58 +08:00
parent e3d8d6388e
commit 5ea9c65328
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
4 changed files with 39 additions and 8 deletions

View File

@ -7751,7 +7751,7 @@ public class MessagesController extends BaseController implements NotificationCe
}));
}
public void unblockAllUsers() {
public void unblockAllUsers(boolean isDeleted, boolean retry) {
if (totalBlockedCount == 0) return;
@ -7762,9 +7762,18 @@ public class MessagesController extends BaseController implements NotificationCe
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 class MessagesController extends BaseController implements NotificationCe
}
unblockAllUsers();
if (retry) {
unblockAllUsers(isDeleted, isDeleted ? false : retry);
}
}

View File

@ -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<Long> ids, boolean added);
@ -155,13 +156,27 @@ public class PrivacyUsersActivity extends BaseFragment implements NotificationCe
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 class PrivacyUsersActivity extends BaseFragment implements NotificationCe
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));
}

View File

@ -144,4 +144,6 @@
<string name="PreviewSendVideo">发送视频</string>
<string name="PreviewSendFile">发送文件</string>
<string name="SentryAnalytics">Sentry 崩溃自动上报</string>
<string name="UnblockDeleted">解禁已删除账号</string>
<string name="UnblockDeletedWarn">您确定要解除屏蔽**所有已删除账号**吗?</string>
</resources>

View File

@ -144,4 +144,6 @@
<string name="PreviewSendVideo">Send Video</string>
<string name="PreviewSendFile">Send File</string>
<string name="SentryAnalytics">Sentry Crash Report</string>
<string name="UnblockDeleted">Unblock Deleted Users</string>
<string name="UnblockDeletedWarn">Are you sure you want to unblock **all deleted users**?</string>
</resources>