Delete messages in chats edited

This commit is contained in:
2025-08-07 13:26:29 +03:30
parent 2c19db1d42
commit ad37f3f26c
@@ -3405,31 +3405,64 @@ public class ActionHandler {
JSONObject selected = messages.getJSONObject(index - 1); JSONObject selected = messages.getJSONObject(index - 1);
UUID messageId = UUID.fromString(selected.getString("message_id")); UUID messageId = UUID.fromString(selected.getString("message_id"));
UUID senderId = UUID.fromString(selected.getString("sender_id")); UUID senderId = UUID.fromString(selected.getString("sender_id"));
boolean isSender = senderId.toString().equals(Session.currentUser.getString("internal_uuid"));
boolean isChannel = chat.getType().equals("channel");
boolean isOwnerOrAdmin = chat.isOwner() || chat.isAdmin();
System.out.println("\n🎯 Selected message by " + selected.getString("sender_name")); System.out.println("\n🎯 Selected message by " + selected.getString("sender_name"));
System.out.println("1. Reply");
System.out.println("2. Forward");
System.out.println("3. React");
if (senderId.toString().equals(Session.currentUser.getString("internal_uuid"))) { // ✔ Show interaction menu based on access
System.out.println("2. Forward");
if (isChannel) {
if (isOwnerOrAdmin) {
System.out.println("1. Reply");
System.out.println("3. React");
if (isSender) {
System.out.println("4. Edit"); System.out.println("4. Edit");
}
System.out.println("5. Delete"); System.out.println("5. Delete");
} }
} else {
System.out.println("1. Reply");
System.out.println("3. React");
if (isSender) {
System.out.println("4. Edit");
}
if (isSender || isOwnerOrAdmin) {
System.out.println("5. Delete");
}
}
System.out.println("0. Back to message list"); System.out.println("0. Back to message list");
System.out.print("➤ Select an action: ");
String choice = scanner.nextLine().trim(); String choice = scanner.nextLine().trim();
switch (choice) { switch (choice) {
case "1" -> replyToMessage(messageId); case "1" -> {
if (!isChannel || isOwnerOrAdmin)
replyToMessage(messageId);
else
System.out.println("❌ You are not allowed to reply.");
}
case "2" -> forwardMessage(messageId); case "2" -> forwardMessage(messageId);
case "3" -> reactToMessage(messageId); case "3" -> {
if (!isChannel || isOwnerOrAdmin)
reactToMessage(messageId);
else
System.out.println("❌ You are not allowed to react.");
}
case "4" -> { case "4" -> {
if (senderId.toString().equals(Session.currentUser.getString("internal_uuid"))) if (isSender)
editMessage(messageId); editMessage(messageId);
else
System.out.println("❌ You can only edit your own messages.");
} }
case "5" -> { case "5" -> {
if (senderId.toString().equals(Session.currentUser.getString("internal_uuid"))) if (!isChannel || isOwnerOrAdmin || isSender)
deleteMessage(messageId); deleteMessage(messageId);
else
System.out.println("❌ You are not allowed to delete this message.");
} }
case "0" -> {} case "0" -> {}
default -> System.out.println("❌ Invalid option."); default -> System.out.println("❌ Invalid option.");