public final class ChatStateManager extends Manager
This class manages Chat State Notifications, which are used to communicate the status of a user in a chat session, thus indicating whether a chat partner is actively engaged in the chat, composing a message, temporarily paused, inactive, or gone. Chat states can be used in the context of a one-to-one chat session or a multi-user chat room.
Because the Chat State protocol is relatively simple, the primary purpose of this manager is to enable or disable the Chat State protocol for Service Discovery purposes.
Furthermore it ensures that every sent message has a chat state notification as required by XEP-0085.
ChatStateManager chatStateManager = xmppSession.getManager(ChatStateManager.class);
chatStateManager.setChatState(ChatState.COMPOSING, chat);
If you want to react to chat states of your chat partner(s), just check for chat state extension and deal with it accordingly.
ChatState chatState = message.getExtension(ChatState.class);
if (chatState == ChatState.COMPOSING) {
// Contact is typing.
} else if (chatState == ChatState.PAUSED) {
// Contact has paused typing.
}
Modifier and Type | Method and Description |
---|---|
AsyncResult<java.lang.Boolean> |
isSupported(Jid jid)
Indicates whether chat state notifications are supported by the peer.
|
boolean |
setChatState(ChatState chatState,
Chat chat)
Sets the chat state for a chat.
|
isEnabled, setEnabled
public final boolean setChatState(ChatState chatState, Chat chat)
Sets the chat state for a chat. If this manager is disabled this method has no effect. Before sending chat states in a one-to-one chat, you should check, if the peer supports it, e.g. like that:
chatStateManager.isSupported(chat.getChatPartner()).thenAccept(result -> {
if (result) {
chatStateManager.setChatState(chatState, chat);
}
});
chatState
- The chat state.chat
- The chat.public final AsyncResult<java.lang.Boolean> isSupported(Jid jid)
Indicates whether chat state notifications are supported by the peer.
jid
- The JID.Copyright © 2014–2019 XMPP.rocks. All rights reserved.