work on archived chats
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package org.to.telegramfinalproject.Database;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ArchivedChatDatabase {
|
||||
public static boolean archiveChat(UUID userId, UUID chatId, String chatType) {
|
||||
String sql = "INSERT INTO archived_chats (user_id, chat_id, chat_type) VALUES (?, ?, ?) ON CONFLICT DO NOTHING";
|
||||
try (Connection conn = ConnectionDb.connect();
|
||||
PreparedStatement ps = conn.prepareStatement(sql)) {
|
||||
ps.setObject(1, userId);
|
||||
ps.setObject(2, chatId);
|
||||
ps.setString(3, chatType);
|
||||
return ps.executeUpdate() > 0;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static boolean unarchiveChat(UUID userId, UUID chatId) {
|
||||
String sql = "DELETE FROM archived_chats WHERE user_id = ? AND chat_id = ?";
|
||||
try (Connection conn = ConnectionDb.connect();
|
||||
PreparedStatement ps = conn.prepareStatement(sql)) {
|
||||
ps.setObject(1, userId);
|
||||
ps.setObject(2, chatId);
|
||||
return ps.executeUpdate() > 0;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isChatArchived(UUID userId, UUID chatId) {
|
||||
String sql = "SELECT 1 FROM archived_chats WHERE user_id = ? AND chat_id = ?";
|
||||
try (Connection conn = ConnectionDb.connect();
|
||||
PreparedStatement ps = conn.prepareStatement(sql)) {
|
||||
ps.setObject(1, userId);
|
||||
ps.setObject(2, chatId);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
return rs.next();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<UUID> getArchivedChats(UUID userId) {
|
||||
List<UUID> list = new ArrayList<>();
|
||||
String sql = "SELECT chat_id FROM archived_chats WHERE user_id = ?";
|
||||
try (Connection conn = ConnectionDb.connect();
|
||||
PreparedStatement ps = conn.prepareStatement(sql)) {
|
||||
ps.setObject(1, userId);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
list.add(UUID.fromString(rs.getString("chat_id")));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import java.sql.SQLException;
|
||||
public class ConnectionDb {
|
||||
private static final String JDBC_URL = "jdbc:postgresql://localhost:5432/Telegram";
|
||||
private static final String USERNAME = "postgres";
|
||||
private static final String PASSWORD = "124postpass";
|
||||
private static final String PASSWORD = "Partow@1384";
|
||||
|
||||
public ConnectionDb() {
|
||||
}
|
||||
|
||||
@@ -444,7 +444,7 @@ public class GroupDatabase {
|
||||
stmt.setObject(2, userId);
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
return rs.next(); // اگر رکوردی پیدا شد یعنی owner است
|
||||
return rs.next();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -460,7 +460,7 @@ public class GroupDatabase {
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
if (rs.next()) {
|
||||
String role = rs.getString("role");
|
||||
return "admin".equals(role) || "owner".equals(role); // owner هم admin هست
|
||||
return "admin".equals(role) || "owner".equals(role);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
@@ -508,7 +508,7 @@ public class GroupDatabase {
|
||||
while (rs.next()) {
|
||||
JSONObject member = new JSONObject();
|
||||
member.put("profile_name", rs.getString("profile_name"));
|
||||
member.put("user_id", rs.getString("user_id")); // آیدی قابل نمایش
|
||||
member.put("user_id", rs.getString("user_id"));
|
||||
member.put("internal_uuid", rs.getObject("internal_uuid").toString());
|
||||
member.put("role", rs.getString("role"));
|
||||
|
||||
|
||||
@@ -264,6 +264,8 @@ public class userDatabase {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public List<User> searchUsers(String keyword, UUID currentUserId) {
|
||||
String query = """
|
||||
SELECT * FROM users
|
||||
|
||||
Reference in New Issue
Block a user