Add initial buddies, protect against buddies we don't know about before using them

This commit is contained in:
Dan Williams 2006-10-19 15:07:21 -04:00
parent 4a09253f5f
commit d784a906e4

View File

@ -72,6 +72,10 @@ class MeshModel(gobject.GObject):
self._pservice.connect("buddy-disappeared", self._pservice.connect("buddy-disappeared",
self._buddy_disappeared_cb) self._buddy_disappeared_cb)
# Add any buddies the PS knows about already
for buddy in self._pservice.get_buddies():
self._buddy_appeared_cb(self._pservice, buddy)
for service in self._pservice.get_services(): for service in self._pservice.get_services():
self._check_service(service) self._check_service(service)
@ -82,8 +86,9 @@ class MeshModel(gobject.GObject):
return self._buddies return self._buddies
def _buddy_activity_changed_cb(self, buddy, cur_activity): def _buddy_activity_changed_cb(self, buddy, cur_activity):
if not self._buddies.has_key(buddy.get_name()):
return
buddy_model = self._buddies[buddy.get_name()] buddy_model = self._buddies[buddy.get_name()]
if cur_activity == None: if cur_activity == None:
self.emit('buddy-moved', buddy_model, None) self.emit('buddy-moved', buddy_model, None)
else: else:
@ -96,6 +101,10 @@ class MeshModel(gobject.GObject):
def _buddy_appeared_cb(self, pservice, buddy): def _buddy_appeared_cb(self, pservice, buddy):
model = BuddyModel(buddy=buddy) model = BuddyModel(buddy=buddy)
if self._buddies.has_key(model.get_name()):
del model
return
model.connect('current-activity-changed', model.connect('current-activity-changed',
self._buddy_activity_changed_cb) self._buddy_activity_changed_cb)
self._buddies[model.get_name()] = model self._buddies[model.get_name()] = model
@ -106,6 +115,8 @@ class MeshModel(gobject.GObject):
self._notify_buddy_change(model, cur_activity) self._notify_buddy_change(model, cur_activity)
def _buddy_disappeared_cb(self, pservice, buddy): def _buddy_disappeared_cb(self, pservice, buddy):
if not self._buddies.has_key(buddy.get_name()):
return
self.emit('buddy-removed', buddy) self.emit('buddy-removed', buddy)
del self._buddies[buddy.get_name()] del self._buddies[buddy.get_name()]