aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/protocol/icq/OperationSetServerStoredContactInfoIcqImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/java/sip/communicator/impl/protocol/icq/OperationSetServerStoredContactInfoIcqImpl.java')
-rw-r--r--src/net/java/sip/communicator/impl/protocol/icq/OperationSetServerStoredContactInfoIcqImpl.java103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/icq/OperationSetServerStoredContactInfoIcqImpl.java b/src/net/java/sip/communicator/impl/protocol/icq/OperationSetServerStoredContactInfoIcqImpl.java
index 9811d85..664061e 100644
--- a/src/net/java/sip/communicator/impl/protocol/icq/OperationSetServerStoredContactInfoIcqImpl.java
+++ b/src/net/java/sip/communicator/impl/protocol/icq/OperationSetServerStoredContactInfoIcqImpl.java
@@ -10,6 +10,7 @@ import java.util.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.ServerStoredDetails.*;
+import net.java.sip.communicator.util.*;
/**
* @author Damian Minkov
@@ -17,7 +18,21 @@ import net.java.sip.communicator.service.protocol.ServerStoredDetails.*;
public class OperationSetServerStoredContactInfoIcqImpl
implements OperationSetServerStoredContactInfo
{
+ /**
+ * The logger.
+ */
+ private static final Logger logger =
+ Logger.getLogger(OperationSetServerStoredContactInfoIcqImpl.class);
+
private InfoRetreiver infoRetreiver;
+
+ /**
+ * If we got several listeners for the same contact lets retrieve once
+ * but deliver result to all.
+ */
+ private Hashtable<String, List<DetailsResponseListener>>
+ listenersForDetails =
+ new Hashtable<String, List<DetailsResponseListener>>();
/**
* The icq provider that created us.
@@ -126,4 +141,92 @@ public class OperationSetServerStoredContactInfoIcqImpl
"The icq provider must be signed on the ICQ service before "
+"being able to communicate.");
}
+
+ /**
+ * Requests all details existing for the specified contact.
+ * @param contact the specified contact
+ * @return a java.util.Iterator over all details existing for the specified
+ * contact.
+ */
+ public Iterator<GenericDetail> requestAllDetailsForContact(
+ final Contact contact, final DetailsResponseListener listener)
+ {
+ assertConnected();
+
+ List<GenericDetail> res =
+ infoRetreiver.getCachedContactDetails(contact.getAddress());
+
+ if(res != null)
+ {
+ if(contact.getImage() != null)
+ {
+ res.add(new ServerStoredDetails.ImageDetail(
+ "Image", contact.getImage()));
+ }
+ return res.iterator();
+ }
+
+ synchronized(listenersForDetails)
+ {
+ List<DetailsResponseListener> ls =
+ listenersForDetails.get(contact.getAddress());
+
+ boolean isFirst = false;
+ if(ls == null)
+ {
+ ls = new ArrayList<DetailsResponseListener>();
+ isFirst = true;
+ listenersForDetails.put(contact.getAddress(), ls);
+ }
+
+ if(!ls.contains(listener))
+ ls.add(listener);
+
+ // there is already scheduled retrieve, will deliver at listener.
+ if(!isFirst)
+ return null;
+ }
+
+ new Thread(new Runnable()
+ {
+ public void run()
+ {
+ List<GenericDetail> result =
+ infoRetreiver.retrieveDetails(contact.getAddress());
+
+ if(contact.getImage() != null)
+ {
+ result.add(new ServerStoredDetails.ImageDetail(
+ "Image", contact.getImage()));
+ }
+
+ List<DetailsResponseListener> listeners;
+
+ synchronized(listenersForDetails)
+ {
+ listeners =
+ listenersForDetails.remove(contact.getAddress());
+ }
+
+ if(listeners == null)
+ return;
+
+ for(DetailsResponseListener l : listeners)
+ {
+ try
+ {
+ l.detailsRetrieved(result.iterator());
+ }
+ catch(Throwable t)
+ {
+ logger.error(
+ "Error delivering for retrieved details", t);
+ }
+ }
+ }
+ }, getClass().getName() + ".RetrieveDetails").start();
+
+ // return null as there is no cache and we will try to retrieve
+ return null;
+ }
}