fix delete all

This commit is contained in:
luvletter2333 2022-03-24 14:28:47 +08:00
parent 2f86e87899
commit 00f7b2c892
No known key found for this signature in database
GPG Key ID: A26A8880836E1978
4 changed files with 15 additions and 30 deletions

View File

@ -4968,38 +4968,26 @@ public class MessagesController extends BaseController implements NotificationCe
});
}
public void deleteUserChannelHistory(TLRPC.Chat chat, TLRPC.User user, int offset) {
public void deleteUserChannelHistory(TLRPC.Chat currentChat, TLRPC.User fromUser, TLRPC.Chat fromChat, int offset) {
long fromId = 0;
if (fromUser != null) {
fromId = fromUser.id;
} else if (fromChat != null){
fromId = fromChat.id;
}
if (offset == 0) {
getMessagesStorage().deleteUserChatHistory(-chat.id, user.id);
getMessagesStorage().deleteUserChatHistory(-currentChat.id, fromId);
}
TLRPC.TL_channels_deleteParticipantHistory req = new TLRPC.TL_channels_deleteParticipantHistory();
req.channel = getInputChannel(chat);
req.participant = getInputPeer(user);
req.channel = getInputChannel(currentChat);
req.participant = fromUser != null ? getInputPeer(fromUser) : getInputPeer(fromChat);
getConnectionsManager().sendRequest(req, (response, error) -> {
if (error == null) {
TLRPC.TL_messages_affectedHistory res = (TLRPC.TL_messages_affectedHistory) response;
if (res.offset > 0) {
deleteUserChannelHistory(chat, user, res.offset);
deleteUserChannelHistory(currentChat, fromUser, fromChat, res.offset);
}
processNewChannelDifferenceParams(res.pts, res.pts_count, chat.id);
}
});
}
public void deleteChannelUserChatHistory(TLRPC.Chat chat, TLRPC.Chat fromChat, int offset) {
if (offset == 0) {
getMessagesStorage().deleteUserChatHistory(-chat.id, fromChat.id);
}
TLRPC.TL_channels_deleteParticipantHistory req = new TLRPC.TL_channels_deleteParticipantHistory();
req.channel = getInputChannel(chat);
req.participant = getInputPeer(fromChat);
getConnectionsManager().sendRequest(req, (response, error) -> {
if (error == null) {
TLRPC.TL_messages_affectedHistory res = (TLRPC.TL_messages_affectedHistory) response;
if (res.offset > 0) {
deleteChannelUserChatHistory(chat, fromChat, res.offset);
}
processNewChannelDifferenceParams(res.pts, res.pts_count, chat.id);
processNewChannelDifferenceParams(res.pts, res.pts_count, currentChat.id);
}
});
}

View File

@ -29052,7 +29052,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("DeleteAllFromSelfAlert", R.string.DeleteAllFromSelfAlert)));
builder.setPositiveButton(LocaleController.getString("DeleteAll", R.string.DeleteAll), (dialogInterface, i) -> {
if (ChatObject.isChannel(currentChat) && currentChat.megagroup && ChatObject.canUserDoAction(currentChat, ChatObject.ACTION_DELETE_MESSAGES)) {
getMessagesController().deleteUserChannelHistory(currentChat, UserConfig.getInstance(currentAccount).getCurrentUser(), 0);
getMessagesController().deleteUserChannelHistory(currentChat, UserConfig.getInstance(currentAccount).getCurrentUser(), null, 0);
} else {
getMessageHelper().deleteUserChannelHistoryWithSearch(getParentActivity(), dialog_id, UserConfig.getInstance(currentAccount).getCurrentUser());
}

View File

@ -4588,10 +4588,7 @@ public class AlertsCreator {
});
}
if (checks[2]) {
if (userFinal != null)
MessagesController.getInstance(currentAccount).deleteUserChannelHistory(chat, userFinal, 0);
else
MessagesController.getInstance(currentAccount).deleteChannelUserChatHistory(chat, chatFinal, 0);
MessagesController.getInstance(currentAccount).deleteUserChannelHistory(chat, userFinal, chatFinal, 0);
}
}
if (onDelete != null) {

View File

@ -142,7 +142,7 @@ public class NekoAccountSettingsActivity extends BaseFragment {
TLRPC.Chat chat = getMessagesController().getChat(peer.channel_id);
if (!chat.broadcast) {
if (ChatObject.isChannel(chat) && chat.megagroup && ChatObject.canUserDoAction(chat, ChatObject.ACTION_DELETE_MESSAGES)) {
getMessagesController().deleteUserChannelHistory(chat, UserConfig.getInstance(currentAccount).getCurrentUser(), 0);
getMessagesController().deleteUserChannelHistory(chat, UserConfig.getInstance(currentAccount).getCurrentUser(), null, 0);
} else {
MessageHelper.getInstance(currentAccount).deleteUserChannelHistoryWithSearch(null, TLdialog.id, getMessagesController().getUser(getUserConfig().clientUserId));
}