Do not duplicate a contact in roster on subscription changes. Fixes #4524.
For performance reasons, get_contact_iters() cannot find a contact if get_shown_groups() returns something different to what has been applied to roster model. The contact was therefore duplicated as it was believed not to be there...
This commit is contained in:
parent
8907f71c86
commit
8d0ff396b1
20
src/gajim.py
20
src/gajim.py
|
@ -1489,7 +1489,7 @@ class Interface:
|
||||||
contacts = gajim.contacts.get_contacts(account, jid)
|
contacts = gajim.contacts.get_contacts(account, jid)
|
||||||
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.
|
# contact removed us.
|
||||||
if contacts:
|
if contacts:
|
||||||
self.roster.remove_contact(jid, account, backend=True)
|
self.roster.remove_contact(jid, account, backend=True)
|
||||||
return
|
return
|
||||||
|
@ -1504,22 +1504,24 @@ class Interface:
|
||||||
else:
|
else:
|
||||||
# it is an existing contact that might has changed
|
# it is an existing contact that might has changed
|
||||||
re_draw = False
|
re_draw = False
|
||||||
# if sub or groups changed: remove and re-add
|
# If contact has changed (sub, ask or group) update roster
|
||||||
# Maybe observer status changed:
|
# Mind about observer status changes:
|
||||||
# according to xep 0162, contact is not an observer anymore when
|
# According to xep 0162, a contact is not an observer anymore when
|
||||||
# we asked him is auth, so also remove him if ask changed
|
# we asked for auth, so also remove him if ask changed
|
||||||
old_groups = contacts[0].get_shown_groups()
|
old_groups = contacts[0].groups
|
||||||
if contacts[0].sub != sub or contacts[0].ask != ask\
|
if contacts[0].sub != sub or contacts[0].ask != ask\
|
||||||
or old_groups != groups:
|
or old_groups != groups:
|
||||||
re_draw = True
|
re_draw = True
|
||||||
|
if re_draw:
|
||||||
|
# c.get_shown_groups() has changed. Reflect that in roster_winodow
|
||||||
|
self.roster.remove_contact(jid, account, force=True)
|
||||||
for contact in contacts:
|
for contact in contacts:
|
||||||
if not name:
|
contact.name = name or ''
|
||||||
name = ''
|
|
||||||
contact.name = name
|
|
||||||
contact.sub = sub
|
contact.sub = sub
|
||||||
contact.ask = ask
|
contact.ask = ask
|
||||||
contact.groups = groups or []
|
contact.groups = groups or []
|
||||||
if re_draw:
|
if re_draw:
|
||||||
|
self.roster.add_contact(jid, account)
|
||||||
# Refilter and update old groups
|
# Refilter and update old groups
|
||||||
for group in old_groups:
|
for group in old_groups:
|
||||||
self.roster.draw_group(group, account)
|
self.roster.draw_group(group, account)
|
||||||
|
|
|
@ -872,12 +872,11 @@ class RosterWindow:
|
||||||
for contact in gajim.contacts.get_contacts(account, jid):
|
for contact in gajim.contacts.get_contacts(account, jid):
|
||||||
for group in groups:
|
for group in groups:
|
||||||
if group in contact.groups:
|
if group in contact.groups:
|
||||||
# Needed when we remove from "General"
|
# Needed when we remove from "General" or "Observers"
|
||||||
contact.groups.remove(group)
|
contact.groups.remove(group)
|
||||||
if update:
|
if update:
|
||||||
gajim.connections[account].update_contact(jid, contact.name,
|
gajim.connections[account].update_contact(jid, contact.name,
|
||||||
contact.groups)
|
contact.groups)
|
||||||
|
|
||||||
self.add_contact(jid, account)
|
self.add_contact(jid, account)
|
||||||
|
|
||||||
# Also redraw old groups
|
# Also redraw old groups
|
||||||
|
|
Loading…
Reference in New Issue