Search in sources :

Example 1 with NotFilter

use of org.jivesoftware.smack.filter.NotFilter in project Smack by igniterealtime.

the class MultiUserChat method enter.

/**
     * Enter a room, as described in XEP-45 7.2.
     *
     * @param conf the configuration used to enter the room.
     * @return the returned presence by the service after the client send the initial presence in order to enter the room.
     * @throws NotConnectedException
     * @throws NoResponseException
     * @throws XMPPErrorException
     * @throws InterruptedException
     * @throws NotAMucServiceException 
     * @see <a href="http://xmpp.org/extensions/xep-0045.html#enter">XEP-45 7.2 Entering a Room</a>
     */
private Presence enter(MucEnterConfiguration conf) throws NotConnectedException, NoResponseException, XMPPErrorException, InterruptedException, NotAMucServiceException {
    final DomainBareJid mucService = room.asDomainBareJid();
    if (!KNOWN_MUC_SERVICES.containsKey(mucService)) {
        if (multiUserChatManager.providesMucService(mucService)) {
            KNOWN_MUC_SERVICES.put(mucService, null);
        } else {
            throw new NotAMucServiceException(this);
        }
    }
    // We enter a room by sending a presence packet where the "to"
    // field is in the form "roomName@service/nickname"
    Presence joinPresence = conf.getJoinPresence(this);
    // Setup the messageListeners and presenceListeners *before* the join presence is send.
    connection.addSyncStanzaListener(messageListener, fromRoomGroupchatFilter);
    connection.addSyncStanzaListener(presenceListener, new AndFilter(fromRoomFilter, StanzaTypeFilter.PRESENCE));
    connection.addSyncStanzaListener(subjectListener, new AndFilter(fromRoomFilter, MessageWithSubjectFilter.INSTANCE, new NotFilter(MessageTypeFilter.ERROR)));
    connection.addSyncStanzaListener(declinesListener, DECLINE_FILTER);
    connection.addPacketInterceptor(presenceInterceptor, new AndFilter(ToMatchesFilter.create(room), StanzaTypeFilter.PRESENCE));
    messageCollector = connection.createStanzaCollector(fromRoomGroupchatFilter);
    // Wait for a presence packet back from the server.
    // @formatter:off
    StanzaFilter responseFilter = new AndFilter(StanzaTypeFilter.PRESENCE, new OrFilter(// We use a bare JID filter for positive responses, since the MUC service/room may rewrite the nickname.
    new AndFilter(FromMatchesFilter.createBare(getRoom()), MUCUserStatusCodeFilter.STATUS_110_PRESENCE_TO_SELF), // JID we send the join presence to.
    new AndFilter(FromMatchesFilter.createFull(joinPresence.getTo()), new StanzaIdFilter(joinPresence), PresenceTypeFilter.ERROR)));
    // @formatter:on
    Presence presence;
    try {
        presence = connection.createStanzaCollectorAndSend(responseFilter, joinPresence).nextResultOrThrow(conf.getTimeout());
    } catch (NotConnectedException | InterruptedException | NoResponseException | XMPPErrorException e) {
        // Ensure that all callbacks are removed if there is an exception
        removeConnectionCallbacks();
        throw e;
    }
    // This presence must be send from a full JID. We use the resourcepart of this JID as nick, since the room may
    // performed roomnick rewriting
    this.nickname = presence.getFrom().asEntityFullJidIfPossible().getResourcepart();
    joined = true;
    // Update the list of joined rooms
    multiUserChatManager.addJoinedRoom(room);
    return presence;
}
Also used : StanzaFilter(org.jivesoftware.smack.filter.StanzaFilter) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) OrFilter(org.jivesoftware.smack.filter.OrFilter) NotAMucServiceException(org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException) AndFilter(org.jivesoftware.smack.filter.AndFilter) StanzaIdFilter(org.jivesoftware.smack.filter.StanzaIdFilter) NotFilter(org.jivesoftware.smack.filter.NotFilter) Presence(org.jivesoftware.smack.packet.Presence) MUCInitialPresence(org.jivesoftware.smackx.muc.packet.MUCInitialPresence) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) DomainBareJid(org.jxmpp.jid.DomainBareJid)

Aggregations

NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)1 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)1 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)1 AndFilter (org.jivesoftware.smack.filter.AndFilter)1 NotFilter (org.jivesoftware.smack.filter.NotFilter)1 OrFilter (org.jivesoftware.smack.filter.OrFilter)1 StanzaFilter (org.jivesoftware.smack.filter.StanzaFilter)1 StanzaIdFilter (org.jivesoftware.smack.filter.StanzaIdFilter)1 Presence (org.jivesoftware.smack.packet.Presence)1 NotAMucServiceException (org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException)1 MUCInitialPresence (org.jivesoftware.smackx.muc.packet.MUCInitialPresence)1 DomainBareJid (org.jxmpp.jid.DomainBareJid)1