mirror of
https://github.com/NekoX-Dev/NekoX.git
synced 2024-12-12 11:51:47 +01:00
Improve deleteUserChannelHistoryWithSearch
This commit is contained in:
parent
1f3a23f728
commit
e136782697
@ -1,21 +1,20 @@
|
||||
package tw.nekomimi.nekogram;
|
||||
|
||||
import org.telegram.messenger.AndroidUtilities;
|
||||
import org.telegram.messenger.MessagesController;
|
||||
import org.telegram.messenger.BaseController;
|
||||
import org.telegram.messenger.UserConfig;
|
||||
import org.telegram.tgnet.ConnectionsManager;
|
||||
import org.telegram.tgnet.TLRPC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MessageHelper {
|
||||
public class MessageHelper extends BaseController {
|
||||
|
||||
private static volatile MessageHelper[] Instance = new MessageHelper[UserConfig.MAX_ACCOUNT_COUNT];
|
||||
private int currentAccount;
|
||||
private int lastReqId;
|
||||
|
||||
public MessageHelper(int num) {
|
||||
currentAccount = num;
|
||||
super(num);
|
||||
}
|
||||
|
||||
public static MessageHelper getInstance(int num) {
|
||||
@ -37,7 +36,7 @@ public class MessageHelper {
|
||||
|
||||
public void deleteUserChannelHistoryWithSearch(final long dialog_id, final TLRPC.User user, final int offset_id) {
|
||||
final TLRPC.TL_messages_search req = new TLRPC.TL_messages_search();
|
||||
req.peer = MessagesController.getInstance(currentAccount).getInputPeer((int) dialog_id);
|
||||
req.peer = getMessagesController().getInputPeer((int) dialog_id);
|
||||
if (req.peer == null) {
|
||||
return;
|
||||
}
|
||||
@ -45,34 +44,36 @@ public class MessageHelper {
|
||||
req.q = "";
|
||||
req.offset_id = offset_id;
|
||||
if (user != null) {
|
||||
req.from_id = MessagesController.getInstance(currentAccount).getInputUser(user);
|
||||
req.from_id = getMessagesController().getInputUser(user);
|
||||
req.flags |= 1;
|
||||
}
|
||||
req.filter = new TLRPC.TL_inputMessagesFilterEmpty();
|
||||
final int currentReqId = ++lastReqId;
|
||||
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
||||
int lastMessageId = offset_id;
|
||||
if (currentReqId == lastReqId) {
|
||||
if (response != null) {
|
||||
TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
|
||||
int size = res.messages.size();
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
ArrayList<Integer> ids = new ArrayList<>();
|
||||
ArrayList<Long> random_ids = new ArrayList<>();
|
||||
int channelId = 0;
|
||||
for (int a = 0; a < res.messages.size(); a++) {
|
||||
TLRPC.Message message = res.messages.get(a);
|
||||
ids.add(message.id);
|
||||
if (message.random_id != 0) {
|
||||
random_ids.add(message.random_id);
|
||||
getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
||||
if (error == null) {
|
||||
int lastMessageId = offset_id;
|
||||
if (currentReqId == lastReqId) {
|
||||
if (response != null) {
|
||||
TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
|
||||
int size = res.messages.size();
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
channelId = message.to_id.channel_id;
|
||||
lastMessageId = message.id;
|
||||
ArrayList<Integer> ids = new ArrayList<>();
|
||||
ArrayList<Long> random_ids = new ArrayList<>();
|
||||
int channelId = 0;
|
||||
for (int a = 0; a < res.messages.size(); a++) {
|
||||
TLRPC.Message message = res.messages.get(a);
|
||||
ids.add(message.id);
|
||||
if (message.random_id != 0) {
|
||||
random_ids.add(message.random_id);
|
||||
}
|
||||
channelId = message.to_id.channel_id;
|
||||
lastMessageId = message.id;
|
||||
}
|
||||
getMessagesController().deleteMessages(ids, random_ids, null, dialog_id, channelId, true, false);
|
||||
deleteUserChannelHistoryWithSearch(dialog_id, user, lastMessageId);
|
||||
}
|
||||
MessagesController.getInstance(currentAccount).deleteMessages(ids, random_ids, null, dialog_id, channelId, true, false);
|
||||
deleteUserChannelHistoryWithSearch(dialog_id, user, lastMessageId);
|
||||
}
|
||||
}
|
||||
}), ConnectionsManager.RequestFlagFailOnServerErrors);
|
||||
|
Loading…
Reference in New Issue
Block a user