Don't add duplicate buddies, and fix up buddy disappearance
This commit is contained in:
parent
6c188f1f0f
commit
f9e2a73b9a
@ -62,9 +62,11 @@ class BuddyList(object):
|
|||||||
|
|
||||||
def _add_buddy(self, host, address, port, servicename, data):
|
def _add_buddy(self, host, address, port, servicename, data):
|
||||||
if len(data) > 0 and 'name' in data.keys():
|
if len(data) > 0 and 'name' in data.keys():
|
||||||
buddy = Buddy(data['name'], data['realname'], servicename, host, address, port)
|
buddy = self._find_buddy_by_service_name(servicename)
|
||||||
self._buddies[data['name']] = buddy
|
if not buddy:
|
||||||
self._notify_listeners(ACTION_BUDDY_ADDED, 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):
|
def _remove_buddy(self, buddy):
|
||||||
nick = buddy.nick()
|
nick = buddy.nick()
|
||||||
@ -72,7 +74,7 @@ class BuddyList(object):
|
|||||||
del self._buddies[nick]
|
del self._buddies[nick]
|
||||||
|
|
||||||
def _find_buddy_by_service_name(self, servicename):
|
def _find_buddy_by_service_name(self, servicename):
|
||||||
for buddy in self._buddies.keys():
|
for buddy in self._buddies.values():
|
||||||
if buddy.servicename() == servicename:
|
if buddy.servicename() == servicename:
|
||||||
return buddy
|
return buddy
|
||||||
return None
|
return None
|
||||||
|
12
chat/chat.py
12
chat/chat.py
@ -270,10 +270,14 @@ class ChatActivity(activity.Activity):
|
|||||||
if action == BuddyList.ACTION_BUDDY_ADDED:
|
if action == BuddyList.ACTION_BUDDY_ADDED:
|
||||||
aniter = self._buddy_list_model.append(None)
|
aniter = self._buddy_list_model.append(None)
|
||||||
self._buddy_list_model.set(aniter, 0, buddy.nick(), 1, buddy)
|
self._buddy_list_model.set(aniter, 0, buddy.nick(), 1, buddy)
|
||||||
elif action == BuddyList.ACCTION_BUDDY_REMOVED:
|
elif action == BuddyList.ACTION_BUDDY_REMOVED:
|
||||||
aniter = self._buddy_list_model.get_iter(buddy.nick())
|
aniter = self._buddy_list_model.get_iter_first()
|
||||||
if aniter:
|
while aniter:
|
||||||
self._buddy_list_model.remove(iter)
|
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):
|
def find_buddy_by_address(self, address):
|
||||||
return self._buddy_list.find_buddy_by_address(address)
|
return self._buddy_list.find_buddy_by_address(address)
|
||||||
|
Loading…
Reference in New Issue
Block a user