Handle remote roster changes.
* Don't traceback when another resource of us is moving contacts to new/different groups. * Always refilter all involved groups. * It is now possible to not update contacts severside when using add/remove_from_groups
This commit is contained in:
parent
9c75374da4
commit
473e2cdbd8
2 changed files with 26 additions and 16 deletions
23
src/gajim.py
23
src/gajim.py
|
@ -1407,28 +1407,30 @@ class Interface:
|
||||||
ask = array[3]
|
ask = array[3]
|
||||||
groups = array[4]
|
groups = array[4]
|
||||||
contacts = gajim.contacts.get_contacts(account, jid)
|
contacts = gajim.contacts.get_contacts(account, jid)
|
||||||
# contact removes us.
|
|
||||||
if (not sub or sub == 'none') and (not ask or ask == 'none') and \
|
if (not sub or sub == 'none') and (not ask or ask == 'none') and \
|
||||||
not name and not groups:
|
not name and not groups:
|
||||||
|
# contact removes us.
|
||||||
if contacts:
|
if contacts:
|
||||||
c = contacts[0]
|
self.roster.remove_contact(jid, account, backend = True)
|
||||||
self.roster.remove_contact(c.jid, account, backend = True)
|
|
||||||
return
|
return
|
||||||
elif not contacts:
|
elif not contacts:
|
||||||
if sub == 'remove':
|
if sub == 'remove':
|
||||||
return
|
return
|
||||||
# Add it to roster
|
# Add new contact to roster
|
||||||
contact = gajim.contacts.create_contact(jid = jid, name = name,
|
contact = gajim.contacts.create_contact(jid = jid, name = name,
|
||||||
groups = groups, show = 'offline', sub = sub, ask = ask)
|
groups = groups, show = 'offline', sub = sub, ask = ask)
|
||||||
gajim.contacts.add_contact(account, contact)
|
gajim.contacts.add_contact(account, contact)
|
||||||
self.roster.add_contact(jid, account)
|
self.roster.add_contact(jid, account)
|
||||||
else:
|
else:
|
||||||
|
# it is an existing contact that might has changed
|
||||||
re_add = False
|
re_add = False
|
||||||
# if sub changed: remove and re-add, maybe observer status changed
|
# if sub or groups changed: remove and re-add
|
||||||
|
# Maybe observer status changed:
|
||||||
# according to xep 0162, contact is not an observer anymore when
|
# according to xep 0162, contact is not an observer anymore when
|
||||||
# we asked him is auth, so also remove him if ask changed
|
# we asked him is auth, so also remove him if ask changed
|
||||||
if contacts[0].sub != sub or contacts[0].ask != ask:
|
old_groups = contacts[0].get_shown_groups()
|
||||||
self.roster.remove_contact(contacts[0].jid, account, force = True)
|
if contacts[0].sub != sub or contacts[0].ask != ask or old_groups != groups:
|
||||||
|
self.roster.remove_contact(jid, account)
|
||||||
re_add = True
|
re_add = True
|
||||||
for contact in contacts:
|
for contact in contacts:
|
||||||
if not name:
|
if not name:
|
||||||
|
@ -1436,10 +1438,13 @@ class Interface:
|
||||||
contact.name = name
|
contact.name = name
|
||||||
contact.sub = sub
|
contact.sub = sub
|
||||||
contact.ask = ask
|
contact.ask = ask
|
||||||
if groups:
|
contact.groups = groups or []
|
||||||
contact.groups = groups
|
|
||||||
if re_add:
|
if re_add:
|
||||||
self.roster.add_contact(jid, account)
|
self.roster.add_contact(jid, account)
|
||||||
|
# Refilter and update oĺd groups
|
||||||
|
for group in old_groups:
|
||||||
|
self.roster.draw_group(group, account)
|
||||||
|
|
||||||
if self.remote_ctrl:
|
if self.remote_ctrl:
|
||||||
self.remote_ctrl.raise_signal('RosterInfo', (account, array))
|
self.remote_ctrl.raise_signal('RosterInfo', (account, array))
|
||||||
|
|
||||||
|
|
|
@ -765,7 +765,7 @@ class RosterWindow:
|
||||||
self.remove_contact(jid, account, force = True, backend = True)
|
self.remove_contact(jid, account, force = True, backend = True)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def add_contact_to_groups(self, jid, account, groups):
|
def add_contact_to_groups(self, jid, account, groups, update = True):
|
||||||
'''Add contact to given groups and redraw them.
|
'''Add contact to given groups and redraw them.
|
||||||
|
|
||||||
Contact on server is updated too. When the contact has a family,
|
Contact on server is updated too. When the contact has a family,
|
||||||
|
@ -775,6 +775,7 @@ class RosterWindow:
|
||||||
jid -- the jid
|
jid -- the jid
|
||||||
account -- the corresponding account
|
account -- the corresponding account
|
||||||
groups -- list of Groups to add the contact to.
|
groups -- list of Groups to add the contact to.
|
||||||
|
update -- update contact on the server
|
||||||
|
|
||||||
'''
|
'''
|
||||||
self.remove_contact(jid, account, force = True)
|
self.remove_contact(jid, account, force = True)
|
||||||
|
@ -783,15 +784,16 @@ class RosterWindow:
|
||||||
if group not in contact.groups:
|
if group not in contact.groups:
|
||||||
# we might be dropped from meta to group
|
# we might be dropped from meta to group
|
||||||
contact.groups.append(group)
|
contact.groups.append(group)
|
||||||
gajim.connections[account].update_contact(jid, contact.name,
|
if update:
|
||||||
contact.groups)
|
gajim.connections[account].update_contact(jid, contact.name,
|
||||||
|
contact.groups)
|
||||||
|
|
||||||
self.add_contact(jid, account)
|
self.add_contact(jid, account)
|
||||||
|
|
||||||
for group in groups:
|
for group in groups:
|
||||||
self._adjust_group_expand_collapse_state(group, account)
|
self._adjust_group_expand_collapse_state(group, account)
|
||||||
|
|
||||||
def remove_contact_from_groups(self, jid, account, groups):
|
def remove_contact_from_groups(self, jid, account, groups, update = True):
|
||||||
'''Remove contact from given groups and redraw them.
|
'''Remove contact from given groups and redraw them.
|
||||||
|
|
||||||
Contact on server is updated too. When the contact has a family,
|
Contact on server is updated too. When the contact has a family,
|
||||||
|
@ -801,6 +803,7 @@ class RosterWindow:
|
||||||
jid -- the jid
|
jid -- the jid
|
||||||
account -- the corresponding account
|
account -- the corresponding account
|
||||||
groups -- list of Groups to remove the contact from
|
groups -- list of Groups to remove the contact from
|
||||||
|
update -- update contact on the server
|
||||||
|
|
||||||
'''
|
'''
|
||||||
self.remove_contact(jid, account, force = True)
|
self.remove_contact(jid, account, force = True)
|
||||||
|
@ -809,11 +812,13 @@ class RosterWindow:
|
||||||
if group in contact.groups:
|
if group in contact.groups:
|
||||||
# Needed when we remove from "General"
|
# Needed when we remove from "General"
|
||||||
contact.groups.remove(group)
|
contact.groups.remove(group)
|
||||||
gajim.connections[account].update_contact(jid, contact.name,
|
if update:
|
||||||
contact.groups)
|
gajim.connections[account].update_contact(jid, contact.name,
|
||||||
|
contact.groups)
|
||||||
|
|
||||||
self.add_contact(jid, account)
|
self.add_contact(jid, account)
|
||||||
|
|
||||||
|
# Also redraw old groups
|
||||||
for group in groups:
|
for group in groups:
|
||||||
self.draw_group(group, account)
|
self.draw_group(group, account)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue