Class Chat

java.lang.Object
it.auties.whatsapp.model.chat.Chat
All Implemented Interfaces:
it.auties.protobuf.model.ProtobufMessage, it.auties.protobuf.model.ProtobufObject, JidProvider

public final class Chat extends Object implements it.auties.protobuf.model.ProtobufMessage, JidProvider
A model class that represents a Chat. A chat can be of two types: a conversation with a contact or a group. This class is only a model, this means that changing its values will have no real effect on WhatsappWeb's servers
  • Field Details

    • jid

      final Jid jid
    • historySyncMessages

    • newJid

      final Jid newJid
    • oldJid

      final Jid oldJid
    • unreadMessagesCount

      int unreadMessagesCount
    • readOnly

      boolean readOnly
    • endOfHistoryTransfer

      boolean endOfHistoryTransfer
    • ephemeralMessageDuration

      ChatEphemeralTimer ephemeralMessageDuration
    • ephemeralMessagesToggleTimeSeconds

      long ephemeralMessagesToggleTimeSeconds
    • endOfHistoryTransferType

      Chat.EndOfHistoryTransferType endOfHistoryTransferType
    • timestampSeconds

      long timestampSeconds
    • name

      String name
    • notSpam

      boolean notSpam
    • archived

      boolean archived
    • disappearInitiator

      ChatDisappear disappearInitiator
    • markedAsUnread

      boolean markedAsUnread
    • participants

      final List<GroupParticipant> participants
    • token

      byte[] token
    • tokenTimestampSeconds

      long tokenTimestampSeconds
    • identityKey

      byte[] identityKey
    • pinnedTimestampSeconds

      int pinnedTimestampSeconds
    • mute

      ChatMute mute
    • wallpaper

      ChatWallpaper wallpaper
    • mediaVisibility

      MediaVisibility mediaVisibility
    • tokenSenderTimestampSeconds

      long tokenSenderTimestampSeconds
    • suspended

      boolean suspended
    • terminated

      boolean terminated
    • foundationTimestampSeconds

      long foundationTimestampSeconds
    • founder

      Jid founder
    • description

      String description
    • support

      boolean support
    • parentGroup

      boolean parentGroup
    • defaultSubGroup

      boolean defaultSubGroup
    • parentGroupJid

      final Jid parentGroupJid
    • displayName

      String displayName
    • phoneJid

      Jid phoneJid
    • shareOwnPhoneNumber

      boolean shareOwnPhoneNumber
    • pnhDuplicateLidThread

      boolean pnhDuplicateLidThread
    • lidJid

      Jid lidJid
    • presences

    • participantsPreKeys

      final Set<Jid> participantsPreKeys
    • pastParticipants

      final Set<GroupPastParticipant> pastParticipants
    • update

      private boolean update
  • Constructor Details

  • Method Details

    • name

      public String name()
      Returns the name of this chat
      Returns:
      a non-null string
    • 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
    • unreadMessages

      public Collection<ChatMessageInfo> unreadMessages()
      Returns all the unread messages in this chat
      Returns:
      a non-null collection
    • hasUnreadMessages

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

      public Optional<ZonedDateTime> pinnedTimestamp()
      Returns an optional value containing the seconds this chat was pinned
      Returns:
      an optional
    • timestamp

      public Optional<ZonedDateTime> timestamp()
      Returns the timestampSeconds for the creation of this chat in seconds since Instant.EPOCH
      Returns:
      an optional
    • ephemeralMessagesToggleTime

      public Optional<ZonedDateTime> ephemeralMessagesToggleTime()
      Returns an optional value containing the seconds in seconds since Instant.EPOCH when ephemeral messages were turned on
      Returns:
      an optional
    • newestMessage

      public Optional<ChatMessageInfo> newestMessage()
      Returns an optional value containing the latest message in chronological terms for this chat
      Returns:
      an optional
    • oldestMessage

      public Optional<ChatMessageInfo> oldestMessage()
      Returns an optional value containing the first message in chronological terms for this chat
      Returns:
      an optional
    • newestStandardMessage

      public Optional<ChatMessageInfo> newestStandardMessage()
      Returns an optional value containing the latest message in chronological terms for this chat with type that isn't server
      Returns:
      an optional
    • oldestStandardMessage

      public Optional<ChatMessageInfo> oldestStandardMessage()
      Returns an optional value containing the first message in chronological terms for this chat with type that isn't server
      Returns:
      an optional
    • isStandardMessage

      private boolean isStandardMessage(ChatMessageInfo info)
    • newestMessageFromMe

      public Optional<ChatMessageInfo> newestMessageFromMe()
      Returns an optional value containing the latest message in chronological terms for this chat sent from you
      Returns:
      an optional
    • oldestMessageFromMe

      public Optional<ChatMessageInfo> oldestMessageFromMe()
      Returns an optional value containing the first message in chronological terms for this chat sent from you
      Returns:
      an optional
    • isMessageFromMe

      private boolean isMessageFromMe(ChatMessageInfo info)
    • newestServerMessage

      public Optional<ChatMessageInfo> newestServerMessage()
      Returns an optional value containing the latest message in chronological terms for this chat with type server
      Returns:
      an optional
    • oldestServerMessage

      public Optional<ChatMessageInfo> oldestServerMessage()
      Returns an optional value containing the first message in chronological terms for this chat with type server
      Returns:
      an optional
    • isServerMessage

      private boolean isServerMessage(ChatMessageInfo info)
    • findMessageBy

      private Optional<ChatMessageInfo> findMessageBy(Function<ChatMessageInfo,Boolean> filter, boolean newest)
    • starredMessages

      public Collection<ChatMessageInfo> starredMessages()
      Returns all the starred messages in this chat
      Returns:
      a non-null list of messages
    • tokenTimestamp

      public Optional<ZonedDateTime> tokenTimestamp()
      Returns the timestampSeconds for the creation of this chat's token
      Returns:
      an optional
    • tokenSenderTimestamp

      public Optional<ZonedDateTime> tokenSenderTimestamp()
      Returns the timestampSeconds for the token sender creation of this chat
      Returns:
      an optional
    • foundationTimestamp

      public Optional<ZonedDateTime> foundationTimestamp()
      Returns the timestampSeconds for the creation of this chat if it's a group
      Returns:
      an optional
    • addMessages

      public void addMessages(Collection<HistorySyncMessage> newMessages)
      Adds a new unspecified amount of messages to this chat and sorts them accordingly
      Parameters:
      newMessages - the non-null messages to add
    • addOldMessages

      public void addOldMessages(Collection<HistorySyncMessage> oldMessages)
      Adds a new unspecified amount of messages to this chat and sorts them accordingly
      Parameters:
      oldMessages - the non-null messages to add
    • addNewMessage

      public boolean addNewMessage(ChatMessageInfo info)
      Adds a message to the chat in the most recent slot available
      Parameters:
      info - the message to add to the chat
      Returns:
      whether the message was added
    • addOldMessage

      public boolean addOldMessage(HistorySyncMessage info)
      Adds a message to the chat in the oldest slot available
      Parameters:
      info - the message to add to the chat
      Returns:
      whether the message was added
    • removeMessage

      public boolean removeMessage(ChatMessageInfo info)
      Remove a message from the chat
      Parameters:
      info - the message to remove
      Returns:
      whether the message was removed
    • removeMessage

      public boolean removeMessage(Predicate<? super ChatMessageInfo> predicate)
      Remove a message from the chat
      Parameters:
      predicate - the predicate that determines if a message should be removed
      Returns:
      whether the message was removed
    • refreshChatTimestamp

      private void refreshChatTimestamp()
    • updateChatTimestamp

      private void updateChatTimestamp(ChatMessageInfo info)
    • removeMessages

      public void removeMessages()
      Removes all messages from the chat
    • messages

      public Collection<HistorySyncMessage> messages()
      Returns an immutable list of messages wrapped in history syncs This is useful for the proto
      Returns:
      a non-null collection
    • addParticipants

      public void addParticipants(Collection<GroupParticipant> participants)
      Adds a collection of participants to this chat
      Parameters:
      participants - the participants to add
    • addParticipant

      public boolean addParticipant(Jid jid, GroupRole role)
      Adds a participant to this chat
      Parameters:
      jid - the non-null jid of the participant
      role - the role of the participant
      Returns:
      whether the participant was added
    • addParticipant

      public boolean addParticipant(GroupParticipant participant)
      Adds a participant to this chat
      Parameters:
      participant - the non-null participant
      Returns:
      whether the participant was added
    • removeParticipant

      public boolean removeParticipant(Jid jid)
      Removes a participant from this chat
      Parameters:
      jid - the non-null jid of the participant
      Returns:
      whether the participant was removed
    • findParticipant

      public Optional<GroupParticipant> findParticipant(Jid jid)
      Finds a participant by jid This method only works if Whatsapp.queryGroupMetadata(JidProvider) has been called before on this chat. By default, all groups that have been used in the last two weeks wil be synced automatically
      Parameters:
      jid - the non-null jid of the participant
      Returns:
      the participant, if present
    • addPastParticipant

      public boolean addPastParticipant(GroupPastParticipant participant)
      Adds a past participant
      Parameters:
      participant - the non-null jid of the past participant
      Returns:
      whether the participant was added
    • addPastParticipants

      public boolean addPastParticipants(List<GroupPastParticipant> pastParticipants)
      Adds a collection of past participants
      Parameters:
      pastParticipants - the non-null list of past participants
      Returns:
      whether the participant were added
    • removePastParticipant

      public boolean removePastParticipant(Jid jid)
      Removes a past participant
      Parameters:
      jid - the non-null jid of the past participant
      Returns:
      whether the participant was removed
    • findPastParticipant

      public Optional<GroupPastParticipant> findPastParticipant(Jid jid)
      Finds a past participant by jid
      Parameters:
      jid - the non-null jid of the past participant
      Returns:
      the past participant, if present
    • participantsPreKeys

      public Set<Jid> participantsPreKeys()
    • addParticipantsPreKeys

      public void addParticipantsPreKeys(Collection<Jid> jids)
    • clearParticipantsPreKeys

      public void clearParticipantsPreKeys()
    • equals

      public boolean equals(Object other)
      Checks if this chat is equal to another chat
      Overrides:
      equals in class Object
      Parameters:
      other - the chat
      Returns:
      a boolean
    • toJid

      public Jid toJid()
      Returns this object as a jid
      Specified by:
      toJid in interface JidProvider
      Returns:
      a non-null jid
    • hashCode

      public int hashCode()
      Returns the hash code for this chat
      Overrides:
      hashCode in class Object
      Returns:
      an int
    • jid

      public Jid jid()
    • historySyncMessages

      public Collection<HistorySyncMessage> historySyncMessages()
    • newJid

      public Optional<Jid> newJid()
    • oldJid

      public Optional<Jid> oldJid()
    • unreadMessagesCount

      public int unreadMessagesCount()
    • readOnly

      public boolean readOnly()
    • endOfHistoryTransfer

      public boolean endOfHistoryTransfer()
    • ephemeralMessageDuration

      public ChatEphemeralTimer ephemeralMessageDuration()
    • ephemeralMessagesToggleTimeSeconds

      public long ephemeralMessagesToggleTimeSeconds()
    • endOfHistoryTransferType

      public Optional<Chat.EndOfHistoryTransferType> endOfHistoryTransferType()
    • timestampSeconds

      public long timestampSeconds()
    • notSpam

      public boolean notSpam()
    • archived

      public boolean archived()
    • disappearInitiator

      public Optional<ChatDisappear> disappearInitiator()
    • markedAsUnread

      public boolean markedAsUnread()
    • participants

      public List<GroupParticipant> participants()
    • token

      public Optional<byte[]> token()
    • tokenTimestampSeconds

      public long tokenTimestampSeconds()
    • identityKey

      public Optional<byte[]> identityKey()
    • pinnedTimestampSeconds

      public int pinnedTimestampSeconds()
    • mute

      public ChatMute mute()
    • wallpaper

      public Optional<ChatWallpaper> wallpaper()
    • mediaVisibility

      public MediaVisibility mediaVisibility()
    • tokenSenderTimestampSeconds

      public long tokenSenderTimestampSeconds()
    • suspended

      public boolean suspended()
    • terminated

      public boolean terminated()
    • foundationTimestampSeconds

      public long foundationTimestampSeconds()
    • founder

      public Optional<Jid> founder()
    • description

      public Optional<String> description()
    • support

      public boolean support()
    • parentGroup

      public boolean parentGroup()
    • defaultSubGroup

      public boolean defaultSubGroup()
    • parentGroupJid

      public Optional<Jid> parentGroupJid()
    • displayName

      public Optional<String> displayName()
    • phoneJid

      public Optional<Jid> phoneJid()
    • pnhDuplicateLidThread

      public boolean pnhDuplicateLidThread()
    • lidJid

      public Optional<Jid> lidJid()
    • presences

      public ConcurrentHashMap<Jid,ContactStatus> presences()
    • pastParticipants

      public Set<GroupPastParticipant> pastParticipants()
    • hasName

      public boolean hasName()
    • shareOwnPhoneNumber

      public boolean shareOwnPhoneNumber()
    • setUnreadMessagesCount

      public Chat setUnreadMessagesCount(int unreadMessagesCount)
    • setReadOnly

      public Chat setReadOnly(boolean readOnly)
    • setEndOfHistoryTransfer

      public Chat setEndOfHistoryTransfer(boolean endOfHistoryTransfer)
    • setEphemeralMessageDuration

      public Chat setEphemeralMessageDuration(ChatEphemeralTimer ephemeralMessageDuration)
    • setEphemeralMessagesToggleTimeSeconds

      public Chat setEphemeralMessagesToggleTimeSeconds(long ephemeralMessagesToggleTimeSeconds)
    • setEndOfHistoryTransferType

      public Chat setEndOfHistoryTransferType(Chat.EndOfHistoryTransferType endOfHistoryTransferType)
    • setTimestampSeconds

      public Chat setTimestampSeconds(long timestampSeconds)
    • setName

      public Chat setName(String name)
    • setNotSpam

      public Chat setNotSpam(boolean notSpam)
    • setArchived

      public Chat setArchived(boolean archived)
    • setDisappearInitiator

      public Chat setDisappearInitiator(ChatDisappear disappearInitiator)
    • setMarkedAsUnread

      public Chat setMarkedAsUnread(boolean markedAsUnread)
    • setToken

      public Chat setToken(byte[] token)
    • setTokenTimestampSeconds

      public Chat setTokenTimestampSeconds(long tokenTimestampSeconds)
    • setIdentityKey

      public Chat setIdentityKey(byte[] identityKey)
    • setPinnedTimestampSeconds

      public Chat setPinnedTimestampSeconds(int pinnedTimestampSeconds)
    • setMute

      public Chat setMute(ChatMute mute)
    • setWallpaper

      public Chat setWallpaper(ChatWallpaper wallpaper)
    • setMediaVisibility

      public Chat setMediaVisibility(MediaVisibility mediaVisibility)
    • setTokenSenderTimestampSeconds

      public Chat setTokenSenderTimestampSeconds(long tokenSenderTimestampSeconds)
    • setSuspended

      public Chat setSuspended(boolean suspended)
    • setTerminated

      public Chat setTerminated(boolean terminated)
    • setFoundationTimestampSeconds

      public Chat setFoundationTimestampSeconds(long foundationTimestampSeconds)
    • setFounder

      public Chat setFounder(Jid founder)
    • setDescription

      public Chat setDescription(String description)
    • setSupport

      public Chat setSupport(boolean support)
    • setParentGroup

      public Chat setParentGroup(boolean parentGroup)
    • setDefaultSubGroup

      public Chat setDefaultSubGroup(boolean defaultSubGroup)
    • setDisplayName

      public Chat setDisplayName(String displayName)
    • setPhoneJid

      public Chat setPhoneJid(Jid phoneJid)
    • setShareOwnPhoneNumber

      public Chat setShareOwnPhoneNumber(boolean shareOwnPhoneNumber)
    • setPnhDuplicateLidThread

      public Chat setPnhDuplicateLidThread(boolean pnhDuplicateLidThread)
    • setLidJid

      public Chat setLidJid(Jid lidJid)
    • hasUpdate

      public boolean hasUpdate()