Package client

Class Message

java.lang.Object
client.Message

public class Message extends Object
Represents a single message within a chat session. This class acts as a data carrier for message content, which can be either plain text or a reference to an image file, along with associated metadata.
  • Constructor Details

    • Message

      public Message(String text, Instant time, User user, Boolean isImage)
      Constructs a new Message instance.
      Parameters:
      text - The message body or the file path to an image.
      time - The timestamp of the message.
      user - The User who sent the message.
      isImage - True if the text parameter represents an image file; false for plain text.
  • Method Details

    • getText

      public String getText()
      Returns the text content or the image path of the message.
      Returns:
      The message string.
    • getTime

      public Instant getTime()
      Returns the timestamp indicating when the message was sent. * @return An Instant representing the time of dispatch.
    • isImage

      public Boolean isImage()
      Checks if this message represents an image.
      Returns:
      True if the message is an image, false otherwise.
    • getUser

      public User getUser()
      Returns the author of the message.
      Returns:
      The User object of the sender.
    • toString

      public String toString()
      Returns a string representation of the message content.
      Overrides:
      toString in class Object
      Returns:
      The text of the message.