Package rocks.xmpp.extensions.chatstates
Class ChatStateManager
- java.lang.Object
-
- rocks.xmpp.core.session.Manager
-
- rocks.xmpp.extensions.chatstates.ChatStateManager
-
- All Implemented Interfaces:
ExtensionProtocol
,InboundMessageHandler
,OutboundMessageHandler
,DiscoverableInfo
public final class ChatStateManager extends Manager implements ExtensionProtocol, DiscoverableInfo, InboundMessageHandler, OutboundMessageHandler
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.
Sending Chat States
Setting your own chat state can either be done in a one-to-one chat session or a group chat.
ChatStateManager chatStateManager = xmppSession.getManager(ChatStateManager.class); chatStateManager.setChatState(ChatState.COMPOSING, chat);
Receiving Chat States
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. }
- See Also:
- XEP-0085: Chat State Notifications
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<String>
getFeatures()
Gets the features.String
getNamespace()
The protocol's main namespace.void
handleInboundMessage(MessageEvent e)
Handles an inbound message.void
handleOutboundMessage(MessageEvent e)
Handles an outbound message.AsyncResult<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.-
Methods inherited from class rocks.xmpp.core.session.Manager
isEnabled, setEnabled
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface rocks.xmpp.extensions.disco.model.info.DiscoverableInfo
getExtensions, getIdentities
-
Methods inherited from interface rocks.xmpp.core.ExtensionProtocol
isEnabled
-
-
-
-
Method Detail
-
setChatState
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); } });
- Parameters:
chatState
- The chat state.chat
- The chat.- Returns:
- True, if the chat state has been sent; false, if it has not been sent (e.g. because it is known that the chat partner does not support chat states).
-
isSupported
public final AsyncResult<Boolean> isSupported(Jid jid)
Indicates whether chat state notifications are supported by the peer.- Parameters:
jid
- The JID.- Returns:
- An async result indicating whether chat state notifications are supported.
- See Also:
- 5.1 Generation of Notifications
-
handleInboundMessage
public void handleInboundMessage(MessageEvent e)
Description copied from interface:InboundMessageHandler
Handles an inbound message.- Specified by:
handleInboundMessage
in interfaceInboundMessageHandler
- Parameters:
e
- The message event.
-
handleOutboundMessage
public void handleOutboundMessage(MessageEvent e)
Description copied from interface:OutboundMessageHandler
Handles an outbound message.- Specified by:
handleOutboundMessage
in interfaceOutboundMessageHandler
- Parameters:
e
- The message event.
-
getNamespace
public final String getNamespace()
Description copied from interface:ExtensionProtocol
The protocol's main namespace. This is used to uniquely identify the extension protocol.- Specified by:
getNamespace
in interfaceExtensionProtocol
- Returns:
- The main namespace.
-
getFeatures
public final Set<String> getFeatures()
Description copied from interface:DiscoverableInfo
Gets the features.- Specified by:
getFeatures
in interfaceDiscoverableInfo
- Returns:
- The features.
-
-