/** * Creates a new presence with the given type and using the given XMPP address as recipient. * * @param to the recipient. * @param type the type. * @since 4.2 */ public Presence(Jid to, Type type) { this(type); setTo(to); }
Presence getJoinPresence(MultiUserChat multiUserChat) { final EntityFullJid jid = JidCreate.entityFullFrom(multiUserChat.getRoom(), nickname); joinPresence.setTo(jid); return joinPresence; }
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); }
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); } }
@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); }
/** * 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); }
/** * 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(); }
response.setTo(presence.getFrom()); connection.sendStanza(response);
presence.setTo(ParserUtils.getJidAttribute(parser, "to")); presence.setFrom(ParserUtils.getJidAttribute(parser, "from")); presence.setStanzaId(parser.getAttributeValue("", "id"));
presence.setTo(this.getWorkgroupJID());
presence.setTo(this.getWorkgroupJID());
joinPresence.setTo(jid);
leavePresence.setTo(myRoomJid);
Presence response = new Presence.Type.subscribed); response.setTo(address); sendPacket(response); Roster roster = mConnection.getRoster(); roster.createEntry(address, name, groups);
protected void doAddContactToListAsync(String address, String name, ContactList list) throws ImException { debug(TAG, "add contact to " + list.getName()); Presence response = new Presence.Type.subscribed); response.setTo(address); sendPacket(response); Roster roster = mConnection.getRoster(); String[] groups = new String[] { list.getName() }; if (name == null) { name = parseAddressName(address); } try { // final String name = parseAddressName(address); // Log.v(tag, msg) roster.createEntry(address, name, groups); // If contact exists locally, don't create another copy Contact contact = makeContact(name, address); if (!containsContact(contact)) notifyContactListUpdated(list, ContactListListener.LIST_CONTACT_ADDED, contact); else debug(TAG, "skip adding existing contact locally " + name); } catch (XMPPException e) { throw new RuntimeException(e); } }
Presence presence = (Presence) packet; Presence presence_request = new Presence(Presence.Type.subscribed); presence_request.setTo(presence.getFrom()); presence_request.setType(Presence.Type.subscribed); presence_request.setFrom("current_logged_in_user"); connection.sendPacket(presence_request); roster.createEntry(presence.getFrom(), null, null);
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); }