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
|
||||
private Instant timestamp;
|
||||
private final String server;
|
||||
//TODO [Stijn] [2026-07-18]: Handle channel types
|
||||
//private final String channel;
|
||||
private final ChatMessageType type;
|
||||
private final String channel;
|
||||
private final String receiver;
|
||||
private final String messageJson;
|
||||
private final boolean notBlocked;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,26 +17,56 @@ public class ChatMessageMapper {
|
|||
.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||
.disable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS);
|
||||
|
||||
public ChatMessage fromDto(ChatMessageDto dto) {
|
||||
public static ChatMessage fromDto(ChatMessageDto dto) {
|
||||
return ChatMessage.builder()
|
||||
.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())
|
||||
.type(fromDto(dto.getType()))
|
||||
.channel(dto.getChannel())
|
||||
.receiver(dto.getReceiver())
|
||||
.messageJson(dto.getMessage())
|
||||
.notBlocked(!dto.getBlocked())
|
||||
.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()
|
||||
.uuid(UUID.fromString(dao.getUuid()))
|
||||
.timestamp(dao.getTimeStamp().toInstant())
|
||||
.server(dao.getServer())
|
||||
.type(fromString(dao.getType()))
|
||||
.channel(dao.getChannel())
|
||||
.receiver(dao.getReceiver())
|
||||
.messageJson(dao.getMiniMessage())
|
||||
.notBlocked(!dao.isBlocked())
|
||||
.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) {
|
||||
try {
|
||||
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 Timestamp timeStamp;
|
||||
private final String server;
|
||||
private final String type;
|
||||
private final String channel;
|
||||
private final String receiver;
|
||||
private final String miniMessage;
|
||||
private final boolean blocked;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import java.util.List;
|
|||
public interface ChatLogMapper {
|
||||
|
||||
@Select("""
|
||||
SELECT uuid, time_stamp, server, mini_message, blocked
|
||||
SELECT uuid, time_stamp, server, type, channel, receiver, mini_message, blocked
|
||||
FROM chat_log
|
||||
WHERE mini_message IS NOT NULL
|
||||
AND time_stamp >= #{since}
|
||||
|
|
|
|||
|
|
@ -68,25 +68,33 @@ components:
|
|||
required:
|
||||
- uuid
|
||||
- message
|
||||
- channel
|
||||
- server
|
||||
- type
|
||||
- timestamp
|
||||
- blocked
|
||||
properties:
|
||||
uuid:
|
||||
type: string
|
||||
format: uuid
|
||||
channel:
|
||||
type: string
|
||||
enum:
|
||||
- CHAT
|
||||
- PARTY
|
||||
- AC
|
||||
- GAC
|
||||
message:
|
||||
type: string
|
||||
server:
|
||||
type: string
|
||||
type:
|
||||
type: string
|
||||
enum:
|
||||
- PUBLIC
|
||||
- GLOBAL
|
||||
- PARTY
|
||||
- GAC
|
||||
- MSG
|
||||
- CUSTOM
|
||||
channel:
|
||||
type: string
|
||||
maxLength: 36
|
||||
receiver:
|
||||
type: string
|
||||
maxLength: 36
|
||||
timestamp:
|
||||
type: string
|
||||
format: date-time
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user