src/net/java/sip/communicator/impl/protocol/jabber/ServerStoredContactListJabberImpl.java
/**
     * When the protocol is online this method is used to fill or resolve
     * the current contact list
     */
When the protocol is online this method is used to fill or resolve
the current contact list
When the protocol is online this method is used to fill or resolve the current contact list
private synchronized void initRoster()
    {
        if(roster.getUnfiledEntryCount() > 0)
        {
            for (RosterEntry item : roster.getUnfiledEntries())
            {
                ContactJabberImpl contact =
                    findContactById(item.getJid());
                if(!isEntryDisplayable(item))
                {
                    if(contact != null)
                    {
                        ContactGroup parent = contact.getParentContactGroup();
                        if(parent instanceof RootContactGroupJabberImpl)
                            ((RootContactGroupJabberImpl)parent)
                                .removeContact(contact);
                        else
                            ((ContactGroupJabberImpl)parent)
                                .removeContact(contact);
                        fireContactRemoved(parent, contact);
                    }
                    continue;
                }
                if(contact == null)
                {
                    contact = new ContactJabberImpl(item, this, true, true);
                    rootGroup.addContact(contact);
                    fireContactAdded(rootGroup, contact);
                }
                else
                {
                    ContactGroup group = contact.getParentContactGroup();
                    if(!rootGroup.equals(group))
                    {
                        contactMoved(group, rootGroup, contact);
                    }
                    contact.setResolved(item);
                    fireContactResolved(rootGroup, contact);
                }
                try
                {
                    parentOperationSet.firePresenceStatusChanged(
                        roster.getPresence(item.getJid()));
                }
                catch(Throwable t)
                {
                    logger.error("Error processing presence", t);
                }
            }
        }
        Iterator<Contact> iter = rootGroup.contacts();
        List<ContactJabberImpl> contactsToRemove
            = new ArrayList<ContactJabberImpl>();
        while(iter.hasNext())
        {
            ContactJabberImpl contact = (ContactJabberImpl)iter.next();
            if(!contact.isResolved())
            {
                contactsToRemove.add(contact);
            }
        }
        for(ContactJabberImpl contact : contactsToRemove)
        {
            rootGroup.removeContact(contact);
            fireContactRemoved(rootGroup, contact);
        }
        contactsToRemove.clear();
        for (RosterGroup item : roster.getGroups())
        {
            ContactGroupJabberImpl group =
                findContactGroup(item.getName());
            if(group != null)
            {
                group.setResolved(item);
                fireGroupEvent(group
                               , ServerStoredGroupEvent.GROUP_RESOLVED_EVENT);
            }
        }
        Iterator<ContactGroup> iterGroups = rootGroup.subgroups();
        List<ContactGroupJabberImpl> groupsToRemove
            = new ArrayList<ContactGroupJabberImpl>();
        while(iterGroups.hasNext())
        {
            ContactGroupJabberImpl group =
                (ContactGroupJabberImpl)iterGroups.next();
            if(!group.isPersistent())
                continue;
            if(!group.isResolved())
            {
                groupsToRemove.add(group);
            }
            Iterator<Contact> iterContacts = group.contacts();
            while(iterContacts.hasNext())
            {
                ContactJabberImpl contact =
                    (ContactJabberImpl)iterContacts.next();
                if(!contact.isResolved())
                {
                    contactsToRemove.add(contact);
                }
            }
            for(ContactJabberImpl contact : contactsToRemove)
            {
                group.removeContact(contact);
                fireContactRemoved(group, contact);
            }
            contactsToRemove.clear();
        }
        for(ContactGroupJabberImpl group: groupsToRemove)
        {
            rootGroup.removeSubGroup(group);
            fireGroupEvent(
                group, ServerStoredGroupEvent.GROUP_REMOVED_EVENT);
        }
        for (RosterGroup item : roster.getGroups())
        {
            ContactGroupJabberImpl group =
                findContactGroup(item.getName());
            if(group == null)
            {
                ContactGroupJabberImpl newGroup = new ContactGroupJabberImpl(
                    item, item.getEntries().iterator(), this, true);
                rootGroup.addSubGroup(newGroup);
                fireGroupEvent(newGroup
                               , ServerStoredGroupEvent.GROUP_CREATED_EVENT);
                if(roster != null)
                {
                    Iterator<Contact> cIter = newGroup.contacts();
                    while(cIter.hasNext())
                    {
                        Jid address = ((ContactJabberImpl)cIter.next())
                                .getAddressAsJid();
                        parentOperationSet.firePresenceStatusChanged(
                            roster.getPresence(address.asBareJid()));
                    }
                }
            }
        }
    }
private synchronized void initRoster ( ) { if ( roster . getUnfiledEntryCount ( ) > 0 ) { for ( RosterEntry item : roster . getUnfiledEntries ( ) ) { ContactJabberImpl contact = findContactById ( item . getJid ( ) ) ; if ( ! isEntryDisplayable ( item ) ) { if ( contact != null ) { ContactGroup parent = contact . getParentContactGroup ( ) ; if ( parent instanceof RootContactGroupJabberImpl ) ( ( RootContactGroupJabberImpl ) parent ) . removeContact ( contact ) ; else ( ( ContactGroupJabberImpl ) parent ) . removeContact ( contact ) ; fireContactRemoved ( parent , contact ) ; } continue ; } if ( contact == null ) { contact = new ContactJabberImpl ( item , this , true , true ) ; rootGroup . addContact ( contact ) ; fireContactAdded ( rootGroup , contact ) ; } else { ContactGroup group = contact . getParentContactGroup ( ) ; if ( ! rootGroup . equals ( group ) ) { contactMoved ( group , rootGroup , contact ) ; } contact . setResolved ( item ) ; fireContactResolved ( rootGroup , contact ) ; } try { parentOperationSet . firePresenceStatusChanged ( roster . getPresence ( item . getJid ( ) ) ) ; } catch ( Throwable t ) { logger . error ( "Error processing presence" , t ) ; } } } Iterator < Contact > iter = rootGroup . contacts ( ) ; List < ContactJabberImpl > contactsToRemove = new ArrayList < ContactJabberImpl > ( ) ; while ( iter . hasNext ( ) ) { ContactJabberImpl contact = ( ContactJabberImpl ) iter . next ( ) ; if ( ! contact . isResolved ( ) ) { contactsToRemove . add ( contact ) ; } } for ( ContactJabberImpl contact : contactsToRemove ) { rootGroup . removeContact ( contact ) ; fireContactRemoved ( rootGroup , contact ) ; } contactsToRemove . clear ( ) ; for ( RosterGroup item : roster . getGroups ( ) ) { ContactGroupJabberImpl group = findContactGroup ( item . getName ( ) ) ; if ( group != null ) { group . setResolved ( item ) ; fireGroupEvent ( group , ServerStoredGroupEvent . GROUP_RESOLVED_EVENT ) ; } } Iterator < ContactGroup > iterGroups = rootGroup . subgroups ( ) ; List < ContactGroupJabberImpl > groupsToRemove = new ArrayList < ContactGroupJabberImpl > ( ) ; while ( iterGroups . hasNext ( ) ) { ContactGroupJabberImpl group = ( ContactGroupJabberImpl ) iterGroups . next ( ) ; if ( ! group . isPersistent ( ) ) continue ; if ( ! group . isResolved ( ) ) { groupsToRemove . add ( group ) ; } Iterator < Contact > iterContacts = group . contacts ( ) ; while ( iterContacts . hasNext ( ) ) { ContactJabberImpl contact = ( ContactJabberImpl ) iterContacts . next ( ) ; if ( ! contact . isResolved ( ) ) { contactsToRemove . add ( contact ) ; } } for ( ContactJabberImpl contact : contactsToRemove ) { group . removeContact ( contact ) ; fireContactRemoved ( group , contact ) ; } contactsToRemove . clear ( ) ; } for ( ContactGroupJabberImpl group : groupsToRemove ) { rootGroup . removeSubGroup ( group ) ; fireGroupEvent ( group , ServerStoredGroupEvent . GROUP_REMOVED_EVENT ) ; } for ( RosterGroup item : roster . getGroups ( ) ) { ContactGroupJabberImpl group = findContactGroup ( item . getName ( ) ) ; if ( group == null ) { ContactGroupJabberImpl newGroup = new ContactGroupJabberImpl ( item , item . getEntries ( ) . iterator ( ) , this , true ) ; rootGroup . addSubGroup ( newGroup ) ; fireGroupEvent ( newGroup , ServerStoredGroupEvent . GROUP_CREATED_EVENT ) ; if ( roster != null ) { Iterator < Contact > cIter = newGroup . contacts ( ) ; while ( cIter . hasNext ( ) ) { Jid address = ( ( ContactJabberImpl ) cIter . next ( ) ) . getAddressAsJid ( ) ; parentOperationSet . firePresenceStatusChanged ( roster . getPresence ( address . asBareJid ( ) ) ) ; } } } } }
When the protocol is online this method is used to fill or resolve
 the current contact list
When the protocol is online this method is used to fill or resolve the current contact list
// first if unfiled entries will move them in a group // some services automatically add contacts from their // addressbook to the roster and those contacts are // with subscription none. If such already exist, // remove them. This is typically our own contact // if there is no such contact create it // if contact exist so resolve it //fire an event saying that the unfiled contact has been //resolved // process status if any that was received // while the roster reply packet was received and // added our presence listener // Fixes a problem where Presence packets can be received // before the roster items packet, and we miss it, // cause we add our listener after roster is received // and smack don't allow to add our listener earlier // now search all root contacts for unresolved ones // the group exist so just resolved. The group will check and // create or resolve its entries //fire an event saying that the group has been resolved // skip non persistent groups // fill in root group // create the group as it doesn't exist //tell listeners about the added group // if presence was already received it, // we must check & dispatch it