primitivus: fixes contact group update
This commit is contained in:
parent
f0fa9b699d
commit
f3a0686176
4 changed files with 40 additions and 14 deletions
|
|
@ -234,20 +234,32 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
self.update()
|
||||
|
||||
def replace(self, jid, groups=None, attributes=None):
|
||||
"""add a contact to the list if doesn't exist, else update it"""
|
||||
"""Add a contact to the list if doesn't exist, else update it.
|
||||
|
||||
@param jid (JID)
|
||||
@param groups (list): list of groups or None to ignore the groups membership.
|
||||
@param attributes (dict)
|
||||
|
||||
XXX: None value for 'groups' has a different meaning than [None] which is for the default group.
|
||||
"""
|
||||
QuickContactList.replace(self, jid, groups, attributes)
|
||||
if jid.bare in self.specials:
|
||||
return
|
||||
if not groups:
|
||||
groups = [None]
|
||||
if not attributes:
|
||||
attributes={}
|
||||
assert isinstance(groups, list)
|
||||
attributes = {}
|
||||
assert isinstance(jid, JID)
|
||||
for group in groups:
|
||||
if not self.groups.has_key(group):
|
||||
self.groups[group] = [True,set()] #[unfold,list_of_contacts]
|
||||
self.groups[group][1].add(jid.bare)
|
||||
if groups is not None:
|
||||
if not groups:
|
||||
groups = [None]
|
||||
for group in [group for group in self.groups if group not in groups]:
|
||||
try: # remove the contact from a previous group
|
||||
self.groups[group][1].remove(jid.bare)
|
||||
except KeyError:
|
||||
pass
|
||||
for group in groups:
|
||||
if group not in self.groups:
|
||||
self.groups[group] = [True, set()] # [unfold, list_of_contacts]
|
||||
self.groups[group][1].add(jid.bare)
|
||||
self.update()
|
||||
|
||||
def remove(self, jid):
|
||||
|
|
@ -264,9 +276,9 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
del self.groups[group]
|
||||
self.update()
|
||||
|
||||
def add(self, jid, param_groups=[None]):
|
||||
def add(self, jid, param_groups=None):
|
||||
"""add a contact to the list"""
|
||||
self.replace(jid,param_groups)
|
||||
self.replace(jid, param_groups)
|
||||
|
||||
def setSpecial(self, special_jid, special_type, show=False):
|
||||
"""Set entity as a special
|
||||
|
|
|
|||
|
|
@ -388,8 +388,7 @@ class PrimitivusApp(QuickApp, InputHistory):
|
|||
if not from_jid in self.contact_list and from_jid.bare != self.profiles[profile]['whoami'].bare:
|
||||
#XXX: needed to show entities which haven't sent any
|
||||
# presence information and which are not in roster
|
||||
#TODO: put these entities in a "not in roster" list
|
||||
self.contact_list.replace(from_jid)
|
||||
self.contact_list.replace(from_jid, ['Not in roster'])
|
||||
|
||||
if JID(self.contact_list.selected).bare != from_jid.bare:
|
||||
self.contact_list.putAlert(from_jid)
|
||||
|
|
|
|||
|
|
@ -54,7 +54,14 @@ class QuickContactList(object):
|
|||
self.specials.clear()
|
||||
|
||||
def replace(self, jid, groups=None, attributes=None):
|
||||
"""add a contact to the list if doesn't exist, else update it"""
|
||||
"""Add a contact to the list if doesn't exist, else update it.
|
||||
|
||||
@param jid (JID)
|
||||
@param groups (list): list of groups or None to ignore the groups membership.
|
||||
@param attributes (dict)
|
||||
|
||||
XXX: None value for 'groups' has a different meaning than [None] which is for the default group.
|
||||
"""
|
||||
if attributes and 'name' in attributes:
|
||||
self.setCache(jid, 'name', attributes['name'])
|
||||
|
||||
|
|
|
|||
|
|
@ -76,6 +76,14 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
|
|||
self.replace(jid)
|
||||
|
||||
def replace(self, contact, groups=None, attributes=None):
|
||||
"""Add a contact to the list if doesn't exist, else update it.
|
||||
|
||||
@param jid (JID)
|
||||
@param groups (list): list of groups or None to ignore the groups membership.
|
||||
@param attributes (dict)
|
||||
|
||||
XXX: None value for 'groups' has a different meaning than [None] which is for the default group.
|
||||
"""
|
||||
debug(_("update %s") % contact)
|
||||
if not self.__find_idx(contact):
|
||||
self.add(contact, groups)
|
||||
|
|
|
|||
Loading…
Reference in a new issue