java.lang.Object
it.polimi.ingsw.am13.client.chat.Chat

public class Chat extends Object
This class stores all the chat messages that meet the following requirements: -they have thisPlayer as a sender or as one of the receivers -the number of receivers is either one, or number of players-1 (all the players aside from the sender)
  • Field Details

    • chat

      private final Map<List<PlayerLobby>,List<ChatMessage>> chat
      This is the map that stores the chat messages, associating to every valid list of PlayerLobby a list of ChatMessage
    • thisPlayer

      private final PlayerLobby thisPlayer
      The player who is associated (owns) to a specific instance of this class
    • otherPlayers

      private final List<PlayerLobby> otherPlayers
      All the other players who are in the same match as thisPlayer
  • Constructor Details

    • Chat

      public Chat(List<PlayerLobby> players, PlayerLobby thisPlayer)
      This constructor sets the value of thisPlayer and otherPlayers, and initializes the chat by associating an empty list to each valid list of PlayerLobby
      Parameters:
      players - all the players of the match thisPlayer is in
      thisPlayer - the player who is associated to a specific instance of this class
  • Method Details

    • addMessage

      public void addMessage(List<PlayerLobby> receivers, ChatMessage chatMessage)
      Adds the chatMessage to the appropriate entry of the chat. This means that if the sender is thisPlayer the message is added to the chat with the receivers; while if thisPlayer is one of the receivers the message is added to the chat with sender, or the chat between all the players if the receivers are all the players who are not the sender. This method assumes that the parameters respect the required format, relying on the checks performed on the server (InvalidReceiversException). It does not check in a complete manner that the parameters are correct.
      Parameters:
      receivers - of the message
      chatMessage - that needs to be added to the chat
    • getChatWith

      public List<ChatMessage> getChatWith(List<PlayerLobby> receivers)
      Parameters:
      receivers - Receivers indicating the specific chatroom whose messages are to be retrieved
      Returns:
      The list of messages of the chatroom with the specified receivers, or null if no chat with those receivers is present