Class 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 Detail

      • 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.