java.lang.Object
it.auties.whatsapp4j.protobuf.chat.Chat
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()
.-
Nested Class Summary
-
Constructor Summary
ConstructorDescriptionChat()
Chat(@NonNull String jid, @NonNull String displayName, @NonNull Messages messages, @NonNull Map<Contact,ContactStatus> presences, @NonNull ChatMute mute, String newJid, long timestamp, int unreadMessages, long pinned, long ephemeralMessageDuration, long ephemeralMessagesToggleTime, boolean isArchived, boolean isReadOnly, boolean isSpam)
-
Method Summary
Modifier and TypeMethodDescriptionstatic Chat.ChatBuilder
builder()
protected boolean
@NonNull String
The non null display name of this chatdisplayName(@NonNull String displayName)
The non null display name of this chat@NonNull Optional<ZonedDateTime>
Returns an optional value containing the time in seconds before a message is automatically deleted from this chat both locally and from WhatsappWeb's serversephemeralMessageDuration(long ephemeralMessageDuration)
The time in seconds before a message is automatically deleted from this chat both locally and from WhatsappWeb's servers.@NonNull Optional<ZonedDateTime>
Returns an optional value containing the time in seconds sinceInstant.EPOCH
when ephemeral messages were turned onephemeralMessagesToggleTime(long ephemeralMessagesToggleTime)
The time in seconds sinceInstant.EPOCH
when ephemeral messages were turned on.boolean
@NonNull Optional<MessageInfo>
Returns an optional value containing the first message in chronological terms for this chatstatic @NonNull Chat
fromAttributes(@NonNull Map<String,String> attrs)
Constructs a new Chat from a map of attributes.int
hashCode()
boolean
Returns a boolean to represent whether this chat has a new jiboolean
This field is used to determine whether a chat is archived or not.isArchived(boolean isArchived)
This field is used to determine whether a chat is archived or not.boolean
Returns a boolean to represent whether ephemeral messages are enabled for this chatboolean
isGroup()
Returns a boolean to represent whether this chat is a group or notboolean
isPinned()
Returns a boolean to represent whether this chat is pinned or notboolean
This field is used to determine whether a chat is read only or not.isReadOnly(boolean isReadOnly)
This field is used to determine whether a chat is read only or not.boolean
isSpam()
This field is used to determine whether a chat was marked as being spam or not.isSpam(boolean isSpam)
This field is used to determine whether a chat was marked as being spam or not.@NonNull String
jid()
The non null unique jid used to identify this chatThe non null unique jid used to identify this chat@NonNull Optional<MessageInfo>
Returns an optional value containing the latest message in chronological terms for this chat@NonNull Messages
messages()
A non null arrayList of messages in this chat sorted chronologicallyA non null arrayList of messages in this chat sorted chronologically@NonNull ChatMute
mute()
The non null mute of this chatThe non null mute of this chatnewJid()
Returns an optional value containing the new jid of this chatThe nullable new unique jid for this Chat.@NonNull Optional<ZonedDateTime>
pinned()
Returns an optional value containing the time this chat was pinnedpinned(long pinned)
The time in seconds sinceInstant.EPOCH
when this chat was pinned to the top.@NonNull Map<Contact,ContactStatus>
A map that holds the status of each participant, excluding yourself, for this chat.presences(@NonNull Map<Contact,ContactStatus> presences)
A map that holds the status of each participant, excluding yourself, for this chat.long
The time in seconds sinceInstant.EPOCH
for the latest message inmessages
timestamp(long timestamp)
The time in seconds sinceInstant.EPOCH
for the latest message inmessages
toString()
int
The number of unread messages in this chat.unreadMessages(int unreadMessages)
The number of unread messages in this chat.
-
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
Constructs a new Chat from a map of attributes. This method is usually used to deserialize a Chat from the attributes of aNode
.- 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 ji- Returns:
- true if this chat has a new jid
-
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
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
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
Returns an optional value containing the time in seconds sinceInstant.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
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
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
-
jid
The non null unique jid used to identify this chat -
displayName
The non null display name of this chat -
messages
A non null arrayList of messages in this chat sorted chronologically -
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 useWhatsappAPI.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 implementingWhatsappListener.onContactPresenceUpdate(it.auties.whatsapp4j.protobuf.chat.Chat, it.auties.whatsapp4j.protobuf.contact.Contact)
. The presence that this map indicates might not line up withContact.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
The non null mute of this chat -
timestamp
public long timestamp()The time in seconds sinceInstant.EPOCH
for the latest message inmessages
-
unreadMessages
public int unreadMessages()The number of unread messages in this chat. To set all the messages as read it's advised to useWhatsappAPI.markAsRead(Chat)
. -
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
The non null unique jid used to identify this chat- Returns:
this
.
-
displayName
The non null display name of this chat- Returns:
this
.
-
messages
A non null arrayList of messages in this chat sorted chronologically- Returns:
this
.
-
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 useWhatsappAPI.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 implementingWhatsappListener.onContactPresenceUpdate(it.auties.whatsapp4j.protobuf.chat.Chat, it.auties.whatsapp4j.protobuf.contact.Contact)
. The presence that this map indicates might not line up withContact.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
The non null mute of this chat- Returns:
this
.
-
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
The time in seconds sinceInstant.EPOCH
for the latest message inmessages
- Returns:
this
.
-
unreadMessages
The number of unread messages in this chat. To set all the messages as read it's advised to useWhatsappAPI.markAsRead(Chat)
.- Returns:
this
.
-
pinned
The time in seconds sinceInstant.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
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
The time in seconds sinceInstant.EPOCH
when ephemeral messages were turned on. If ephemeral messages aren't enabled, this field has a value of 0.- Returns:
this
.
-
isArchived
This field is used to determine whether a chat is archived or not.- Returns:
this
.
-
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
This field is used to determine whether a chat was marked as being spam or not.- Returns:
this
.
-
equals
-
canEqual
-
hashCode
public int hashCode() -
toString
-