Cache handle-buddies so we can get them when the buddy has already left
This commit is contained in:
parent
c9908a6d27
commit
f1df5361e1
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user