Cache handle-buddies so we can get them when the buddy has already left

This commit is contained in:
Morgan Collett 2007-10-03 20:39:07 +01:00
parent c9908a6d27
commit f1df5361e1

View File

@ -90,6 +90,8 @@ class Activity(gobject.GObject):
self._tags = None self._tags = None
self._private = True self._private = True
self._joined = False self._joined = False
# Cache for get_buddy_by_handle
self._handle_to_buddy = {}
def _get_properties_reply_cb(self, new_props): def _get_properties_reply_cb(self, new_props):
self._properties_changed_cb(new_props) self._properties_changed_cb(new_props)
@ -215,10 +217,22 @@ class Activity(gobject.GObject):
return buddies return buddies
def get_buddy_by_handle(self, handle): def get_buddy_by_handle(self, handle):
"""Retrieve the Buddy object given a telepathy handle.""" """Retrieve the Buddy object given a telepathy handle.
buddies are cached in self._handle_to_buddy, so we can
still get the buddy after they have left the activity.
"""
buddy = self._handle_to_buddy.get(handle, None)
if not buddy:
try:
buddyhandle = self._activity.GetBuddyByHandle(handle) buddyhandle = self._activity.GetBuddyByHandle(handle)
except:
# FIXME: Need to catch NotFoundError but that's defined
# in presence-service psutils
buddyhandle = None
if buddyhandle: if buddyhandle:
buddy = self._ps_new_object(buddyhandle) buddy = self._ps_new_object(buddyhandle)
self._handle_to_buddy[handle] = buddy
else: else:
buddy = None buddy = None
return buddy return buddy