src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java
/**
         * Fires the status change, respecting resource priorities.
         *
         * @param presence the presence changed.
         */
Fires the status change, respecting resource priorities.
@param presence the presence changed.
Fires the status change respecting resource priorities . @param presence the presence changed .
void firePresenceStatusChanged(Presence presence)
        {
            if(storeEvents && storedPresences != null)
            {
                storedPresences.add(presence);
                return;
            }
            try
            {
                Jid userID = presence.getFrom().asBareJid();
                OperationSetMultiUserChat mucOpSet =
                    parentProvider.getOperationSet(
                        OperationSetMultiUserChat.class);
                if(mucOpSet != null)
                {
                    List<ChatRoom> chatRooms
                        = mucOpSet.getCurrentlyJoinedChatRooms();
                    for(ChatRoom chatRoom : chatRooms)
                    {
                        if(chatRoom.getName().equals(userID.toString()))
                        {
                            userID = presence.getFrom();
                            break;
                        }
                    }
                }
                if (logger.isDebugEnabled())
                    logger.debug("Received a status update for buddy=" + userID);
                TreeSet<Presence> userStats = statuses.get(userID);
                if(userStats == null)
                {
                    userStats = new TreeSet<>(new Comparator<Presence>()
                     {
                        public int compare(Presence o1, Presence o2)
                        {
                            int res = o2.getPriority() - o1.getPriority();
                            if(res == 0)
                            {
                                res = jabberStatusToPresenceStatus(
                                        o2, parentProvider).getStatus()
                                      - jabberStatusToPresenceStatus(
                                            o1, parentProvider).getStatus();
                                if(res == 0)
                                {
                                    res = o1.getFrom().compareTo(
                                        o2.getFrom());
                                }
                            }
                            return res;
                        }
                    });
                    statuses.put(userID, userStats);
                }
                else
                {
                    Resourcepart resource = presence.getFrom().getResourceOrEmpty();
                    for (Iterator<Presence> iter = userStats.iterator();
                            iter.hasNext();)
                    {
                        Presence p = iter.next();
                        if (p.getFrom().getResourceOrEmpty().equals(resource))
                        {
                            iter.remove();
                        }
                    }
                }
                if(!jabberStatusToPresenceStatus(presence, parentProvider)
                        .equals(
                            parentProvider
                                .getJabberStatusEnum()
                                    .getStatus(JabberStatusEnum.OFFLINE)))
                {
                    userStats.add(presence);
                }
                Presence currentPresence;
                if (userStats.size() == 0)
                {
                    currentPresence = presence;
                    /*
                     * We no longer have statuses for userID so it doesn't make
                     * sense to retain (1) the TreeSet and (2) its slot in the
                     * statuses Map.
                     */
                    statuses.remove(userID);
                }
                else
                    currentPresence = userStats.first();
                ContactJabberImpl sourceContact
                    = ssContactList.findContactById(userID);
                if (sourceContact == null)
                {
                    logger.warn("No source contact found for id=" + userID);
                    return;
                }
                es may be the same and only change in status message
                sourceContact.setStatusMessage(currentPresence.getStatus());
                updateContactStatus(
                    sourceContact,
                    jabberStatusToPresenceStatus(
                        currentPresence, parentProvider));
            }
            catch (IllegalStateException | IllegalArgumentException ex)
            {
                logger.error("Failed changing status", ex);
            }
        }
void firePresenceStatusChanged ( Presence presence ) { if ( storeEvents && storedPresences != null ) { storedPresences . add ( presence ) ; return ; } try { Jid userID = presence . getFrom ( ) . asBareJid ( ) ; OperationSetMultiUserChat mucOpSet = parentProvider . getOperationSet ( OperationSetMultiUserChat . class ) ; if ( mucOpSet != null ) { List < ChatRoom > chatRooms = mucOpSet . getCurrentlyJoinedChatRooms ( ) ; for ( ChatRoom chatRoom : chatRooms ) { if ( chatRoom . getName ( ) . equals ( userID . toString ( ) ) ) { userID = presence . getFrom ( ) ; break ; } } } if ( logger . isDebugEnabled ( ) ) logger . debug ( "Received a status update for buddy=" + userID ) ; TreeSet < Presence > userStats = statuses . get ( userID ) ; if ( userStats == null ) { userStats = new TreeSet < > ( new Comparator < Presence > ( ) { public int compare ( Presence o1 , Presence o2 ) { int res = o2 . getPriority ( ) - o1 . getPriority ( ) ; if ( res == 0 ) { res = jabberStatusToPresenceStatus ( o2 , parentProvider ) . getStatus ( ) - jabberStatusToPresenceStatus ( o1 , parentProvider ) . getStatus ( ) ; if ( res == 0 ) { res = o1 . getFrom ( ) . compareTo ( o2 . getFrom ( ) ) ; } } return res ; } } ) ; statuses . put ( userID , userStats ) ; } else { Resourcepart resource = presence . getFrom ( ) . getResourceOrEmpty ( ) ; for ( Iterator < Presence > iter = userStats . iterator ( ) ; iter . hasNext ( ) ; ) { Presence p = iter . next ( ) ; if ( p . getFrom ( ) . getResourceOrEmpty ( ) . equals ( resource ) ) { iter . remove ( ) ; } } } if ( ! jabberStatusToPresenceStatus ( presence , parentProvider ) . equals ( parentProvider . getJabberStatusEnum ( ) . getStatus ( JabberStatusEnum . OFFLINE ) ) ) { userStats . add ( presence ) ; } Presence currentPresence ; if ( userStats . size ( ) == 0 ) { currentPresence = presence ; /*
                     * We no longer have statuses for userID so it doesn't make
                     * sense to retain (1) the TreeSet and (2) its slot in the
                     * statuses Map.
                     */ statuses . remove ( userID ) ; } else currentPresence = userStats . first ( ) ; ContactJabberImpl sourceContact = ssContactList . findContactById ( userID ) ; if ( sourceContact == null ) { logger . warn ( "No source contact found for id=" + userID ) ; return ; } sourceContact . setStatusMessage ( currentPresence . getStatus ( ) ) ; updateContactStatus ( sourceContact , jabberStatusToPresenceStatus ( currentPresence , parentProvider ) ) ; } catch ( IllegalStateException | IllegalArgumentException ex ) { logger . error ( "Failed changing status" , ex ) ; } }
Fires the status change, respecting resource priorities.
Fires the status change respecting resource priorities .
// all contact statuses that are received from all its resources // ordered by priority(higher first) and those with equal // priorities order with the one that is most connected as // first // if statuses are with same priorities // return which one is more available // counts the JabberStatusEnum order // We have run out of "logical" ways to order // the presences inside the TreeSet. We have // make sure we are consinstent with equals. // We do this by comparing the unique resource // names. If this evaluates to 0 again, then we // can safely assume this presence object // represents the same resource and by that the // same client. // remove the status for this resource // if we are online we will update its value with the new // status // statuses may be the same and only change in status message