Change _buddy_to_handle to _buddy_path_to_handle to avoid mad creation of buddy object when they leave

This commit is contained in:
Morgan Collett 2007-10-12 16:33:52 +01:00
parent dd83813b9e
commit d4f16ac02a

View File

@ -92,9 +92,9 @@ 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 # Cache for get_buddy_by_handle, maps handles to buddy object paths
self._handle_to_buddy = {} self._handle_to_buddy_path = {}
self._buddy_to_handle = {} self._buddy_path_to_handle = {}
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)
@ -185,9 +185,8 @@ class Activity(gobject.GObject):
def _buddy_handle_joined_cb(self, object_path, handle): def _buddy_handle_joined_cb(self, object_path, handle):
gobject.idle_add(self._emit_buddy_joined_signal, object_path) gobject.idle_add(self._emit_buddy_joined_signal, object_path)
buddy = self._ps_new_object(object_path) self._handle_to_buddy_path[handle] = object_path
self._handle_to_buddy[handle] = buddy self._buddy_path_to_handle[object_path] = handle
self._buddy_to_handle[buddy] = handle
def _emit_buddy_left_signal(self, object_path): def _emit_buddy_left_signal(self, object_path):
"""Generate buddy-left GObject signal with presence Buddy object """Generate buddy-left GObject signal with presence Buddy object
@ -199,9 +198,8 @@ class Activity(gobject.GObject):
def _buddy_left_cb(self, object_path): def _buddy_left_cb(self, object_path):
gobject.idle_add(self._emit_buddy_left_signal, object_path) gobject.idle_add(self._emit_buddy_left_signal, object_path)
buddy = self._ps_new_object(object_path) handle = self._buddy_path_to_handle.pop(object_path)
handle = self._buddy_to_handle.pop(buddy) self._handle_to_buddy_path.pop(handle, None)
self._handle_to_buddy.pop(handle, None)
def _emit_new_channel_signal(self, object_path): def _emit_new_channel_signal(self, object_path):
"""Generate new-channel GObject signal with channel object path """Generate new-channel GObject signal with channel object path
@ -228,10 +226,11 @@ class Activity(gobject.GObject):
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 buddy object paths are cached in self._handle_to_buddy_path,
still get the buddy without calling PS. so we can get the buddy without calling PS.
""" """
buddy = self._handle_to_buddy.get(handle, None) object_path = self._handle_to_buddy_path.get(handle, None)
buddy = self._ps_new_object(object_path)
return buddy return buddy
def invite(self, buddy, message, response_cb): def invite(self, buddy, message, response_cb):