Add type, channel, and receiver fields to chat model and database handling.
This commit is contained in:
parent
7750bf6439
commit
1c2478e8d0
|
|
@ -15,8 +15,9 @@ public class ChatMessage {
|
||||||
@Setter
|
@Setter
|
||||||
private Instant timestamp;
|
private Instant timestamp;
|
||||||
private final String server;
|
private final String server;
|
||||||
//TODO [Stijn] [2026-07-18]: Handle channel types
|
private final ChatMessageType type;
|
||||||
//private final String channel;
|
private final String channel;
|
||||||
|
private final String receiver;
|
||||||
private final String messageJson;
|
private final String messageJson;
|
||||||
private final boolean notBlocked;
|
private final boolean notBlocked;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,26 +17,56 @@ public class ChatMessageMapper {
|
||||||
.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||||
.disable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS);
|
.disable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS);
|
||||||
|
|
||||||
public ChatMessage fromDto(ChatMessageDto dto) {
|
public static ChatMessage fromDto(ChatMessageDto dto) {
|
||||||
return ChatMessage.builder()
|
return ChatMessage.builder()
|
||||||
.uuid(dto.getUuid())
|
.uuid(dto.getUuid())
|
||||||
.timestamp(dto.getTimestamp().toInstant())//TODO [Stijn] [2026-07-18]: Check this works, might be sending instant instead
|
.timestamp(dto.getTimestamp().toInstant())
|
||||||
.server(dto.getServer())
|
.server(dto.getServer())
|
||||||
|
.type(fromDto(dto.getType()))
|
||||||
|
.channel(dto.getChannel())
|
||||||
|
.receiver(dto.getReceiver())
|
||||||
.messageJson(dto.getMessage())
|
.messageJson(dto.getMessage())
|
||||||
.notBlocked(!dto.getBlocked())
|
.notBlocked(!dto.getBlocked())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChatMessage fromDao(ChatLogDao dao) {
|
private static ChatMessageType fromDto(ChatMessageDto.TypeEnum type) {
|
||||||
|
return switch (type) {
|
||||||
|
case PUBLIC -> ChatMessageType.PUBLIC;
|
||||||
|
case GLOBAL -> ChatMessageType.GLOBAL;
|
||||||
|
case PARTY -> ChatMessageType.PARTY;
|
||||||
|
case GAC -> ChatMessageType.GAC;
|
||||||
|
case MSG -> ChatMessageType.MSG;
|
||||||
|
case CUSTOM -> ChatMessageType.CUSTOM;
|
||||||
|
case UNKNOWN_DEFAULT_OPEN_API -> throw new IllegalArgumentException("Unknown chat message type");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ChatMessage fromDao(ChatLogDao dao) {
|
||||||
return ChatMessage.builder()
|
return ChatMessage.builder()
|
||||||
.uuid(UUID.fromString(dao.getUuid()))
|
.uuid(UUID.fromString(dao.getUuid()))
|
||||||
.timestamp(dao.getTimeStamp().toInstant())
|
.timestamp(dao.getTimeStamp().toInstant())
|
||||||
.server(dao.getServer())
|
.server(dao.getServer())
|
||||||
|
.type(fromString(dao.getType()))
|
||||||
|
.channel(dao.getChannel())
|
||||||
|
.receiver(dao.getReceiver())
|
||||||
.messageJson(dao.getMiniMessage())
|
.messageJson(dao.getMiniMessage())
|
||||||
.notBlocked(!dao.isBlocked())
|
.notBlocked(!dao.isBlocked())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ChatMessageType fromString(String type) {
|
||||||
|
return switch (type) {
|
||||||
|
case "public" -> ChatMessageType.PUBLIC;
|
||||||
|
case "global" -> ChatMessageType.GLOBAL;
|
||||||
|
case "party" -> ChatMessageType.PARTY;
|
||||||
|
case "gac" -> ChatMessageType.GAC;
|
||||||
|
case "msg" -> ChatMessageType.MSG;
|
||||||
|
case "custom" -> ChatMessageType.CUSTOM;
|
||||||
|
default -> throw new IllegalArgumentException("Unknown chat message type");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public static String toJson(ChatMessage chatMessage) {
|
public static String toJson(ChatMessage chatMessage) {
|
||||||
try {
|
try {
|
||||||
return OBJECT_MAPPER.writeValueAsString(chatMessage);
|
return OBJECT_MAPPER.writeValueAsString(chatMessage);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.alttd.altitudeweb.controllers.chat;
|
||||||
|
|
||||||
|
public enum ChatMessageType {
|
||||||
|
PUBLIC,
|
||||||
|
GLOBAL,
|
||||||
|
PARTY,
|
||||||
|
GAC,
|
||||||
|
MSG,
|
||||||
|
CUSTOM;
|
||||||
|
}
|
||||||
|
|
@ -12,6 +12,9 @@ public class ChatLogDao {
|
||||||
private final String uuid;
|
private final String uuid;
|
||||||
private final Timestamp timeStamp;
|
private final Timestamp timeStamp;
|
||||||
private final String server;
|
private final String server;
|
||||||
|
private final String type;
|
||||||
|
private final String channel;
|
||||||
|
private final String receiver;
|
||||||
private final String miniMessage;
|
private final String miniMessage;
|
||||||
private final boolean blocked;
|
private final boolean blocked;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import java.util.List;
|
||||||
public interface ChatLogMapper {
|
public interface ChatLogMapper {
|
||||||
|
|
||||||
@Select("""
|
@Select("""
|
||||||
SELECT uuid, time_stamp, server, mini_message, blocked
|
SELECT uuid, time_stamp, server, type, channel, receiver, mini_message, blocked
|
||||||
FROM chat_log
|
FROM chat_log
|
||||||
WHERE mini_message IS NOT NULL
|
WHERE mini_message IS NOT NULL
|
||||||
AND time_stamp >= #{since}
|
AND time_stamp >= #{since}
|
||||||
|
|
|
||||||
|
|
@ -68,25 +68,33 @@ components:
|
||||||
required:
|
required:
|
||||||
- uuid
|
- uuid
|
||||||
- message
|
- message
|
||||||
- channel
|
|
||||||
- server
|
- server
|
||||||
|
- type
|
||||||
- timestamp
|
- timestamp
|
||||||
- blocked
|
- blocked
|
||||||
properties:
|
properties:
|
||||||
uuid:
|
uuid:
|
||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
channel:
|
|
||||||
type: string
|
|
||||||
enum:
|
|
||||||
- CHAT
|
|
||||||
- PARTY
|
|
||||||
- AC
|
|
||||||
- GAC
|
|
||||||
message:
|
message:
|
||||||
type: string
|
type: string
|
||||||
server:
|
server:
|
||||||
type: string
|
type: string
|
||||||
|
type:
|
||||||
|
type: string
|
||||||
|
enum:
|
||||||
|
- PUBLIC
|
||||||
|
- GLOBAL
|
||||||
|
- PARTY
|
||||||
|
- GAC
|
||||||
|
- MSG
|
||||||
|
- CUSTOM
|
||||||
|
channel:
|
||||||
|
type: string
|
||||||
|
maxLength: 36
|
||||||
|
receiver:
|
||||||
|
type: string
|
||||||
|
maxLength: 36
|
||||||
timestamp:
|
timestamp:
|
||||||
type: string
|
type: string
|
||||||
format: date-time
|
format: date-time
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user