mirror of
https://github.com/MGislv/NekoX.git
synced 2024-07-04 11:13:36 +00:00
Fix delete & ban channel
This commit is contained in:
parent
21e8c8432e
commit
4c8c6de621
|
@ -4911,18 +4911,18 @@ public class MessagesController extends BaseController implements NotificationCe
|
|||
});
|
||||
}
|
||||
|
||||
public void deleteChannelUserChannelHistory(TLRPC.Chat chat, long channel_id, int offset) {
|
||||
public void deleteChannelUserChatHistory(TLRPC.Chat chat, TLRPC.Chat fromChat, int offset) {
|
||||
if (offset == 0) {
|
||||
getMessagesStorage().deleteUserChatHistory(-chat.id, channel_id);
|
||||
getMessagesStorage().deleteUserChatHistory(-chat.id, fromChat.id);
|
||||
}
|
||||
TLRPC.TL_channels_deleteParticipantHistory req = new TLRPC.TL_channels_deleteParticipantHistory();
|
||||
req.channel = getInputChannel(chat);
|
||||
req.participant = getInputPeer(channel_id);
|
||||
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) {
|
||||
deleteChannelUserChannelHistory(chat, channel_id, res.offset);
|
||||
deleteChannelUserChatHistory(chat, fromChat, res.offset);
|
||||
}
|
||||
processNewChannelDifferenceParams(res.pts, res.pts_count, chat.id);
|
||||
}
|
||||
|
|
|
@ -49954,10 +49954,10 @@ public class TLRPC {
|
|||
}
|
||||
|
||||
public static class TL_channels_reportSpam extends TLObject {
|
||||
public static int constructor = 0xfe087810;
|
||||
public static int constructor = 0xf44a8315;
|
||||
|
||||
public InputChannel channel;
|
||||
public InputUser user_id;
|
||||
public InputPeer participant;
|
||||
public ArrayList<Integer> id = new ArrayList<>();
|
||||
|
||||
public TLObject deserializeResponse(AbstractSerializedData stream, int constructor, boolean exception) {
|
||||
|
@ -49967,7 +49967,7 @@ public class TLRPC {
|
|||
public void serializeToStream(AbstractSerializedData stream) {
|
||||
stream.writeInt32(constructor);
|
||||
channel.serializeToStream(stream);
|
||||
user_id.serializeToStream(stream);
|
||||
participant.serializeToStream(stream);
|
||||
stream.writeInt32(0x1cb5c415);
|
||||
int count = id.size();
|
||||
stream.writeInt32(count);
|
||||
|
|
|
@ -4166,6 +4166,7 @@ public class AlertsCreator {
|
|||
final boolean[] checks = new boolean[3];
|
||||
final boolean[] deleteForAll = {true};
|
||||
TLRPC.User actionUser = null;
|
||||
TLRPC.Chat actionChat = null;
|
||||
boolean canRevokeInbox = user != null && MessagesController.getInstance(currentAccount).canRevokePmInbox;
|
||||
int revokeTimeLimit;
|
||||
if (user != null) {
|
||||
|
@ -4177,21 +4178,20 @@ public class AlertsCreator {
|
|||
boolean hasNotOut = false;
|
||||
int myMessagesCount = 0;
|
||||
boolean canDeleteInbox = encryptedChat == null && user != null && canRevokeInbox && revokeTimeLimit == 0x7fffffff;
|
||||
// NekoX: Temporarily Fix Ban Channel
|
||||
long channel_id = 1; // should be negative if is from a user-channel
|
||||
if (chat != null && chat.megagroup && !scheduled) {
|
||||
long linked_channel_id = - MessagesController.getInstance(currentAccount).getChatFull(chat.id).linked_chat_id;
|
||||
boolean canBan = ChatObject.canBlockUsers(chat);
|
||||
if (selectedMessage != null) {
|
||||
if (selectedMessage.messageOwner.action == null || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionEmpty ||
|
||||
selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionChatDeleteUser ||
|
||||
selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionChatJoinedByLink ||
|
||||
selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionChatAddUser) {
|
||||
actionUser = MessagesController.getInstance(currentAccount).getUser(selectedMessage.messageOwner.from_id.user_id);
|
||||
}
|
||||
if (selectedMessage.messageOwner.from_id.user_id == 0 && ChatObject.isChannel(selectedMessage.messageOwner.from_id.channel_id, currentAccount) && selectedMessage.messageOwner.from_id.channel_id != -linked_channel_id) {
|
||||
channel_id = -selectedMessage.messageOwner.from_id.channel_id;
|
||||
actionUser = null;
|
||||
if (selectedMessage.messageOwner.from_id.user_id != 0) {
|
||||
actionUser = MessagesController.getInstance(currentAccount).getUser(selectedMessage.messageOwner.from_id.user_id);
|
||||
} else if (selectedMessage.messageOwner.from_id.channel_id != 0) {
|
||||
actionChat = MessagesController.getInstance(currentAccount).getChat(selectedMessage.messageOwner.from_id.channel_id);
|
||||
} else if (selectedMessage.messageOwner.from_id.chat_id != 0) {
|
||||
actionChat = MessagesController.getInstance(currentAccount).getChat(selectedMessage.messageOwner.from_id.chat_id);
|
||||
}
|
||||
}
|
||||
boolean hasOutgoing = !selectedMessage.isSendError() && selectedMessage.getDialogId() == mergeDialogId && (selectedMessage.messageOwner.action == null || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionEmpty) && selectedMessage.isOut() && (currentDate - selectedMessage.messageOwner.date) <= revokeTimeLimit;
|
||||
if (hasOutgoing) {
|
||||
|
@ -4206,13 +4206,7 @@ public class AlertsCreator {
|
|||
if (from_id == -1) {
|
||||
from_id = msg.getFromChatId();
|
||||
}
|
||||
if (from_id < 0 && from_id == msg.getSenderId() && from_id != linked_channel_id) {
|
||||
channel_id = from_id;
|
||||
continue;
|
||||
}
|
||||
if (from_id < 0 || from_id != msg.getSenderId()) {
|
||||
if (channel_id != msg.getSenderId())
|
||||
channel_id = 0;
|
||||
from_id = -2;
|
||||
break;
|
||||
}
|
||||
|
@ -4237,13 +4231,13 @@ public class AlertsCreator {
|
|||
actionUser = MessagesController.getInstance(currentAccount).getUser(from_id);
|
||||
}
|
||||
}
|
||||
if ((actionUser != null && actionUser.id != UserConfig.getInstance(currentAccount).getClientUserId()) || channel_id < 0) {
|
||||
if (loadParticipant == 1 && !chat.creator) {
|
||||
if ((actionUser != null && actionUser.id != UserConfig.getInstance(currentAccount).getClientUserId()) || (actionChat != null && !ChatObject.hasAdminRights(actionChat))) {
|
||||
if (loadParticipant == 1 && !chat.creator && actionUser != null) {
|
||||
final AlertDialog[] progressDialog = new AlertDialog[]{new AlertDialog(activity, 3)};
|
||||
|
||||
TLRPC.TL_channels_getParticipant req = new TLRPC.TL_channels_getParticipant();
|
||||
req.channel = MessagesController.getInputChannel(chat);
|
||||
req.participant = channel_id < 0 ? MessagesController.getInstance(currentAccount).getInputPeer(channel_id) : MessagesController.getInputPeer(actionUser);
|
||||
req.participant = MessagesController.getInputPeer(actionUser);
|
||||
int requestId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
||||
try {
|
||||
progressDialog[0].dismiss();
|
||||
|
@ -4273,9 +4267,8 @@ public class AlertsCreator {
|
|||
}
|
||||
FrameLayout frameLayout = new FrameLayout(activity);
|
||||
int num = 0;
|
||||
String name = actionUser != null ? ContactsController.formatName(actionUser.first_name, actionUser.last_name) : actionChat.title;
|
||||
for (int a = 0; a < 3; a++) {
|
||||
if (loadParticipant == 0) break;
|
||||
if (a == 1 && channel_id < 0) continue;
|
||||
if ((loadParticipant == 2 || !canBan) && a == 0) {
|
||||
continue;
|
||||
}
|
||||
|
@ -4287,13 +4280,7 @@ public class AlertsCreator {
|
|||
} else if (a == 1) {
|
||||
cell.setText(LocaleController.getString("DeleteReportSpam", R.string.DeleteReportSpam), "", false, false);
|
||||
} else {
|
||||
if (actionUser != null)
|
||||
cell.setText(LocaleController.formatString("DeleteAllFrom", R.string.DeleteAllFrom, ContactsController.formatName(actionUser.first_name, actionUser.last_name)), "", false, false);
|
||||
else {
|
||||
TLRPC.Chat channel = MessagesController.getInstance(currentAccount).getChat(-channel_id);
|
||||
if (channel != null)
|
||||
cell.setText(LocaleController.formatString("DeleteAllFrom", R.string.DeleteAllFrom, ContactsController.formatName("Channel", channel.title)), "", false, false);
|
||||
}
|
||||
cell.setText(LocaleController.formatString("DeleteAllFrom", R.string.DeleteAllFrom, name), "", false, false);
|
||||
}
|
||||
cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
|
||||
frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 0, 48 * num, 0, 0));
|
||||
|
@ -4392,7 +4379,7 @@ public class AlertsCreator {
|
|||
}
|
||||
}
|
||||
final TLRPC.User userFinal = actionUser;
|
||||
long finalChannel_id = channel_id;
|
||||
final TLRPC.Chat chatFinal = actionChat;
|
||||
builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialogInterface, i) -> {
|
||||
ArrayList<Integer> ids = null;
|
||||
if (selectedMessage != null) {
|
||||
|
@ -4444,29 +4431,28 @@ public class AlertsCreator {
|
|||
selectedMessages[a].clear();
|
||||
}
|
||||
}
|
||||
if (userFinal != null) {
|
||||
if (userFinal != null || chatFinal != null) {
|
||||
if (checks[0]) {
|
||||
MessagesController.getInstance(currentAccount).deleteParticipantFromChat(chat.id, userFinal, chatInfo);
|
||||
MessagesController.getInstance(currentAccount).deleteParticipantFromChat(chat.id, userFinal, chatFinal, chatInfo, false, false);
|
||||
}
|
||||
if (checks[1]) {
|
||||
TLRPC.TL_channels_reportSpam req = new TLRPC.TL_channels_reportSpam();
|
||||
req.channel = MessagesController.getInputChannel(chat);
|
||||
req.user_id = MessagesController.getInstance(currentAccount).getInputUser(userFinal);
|
||||
if (userFinal != null) {
|
||||
req.participant = MessagesController.getInputPeer(userFinal);
|
||||
} else {
|
||||
req.participant = MessagesController.getInputPeer(chatFinal);
|
||||
}
|
||||
req.id = ids;
|
||||
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
|
||||
|
||||
});
|
||||
}
|
||||
if (checks[2]) {
|
||||
MessagesController.getInstance(currentAccount).deleteUserChannelHistory(chat, userFinal, 0);
|
||||
}
|
||||
} else if (finalChannel_id < 0) {
|
||||
MessagesController messagesController = MessagesController.getInstance(currentAccount);
|
||||
if(checks[0])
|
||||
messagesController.deleteParticipantFromChat(chat.id, null, messagesController.getChat(-finalChannel_id), null, true, false);
|
||||
// Report Spam and Delete all is not supported yet
|
||||
if(checks[2]) {
|
||||
messagesController.deleteChannelUserChannelHistory(chat, finalChannel_id, 0);
|
||||
if (userFinal != null)
|
||||
MessagesController.getInstance(currentAccount).deleteUserChannelHistory(chat, userFinal, 0);
|
||||
else
|
||||
MessagesController.getInstance(currentAccount).deleteChannelUserChatHistory(chat, chatFinal, 0);
|
||||
}
|
||||
}
|
||||
if (onDelete != null) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user