/** * Method is responsible for processing outgoing subscribed and unsubscribed presence (i.e. in the * sender session manager). * * <p>Presence packet is forwarded to the destination with the JID stripped from the resource, a * subscription state is being updated and, in case there was a change, a roster push is being * sent to all user resources. Also, in case of presence type out_subscribed server send current * presence to the user from each of the contact's available resources. For the presence type * out_unsubscribed an unavailable presence is sent. * * @param packet packet is which being processed. * @param session user session which keeps all the user session data and also gives an access to * the user's repository data. * @param results this a collection with packets which have been generated as input packet * processing results. * @param settings this map keeps plugin specific settings loaded from the Tigase server * configuration. * @param pres_type specifies type of the presence. * @throws NoConnectionIdException * @throws NotAuthorizedException * @throws TigaseDBException */ protected void processOutSubscribed( Packet packet, XMPPResourceConnection session, Queue<Packet> results, Map<String, Object> settings, RosterAbstract.PresenceType pres_type) throws NotAuthorizedException, TigaseDBException, NoConnectionIdException { // According to RFC-3921 I must forward all these kind presence // requests, it allows to re-synchronize // subscriptions in case of synchronization loss forwardPresence(results, packet, session.getJID().copyWithoutResource()); Element initial_presence = session.getPresence(); JID buddy = packet.getStanzaTo().copyWithoutResource(); boolean subscr_changed = roster_util.updateBuddySubscription(session, pres_type, buddy); if (autoAuthorize && (pres_type == RosterAbstract.PresenceType.out_subscribed)) { roster_util.setBuddySubscription( session, RosterAbstract.SubscriptionType.both, buddy.copyWithoutResource()); } if (subscr_changed) { roster_util.updateBuddyChange(session, results, roster_util.getBuddyItem(session, buddy)); if (initial_presence != null) { if (pres_type == RosterAbstract.PresenceType.out_subscribed) { // The contact's server MUST then also send current presence to the user // from each of the contact's available resources. List<XMPPResourceConnection> activeSessions = session.getActiveSessions(); for (XMPPResourceConnection userSessions : activeSessions) { Element presence = userSessions.getPresence(); sendPresence(StanzaType.available, userSessions.getjid(), buddy, results, presence); } roster_util.setPresenceSent(session, buddy, true); } else { sendPresence(StanzaType.unavailable, session.getJID(), buddy, results, null); } } // end of if (subscr_changed) } }