Integrate ChatLogHandler across chat modules and add centralized message logging with validation through ChatLogMapper.
This commit is contained in:
@@ -16,11 +16,14 @@ public class ChatLogQueries {
|
||||
|
||||
protected static void createChatLogTable() {
|
||||
String nicknamesTableQuery = """
|
||||
CREATE TABLE chat_log (
|
||||
CREATE TABLE IF NOT EXISTSq:Q chat_log (
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
uuid CHAR(36) NOT NULL,
|
||||
time_stamp TIMESTAMP(6) NOT NULL,
|
||||
server VARCHAR(50) NOT NULL,
|
||||
type VARCHAR(16) NOT NULL DEFAULT 'public',
|
||||
channel VARCHAR(36) DEFAULT NULL,
|
||||
receiver CHAR(36) DEFAULT NULL,
|
||||
chat_message VARCHAR(300) NOT NULL,
|
||||
mini_message JSON,
|
||||
blocked BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
@@ -38,7 +41,7 @@ public class ChatLogQueries {
|
||||
}
|
||||
|
||||
public static @NotNull CompletableFuture<Boolean> storeMessages(HashMap<UUID, List<ChatLog>> chatMessages) {
|
||||
String insertQuery = "INSERT INTO chat_log (uuid, time_stamp, server, chat_message, mini_message, blocked) VALUES (?, ?, ?, ?, ?, ?)";
|
||||
String insertQuery = "INSERT INTO chat_log (uuid, time_stamp, server, type, channel, receiver, chat_message, mini_message, blocked) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try (Connection connection = DatabaseConnection.createTransactionConnection()) {
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(insertQuery);
|
||||
@@ -67,7 +70,7 @@ public class ChatLogQueries {
|
||||
}
|
||||
|
||||
public static @NotNull CompletableFuture<List<ChatLog>> retrieveMessages(ChatLogHandler chatLogHandler, UUID uuid, Duration duration, String server) {
|
||||
String query = "SELECT * FROM chat_log WHERE uuid = ? AND time_stamp > ? AND server = ?";
|
||||
String query = "SELECT * FROM chat_log WHERE uuid = ? AND time_stamp > ? AND server = ? AND type = 'public'";
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try (Connection connection = DatabaseConnection.getConnection()) {
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(query);
|
||||
@@ -77,8 +80,7 @@ public class ChatLogQueries {
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
List<ChatLog> chatLogs = new ArrayList<>();
|
||||
while (resultSet.next()) {
|
||||
ChatLog chatLog = chatLogHandler.loadFromResultSet(resultSet);
|
||||
chatLogs.add(chatLog);
|
||||
chatLogHandler.loadFromResultSet(resultSet).ifPresent(chatLogs::add);
|
||||
}
|
||||
return chatLogs;
|
||||
} catch (SQLException sqlException) {
|
||||
|
||||
Reference in New Issue
Block a user