Module whatsapp4j

Class Chat

java.lang.Object
it.auties.whatsapp4j.protobuf.chat.Chat

public class Chat extends Object
A model class that represents a Chat. A chat can be of two types: a conversation with a contact or a group. To check if this chat is a group use isGroup() or WhatsappUtils.isGroup(String). This class is only a model, this means that changing its values will have no real effect on WhatsappWeb's servers. Instead, methods inside WhatsappAPI should be used. This class also offers a builder, accessible using builder().
  • Constructor Details

    • Chat

      public Chat(@NonNull @NonNull String jid, @NonNull @NonNull String displayName, @NonNull @NonNull Messages messages, @NonNull @NonNull Map<Contact,ContactStatus> presences, @NonNull @NonNull ChatMute mute, String newJid, long timestamp, int unreadMessages, long pinned, long ephemeralMessageDuration, long ephemeralMessagesToggleTime, boolean isArchived, boolean isReadOnly, boolean isSpam)
    • Chat

      public Chat()
  • Method Details

    • fromAttributes

      @NonNull public static @NonNull Chat fromAttributes(@NonNull @NonNull Map<String,String> attrs)
      Constructs a new Chat from a map of attributes. This method is usually used to deserialize a Chat from the attributes of a Node.
      Returns:
      a new instance of Chat
    • isGroup

      public boolean isGroup()
      Returns a boolean to represent whether this chat is a group or not
      Returns:
      true if this chat is a group
    • isPinned

      public boolean isPinned()
      Returns a boolean to represent whether this chat is pinned or not
      Returns:
      true if this chat is pinned
    • isEphemeral

      public boolean isEphemeral()
      Returns a boolean to represent whether ephemeral messages are enabled for this chat
      Returns:
      true if ephemeral messages are enabled for this chat
    • hasNewJid

      public boolean hasNewJid()
      Returns a boolean to represent whether this chat has a new jid
      Returns:
      true if this chat has a new jid
    • hasUnreadMessages

      public boolean hasUnreadMessages()
      Returns a boolean to represent whether this chat has unread messages
      Returns:
      true if this chat has unread messages
    • isMarkedRead

      public boolean isMarkedRead()
      Returns a boolean to represent whether this chat is marked as read
      Returns:
      true if this chat is marked as read
    • isManuallyMarkedUnread

      public boolean isManuallyMarkedUnread()
      Returns a boolean to represent whether this chat was manually marked as unread
      Returns:
      true if this chat is marked as unread
    • newJid

      @NonNull public @NonNull Optional<String> newJid()
      Returns an optional value containing the new jid of this chat
      Returns:
      a non empty optional if the new jid is not null, otherwise an empty optional
    • pinned

      @NonNull public @NonNull Optional<ZonedDateTime> pinned()
      Returns an optional value containing the time this chat was pinned
      Returns:
      a non empty optional if the chat is pinned, otherwise an empty optional
    • ephemeralMessageDuration

      @NonNull public @NonNull Optional<ZonedDateTime> ephemeralMessageDuration()
      Returns an optional value containing the time in seconds before a message is automatically deleted from this chat both locally and from WhatsappWeb's servers
      Returns:
      a non empty optional if ephemeral messages are enabled for this chat, otherwise an empty optional
    • ephemeralMessagesToggleTime

      @NonNull public @NonNull Optional<ZonedDateTime> ephemeralMessagesToggleTime()
      Returns an optional value containing the time in seconds since Instant.EPOCH when ephemeral messages were turned on
      Returns:
      a non empty optional if ephemeral messages are enabled for this chat, otherwise an empty optional
    • lastMessage

      @NonNull public @NonNull Optional<MessageInfo> lastMessage()
      Returns an optional value containing the latest message in chronological terms for this chat
      Returns:
      a non empty optional if messages isn't empty, otherwise an empty optional
    • firstMessage

      @NonNull public @NonNull Optional<MessageInfo> firstMessage()
      Returns an optional value containing the first message in chronological terms for this chat
      Returns:
      a non empty optional if messages isn't empty, otherwise an empty optional
    • builder

      public static Chat.ChatBuilder builder()
    • jid

      @NonNull public @NonNull String jid()
      The non null unique jid used to identify this chat
    • displayName

      @NonNull public @NonNull String displayName()
      The non null display name of this chat
    • messages

      @NonNull public @NonNull Messages messages()
      A non null arrayList of messages in this chat sorted chronologically
    • presences

      @NonNull public @NonNull Map<Contact,ContactStatus> presences()
      A map that holds the status of each participant, excluding yourself, for this chat. If the chat is not a group, this map's size will range from 0 to 1. Otherwise, it will range from 0 to the number of participants - 1. It is important to remember that is not guaranteed that every participant will be present as a key. In this case, if this chat is a group, it can be safely assumed that the user is not available. Otherwise, it's recommended to use WhatsappAPI.subscribeToContactPresence(Contact) to force Whatsapp to send updates regarding the status of the other participant. It's also possible to listen for updates to a contact's presence in a group or in a conversation by implementing WhatsappListener.onContactPresenceUpdate(it.auties.whatsapp4j.protobuf.chat.Chat, it.auties.whatsapp4j.protobuf.contact.Contact). The presence that this map indicates might not line up with Contact.lastKnownPresence() if the contact is composing, recording or paused. This is because a contact can be online on Whatsapp and composing, recording or paused in a specific chat.
    • mute

      @NonNull public @NonNull ChatMute mute()
      The non null mute of this chat
    • timestamp

      public long timestamp()
      The time in seconds since Instant.EPOCH for the latest message in messages
    • unreadMessages

      public int unreadMessages()
      The number of unread messages in this chat. If this field is negative, this chat is marked as unread.
    • isArchived

      public boolean isArchived()
      This field is used to determine whether a chat is archived or not.
    • isReadOnly

      public boolean isReadOnly()
      This field is used to determine whether a chat is read only or not. If true, it means that it's not possible to send messages here. This is the case, for example, for groups where only admins can send messages.
    • isSpam

      public boolean isSpam()
      This field is used to determine whether a chat was marked as being spam or not.
    • jid

      public Chat jid(@NonNull @NonNull String jid)
      The non null unique jid used to identify this chat
      Returns:
      this.
    • displayName

      public Chat displayName(@NonNull @NonNull String displayName)
      The non null display name of this chat
      Returns:
      this.
    • messages

      public Chat messages(@NonNull @NonNull Messages messages)
      A non null arrayList of messages in this chat sorted chronologically
      Returns:
      this.
    • presences

      public Chat presences(@NonNull @NonNull Map<Contact,ContactStatus> presences)
      A map that holds the status of each participant, excluding yourself, for this chat. If the chat is not a group, this map's size will range from 0 to 1. Otherwise, it will range from 0 to the number of participants - 1. It is important to remember that is not guaranteed that every participant will be present as a key. In this case, if this chat is a group, it can be safely assumed that the user is not available. Otherwise, it's recommended to use WhatsappAPI.subscribeToContactPresence(Contact) to force Whatsapp to send updates regarding the status of the other participant. It's also possible to listen for updates to a contact's presence in a group or in a conversation by implementing WhatsappListener.onContactPresenceUpdate(it.auties.whatsapp4j.protobuf.chat.Chat, it.auties.whatsapp4j.protobuf.contact.Contact). The presence that this map indicates might not line up with Contact.lastKnownPresence() if the contact is composing, recording or paused. This is because a contact can be online on Whatsapp and composing, recording or paused in a specific chat.
      Returns:
      this.
    • mute

      public Chat mute(@NonNull @NonNull ChatMute mute)
      The non null mute of this chat
      Returns:
      this.
    • newJid

      public Chat newJid(String newJid)
      The nullable new unique jid for this Chat. This field is not null when a contact changes phone number and connects their new phone number with Whatsapp.
      Returns:
      this.
    • timestamp

      public Chat timestamp(long timestamp)
      The time in seconds since Instant.EPOCH for the latest message in messages
      Returns:
      this.
    • unreadMessages

      public Chat unreadMessages(int unreadMessages)
      The number of unread messages in this chat. If this field is negative, this chat is marked as unread.
      Returns:
      this.
    • pinned

      public Chat pinned(long pinned)
      The time in seconds since Instant.EPOCH when this chat was pinned to the top. If the chat isn't pinned, this field has a value of 0.
      Returns:
      this.
    • ephemeralMessageDuration

      public Chat ephemeralMessageDuration(long ephemeralMessageDuration)
      The time in seconds before a message is automatically deleted from this chat both locally and from WhatsappWeb's servers. If ephemeral messages aren't enabled, this field has a value of 0
      Returns:
      this.
    • ephemeralMessagesToggleTime

      public Chat ephemeralMessagesToggleTime(long ephemeralMessagesToggleTime)
      The time in seconds since Instant.EPOCH when ephemeral messages were turned on. If ephemeral messages aren't enabled, this field has a value of 0.
      Returns:
      this.
    • isArchived

      public Chat isArchived(boolean isArchived)
      This field is used to determine whether a chat is archived or not.
      Returns:
      this.
    • isReadOnly

      public Chat isReadOnly(boolean isReadOnly)
      This field is used to determine whether a chat is read only or not. If true, it means that it's not possible to send messages here. This is the case, for example, for groups where only admins can send messages.
      Returns:
      this.
    • isSpam

      public Chat isSpam(boolean isSpam)
      This field is used to determine whether a chat was marked as being spam or not.
      Returns:
      this.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object