Skip to content

Commit

Permalink
feat: support unblock deleted users
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed May 9, 2024
1 parent e3d8d63 commit 5ea9c65
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7751,7 +7751,7 @@ public void getBlockedPeers(boolean reset) {
}));
}

public void unblockAllUsers() {
public void unblockAllUsers(boolean isDeleted, boolean retry) {

if (totalBlockedCount == 0) return;

Expand All @@ -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) -> {

Expand All @@ -7779,7 +7788,9 @@ public void unblockAllUsers() {

}

unblockAllUsers();
if (retry) {
unblockAllUsers(isDeleted, isDeleted ? false : retry);
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand All @@ -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));

}

Expand Down
2 changes: 2 additions & 0 deletions TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions TMessagesProj/src/main/res/values/strings_na.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit 5ea9c65

Please sign in to comment.