bigboard r7256 - trunk/bigboard



Author: otaylor
Date: Fri Feb  8 00:27:54 2008
New Revision: 7256
URL: http://svn.gnome.org/viewvc/bigboard?rev=7256&view=rev

Log:
* Track changes to buddy properties
* Fix bug where after reconnection we got a stale item
  in the people list with a resource from the previous connection
  generation


Modified:
   trunk/bigboard/people_tracker.py

Modified: trunk/bigboard/people_tracker.py
==============================================================================
--- trunk/bigboard/people_tracker.py	(original)
+++ trunk/bigboard/people_tracker.py	Fri Feb  8 00:27:54 2008
@@ -193,6 +193,17 @@
 
     ##############################################################
 
+    def __buddy_alias_changed(self, buddy):
+        self.__update_name()
+        
+    def __buddy_icon_changed(self, buddy):
+        self.__update_icon_url()
+        
+    def __buddy_is_online_changed(self, buddy):
+        self.__update_online()
+        
+    ##############################################################
+
     def __update_name(self):
         name = None
         # We prefer the name in the user to the name in the contact, because
@@ -316,6 +327,19 @@
         if self.xmpps != xmpps:
             self.xmpps = xmpps
             self.emit('xmpps-changed')
+
+    def __update_buddy_connections(self, old_buddies, new_buddies):
+        for buddy in old_buddies:
+            if not buddy in new_buddies:
+                buddy.disconnect(self.__buddy_alias_changed)
+                buddy.disconnect(self.__buddy_icon_changed)
+                buddy.disconnect(self.__buddy_is_online_changed)
+                
+        for buddy in new_buddies:
+            if not buddy in old_buddies:
+                buddy.connect(self.__buddy_alias_changed, 'alias')
+                buddy.connect(self.__buddy_icon_changed, 'icon')
+                buddy.connect(self.__buddy_is_online_changed, 'isOnline')
             
     def __update_aim_buddies(self):
         aim_buddies = set()
@@ -330,6 +354,7 @@
         aim_buddies.sort()
     
         if self.aim_buddies != aim_buddies:
+            self.__update_buddy_connections(self.aim_buddies, aim_buddies)
             self.aim_buddies = aim_buddies
             self.emit('aim-buddies-changed')
 
@@ -350,6 +375,7 @@
         xmpp_buddies.sort()
     
         if self.xmpp_buddies != xmpp_buddies:
+            self.__update_buddy_connections(self.xmpp_buddies, xmpp_buddies)
             self.xmpp_buddies = xmpp_buddies
             self.emit('xmpp-buddies-changed')
             
@@ -370,6 +396,7 @@
         local_buddies.sort()
 
         if self.local_buddies != local_buddies:
+            self.__update_buddy_connections(self.local_buddies, local_buddies)
             self.local_buddies = local_buddies
             self.emit('local-buddies-changed')
             
@@ -433,14 +460,19 @@
             self.status = status
             self.emit('status-changed')
 
+    # Resource is defined to hash/equal based on the ID, but we actually
+    # want to treat Person objects on reconnection to the server as different
+    # from Person objects from the previous connection, so we use id()
+    # 'is', rather than hash() and and '=='
+    #
     def __hash__(self):
-        return hash(self.resource)
+        return id(self.resource)
 
     def __eq__(self, other):
         if isinstance(other, Person):
-            return self.resource == other.resource
+            return self.resource is other.resource
         else:
-            return self.resource == other
+            return self.resource is other
 
 class PersonSet(gobject.GObject):
     """A list of Person objects with change notification



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