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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe constants of this enumerated type describe the various types of transfers that can regard a chat history sync -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate booleanprivate Stringprivate ChatDisappearprivate Stringprivate booleanprivate Chat.EndOfHistoryTransferTypeprivate ChatEphemeralTimerprivate longprivate longprivate Jidprivate final ConcurrentLinkedHashedDequeue<HistorySyncMessage> private byte[]private final Jidprivate Jidprivate booleanprivate MediaVisibilityprivate ChatMuteprivate Stringprivate final Jidprivate booleanprivate final Jidprivate booleanprivate final Jidprivate final List<GroupParticipant> private final Set<GroupPastParticipant> private Jidprivate intprivate booleanprivate final ConcurrentHashMap<Jid, ContactStatus> private booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate longprivate byte[]private longprivate longprivate intprivate booleanprivate ChatWallpaper -
Constructor Summary
ConstructorsConstructorDescriptionChat(Jid jid, ConcurrentLinkedHashedDequeue<HistorySyncMessage> historySyncMessages, Jid newJid, Jid oldJid, int unreadMessagesCount, boolean readOnly, boolean endOfHistoryTransfer, ChatEphemeralTimer ephemeralMessageDuration, long ephemeralMessagesToggleTimeSeconds, Chat.EndOfHistoryTransferType endOfHistoryTransferType, long timestampSeconds, String name, boolean notSpam, boolean archived, ChatDisappear disappearInitiator, boolean markedAsUnread, List<GroupParticipant> participants, byte[] token, long tokenTimestampSeconds, byte[] identityKey, int pinnedTimestampSeconds, ChatMute mute, ChatWallpaper wallpaper, MediaVisibility mediaVisibility, long tokenSenderTimestampSeconds, boolean suspended, boolean terminated, long foundationTimestampSeconds, Jid founder, String description, boolean support, boolean parentGroup, boolean defaultSubGroup, Jid parentGroupJid, String displayName, Jid phoneJid, boolean shareOwnPhoneNumber, boolean pnhDuplicateLidThread, Jid lidJid) Chat(Jid jid, ConcurrentLinkedHashedDequeue<HistorySyncMessage> historySyncMessages, Jid newJid, Jid oldJid, int unreadMessagesCount, boolean readOnly, boolean endOfHistoryTransfer, ChatEphemeralTimer ephemeralMessageDuration, long ephemeralMessagesToggleTimeSeconds, Chat.EndOfHistoryTransferType endOfHistoryTransferType, long timestampSeconds, String name, boolean notSpam, boolean archived, ChatDisappear disappearInitiator, boolean markedAsUnread, List<GroupParticipant> participants, byte[] token, long tokenTimestampSeconds, byte[] identityKey, int pinnedTimestampSeconds, ChatMute mute, ChatWallpaper wallpaper, MediaVisibility mediaVisibility, long tokenSenderTimestampSeconds, boolean suspended, boolean terminated, long foundationTimestampSeconds, Jid founder, String description, boolean support, boolean parentGroup, boolean defaultSubGroup, Jid parentGroupJid, String displayName, Jid phoneJid, boolean shareOwnPhoneNumber, boolean pnhDuplicateLidThread, Jid lidJid, ConcurrentHashMap<Jid, ContactStatus> presences, Set<Jid> participantsPreKeys, Set<GroupPastParticipant> pastParticipants) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMessages(Collection<HistorySyncMessage> newMessages) Adds a new unspecified amount of messages to this chat and sorts them accordinglybooleanaddNewMessage(ChatMessageInfo info) Adds a message to the chat in the most recent slot availablebooleanAdds a message to the chat in the oldest slot availablevoidaddOldMessages(Collection<HistorySyncMessage> oldMessages) Adds a new unspecified amount of messages to this chat and sorts them accordinglybooleanaddParticipant(GroupParticipant participant) Adds a participant to this chatbooleanaddParticipant(Jid jid, GroupRole role) Adds a participant to this chatvoidaddParticipants(Collection<GroupParticipant> participants) Adds a collection of participants to this chatvoidaddParticipantsPreKeys(Collection<Jid> jids) booleanaddPastParticipant(GroupPastParticipant participant) Adds a past participantbooleanaddPastParticipants(List<GroupPastParticipant> pastParticipants) Adds a collection of past participantsbooleanarchived()voidbooleanbooleanReturns an optional value containing the seconds in seconds sinceInstant.EPOCHwhen ephemeral messages were turned onlongbooleanChecks if this chat is equal to another chatprivate Optional<ChatMessageInfo> findMessageBy(Function<ChatMessageInfo, Boolean> filter, boolean newest) findParticipant(Jid jid) Finds a participant by jid This method only works ifWhatsapp.queryGroupMetadata(JidProvider)has been called before on this chat.findPastParticipant(Jid jid) Finds a past participant by jidReturns the timestampSeconds for the creation of this chat if it's a grouplongfounder()inthashCode()Returns the hash code for this chatbooleanhasName()booleanReturns a boolean to represent whether this chat has unread messagesbooleanOptional<byte[]> booleanReturns a boolean to represent whether ephemeral messages are enabled for this chatbooleanisGroup()Returns a boolean to represent whether this chat is a group or notprivate booleanbooleanisPinned()Returns a boolean to represent whether this chat is pinned or notprivate booleanprivate booleanjid()lidJid()booleanmessages()Returns an immutable list of messages wrapped in history syncs This is useful for the protomute()name()Returns the name of this chatReturns an optional value containing the latest message in chronological terms for this chatReturns an optional value containing the latest message in chronological terms for this chat sent from youReturns an optional value containing the latest message in chronological terms for this chat with type serverReturns an optional value containing the latest message in chronological terms for this chat with type that isn't servernewJid()booleannotSpam()Returns an optional value containing the first message in chronological terms for this chatReturns an optional value containing the first message in chronological terms for this chat sent from youReturns an optional value containing the first message in chronological terms for this chat with type serverReturns an optional value containing the first message in chronological terms for this chat with type that isn't serveroldJid()booleanphoneJid()Returns an optional value containing the seconds this chat was pinnedintbooleanbooleanreadOnly()private voidbooleanremoveMessage(ChatMessageInfo info) Remove a message from the chatbooleanremoveMessage(Predicate<? super ChatMessageInfo> predicate) Remove a message from the chatvoidRemoves all messages from the chatbooleanremoveParticipant(Jid jid) Removes a participant from this chatbooleanremovePastParticipant(Jid jid) Removes a past participantsetArchived(boolean archived) setDefaultSubGroup(boolean defaultSubGroup) setDescription(String description) setDisappearInitiator(ChatDisappear disappearInitiator) setDisplayName(String displayName) setEndOfHistoryTransfer(boolean endOfHistoryTransfer) setEndOfHistoryTransferType(Chat.EndOfHistoryTransferType endOfHistoryTransferType) setEphemeralMessageDuration(ChatEphemeralTimer ephemeralMessageDuration) setEphemeralMessagesToggleTimeSeconds(long ephemeralMessagesToggleTimeSeconds) setFoundationTimestampSeconds(long foundationTimestampSeconds) setFounder(Jid founder) setIdentityKey(byte[] identityKey) setMarkedAsUnread(boolean markedAsUnread) setMediaVisibility(MediaVisibility mediaVisibility) setNotSpam(boolean notSpam) setParentGroup(boolean parentGroup) setPhoneJid(Jid phoneJid) setPinnedTimestampSeconds(int pinnedTimestampSeconds) setPnhDuplicateLidThread(boolean pnhDuplicateLidThread) setReadOnly(boolean readOnly) setShareOwnPhoneNumber(boolean shareOwnPhoneNumber) setSupport(boolean support) setSuspended(boolean suspended) setTerminated(boolean terminated) setTimestampSeconds(long timestampSeconds) setToken(byte[] token) setTokenSenderTimestampSeconds(long tokenSenderTimestampSeconds) setTokenTimestampSeconds(long tokenTimestampSeconds) setUnreadMessagesCount(int unreadMessagesCount) setWallpaper(ChatWallpaper wallpaper) booleanReturns all the starred messages in this chatbooleansupport()booleanbooleanReturns the timestampSeconds for the creation of this chat in seconds sinceInstant.EPOCHlongtoJid()Returns this object as a jidOptional<byte[]> token()Returns the timestampSeconds for the token sender creation of this chatlongReturns the timestampSeconds for the creation of this chat's tokenlongReturns all the unread messages in this chatintprivate void
-
Field Details
-
jid
-
historySyncMessages
-
newJid
-
oldJid
-
unreadMessagesCount
private int unreadMessagesCount -
readOnly
private boolean readOnly -
endOfHistoryTransfer
private boolean endOfHistoryTransfer -
ephemeralMessageDuration
-
ephemeralMessagesToggleTimeSeconds
private long ephemeralMessagesToggleTimeSeconds -
endOfHistoryTransferType
-
timestampSeconds
private long timestampSeconds -
name
-
notSpam
private boolean notSpam -
archived
private boolean archived -
disappearInitiator
-
markedAsUnread
private boolean markedAsUnread -
participants
-
token
private byte[] token -
tokenTimestampSeconds
private long tokenTimestampSeconds -
identityKey
private byte[] identityKey -
pinnedTimestampSeconds
private int pinnedTimestampSeconds -
mute
-
wallpaper
-
mediaVisibility
-
tokenSenderTimestampSeconds
private long tokenSenderTimestampSeconds -
suspended
private boolean suspended -
terminated
private boolean terminated -
foundationTimestampSeconds
private long foundationTimestampSeconds -
founder
-
description
-
support
private boolean support -
parentGroup
private boolean parentGroup -
defaultSubGroup
private boolean defaultSubGroup -
parentGroupJid
-
displayName
-
phoneJid
-
pnhDuplicateLidThread
private boolean pnhDuplicateLidThread -
lidJid
-
update
private boolean update -
presences
-
participantsPreKeys
-
pastParticipants
-
-
Constructor Details
-
Chat
public Chat(Jid jid, ConcurrentLinkedHashedDequeue<HistorySyncMessage> historySyncMessages, Jid newJid, Jid oldJid, int unreadMessagesCount, boolean readOnly, boolean endOfHistoryTransfer, ChatEphemeralTimer ephemeralMessageDuration, long ephemeralMessagesToggleTimeSeconds, Chat.EndOfHistoryTransferType endOfHistoryTransferType, long timestampSeconds, String name, boolean notSpam, boolean archived, ChatDisappear disappearInitiator, boolean markedAsUnread, List<GroupParticipant> participants, byte[] token, long tokenTimestampSeconds, byte[] identityKey, int pinnedTimestampSeconds, ChatMute mute, ChatWallpaper wallpaper, MediaVisibility mediaVisibility, long tokenSenderTimestampSeconds, boolean suspended, boolean terminated, long foundationTimestampSeconds, Jid founder, String description, boolean support, boolean parentGroup, boolean defaultSubGroup, Jid parentGroupJid, String displayName, Jid phoneJid, boolean shareOwnPhoneNumber, boolean pnhDuplicateLidThread, Jid lidJid, ConcurrentHashMap<Jid, ContactStatus> presences, Set<Jid> participantsPreKeys, Set<GroupPastParticipant> pastParticipants) -
Chat
public Chat(Jid jid, ConcurrentLinkedHashedDequeue<HistorySyncMessage> historySyncMessages, Jid newJid, Jid oldJid, int unreadMessagesCount, boolean readOnly, boolean endOfHistoryTransfer, ChatEphemeralTimer ephemeralMessageDuration, long ephemeralMessagesToggleTimeSeconds, Chat.EndOfHistoryTransferType endOfHistoryTransferType, long timestampSeconds, String name, boolean notSpam, boolean archived, ChatDisappear disappearInitiator, boolean markedAsUnread, List<GroupParticipant> participants, byte[] token, long tokenTimestampSeconds, byte[] identityKey, int pinnedTimestampSeconds, ChatMute mute, ChatWallpaper wallpaper, MediaVisibility mediaVisibility, long tokenSenderTimestampSeconds, boolean suspended, boolean terminated, long foundationTimestampSeconds, Jid founder, String description, boolean support, boolean parentGroup, boolean defaultSubGroup, Jid parentGroupJid, String displayName, Jid phoneJid, boolean shareOwnPhoneNumber, boolean pnhDuplicateLidThread, Jid lidJid)
-
-
Method Details
-
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
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
Returns an optional value containing the seconds this chat was pinned- Returns:
- an optional
-
timestamp
Returns the timestampSeconds for the creation of this chat in seconds sinceInstant.EPOCH- Returns:
- an optional
-
ephemeralMessagesToggleTime
Returns an optional value containing the seconds in seconds sinceInstant.EPOCHwhen ephemeral messages were turned on- Returns:
- an optional
-
newestMessage
Returns an optional value containing the latest message in chronological terms for this chat- Returns:
- an optional
-
oldestMessage
Returns an optional value containing the first message in chronological terms for this chat- Returns:
- an optional
-
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
Returns an optional value containing the first message in chronological terms for this chat with type that isn't server- Returns:
- an optional
-
isStandardMessage
-
newestMessageFromMe
Returns an optional value containing the latest message in chronological terms for this chat sent from you- Returns:
- an optional
-
oldestMessageFromMe
Returns an optional value containing the first message in chronological terms for this chat sent from you- Returns:
- an optional
-
isMessageFromMe
-
newestServerMessage
Returns an optional value containing the latest message in chronological terms for this chat with type server- Returns:
- an optional
-
oldestServerMessage
Returns an optional value containing the first message in chronological terms for this chat with type server- Returns:
- an optional
-
isServerMessage
-
findMessageBy
private Optional<ChatMessageInfo> findMessageBy(Function<ChatMessageInfo, Boolean> filter, boolean newest) -
starredMessages
Returns all the starred messages in this chat- Returns:
- a non-null list of messages
-
tokenTimestamp
Returns the timestampSeconds for the creation of this chat's token- Returns:
- an optional
-
tokenSenderTimestamp
Returns the timestampSeconds for the token sender creation of this chat- Returns:
- an optional
-
foundationTimestamp
Returns the timestampSeconds for the creation of this chat if it's a group- Returns:
- an optional
-
addMessages
Adds a new unspecified amount of messages to this chat and sorts them accordingly- Parameters:
newMessages- the non-null messages to add
-
addOldMessages
Adds a new unspecified amount of messages to this chat and sorts them accordingly- Parameters:
oldMessages- the non-null messages to add
-
addNewMessage
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
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
Remove a message from the chat- Parameters:
info- the message to remove- Returns:
- whether the message was removed
-
removeMessage
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
-
removeMessages
public void removeMessages()Removes all messages from the chat -
messages
Returns an immutable list of messages wrapped in history syncs This is useful for the proto- Returns:
- a non-null collection
-
addParticipants
Adds a collection of participants to this chat- Parameters:
participants- the participants to add
-
addParticipant
Adds a participant to this chat- Parameters:
jid- the non-null jid of the participantrole- the role of the participant- Returns:
- whether the participant was added
-
addParticipant
Adds a participant to this chat- Parameters:
participant- the non-null participant- Returns:
- whether the participant was added
-
removeParticipant
Removes a participant from this chat- Parameters:
jid- the non-null jid of the participant- Returns:
- whether the participant was removed
-
findParticipant
Finds a participant by jid This method only works ifWhatsapp.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
Adds a past participant- Parameters:
participant- the non-null jid of the past participant- Returns:
- whether the participant was added
-
addPastParticipants
Adds a collection of past participants- Parameters:
pastParticipants- the non-null list of past participants- Returns:
- whether the participant were added
-
removePastParticipant
Removes a past participant- Parameters:
jid- the non-null jid of the past participant- Returns:
- whether the participant was removed
-
findPastParticipant
Finds a past participant by jid- Parameters:
jid- the non-null jid of the past participant- Returns:
- the past participant, if present
-
participantsPreKeys
-
addParticipantsPreKeys
-
clearParticipantsPreKeys
public void clearParticipantsPreKeys() -
equals
Checks if this chat is equal to another chat -
toJid
Returns this object as a jid- Specified by:
toJidin interfaceJidProvider- Returns:
- a non-null jid
-
hashCode
public int hashCode()Returns the hash code for this chat -
jid
-
historySyncMessages
-
newJid
-
oldJid
-
unreadMessagesCount
public int unreadMessagesCount() -
readOnly
public boolean readOnly() -
endOfHistoryTransfer
public boolean endOfHistoryTransfer() -
ephemeralMessageDuration
-
ephemeralMessagesToggleTimeSeconds
public long ephemeralMessagesToggleTimeSeconds() -
endOfHistoryTransferType
-
timestampSeconds
public long timestampSeconds() -
notSpam
public boolean notSpam() -
archived
public boolean archived() -
disappearInitiator
-
markedAsUnread
public boolean markedAsUnread() -
participants
-
token
-
tokenTimestampSeconds
public long tokenTimestampSeconds() -
identityKey
-
pinnedTimestampSeconds
public int pinnedTimestampSeconds() -
mute
-
wallpaper
-
mediaVisibility
-
tokenSenderTimestampSeconds
public long tokenSenderTimestampSeconds() -
suspended
public boolean suspended() -
terminated
public boolean terminated() -
foundationTimestampSeconds
public long foundationTimestampSeconds() -
founder
-
description
-
support
public boolean support() -
parentGroup
public boolean parentGroup() -
defaultSubGroup
public boolean defaultSubGroup() -
parentGroupJid
-
displayName
-
phoneJid
-
pnhDuplicateLidThread
public boolean pnhDuplicateLidThread() -
lidJid
-
presences
-
pastParticipants
-
hasName
public boolean hasName() -
setUnreadMessagesCount
-
setReadOnly
-
setEndOfHistoryTransfer
-
setEphemeralMessageDuration
-
setEphemeralMessagesToggleTimeSeconds
-
setEndOfHistoryTransferType
-
setTimestampSeconds
-
setName
-
setNotSpam
-
setArchived
-
setDisappearInitiator
-
setMarkedAsUnread
-
setToken
-
setTokenTimestampSeconds
-
setIdentityKey
-
setPinnedTimestampSeconds
-
setMute
-
setWallpaper
-
setMediaVisibility
-
setTokenSenderTimestampSeconds
-
setSuspended
-
setTerminated
-
setFoundationTimestampSeconds
-
setFounder
-
setDescription
-
setSupport
-
setParentGroup
-
setDefaultSubGroup
-
setDisplayName
-
setPhoneJid
-
setPnhDuplicateLidThread
-
setLidJid
-
hasUpdate
public boolean hasUpdate()
-