Package rocks.xmpp.im.chat
Class ChatManager
- java.lang.Object
-
- rocks.xmpp.core.session.Manager
-
- rocks.xmpp.im.chat.ChatManager
-
public final class ChatManager extends Manager
This class manages one-to-one chat sessions, which are described in 5.1. One-to-One Chat Sessions and XEP-0201: Best Practices for Message Threads.Creating a new chat session
ChatSession chatSession = xmppSession.getManager(ChatManager.class).createChatSession(chatPartner);Listen for new chat sessions
When a contact initiates a new chat session with you, you can listen for it with
addChatSessionListener(Consumer). The listener will be called either if you created the session programmatically as shown above, or if it is created by a contact, i.e. because he or she sent you a chat message.You should add a
Chat.addInboundMessageListener(Consumer)to the chat session in order to listen for messages.xmppSession.getManager(ChatManager.class).addChatSessionListener(chatSessionEvent -> { ChatSession chatSession = chatSessionEvent.getChatSession(); chatSession.addInboundMessageListener(e -> { Message message = e.getMessage(); }); });
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChatSessionListener(Consumer<ChatSessionEvent> chatSessionListener)Adds a chat session listener.ChatSessioncreateChatSession(Jid chatPartner)Creates a new chat session or returns an existing one for the given chat partner and notifies any chat session listeners about it.ChatSessioncreateChatSession(Jid chatPartner, String threadId)Creates a new chat session with a given thread id or returns an existing one for the given chat partner and notifies any chat session listeners about it.voidremoveChatSessionListener(Consumer<ChatSessionEvent> chatSessionListener)Removes a previously added chat session listener.-
Methods inherited from class rocks.xmpp.core.session.Manager
isEnabled, setEnabled
-
-
-
-
Method Detail
-
addChatSessionListener
public void addChatSessionListener(Consumer<ChatSessionEvent> chatSessionListener)
Adds a chat session listener.- Parameters:
chatSessionListener- The listener.- See Also:
removeChatSessionListener(Consumer)
-
removeChatSessionListener
public void removeChatSessionListener(Consumer<ChatSessionEvent> chatSessionListener)
Removes a previously added chat session listener.- Parameters:
chatSessionListener- The listener.- See Also:
addChatSessionListener(Consumer)
-
createChatSession
public final ChatSession createChatSession(Jid chatPartner)
Creates a new chat session or returns an existing one for the given chat partner and notifies any chat session listeners about it.- Parameters:
chatPartner- The chat partner.- Returns:
- The chat session.
-
createChatSession
public final ChatSession createChatSession(Jid chatPartner, String threadId)
Creates a new chat session with a given thread id or returns an existing one for the given chat partner and notifies any chat session listeners about it.- Parameters:
chatPartner- The chat partner.threadId- The thread id to use for this chat session.- Returns:
- The chat session.
-
-