[sip-comm-cvs] CVS update: /sip-communicator/src/net/java/sip/communicator/impl/protocol/icq/, /sip-communicator/test/net/java/sip/communicator/slick/protocol/icq/

damencho at dev.java.net damencho at dev.java.net
Fri Apr 6 11:08:32 CEST 2007


User: damencho
Date: 2007-04-06 09:08:32+0000
Modified:
   sip-communicator/src/net/java/sip/communicator/impl/protocol/icq/OperationSetPersistentPresenceIcqImpl.java
   sip-communicator/src/net/java/sip/communicator/impl/protocol/icq/ContactGroupIcqImpl.java
   sip-communicator/src/net/java/sip/communicator/impl/protocol/icq/ServerStoredContactListIcqImpl.java
   sip-communicator/src/net/java/sip/communicator/impl/protocol/icq/VolatileBuddy.java
   sip-communicator/src/net/java/sip/communicator/impl/protocol/icq/OperationSetBasicInstantMessagingIcqImpl.java
   sip-communicator/src/net/java/sip/communicator/impl/protocol/icq/ProtocolProviderServiceIcqImpl.java
   sip-communicator/test/net/java/sip/communicator/slick/protocol/icq/TestOperationSetPersistentPresence.java
   sip-communicator/test/net/java/sip/communicator/slick/protocol/icq/TestOperationSetPresence.java

Log:
 1. Added AwaitingAuthorization group
 2. Support for Aim

File Changes:

Directory: /sip-communicator/src/net/java/sip/communicator/impl/protocol/icq/
=============================================================================

File [changed]: OperationSetPersistentPresenceIcqImpl.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/protocol/icq/OperationSetPersistentPresenceIcqImpl.java?r1=1.29&r2=1.30
Delta lines:  +288 -38
----------------------
--- OperationSetPersistentPresenceIcqImpl.java	2007-03-21 23:16:52+0000	1.29
+++ OperationSetPersistentPresenceIcqImpl.java	2007-04-06 09:08:30+0000	1.30
@@ -121,21 +121,33 @@
     private AuthListener authListener = new AuthListener();
 
     /**
+     * The timer scheduling task that will query awaiting authorization
+     * contacts for their status
+     */
+    private Timer presenceQueryTimer = null;
+    
+    /**
+     *  Interval between queries for awaiting authorization
+     *  contact statuses
+     */ 
+    private long PRESENCE_QUERY_INTERVAL = 120000l;
+
+    /**
+     *  Used to request authorization when a user comes online 
+     *  and haven't granted one
+     */
+    private OperationSetExtendedAuthorizationsIcqImpl opSetExtendedAuthorizations = null;
+    
+    /**
+     *  Buddies seen availabel
+     */
+    private Vector buddiesSeenAvailable = new Vector();
+    
+    /**
      * The array list we use when returning from the getSupportedStatusSet()
      * method.
      */
-    private static final ArrayList supportedPresenceStatusSet = new ArrayList();
-    static{
-        supportedPresenceStatusSet.add(IcqStatusEnum.AWAY);
-        supportedPresenceStatusSet.add(IcqStatusEnum.DO_NOT_DISTURB);
-        supportedPresenceStatusSet.add(IcqStatusEnum.FREE_FOR_CHAT);
-        supportedPresenceStatusSet.add(IcqStatusEnum.INVISIBLE);
-        supportedPresenceStatusSet.add(IcqStatusEnum.NOT_AVAILABLE);
-        supportedPresenceStatusSet.add(IcqStatusEnum.OCCUPIED);
-        supportedPresenceStatusSet.add(IcqStatusEnum.OFFLINE);
-        supportedPresenceStatusSet.add(IcqStatusEnum.ONLINE);
-    }
-
+    private ArrayList supportedPresenceStatusSet = new ArrayList();
 
     /**
      * A map containing bindings between SIP Communicator's icq presence status
@@ -584,10 +596,27 @@
 
         logger.trace("Going to remove contact from ss-list : " + contact);
         
+        if( !contactGroup.isPersistent()
+            && contactIcqImpl.getJoustSimBuddy().isAwaitingAuthorization())
+        {
+            // this is contact in AwaitingAuthorization group
+            // we must find the original parent and remove it from there
+            ContactGroupIcqImpl origParent = 
+                ssContactList.findGroup(contactIcqImpl.getJoustSimBuddy());
+            
+            if(origParent != null)
+            {
+                origParent.getJoustSimSourceGroup().
+                    deleteBuddy(contactIcqImpl.getJoustSimBuddy());
+            }
+        }
+        else
+        {
         MutableGroup joustSimContactGroup = contactGroup.getJoustSimSourceGroup();
 
         joustSimContactGroup.deleteBuddy(contactIcqImpl.getJoustSimBuddy());
     }
+    }
 
     /**
      * Returns a reference to the contact with the specified ID in case we have
@@ -639,8 +668,40 @@
         MainBosService bosService
             = icqProvider.getAimConnection().getBosService();
 
+        if(!icqProvider.USING_ICQ)
+        {
+            if(status.equals(IcqStatusEnum.AWAY))
+            {
+                if(getPresenceStatus().equals(IcqStatusEnum.INVISIBLE))
+                    bosService.setVisibleStatus(true);
+                
+                bosService.getOscarConnection().sendSnac(new SetInfoCmd(
+                    new InfoData(null, "I'm away!", null, null)));
+            }
+            else if(status.equals(IcqStatusEnum.INVISIBLE))
+            {
+                if(getPresenceStatus().equals(IcqStatusEnum.AWAY))
+                    bosService.getOscarConnection().sendSnac(new SetInfoCmd(
+                        new InfoData(null, InfoData.NOT_AWAY, null, null)));
+                
+                bosService.setVisibleStatus(false);
+            }
+            else if(status.equals(IcqStatusEnum.ONLINE))
+            {
+                if(getPresenceStatus().equals(IcqStatusEnum.INVISIBLE))
+                    bosService.setVisibleStatus(true);
+                else if(getPresenceStatus().equals(IcqStatusEnum.AWAY))
+                {
+                    bosService.getOscarConnection().sendSnac(new SetInfoCmd(
+                        new InfoData(null, InfoData.NOT_AWAY, null, null)));
+                }
+            }
+        }
+        else
+        {
         bosService.getOscarConnection().sendSnac(new SetExtraInfoCmd(icqStatus));
         bosService.setStatusMessage(statusMessage);
+        }
 
         //so that everyone sees the change.
         queryContactStatus(
@@ -765,6 +826,25 @@
                 "The specified group is not an icq contact group."
                 + newParent);
 
+        ContactGroupIcqImpl theAwaitingAuthorizationGroup = 
+            ssContactList.findContactGroup(
+                ssContactList.awaitingAuthorizationGroupName);
+        
+        if(newParent.equals(theAwaitingAuthorizationGroup))
+                throw new IllegalArgumentException(
+                "Cannot move contacts to this group : " + 
+                    theAwaitingAuthorizationGroup);
+        
+        if(((ContactIcqImpl)contactToMove).isPersistent() 
+            && !contactToMove.getParentContactGroup().isPersistent())
+        {
+            if(contactToMove.getParentContactGroup().equals(
+                theAwaitingAuthorizationGroup))
+                throw new IllegalArgumentException(
+                "Cannot move contacts from this group : " + 
+                    theAwaitingAuthorizationGroup);
+        }
+        
         ssContactList.moveContact((ContactIcqImpl)contactToMove,
                                   (ContactGroupIcqImpl)newParent);
     }
@@ -802,6 +882,23 @@
      */
     public Iterator getSupportedStatusSet()
     {
+        if(supportedPresenceStatusSet.size() == 0)
+        {
+            supportedPresenceStatusSet.add(IcqStatusEnum.ONLINE);
+            
+            if(icqProvider.USING_ICQ)
+            {
+                supportedPresenceStatusSet.add(IcqStatusEnum.DO_NOT_DISTURB);
+                supportedPresenceStatusSet.add(IcqStatusEnum.FREE_FOR_CHAT);
+                supportedPresenceStatusSet.add(IcqStatusEnum.NOT_AVAILABLE);
+                supportedPresenceStatusSet.add(IcqStatusEnum.OCCUPIED);                
+            }
+            
+            supportedPresenceStatusSet.add(IcqStatusEnum.AWAY);
+            supportedPresenceStatusSet.add(IcqStatusEnum.INVISIBLE);
+            supportedPresenceStatusSet.add(IcqStatusEnum.OFFLINE);
+        }
+        
         return supportedPresenceStatusSet.iterator();
     }
 
@@ -1250,6 +1347,25 @@
                 icqProvider.getAimConnection().getExternalServiceManager().
                     getIconServiceArbiter().addIconRequestListener(
                         new IconUpdateListener());
+                
+                if(icqProvider.USING_ICQ)
+                {
+                    opSetExtendedAuthorizations = 
+                        (OperationSetExtendedAuthorizationsIcqImpl)
+                            icqProvider.getSupportedOperationSets()
+                            .get(OperationSetExtendedAuthorizations.class.getName());
+                
+                    if(presenceQueryTimer == null)
+                        presenceQueryTimer = new Timer();
+                    else
+                        presenceQueryTimer.cancel();
+
+                    AwaitingAuthorizationContactsPresenceTimer
+                        queryTask = new AwaitingAuthorizationContactsPresenceTimer();
+
+                    presenceQueryTimer.scheduleAtFixedRate(
+                            queryTask, PRESENCE_QUERY_INTERVAL, PRESENCE_QUERY_INTERVAL);
+                }
             }
             else if(evt.getNewState() == RegistrationState.UNREGISTERED
                  || evt.getNewState() == RegistrationState.AUTHENTICATION_FAILED
@@ -1358,9 +1474,13 @@
         {
             logger.debug("Received our own user info: " + userInfo);
             logger.debug("previous status was: " + currentIcqStatus);
+            logger.debug("new status is: " + userInfo.getIcqStatus());
 
             //update the last received field.
             long oldStatus  = currentIcqStatus;
+            
+            if(icqProvider.USING_ICQ)
+            {
             currentIcqStatus = userInfo.getIcqStatus();
 
             //it might happen that the info here is -1 (in case we're going back
@@ -1374,6 +1494,24 @@
                 fireProviderPresenceStatusChangeEvent(oldStatus,
                                                       currentIcqStatus);
         }
+            else
+            {
+                if(userInfo.getAwayStatus() != null && userInfo.getAwayStatus().equals(Boolean.TRUE))
+                {
+                    currentIcqStatus = presenceStatusToIcqStatusLong(IcqStatusEnum.AWAY);
+                }
+                else if(userInfo.getIcqStatus() != -1)
+                {
+                    currentIcqStatus = userInfo.getIcqStatus();
+                }
+                else // online status
+                    currentIcqStatus = ICQ_ONLINE_MASK;                
+                
+                if( oldStatus != currentIcqStatus )
+                    fireProviderPresenceStatusChangeEvent(oldStatus,
+                                                        currentIcqStatus);
+            }
+        }
     }
 
     /**
@@ -1408,8 +1546,20 @@
             }
             PresenceStatus oldStatus
                 = sourceContact.getPresenceStatus();
-            PresenceStatus newStatus
-                = icqStatusLongToPresenceStatus(info.getIcqStatus());
+            
+            PresenceStatus newStatus = null;
+            
+            if(!icqProvider.USING_ICQ)
+            {
+                Boolean awayStatus = info.getAwayStatus();
+                if(awayStatus == null || awayStatus.equals(Boolean.FALSE))
+                    newStatus = IcqStatusEnum.ONLINE;
+                else
+                    newStatus = IcqStatusEnum.AWAY;
+            }
+            else
+                newStatus = icqStatusLongToPresenceStatus(info.getIcqStatus());
+            
             sourceContact.updatePresenceStatus(newStatus);
 
             ContactGroupIcqImpl parent
@@ -1493,12 +1643,21 @@
             authorizationHandler.processAuthorizationResponse(
                 new AuthorizationResponse(AuthorizationResponse.REJECT, reason)
                 , srcContact);
+            try
+            {
+                unsubscribe(srcContact);
+            } catch (OperationFailedException ex)
+            {
+                logger.error("cannot remove denied contact : " + srcContact, ex);
+            }
         }
 
         public void authorizationAccepted(Screenname screenname, String reason)
         {
             logger.trace("authorizationAccepted from " + screenname);
             Contact srcContact = findContactByID(screenname.getFormatted());
+            ssContactList.moveAwaitingAuthorizationContact(
+                (ContactIcqImpl)srcContact);
 
             authorizationHandler.processAuthorizationResponse(
                 new AuthorizationResponse(AuthorizationResponse.ACCEPT, reason)
@@ -1537,13 +1696,50 @@
             logger.trace("authorizationRequired from " + screenname);
 
             logger.trace("finding buddy : " + screenname);
-            Contact srcContact = findContactByID(screenname.getFormatted());
+            ContactIcqImpl srcContact = 
+                ssContactList.findContactByScreenName(screenname.getFormatted());
 
             if(srcContact == null)
             {
-                ContactGroup parent = ssContactList.findContactGroup(parentGroup);
-                srcContact = 
-                    createUnresolvedContact(screenname.getFormatted(), null, parent);
+                ContactGroupIcqImpl parent = 
+                    ssContactList.findContactGroup(parentGroup);
+                srcContact = ssContactList.
+                    createUnresolvedContact((ContactGroupIcqImpl)parent, screenname);
+                
+                Buddy buddy = ((ContactIcqImpl)srcContact).getJoustSimBuddy();
+                
+                if(buddy instanceof VolatileBuddy)
+                    ((VolatileBuddy)buddy).setAwaitingAuthorization(true);
+                
+                 ContactGroupIcqImpl theAwaitingAuthorizationGroup = 
+                     ssContactList.findContactGroup(ssContactList.awaitingAuthorizationGroupName);   
+                 
+                 
+                if(theAwaitingAuthorizationGroup == null)
+                {
+                    List emptyBuddies = new LinkedList();
+                    theAwaitingAuthorizationGroup = new ContactGroupIcqImpl(
+                        new VolatileGroup(ssContactList.awaitingAuthorizationGroupName), 
+                        emptyBuddies, ssContactList, false);
+
+                    ((RootContactGroupIcqImpl)ssContactList.getRootGroup()).
+                        addSubGroup(theAwaitingAuthorizationGroup);
+
+                    ssContactList.fireGroupEvent(theAwaitingAuthorizationGroup
+                        , ServerStoredGroupEvent.GROUP_CREATED_EVENT);
+                }
+                 
+                 
+                 ((ContactGroupIcqImpl)parent).removeContact(srcContact);
+                 theAwaitingAuthorizationGroup.addContact(srcContact);
+                 
+                 Object lock = new Object();
+                 synchronized(lock){
+                     try{ lock.wait(500); }catch(Exception e){}
+                 };
+                 
+                 fireSubscriptionMovedEvent(srcContact, 
+                     parent, theAwaitingAuthorizationGroup);
             }
 
             AuthorizationRequest authRequest =
@@ -1605,4 +1801,58 @@
                 contact.setImage(icon);
         }
     }
+    
+    private class AwaitingAuthorizationContactsPresenceTimer
+        extends TimerTask
+    {
+        public void run()
+        {
+            logger.trace("Running status retreiver for AwaitingAuthorizationContacts");
+            
+            ContactGroupIcqImpl theAwaitingAuthorizationGroup = 
+                ssContactList.findContactGroup(
+                    ssContactList.awaitingAuthorizationGroupName);
+            
+            if(theAwaitingAuthorizationGroup == null)
+                return;
+            
+            Iterator iter = theAwaitingAuthorizationGroup.contacts();
+            while (iter.hasNext())
+            {
+                ContactIcqImpl sourceContact = (ContactIcqImpl)iter.next();
+
+                PresenceStatus newStatus = queryContactStatus(sourceContact.getAddress());
+
+                PresenceStatus oldStatus
+                    = sourceContact.getPresenceStatus();
+                
+                if(newStatus.equals(oldStatus))
+                   continue; 
+
+                sourceContact.updatePresenceStatus(newStatus);
+
+                ContactGroupIcqImpl parent
+                    = ssContactList.findContactGroup(sourceContact);
+
+                fireContactPresenceStatusChangeEvent(sourceContact, theAwaitingAuthorizationGroup,
+                                                 oldStatus, newStatus);
+                
+                if( !newStatus.equals(IcqStatusEnum.OFFLINE) &&
+                    !buddiesSeenAvailable.contains(sourceContact.getAddress()))
+                {
+                    buddiesSeenAvailable.add(sourceContact.getAddress());
+                    try
+                    {
+                        AuthorizationRequest req = new AuthorizationRequest();
+                        req.setReason("I'm resending my request. Please authorize me!");
+                        
+                        opSetExtendedAuthorizations.reRequestAuthorization(req, sourceContact);
+                    } catch (OperationFailedException ex)
+                    {
+                        logger.error("failed to reRequestAuthorization", ex);
+                    }
+                }   
+            }           
+        }
+    }
 }
\ No newline at end of file

File [changed]: ContactGroupIcqImpl.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/protocol/icq/ContactGroupIcqImpl.java?r1=1.15&r2=1.16
Delta lines:  +11 -0
--------------------
--- ContactGroupIcqImpl.java	2006-09-29 14:29:51+0000	1.15
+++ ContactGroupIcqImpl.java	2007-04-06 09:08:30+0000	1.16
@@ -10,6 +10,7 @@
 
 import net.java.sip.communicator.service.protocol.*;
 import net.kano.joustsim.oscar.oscar.service.ssi.*;
+import net.java.sip.communicator.util.*;
 
 /**
  * The ICQ implementation of the ContactGroup interface. Intances of this class
@@ -88,6 +89,9 @@
 
         for (int i = 0; i < groupMembers.size(); i++)
         {
+            // here we are not checking for AwaitingAuthorization buddies
+            // as we are creating group with list of buddies
+            // these checks must have been made already
             addContact( new ContactIcqImpl((Buddy)groupMembers.get(i),
                                            ssclCallback, true, true) );
         }
@@ -529,6 +533,13 @@
         while(serverBuddiesIter.hasNext())
         {
             Buddy buddy = (Buddy)serverBuddiesIter.next();
+
+            if(buddy.isAwaitingAuthorization())
+            {
+                ssclCallback.addAwaitingAuthorizationContact(buddy);
+                continue;
+            }
+            
             ContactIcqImpl contact
                 = findContact(buddy.getScreenname().getFormatted());
 

File [changed]: ServerStoredContactListIcqImpl.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/protocol/icq/ServerStoredContactListIcqImpl.java?r1=1.27&r2=1.28
Delta lines:  +165 -10
----------------------
--- ServerStoredContactListIcqImpl.java	2007-02-08 14:54:46+0000	1.27
+++ ServerStoredContactListIcqImpl.java	2007-04-06 09:08:30+0000	1.28
@@ -94,7 +94,12 @@
     /**
      * Used for retrieveing missing nicks on specified contacts
      */
-    private NickRetriever nickRetriever = new NickRetriever();
+    private NickRetriever nickRetriever = null;
+    
+    /**
+     * Used for retrieveing missing nicks on specified contacts
+     */
+    static String awaitingAuthorizationGroupName = new String("Awaiting authorization");    
 
     /**
      * Creates a ServerStoredContactList wrapper for the specified BuddyList.
@@ -119,11 +124,16 @@
 
         // waiting for the first contact to come
         // to start retreiving the missing nicknames
+        if(icqProvider.USING_ICQ)
+        {
+            nickRetriever = new NickRetriever();
+            
         parentOperationSet.addContactPresenceStatusListener(nickRetriever);
 
         // start the nick retreiver thread
         nickRetriever.start();
     }
+    }
 
     /**
      * Returns the root group of the contact list.
@@ -169,7 +179,7 @@
      * @param group the ContactGroup that has been created/modified/removed
      * @param eventID the id of the event to generate.
      */
-    private void fireGroupEvent(ContactGroupIcqImpl group, int eventID)
+    void fireGroupEvent(ContactGroupIcqImpl group, int eventID)
     {
         //bail out if no one's listening
         if(parentOperationSet == null){
@@ -462,6 +472,7 @@
      */
     ContactIcqImpl createVolatileContact(Screenname screenname)
     {
+        logger.trace("createVolatileContact " + screenname);
         //First create the new volatile contact;
         Buddy volatileBuddy = new VolatileBuddy(screenname);
 
@@ -512,6 +523,7 @@
     ContactIcqImpl createUnresolvedContact(ContactGroupIcqImpl parentGroup,
                                            Screenname  screenname)
     {
+        logger.trace("createUnresolvedContact " + screenname);
         //First create the new volatile contact;
         Buddy volatileBuddy = new VolatileBuddy(screenname);
 
@@ -704,7 +716,8 @@
             ContactGroupIcqImpl gr =
                 (ContactGroupIcqImpl)getRootGroup().getGroup(i);
 
-            if(!gr.isPersistent())
+            if(!gr.isPersistent() && 
+                    !gr.getGroupName().equals(awaitingAuthorizationGroupName))
                 return gr;
         }
 
@@ -721,9 +734,117 @@
      */
     protected void addContactForUpdate(ContactIcqImpl c)
     {
+        if(icqProvider.USING_ICQ)
         nickRetriever.addContact(c);
     }
 
+    protected void addAwaitingAuthorizationContact(Buddy buddy)
+    {
+        //Check whether a Awaiting authorization group already exists and if not create
+        //one
+        ContactGroupIcqImpl theAwaitingAuthorizationGroup = 
+                findContactGroup(awaitingAuthorizationGroupName);
+        
+        if(theAwaitingAuthorizationGroup == null)
+        {
+            List emptyBuddies = new LinkedList();
+            theAwaitingAuthorizationGroup = new ContactGroupIcqImpl(
+                new VolatileGroup(awaitingAuthorizationGroupName), emptyBuddies, this, false);
+
+            this.rootGroup.addSubGroup(theAwaitingAuthorizationGroup);
+
+            fireGroupEvent(theAwaitingAuthorizationGroup
+                           , ServerStoredGroupEvent.GROUP_CREATED_EVENT);
+        }        
+
+        ContactGroupIcqImpl oldParentGroup = null;
+        ContactIcqImpl newContact
+                = findContactByScreenName(buddy.getScreenname().getFormatted());
+
+        if(newContact != null)
+            oldParentGroup = (ContactGroupIcqImpl)newContact.getParentContactGroup();
+
+        boolean fireResolvedEvent = false;
+
+        if(newContact == null)
+        {
+            newContact = new ContactIcqImpl(
+                buddy, ServerStoredContactListIcqImpl.this, true, true);
+        }
+        else
+        {
+            oldParentGroup.removeContact(newContact);
+            
+            newContact.setJoustSimBuddy(buddy);
+            newContact.setPersistent(true);
+            if(!newContact.isResolved())
+            {
+                newContact.setResolved(true);
+                fireResolvedEvent = true;
+            }
+        }
+
+        theAwaitingAuthorizationGroup.addContact(newContact);
+
+        int index = theAwaitingAuthorizationGroup.findContactIndex(newContact);
+
+        //register a listener for name changes of this buddy
+        buddy.addBuddyListener(jsimBuddyListener);
+
+        //tell listeners about the added group
+        if(oldParentGroup == null)
+        {
+            fireContactAdded(theAwaitingAuthorizationGroup, newContact, index);
+        }
+        else if(oldParentGroup != theAwaitingAuthorizationGroup)
+        {
+            fireContactMoved(oldParentGroup, theAwaitingAuthorizationGroup
+                             , newContact, index);
+        }
+
+        //fire an event in case the contact has just been resolved.
+        if(fireResolvedEvent)
+        {
+            fireContactResolved(theAwaitingAuthorizationGroup, newContact);
+        }
+    }
+    
+    protected void moveAwaitingAuthorizationContact(ContactIcqImpl contact)
+    {
+        ContactGroupIcqImpl parentGroup = findGroup(contact.getJoustSimBuddy());
+        
+        if(parentGroup == null)
+            return;
+        
+        findContactGroup(awaitingAuthorizationGroupName).removeContact(contact);
+        parentGroup.addContact(contact);
+        
+        fireContactMoved(findContactGroup(awaitingAuthorizationGroupName),
+            parentGroup, contact, parentGroup.findContactIndex(contact));
+    }
+    
+    ContactGroupIcqImpl findGroup(Buddy buddy)
+    {
+        Iterator iter = rootGroup.subgroups();
+        while (iter.hasNext())
+        {
+            ContactGroupIcqImpl elem = (ContactGroupIcqImpl) iter.next();
+            
+            if(!elem.isPersistent() || !elem.isResolved())
+                continue;
+            
+            Iterator bs = elem.getJoustSimSourceGroup().getBuddiesCopy().iterator();
+            while (bs.hasNext())
+            {
+                Buddy b = (Buddy) bs.next();
+                if(b == buddy)
+                    return elem;
+            }
+        }
+        
+        return null;
+    }
+
     private class BuddyListListener
         implements BuddyListLayoutListener
     {
@@ -850,6 +971,7 @@
         public void buddyAdded(BuddyList list, Group joustSimGroup, List oldItems,
                                List newItems, Buddy buddy)
         {
+            logger.trace("Received buddyAdded " + buddy);
             //it is possible that the buddy being added is already in our
             //contact list. For example if they have sent a message to us they
             //would have been added to the local contact list as a
@@ -871,6 +993,12 @@
                 return;
             }
 
+            if(buddy.isAwaitingAuthorization())
+            {
+                addAwaitingAuthorizationContact(buddy);
+                return;
+            }
+
             if(newContact == null)
             {
                 newContact = new ContactIcqImpl(
@@ -931,12 +1059,39 @@
             ContactGroupIcqImpl parentGroup = findContactGroup(group);
             ContactIcqImpl contactToRemove = parentGroup.findContact(buddy);
 
+            if(contactToRemove == null)
+            {
+                // this buddy is not in this group
+                // it can be in awaiting authorization group
+                // will search it there
+                
+                ContactGroupIcqImpl theAwaitingAuthorizationGroup = 
+                    findContactGroup(awaitingAuthorizationGroupName);
+                if(theAwaitingAuthorizationGroup != null)
+                {
+                    contactToRemove = 
+                        theAwaitingAuthorizationGroup.
+                            findContact(buddy.getScreenname().getFormatted());
+                    
+                    if(contactToRemove == null)
+                        return;
+                    
+                    theAwaitingAuthorizationGroup.removeContact(contactToRemove);
+
+                    buddy.removeBuddyListener(jsimBuddyListener);
+
+                    fireContactRemoved(theAwaitingAuthorizationGroup, contactToRemove);
+                }
+            }
+            else
+            {
             parentGroup.removeContact(contactToRemove);
 
             buddy.removeBuddyListener(jsimBuddyListener);
 
             fireContactRemoved(parentGroup, contactToRemove);
         }
+        }
 
         /**
          * Called by joust sim when contacts in a group have been reordered.

File [changed]: VolatileBuddy.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/protocol/icq/VolatileBuddy.java?r1=1.4&r2=1.5
Delta lines:  +13 -2
--------------------
--- VolatileBuddy.java	2006-08-10 08:36:56+0000	1.4
+++ VolatileBuddy.java	2007-04-06 09:08:30+0000	1.5
@@ -20,6 +20,12 @@
     private Screenname screenname = null;
 
     /**
+     *  Use when creating unresolved contact during authorization process
+     *  to display contact in the group with awaiting authorization contacts
+     */
+    private boolean isAwaitingAuthorization = false;
+
+    /**
      * Constructs a <tt>VolatileBuddy</tt> from the specified screenname.
      * @param screenname the <tt>screenname</tt> to construct the buddy from.
      */
@@ -56,5 +62,10 @@
     public BuddyList getBuddyList(){return null;}
     public boolean isActive(){return false;}
     public void removeBuddyListener(BuddyListener listener){}
-    public boolean isAwaitingAuthorization(){return false;}
+    public boolean isAwaitingAuthorization(){return isAwaitingAuthorization;}
+    
+    public void setAwaitingAuthorization(boolean value)
+    {
+        this.isAwaitingAuthorization = value;
+    }
 }

File [changed]: OperationSetBasicInstantMessagingIcqImpl.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/protocol/icq/OperationSetBasicInstantMessagingIcqImpl.java?r1=1.19&r2=1.20
Delta lines:  +6 -2
-------------------
--- OperationSetBasicInstantMessagingIcqImpl.java	2007-03-07 21:52:28+0000	1.19
+++ OperationSetBasicInstantMessagingIcqImpl.java	2007-04-06 09:08:30+0000	1.20
@@ -365,7 +365,10 @@
      */
     public boolean isOfflineMessagingSupported()
     {
+        if(icqProvider.USING_ICQ)
         return true;
+        else
+            return false;
     }
 
     /**
@@ -397,6 +400,7 @@
                     icqProvider.getSupportedOperationSets()
                         .get(OperationSetPersistentPresence.class.getName());
 
+                if(icqProvider.USING_ICQ)
                 retreiveOfflineMessages();
 
                 // run keepalive thread

File [changed]: ProtocolProviderServiceIcqImpl.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/protocol/icq/ProtocolProviderServiceIcqImpl.java?r1=1.30&r2=1.31
Delta lines:  +48 -31
---------------------
--- ProtocolProviderServiceIcqImpl.java	2007-02-28 14:34:17+0000	1.30
+++ ProtocolProviderServiceIcqImpl.java	2007-04-06 09:08:30+0000	1.31
@@ -92,6 +92,11 @@
         = new ProtocolIconIcqImpl();
     
     /**
+     *  Property whether we are using AIM or ICQ service
+     */
+    boolean USING_ICQ = true;
+    
+    /**
      * Returns the state of the registration of this protocol provider
      * @return the <tt>RegistrationState</tt> that this provider is
      * currently in or null in case it is in a unknown state.
@@ -382,6 +387,15 @@
         {
             this.accountID = accountID;
 
+            try
+            {
+                Long.parseLong(accountID.getUserID());
+            } catch (NumberFormatException ex)
+            {
+                // if its icq its number can be parsed
+                USING_ICQ = false;
+            }
+            
             //initialize the presence operationset
             OperationSetPersistentPresence persistentPresence =
                 new OperationSetPersistentPresenceIcqImpl(this, screenname);
@@ -410,6 +424,8 @@
                 OperationSetTypingNotifications.class.getName(),
                 typingNotifications);
 
+            if(USING_ICQ)
+            {
             this.infoRetreiver = new InfoRetreiver(this, screenname);
 
             OperationSetServerStoredContactInfo serverStoredContactInfo =
@@ -445,6 +461,7 @@
             supportedOperationSets.put(
                 OperationSetExtendedAuthorizations.class.getName(),
                 extendedAuth);
+            }
             
             isInitialized = true;
         }

Directory: /sip-communicator/test/net/java/sip/communicator/slick/protocol/icq/
===============================================================================

File [changed]: TestOperationSetPersistentPresence.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/test/net/java/sip/communicator/slick/protocol/icq/TestOperationSetPersistentPresence.java?r1=1.13&r2=1.14
Delta lines:  +2 -1
-------------------
--- TestOperationSetPersistentPresence.java	2006-09-27 12:30:01+0000	1.13
+++ TestOperationSetPersistentPresence.java	2007-04-06 09:08:30+0000	1.14
@@ -141,7 +141,8 @@
             // the sever creates a group NotInContactList,
             // beacuse the buddy we are sending message to is not in
             // the contactlist. So this group must be ignored
-            if(!group.getGroupName().equals("NotInContactList"))
+            // all not persistent groups must be ignored
+            if(group.isPersistent())
             {
                 assertNotNull("Group " + group.getGroupName() +
                               " was returned by "

File [changed]: TestOperationSetPresence.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/test/net/java/sip/communicator/slick/protocol/icq/TestOperationSetPresence.java?r1=1.32&r2=1.33
Delta lines:  +20 -5
--------------------
--- TestOperationSetPresence.java	2007-03-28 20:45:00+0000	1.32
+++ TestOperationSetPresence.java	2007-04-06 09:08:30+0000	1.33
@@ -576,11 +576,26 @@
             operationSetPresence.removeSubscriptionListener(subEvtCollector);
         }
         
-        assertEquals("Subscription event dispatching failed."
-                     , 1, subEvtCollector.collectedEvents.size());
-
-        EventObject evt =
-            (EventObject)subEvtCollector.collectedEvents.get(0);
+        // after adding awaitingAuthorization group here are catched 3 events
+        // 1 - creating unresolved contact
+        // 2 - move of the contact to awaitingAuthorization group 
+        // 3 - move of the contact from awaitingAuthorization group to original group
+        assertTrue("Subscription event dispatching failed."
+                     , subEvtCollector.collectedEvents.size() > 0);
+
+        EventObject evt = null;
+        
+        Iterator events = subEvtCollector.collectedEvents.iterator();
+        while (events.hasNext())
+        {
+            Object elem = events.next();
+            if(elem instanceof SubscriptionEvent)
+            {
+                if(((SubscriptionEvent)elem).getEventID() 
+                    == SubscriptionEvent.SUBSCRIPTION_CREATED)
+                    evt = (SubscriptionEvent)elem;
+            }
+        }
 
         Object source = null;
         Contact srcContact = null;




---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe at sip-communicator.dev.java.net
For additional commands, e-mail: cvs-help at sip-communicator.dev.java.net





More information about the commits mailing list