Don't add duplicate buddies, and fix up buddy disappearance

This commit is contained in:
Dan Williams 2006-04-24 13:42:01 -04:00
parent 6c188f1f0f
commit f9e2a73b9a
2 changed files with 14 additions and 8 deletions

View File

@ -62,6 +62,8 @@ class BuddyList(object):
def _add_buddy(self, host, address, port, servicename, data):
if len(data) > 0 and 'name' in data.keys():
buddy = self._find_buddy_by_service_name(servicename)
if not buddy:
buddy = Buddy(data['name'], data['realname'], servicename, host, address, port)
self._buddies[data['name']] = buddy
self._notify_listeners(ACTION_BUDDY_ADDED, buddy)
@ -72,7 +74,7 @@ class BuddyList(object):
del self._buddies[nick]
def _find_buddy_by_service_name(self, servicename):
for buddy in self._buddies.keys():
for buddy in self._buddies.values():
if buddy.servicename() == servicename:
return buddy
return None

View File

@ -270,10 +270,14 @@ class ChatActivity(activity.Activity):
if action == BuddyList.ACTION_BUDDY_ADDED:
aniter = self._buddy_list_model.append(None)
self._buddy_list_model.set(aniter, 0, buddy.nick(), 1, buddy)
elif action == BuddyList.ACCTION_BUDDY_REMOVED:
aniter = self._buddy_list_model.get_iter(buddy.nick())
if aniter:
self._buddy_list_model.remove(iter)
elif action == BuddyList.ACTION_BUDDY_REMOVED:
aniter = self._buddy_list_model.get_iter_first()
while aniter:
list_buddy = self._buddy_list_model.get_value(aniter, 1)
if buddy == list_buddy:
self._buddy_list_model.remove(aniter)
break
aniter = self._buddy_list_model.iter_next(aniter)
def find_buddy_by_address(self, address):
return self._buddy_list.find_buddy_by_address(address)