Delete chat (one/both side)
This commit is contained in:
@@ -1191,11 +1191,11 @@ public class ActionHandler {
|
||||
case "2" -> toggleBlock(chat.getOtherUserId());
|
||||
case "3" -> {
|
||||
deleteChat(chat.getId(), false);
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
case "4" -> {
|
||||
deleteChat(chat.getId(), true);
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
case "5" -> {
|
||||
JSONObject reqProfile = new JSONObject();
|
||||
|
||||
@@ -66,7 +66,7 @@ public class MessageDatabase {
|
||||
}
|
||||
|
||||
public static void markGloballyDeleted(UUID chatId) {
|
||||
String sql = "UPDATE messages SET deleted_globally = true WHERE receiver_id = ? AND receiver_type = 'private'";
|
||||
String sql = "UPDATE messages SET is_deleted_globally = true WHERE receiver_id = ? AND receiver_type = 'private'";
|
||||
try (Connection conn = ConnectionDb.connect(); PreparedStatement ps = conn.prepareStatement(sql)) {
|
||||
ps.setObject(1, chatId);
|
||||
ps.executeUpdate();
|
||||
|
||||
@@ -231,22 +231,20 @@ public class PrivateChatDatabase {
|
||||
}
|
||||
|
||||
|
||||
public static void clearDeletedFlag(UUID senderId, UUID receiverId) {
|
||||
public static void clearDeletedFlag(UUID senderId, UUID chatId) {
|
||||
String sql = """
|
||||
UPDATE private_chat
|
||||
SET user1_deleted = CASE WHEN user1_id = ? THEN false ELSE user1_deleted END,
|
||||
user2_deleted = CASE WHEN user2_id = ? THEN false ELSE user2_deleted END
|
||||
WHERE (user1_id = ? AND user2_id = ?) OR (user1_id = ? AND user2_id = ?)
|
||||
""";
|
||||
SET user1_deleted = CASE WHEN user1_id = ? THEN FALSE ELSE user1_deleted END,
|
||||
user2_deleted = CASE WHEN user2_id = ? THEN FALSE ELSE user2_deleted END
|
||||
WHERE chat_id = ?
|
||||
""";
|
||||
|
||||
try (Connection conn = ConnectionDb.connect(); PreparedStatement ps = conn.prepareStatement(sql)) {
|
||||
ps.setObject(1, senderId);
|
||||
ps.setObject(2, senderId);
|
||||
ps.setObject(3, senderId);
|
||||
ps.setObject(4, receiverId);
|
||||
ps.setObject(5, receiverId);
|
||||
ps.setObject(6, senderId);
|
||||
ps.executeUpdate();
|
||||
ps.setObject(3, chatId);
|
||||
int rows = ps.executeUpdate();
|
||||
System.out.println("✅ clearDeletedFlag updated rows = " + rows);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -255,4 +253,5 @@ public class PrivateChatDatabase {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2181,8 +2181,7 @@ public class ClientHandler implements Runnable {
|
||||
return new ResponseModel("error", "Unauthorized");
|
||||
|
||||
UUID chatId = UUID.fromString(json.getString("chat_id"));
|
||||
boolean bothSides = json.optBoolean("both_sides", false);
|
||||
|
||||
boolean bothSides = json.optBoolean("both_sides", json.optBoolean("both", false));
|
||||
PrivateChat chat = PrivateChatDatabase.findById(chatId);
|
||||
if (chat == null) return new ResponseModel("error", "Chat not found.");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user