From f9e2a73b9aa8ea9129629a1f772434edd6616569 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 24 Apr 2006 13:42:01 -0400 Subject: [PATCH] Don't add duplicate buddies, and fix up buddy disappearance --- chat/BuddyList.py | 10 ++++++---- chat/chat.py | 12 ++++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/chat/BuddyList.py b/chat/BuddyList.py index fa3afb0b..e5fd0763 100644 --- a/chat/BuddyList.py +++ b/chat/BuddyList.py @@ -62,9 +62,11 @@ class BuddyList(object): def _add_buddy(self, host, address, port, servicename, data): if len(data) > 0 and 'name' in data.keys(): - buddy = Buddy(data['name'], data['realname'], servicename, host, address, port) - self._buddies[data['name']] = buddy - self._notify_listeners(ACTION_BUDDY_ADDED, buddy) + 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) def _remove_buddy(self, buddy): nick = buddy.nick() @@ -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 diff --git a/chat/chat.py b/chat/chat.py index 53057239..b990ae96 100755 --- a/chat/chat.py +++ b/chat/chat.py @@ -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)