org.jivesoftware.smack.filter.OrFilter Java Examples
The following examples show how to use
org.jivesoftware.smack.filter.OrFilter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MultiUserChat.java From Smack with Apache License 2.0 | 5 votes |
/** * Leave the chat room. * * @return the leave presence as reflected by the MUC. * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. * @throws XMPPErrorException if there was an XMPP error returned. * @throws NoResponseException if there was no response from the remote entity. * @throws MucNotJoinedException if not joined to the Multi-User Chat. */ public synchronized Presence leave() throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException, MucNotJoinedException { // Note that this method is intentionally not guarded by // "if (!joined) return" because it should be always be possible to leave the room in case the instance's // state does not reflect the actual state. final EntityFullJid myRoomJid = this.myRoomJid; if (myRoomJid == null) { throw new MucNotJoinedException(this); } // We leave a room by sending a presence packet where the "to" // field is in the form "roomName@service/nickname" Presence leavePresence = connection.getStanzaFactory().buildPresenceStanza() .ofType(Presence.Type.unavailable) .to(myRoomJid) .build(); StanzaFilter reflectedLeavePresenceFilter = new AndFilter( StanzaTypeFilter.PRESENCE, new StanzaIdFilter(leavePresence), new OrFilter( new AndFilter(FromMatchesFilter.createFull(myRoomJid), PresenceTypeFilter.UNAVAILABLE, MUCUserStatusCodeFilter.STATUS_110_PRESENCE_TO_SELF), new AndFilter(fromRoomFilter, PresenceTypeFilter.ERROR) ) ); // Reset occupant information first so that we are assume that we left the room even if sendStanza() would // throw. userHasLeft(); Presence reflectedLeavePresence = connection.createStanzaCollectorAndSend(reflectedLeavePresenceFilter, leavePresence).nextResultOrThrow(); return reflectedLeavePresence; }
Example #2
Source File: Node.java From Smack with Apache License 2.0 | 5 votes |
/** * Register an listener for item delete events. This listener * gets called whenever an item is deleted from the node. * * @param listener The handler for the event */ public void addItemDeleteListener(ItemDeleteListener listener) { StanzaListener delListener = new ItemDeleteTranslator(listener); itemDeleteToListenerMap.put(listener, delListener); EventContentFilter deleteItem = new EventContentFilter(EventElementType.items.toString(), "retract"); EventContentFilter purge = new EventContentFilter(EventElementType.purge.toString()); // TODO: Use AsyncButOrdered (with Node as Key?) pubSubManager.getConnection().addSyncStanzaListener(delListener, new OrFilter(deleteItem, purge)); }
Example #3
Source File: NoOp.java From jmeter-bzm-plugins with Apache License 2.0 | 4 votes |
@Override public PacketFilter getPacketFilter() { return new OrFilter(PacketTypeFilter.MESSAGE, PacketTypeFilter.PRESENCE, new PacketTypeFilter(IQ.class)); }
Example #4
Source File: MultiUserChat.java From Smack with Apache License 2.0 | 4 votes |
/** * 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 if the XMPP connection is not connected. * @throws NoResponseException if there was no response from the remote entity. * @throws XMPPErrorException if there was an XMPP error returned. * @throws InterruptedException if the calling thread was interrupted. * @throws NotAMucServiceException if the entity is not a MUC serivce. * @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 (!multiUserChatManager.providesMucService(mucService)) { 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.addStanzaListener(messageListener, fromRoomGroupchatFilter); StanzaFilter presenceFromRoomFilter = new AndFilter(fromRoomFilter, StanzaTypeFilter.PRESENCE, PossibleFromTypeFilter.ENTITY_FULL_JID); connection.addStanzaListener(presenceListener, presenceFromRoomFilter); // @formatter:off connection.addStanzaListener(subjectListener, new AndFilter(fromRoomFilter, MessageWithSubjectFilter.INSTANCE, new NotFilter(MessageTypeFilter.ERROR), // According to XEP-0045 ยง 8.1 "A message with a <subject/> and a <body/> or a <subject/> and a <thread/> is a // legitimate message, but it SHALL NOT be interpreted as a subject change." new NotFilter(MessageWithBodiesFilter.INSTANCE), new NotFilter(MessageWithThreadFilter.INSTANCE)) ); // @formatter:on connection.addStanzaListener(declinesListener, new AndFilter(fromRoomFilter, DECLINE_FILTER)); connection.addStanzaSendingListener(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), // In case there is an error reply, we match on an error presence with the same stanza id and from the full // JID we send the join presence to. new AndFilter(FromMatchesFilter.createFull(joinPresence.getTo()), new StanzaIdFilter(joinPresence), PresenceTypeFilter.ERROR) ) ); // @formatter:on StanzaCollector presenceStanzaCollector = null; Presence presence; try { // This stanza collector will collect the final self presence from the MUC, which also signals that we have successful entered the MUC. StanzaCollector selfPresenceCollector = connection.createStanzaCollectorAndSend(responseFilter, joinPresence); StanzaCollector.Configuration presenceStanzaCollectorConfguration = StanzaCollector.newConfiguration().setCollectorToReset( selfPresenceCollector).setStanzaFilter(presenceFromRoomFilter); // This stanza collector is used to reset the timeout of the selfPresenceCollector. presenceStanzaCollector = connection.createStanzaCollector(presenceStanzaCollectorConfguration); presence = selfPresenceCollector.nextResultOrThrow(conf.getTimeout()); } catch (NotConnectedException | InterruptedException | NoResponseException | XMPPErrorException e) { // Ensure that all callbacks are removed if there is an exception removeConnectionCallbacks(); throw e; } finally { if (presenceStanzaCollector != null) { presenceStanzaCollector.cancel(); } } // 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 Resourcepart receivedNickname = presence.getFrom().getResourceOrThrow(); setNickname(receivedNickname); // Update the list of joined rooms multiUserChatManager.addJoinedRoom(room); return presence; }