r6926 - in dumbhippo/trunk: . openfire/src/plugins/hippo/src/java/com/dumbhippo/jive server/src/com/dumbhippo/server server/src/com/dumbhippo/server/dm server/src/com/dumbhippo/server/impl



Author: hp
Date: 2007-11-19 13:32:41 -0600 (Mon, 19 Nov 2007)
New Revision: 6926

Modified:
   dumbhippo/trunk/.classpath
   dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/ContactsIQHandler.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/IdentitySpider.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ContactDMO.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/dm/UserDMO.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java
Log:
add xmpps property to ContactDMO; add setContactStatus operating on a contact

Modified: dumbhippo/trunk/.classpath
===================================================================
--- dumbhippo/trunk/.classpath	2007-11-16 23:56:40 UTC (rev 6925)
+++ dumbhippo/trunk/.classpath	2007-11-19 19:32:41 UTC (rev 6926)
@@ -112,5 +112,6 @@
 	<classpathentry kind="lib" path="openfire/src/plugins/userImportExport/lib/msv.jar"/>
 	<classpathentry kind="lib" path="openfire/src/plugins/userImportExport/lib/isorelax.jar"/>
 	<classpathentry kind="var" path="HIPPO_TRUNK_LIB/server/dom4j-1.6.1.jar"/>
+	<classpathentry kind="lib" path="lib/server/facebook.jar"/>
 	<classpathentry kind="output" path="eclipse-build"/>
 </classpath>

Modified: dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/ContactsIQHandler.java
===================================================================
--- dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/ContactsIQHandler.java	2007-11-16 23:56:40 UTC (rev 6925)
+++ dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/ContactsIQHandler.java	2007-11-19 19:32:41 UTC (rev 6926)
@@ -4,9 +4,11 @@
 
 import com.dumbhippo.jive.annotations.IQHandler;
 import com.dumbhippo.jive.annotations.IQMethod;
+import com.dumbhippo.persistence.Contact;
 import com.dumbhippo.persistence.ContactStatus;
 import com.dumbhippo.persistence.User;
 import com.dumbhippo.server.IdentitySpider;
+import com.dumbhippo.server.dm.ContactDMO;
 import com.dumbhippo.server.dm.UserDMO;
 import com.dumbhippo.server.util.EJBUtil;
 import com.dumbhippo.server.views.UserViewpoint;
@@ -19,9 +21,9 @@
 		super("Mugshot contacts IQ Handler");
 	}
 
-	@IQMethod(name="setContactStatus", type=IQ.Type.set)
+	@IQMethod(name="setUserContactStatus", type=IQ.Type.set)
 	@IQParams({ "user", "status" })
-	public void setContactStatus(UserViewpoint viewpoint, UserDMO userDMO, int statusOrdinal) throws IQException {
+	public void setUserContactStatus(UserViewpoint viewpoint, UserDMO userDMO, int statusOrdinal) throws IQException {
 		IdentitySpider identitySpider = EJBUtil.defaultLookup(IdentitySpider.class);
 		
 		User user = identitySpider.lookupUser(userDMO.getKey());
@@ -38,4 +40,23 @@
 		identitySpider.setContactStatus(viewpoint, user, status);
 	}
 
+	@IQMethod(name="setContactStatus", type=IQ.Type.set)
+	@IQParams({ "contact", "status" })
+	public void setContactStatus(UserViewpoint viewpoint, ContactDMO contactDMO, int statusOrdinal) throws IQException {
+		IdentitySpider identitySpider = EJBUtil.defaultLookup(IdentitySpider.class);
+		
+		Contact contact = identitySpider.lookupContact(contactDMO.getKey());
+		if (contact == null)
+			throw IQException.createBadRequest("Unknown contact " + contactDMO.getKey());
+		
+		ContactStatus status;
+		try {
+			 status = ContactStatus.values()[statusOrdinal];
+		} catch (ArrayIndexOutOfBoundsException e) {
+			throw IQException.createBadRequest("Bad contact status " + statusOrdinal); 
+		}
+		
+		identitySpider.setContactStatus(viewpoint, contact, status);
+	}
+	
 }

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/IdentitySpider.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/IdentitySpider.java	2007-11-16 23:56:40 UTC (rev 6925)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/IdentitySpider.java	2007-11-19 19:32:41 UTC (rev 6926)
@@ -164,6 +164,8 @@
 	 */
 	public User lookupUser(Guid guid);
 	
+	public Contact lookupContact(Guid guid);
+	
 	public <T extends GuidPersistable> T lookupGuidString(Class<T> klass, String id) throws ParseException, NotFoundException;
 	public <T extends GuidPersistable> T lookupGuid(Class<T> klass, Guid id) throws NotFoundException;
 	
@@ -239,6 +241,8 @@
 	
 	public void setContactStatus(UserViewpoint viewpoint, User contactUser, ContactStatus status);
 
+	public void setContactStatus(UserViewpoint viewpoint, Contact contact, ContactStatus status);
+	
 	/** 
 	 * Get all Contact objects associated with a given user. "Get my address book entries."
 	 * Not all Contact in the list will have an associated User

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ContactDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ContactDMO.java	2007-11-16 23:56:40 UTC (rev 6925)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ContactDMO.java	2007-11-19 19:32:41 UTC (rev 6926)
@@ -18,8 +18,21 @@
 import com.dumbhippo.persistence.ContactClaim;
 import com.dumbhippo.persistence.EmailResource;
 import com.dumbhippo.persistence.Resource;
+import com.dumbhippo.persistence.XmppResource;
 import com.dumbhippo.server.NotFoundException;
 
+/** 
+ * ContactDMO is not quite a straight wrapper of a Contact in the database, because 
+ * we go ahead and merge the info from the User a contact refers to. This is done 
+ * on the server side because if we had a web view of contacts, we'd want it to 
+ * be consistent with the client.
+ * 
+ * There are several downsides to this approach, though; the change notification 
+ * is busted right now, i.e. changing the User won't update the Contact. In addition 
+ * this approach means sending some info to the client twice, once in the User object
+ * and once as part of the Contact.
+ *
+ */
 @DMO(classId="http://online.gnome.org/p/o/contact";, resourceBase="/o/contact")
 @DMFilter("viewer.canSeeContact(this)")
 public abstract class ContactDMO extends DMObject<Guid> {
@@ -45,7 +58,16 @@
 
 	@DMProperty(defaultInclude=true)
 	public String getName() {
-		return contact.getNickname();
+		String nick = contact.getNickname();
+		if (nick == null) {
+			UserDMO user = getUser();
+			if (user != null)
+				return user.getName();
+			else
+				return null;
+		} else {
+			return nick;
+		}
 	}
 	
 	private UserDMO getUserDMOFromAccount(Account account) {
@@ -103,6 +125,26 @@
 	}	
 	
 	@DMProperty(defaultInclude=true)
+	public Set<String> getXmpps() {
+		Set<String> results = new HashSet<String>();
+		
+		for (ContactClaim cc : contact.getResources()) {
+			Resource r = cc.getResource();
+			if (r instanceof XmppResource)
+				results.add(((XmppResource)r).getJid());
+		}
+		
+		// merge in any xmpps from the User if we can see them
+		UserDMO user = getUser();
+		if (user != null) {
+			// user.getXmpps() should be filtered to our viewpoint already
+			results.addAll(user.getXmpps());
+		}
+		
+		return results;
+	}		
+	
+	@DMProperty(defaultInclude=true)
 	public UserDMO getUser() {
 		for (ContactClaim cc : contact.getResources()) {
 			Resource r = cc.getResource();

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/UserDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/UserDMO.java	2007-11-16 23:56:40 UTC (rev 6925)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/UserDMO.java	2007-11-19 19:32:41 UTC (rev 6926)
@@ -322,6 +322,19 @@
 	}
 
 	@DMProperty
+	@DMFilter("viewer.canSeeFriendsOnly(this)")
+	public Set<String> getXmpps() {
+		Set<String> results = new HashSet<String>();
+		for (AccountClaim ac : user.getAccountClaims()) {
+			Resource r = ac.getResource();
+			if (r instanceof XmppResource)
+				results.add(((XmppResource)r).getJid());
+		}
+		
+		return results;
+	}	
+	
+	@DMProperty
 	@DMFilter("viewer.canSeePrivate(this)")
 	public Set<String> getGoogleEnabledEmails() {
 		Set<String> results = new HashSet<String>();

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java	2007-11-16 23:56:40 UTC (rev 6925)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java	2007-11-19 19:32:41 UTC (rev 6926)
@@ -63,6 +63,7 @@
 import com.dumbhippo.server.NotFoundException;
 import com.dumbhippo.server.Notifier;
 import com.dumbhippo.server.RevisionControl;
+import com.dumbhippo.server.dm.ContactDMO;
 import com.dumbhippo.server.dm.DataService;
 import com.dumbhippo.server.dm.UserClientMatcher;
 import com.dumbhippo.server.dm.UserDMO;
@@ -133,6 +134,10 @@
 		return em.find(User.class, guid.toString());
 	}
 	
+	public Contact lookupContact(Guid guid) {
+		return em.find(Contact.class, guid.toString());
+	}
+	
 	public <T extends GuidPersistable> T lookupGuidString(Class<T> klass,
 			String id) throws ParseException, NotFoundException {
 		if (klass.equals(Post.class) || klass.equals(Group.class))
@@ -362,9 +367,9 @@
 		}
 	}
 
-	private void invalidateContactStatus(Guid contacterId, Guid contactId) {
-		DataService.currentSessionRW().changed(UserDMO.class, contactId, "contactStatus",
-			new UserClientMatcher(contacterId));
+	private void invalidateContactStatus(Guid contacterUserId, Guid contactUserId) {
+		DataService.currentSessionRW().changed(UserDMO.class, contactUserId, "contactStatus",
+			new UserClientMatcher(contacterUserId));
 	}
 	
 	public void addVerifiedOwnershipClaim(User claimedOwner, Resource res) {
@@ -669,14 +674,30 @@
 				contact = doCreateContact(viewer, contactUser.getAccount());
 			}
 			
+			setContactStatus(viewpoint, contact, status);
+		}
+	}
+
+	public void setContactStatus(UserViewpoint viewpoint, Contact contact, ContactStatus status) {
+		User viewer = viewpoint.getViewer();
+		
+		if (status == ContactStatus.NONCONTACT) {
+			removeContactPerson(viewer, contact);
+		} else {
 			if (contact.getStatus() != status) {
 				contact.setStatus(status);
-				invalidateContactStatus(viewer.getGuid(), contactUser.getGuid());
-				LiveState.getInstance().invalidateContacters(contactUser.getGuid());
+				
+				DataService.currentSessionRW().changed(ContactDMO.class, contact.getGuid(), "status");
+				
+				User contactUser = getUser(contact);
+				if (contactUser != null) {
+					invalidateContactStatus(viewer.getGuid(), contactUser.getGuid());
+					LiveState.getInstance().invalidateContacters(contactUser.getGuid());
+				}
 			}
 		}
-	}
-
+	}	
+	
 	// get all contacts, even if they have no user
 	public Set<Guid> computeContacts(Guid userId) {
 		User user = em.find(User.class, userId.toString());



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]