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,12 +217,24 @@ 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.
|
||||||
buddyhandle = self._activity.GetBuddyByHandle(handle)
|
|
||||||
if buddyhandle:
|
buddies are cached in self._handle_to_buddy, so we can
|
||||||
buddy = self._ps_new_object(buddyhandle)
|
still get the buddy after they have left the activity.
|
||||||
else:
|
"""
|
||||||
buddy = None
|
buddy = self._handle_to_buddy.get(handle, None)
|
||||||
|
if not buddy:
|
||||||
|
try:
|
||||||
|
buddyhandle = self._activity.GetBuddyByHandle(handle)
|
||||||
|
except:
|
||||||
|
# FIXME: Need to catch NotFoundError but that's defined
|
||||||
|
# in presence-service psutils
|
||||||
|
buddyhandle = None
|
||||||
|
if buddyhandle:
|
||||||
|
buddy = self._ps_new_object(buddyhandle)
|
||||||
|
self._handle_to_buddy[handle] = buddy
|
||||||
|
else:
|
||||||
|
buddy = None
|
||||||
return buddy
|
return buddy
|
||||||
|
|
||||||
def invite(self, buddy, message, response_cb):
|
def invite(self, buddy, message, response_cb):
|
||||||
|
Loading…
Reference in New Issue
Block a user