Search in sources :

Example 1 with DiscussionHistory

use of org.jivesoftware.smackx.muc.DiscussionHistory in project camel by apache.

the class XmppConsumer method doStart.

@Override
protected void doStart() throws Exception {
    try {
        connection = endpoint.createConnection();
    } catch (SmackException e) {
        if (endpoint.isTestConnectionOnStartup()) {
            throw new RuntimeException("Could not connect to XMPP server.", e);
        } else {
            LOG.warn(e.getMessage());
            if (getExceptionHandler() != null) {
                getExceptionHandler().handleException(e.getMessage(), e);
            }
            scheduleDelayedStart();
            return;
        }
    }
    chatManager = ChatManager.getInstanceFor(connection);
    chatManager.addChatListener(this);
    OrFilter pubsubPacketFilter = new OrFilter();
    if (endpoint.isPubsub()) {
        //xep-0060: pubsub#notification_type can be 'headline' or 'normal'
        pubsubPacketFilter.addFilter(new MessageTypeFilter(Type.headline));
        pubsubPacketFilter.addFilter(new MessageTypeFilter(Type.normal));
        connection.addPacketListener(this, pubsubPacketFilter);
    }
    if (endpoint.getRoom() == null) {
        privateChat = chatManager.getThreadChat(endpoint.getChatId());
        if (privateChat != null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Adding listener to existing chat opened to " + privateChat.getParticipant());
            }
            privateChat.addMessageListener(this);
        } else {
            privateChat = ChatManager.getInstanceFor(connection).createChat(endpoint.getParticipant(), endpoint.getChatId(), this);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Opening private chat to " + privateChat.getParticipant());
            }
        }
    } else {
        // add the presence packet listener to the connection so we only get packets that concerns us
        // we must add the listener before creating the muc
        final AndFilter packetFilter = new AndFilter(new PacketTypeFilter(Presence.class));
        connection.addPacketListener(this, packetFilter);
        muc = new MultiUserChat(connection, endpoint.resolveRoom(connection));
        muc.addMessageListener(this);
        DiscussionHistory history = new DiscussionHistory();
        // we do not want any historical messages
        history.setMaxChars(0);
        muc.join(endpoint.getNickname(), null, history, SmackConfiguration.getDefaultPacketReplyTimeout());
        if (LOG.isInfoEnabled()) {
            LOG.info("Joined room: {} as: {}", muc.getRoom(), endpoint.getNickname());
        }
    }
    this.startRobustConnectionMonitor();
    super.doStart();
}
Also used : MessageTypeFilter(org.jivesoftware.smack.filter.MessageTypeFilter) AndFilter(org.jivesoftware.smack.filter.AndFilter) MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) DiscussionHistory(org.jivesoftware.smackx.muc.DiscussionHistory) SmackException(org.jivesoftware.smack.SmackException) Presence(org.jivesoftware.smack.packet.Presence) PacketTypeFilter(org.jivesoftware.smack.filter.PacketTypeFilter) OrFilter(org.jivesoftware.smack.filter.OrFilter)

Example 2 with DiscussionHistory

use of org.jivesoftware.smackx.muc.DiscussionHistory in project camel by apache.

the class XmppGroupChatProducer method initializeChat.

protected synchronized void initializeChat() throws XMPPException, SmackException {
    if (chat == null) {
        room = endpoint.resolveRoom(connection);
        chat = new MultiUserChat(connection, room);
        DiscussionHistory history = new DiscussionHistory();
        // we do not want any historical messages
        history.setMaxChars(0);
        chat.join(endpoint.getNickname(), null, history, SmackConfiguration.getDefaultPacketReplyTimeout());
        if (LOG.isInfoEnabled()) {
            LOG.info("Joined room: {} as: {}", room, endpoint.getNickname());
        }
    }
}
Also used : MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) DiscussionHistory(org.jivesoftware.smackx.muc.DiscussionHistory)

Aggregations

DiscussionHistory (org.jivesoftware.smackx.muc.DiscussionHistory)2 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)2 SmackException (org.jivesoftware.smack.SmackException)1 AndFilter (org.jivesoftware.smack.filter.AndFilter)1 MessageTypeFilter (org.jivesoftware.smack.filter.MessageTypeFilter)1 OrFilter (org.jivesoftware.smack.filter.OrFilter)1 PacketTypeFilter (org.jivesoftware.smack.filter.PacketTypeFilter)1 Presence (org.jivesoftware.smack.packet.Presence)1