/** * Creates and returns a copy of this presence stanza. * <p> * This does not perform a deep clone, as extension elements are shared between the new and old * instance. * </p> * @return a clone of this presence. */ @Override public Presence clone() { return new Presence(this); }
/** * Closes the connection by setting presence to unavailable then closing the connection to * the XMPP server. The XMPPConnection can still be used for connecting to the server * again. * */ public void disconnect() { Presence unavailablePresence = null; if (isAuthenticated()) { unavailablePresence = new Presence(Presence.Type.unavailable); } try { disconnect(unavailablePresence); } catch (NotConnectedException e) { LOGGER.log(Level.FINEST, "Connection is already disconnected", e); } }
/** * Returns a List of Presence objects for all of a user's current presences if no presence information is available, * such as when you are not subscribed to the user's presence updates. * * @param bareJid an XMPP ID, e.g. jdoe@example.com. * @return a List of Presence objects for all the user's current presences, or an unavailable presence if no * presence information is available. */ public List<Presence> getAllPresences(BareJid bareJid) { Map<Resourcepart, Presence> userPresences = getPresencesInternal(bareJid); List<Presence> res; if (userPresences == null) { // Create an unavailable presence if none was found Presence unavailable = new Presence(Presence.Type.unavailable); unavailable.setFrom(bareJid); res = new ArrayList<>(Arrays.asList(unavailable)); } else { res = new ArrayList<>(userPresences.values().size()); for (Presence presence : userPresences.values()) { res.add(presence.clone()); } } return res; }
private static Presence getNewPresence() { Presence presence = new Presence(Presence.Type.available); presence.setStanzaId(null); return presence; } }
public void sendSubscriptionRequest(BareJid jid) throws NotLoggedInException, NotConnectedException, InterruptedException { final XMPPConnection connection = getAuthenticatedConnectionOrThrow(); // Create a presence subscription packet and send. Presence presencePacket = new Presence(Presence.Type.subscribe); presencePacket.setTo(jid); connection.sendStanza(presencePacket); }
/** * Cancel the presence subscription the XMPP entity representing this roster entry has with us. * * @throws NotConnectedException * @throws InterruptedException * @since 4.2 */ public void cancelSubscription() throws NotConnectedException, InterruptedException { Presence unsubscribed = new Presence(item.getJid(), Type.unsubscribed); connection().sendStanza(unsubscribed); }
if (resources != null) { for (Resourcepart resource : resources.keySet()) { packetUnavailable = new Presence(Presence.Type.unavailable); EntityBareJid bareUserJid = user.asEntityBareJidIfPossible(); if (bareUserJid == null) {
MucEnterConfiguration(Builder builder) { nickname = builder.nickname; password = builder.password; maxChars = builder.maxChars; maxStanzas = builder.maxStanzas; seconds = builder.seconds; since = builder.since; timeout = builder.timeout; if (builder.joinPresence == null) { joinPresence = new Presence(Presence.Type.available); } else { joinPresence = builder.joinPresence.clone(); } // Indicate the the client supports MUC joinPresence.addExtension(new MUCInitialPresence(password, maxChars, maxStanzas, seconds, since)); }
public void sendFriendshipRequest(BareJid bareJid) throws NotConnectedException, InterruptedException { Presence presence = new Presence(Presence.Type.subscribe); presence.setTo(bareJid); friendshipRequestedCache.put(bareJid, null); connection().sendStanza(presence); }
public void unfriend(Jid friend) throws NotConnectedException, InterruptedException { if (isMyFriend(friend)) { Presence presence = new Presence(Presence.Type.unsubscribed); presence.setTo(friend); connection().sendStanza(presence); } }
/** * Returns the presence info for a particular user's resource, or unavailable presence * if the user is offline or if no presence information is available, such as * when you are not subscribed to the user's presence updates. * * @param userWithResource a fully qualified XMPP ID including a resource (user@domain/resource). * @return the user's current presence, or unavailable presence if the user is offline * or if no presence information is available. */ public Presence getPresenceResource(FullJid userWithResource) { BareJid key = userWithResource.asBareJid(); Resourcepart resource = userWithResource.getResourcepart(); Map<Resourcepart, Presence> userPresences = getPresencesInternal(key); if (userPresences == null) { Presence presence = new Presence(Presence.Type.unavailable); presence.setFrom(userWithResource); return presence; } else { Presence presence = userPresences.get(resource); if (presence == null) { presence = new Presence(Presence.Type.unavailable); presence.setFrom(userWithResource); return presence; } else { return presence.clone(); } } }
protected void afterSuccessfulLogin(final boolean resumed) throws NotConnectedException, InterruptedException { // Indicate that we're now authenticated. this.authenticated = true; // If debugging is enabled, change the the debug window title to include the // name we are now logged-in as. // If DEBUG was set to true AFTER the connection was created the debugger // will be null if (debugger != null) { debugger.userHasLogged(user); } callConnectionAuthenticatedListener(resumed); // Set presence to online. It is important that this is done after // callConnectionAuthenticatedListener(), as this call will also // eventually load the roster. And we should load the roster before we // send the initial presence. if (config.isSendPresence() && !resumed) { sendStanza(new Presence(Presence.Type.available)); } }
@Override public void processStanza(Stanza stanza) throws NotConnectedException, InterruptedException { if (!isFromProvisioningService(stanza, true)) { return; } Message message = (Message) stanza; Unfriend unfriend = Unfriend.from(message); BareJid unfriendJid = unfriend.getJid(); final XMPPConnection connection = connection(); Roster roster = Roster.getInstanceFor(connection); if (!roster.isSubscribedToMyPresence(unfriendJid)) { LOGGER.warning("Ignoring <unfriend/> request '" + stanza + "' because " + unfriendJid + " is already not subscribed to our presence."); return; } Presence unsubscribed = new Presence(Presence.Type.unsubscribed); unsubscribed.setTo(unfriendJid); connection.sendStanza(unsubscribed); } }, UNFRIEND_MESSAGE);
/** * Pre-approve user presence subscription. * * @param user the user. (e.g. johndoe@jabber.org) * @throws NotLoggedInException if not logged in. * @throws NotConnectedException * @throws InterruptedException * @throws FeatureNotSupportedException if pre-approving is not supported. * @since 4.2 */ public void preApprove(BareJid user) throws NotLoggedInException, NotConnectedException, InterruptedException, FeatureNotSupportedException { final XMPPConnection connection = connection(); if (!isSubscriptionPreApprovalSupported()) { throw new FeatureNotSupportedException("Pre-approving"); } Presence presencePacket = new Presence(Presence.Type.subscribed); presencePacket.setTo(user); connection.sendStanza(presencePacket); }
String control = controlBuilder.toString(); Presence presenceModeInConstructor = new Presence(Presence.Type.available, status, priority, mode1); presenceModeInConstructor.setStanzaId(null);
/** * Changes the occupant's availability status within the room. The presence type * will remain available but with a new status that describes the presence update and * a new presence mode (e.g. Extended away). * * @param status a text message describing the presence update. * @param mode the mode type for the presence update. * @throws NotConnectedException * @throws InterruptedException * @throws MucNotJoinedException */ public void changeAvailabilityStatus(String status, Presence.Mode mode) throws NotConnectedException, InterruptedException, MucNotJoinedException { final EntityFullJid myRoomJid = this.myRoomJid; if (myRoomJid == null) { throw new MucNotJoinedException(this); } // Check that we already have joined the room before attempting to change the // availability status. if (!joined) { throw new MucNotJoinedException(this); } // We change the availability status by sending a presence packet to the room with the // new presence status and mode Presence joinPresence = new Presence(Presence.Type.available); joinPresence.setStatus(status); joinPresence.setMode(mode); joinPresence.setTo(myRoomJid); // Send join packet. connection.sendStanza(joinPresence); }
@Test public void presenceTest() { Presence presence = new Presence(Presence.Type.subscribe, null, 0, Mode.away); presence.setStanzaId("presence-id"); String string = presence.toString(); assertEquals("Presence Stanza [id=presence-id,type=subscribe,mode=away,prio=0,]", string); }
@Test public void helperTest() { Presence presence = new Presence(Presence.Type.available); IdleElement.addToPresence(presence); IdleElement element = IdleElement.fromPresence(presence); assertNotNull(element); } }
/** * Returns true if the workgroup is available for receiving new requests. The workgroup will be * available only when agents are available for this workgroup. * * @return true if the workgroup is available for receiving new requests. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException */ public boolean isAvailable() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Presence directedPresence = new Presence(Presence.Type.available); directedPresence.setTo(workgroupJID); StanzaFilter typeFilter = new StanzaTypeFilter(Presence.class); StanzaFilter fromFilter = FromMatchesFilter.create(workgroupJID); StanzaCollector collector = connection.createStanzaCollectorAndSend(new AndFilter(fromFilter, typeFilter), directedPresence); Presence response = collector.nextResultOrThrow(); return Presence.Type.available == response.getType(); }
@Test public void setPresenceTypeTest() throws IOException, SAXException { Presence.Type type = Presence.Type.unavailable; Presence.Type type2 = Presence.Type.subscribe; StringBuilder controlBuilder = new StringBuilder(); controlBuilder.append("<presence") .append(" type=\"") .append(type) .append("\">") .append("</presence>"); String control = controlBuilder.toString(); Presence presenceTypeInConstructor = new Presence(type); presenceTypeInConstructor.setStanzaId(null); assertEquals(type, presenceTypeInConstructor.getType()); assertXMLEqual(control, presenceTypeInConstructor.toXML(StreamOpen.CLIENT_NAMESPACE).toString()); controlBuilder = new StringBuilder(); controlBuilder.append("<presence") .append(" type=\"") .append(type2) .append("\">") .append("</presence>"); control = controlBuilder.toString(); Presence presenceTypeSet = getNewPresence(); presenceTypeSet.setType(type2); assertEquals(type2, presenceTypeSet.getType()); assertXMLEqual(control, presenceTypeSet.toXML(StreamOpen.CLIENT_NAMESPACE).toString()); }