Class ChatService

java.lang.Object
vaultWeb.services.ChatService

@Service public class ChatService extends Object
Service responsible for handling chat-related operations.

This service provides methods to save chat messages for both group chats and private chats. Messages are stored as end-to-end encrypted payloads for both chat types. The service supports identifying the sender either by ID or username and can handle automatic timestamping if none is provided.

Main responsibilities:

  • Validate sender existence by ID or username.
  • Associate messages with a group or private chat.
  • Persist chat messages into the database.
  • Constructor Details

    • ChatService

      public ChatService()
  • Method Details

    • saveMessage

      public ChatMessage saveMessage(ChatMessageDto dto)
      Saves a chat message to a group or private chat.

      The sender is identified either by ID or username. If a timestamp is not provided, the current time is used. The message must belong to either a group or a private chat. All chat messages must provide an end-to-end encrypted payload.

      Parameters:
      dto - DTO containing the message content, sender information, timestamp, and either a groupId or privateChatId.
      Returns:
      The persisted ChatMessage entity with an end-to-end payload.
      Throws:
      UserNotFoundException - if the sender cannot be found by ID or username.
      GroupNotFoundException - if neither groupId nor privateChatId is provided, or if the specified group/private chat does not exist.
      IllegalArgumentException - if encrypted payload metadata is missing.