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