restore metacontct correctly when we connect to server and we already have contacts in roster (stored locally). Fixes #5156

This commit is contained in:
Yann Leboulanger 2009-07-12 13:33:29 +02:00
parent 36d16d1eb0
commit 15b3ba35b1
3 changed files with 35 additions and 1 deletions

View File

@ -379,6 +379,12 @@ class Contacts:
#FIXME: can this append ? #FIXME: can this append ?
assert False assert False
def get_metacontacts_tags(self, account):
'''return a list of tags for a given account'''
if not account in self._metacontacts_tags:
return []
return self._metacontacts_tags[account].keys()
def get_metacontacts_tag(self, account, jid): def get_metacontacts_tag(self, account, jid):
'''Returns the tag of a jid''' '''Returns the tag of a jid'''
if not account in self._metacontacts_tags: if not account in self._metacontacts_tags:
@ -462,6 +468,9 @@ class Contacts:
[{'account': acct, 'jid': jid, 'order': order}, ] [{'account': acct, 'jid': jid, 'order': order}, ]
'order' is optional''' 'order' is optional'''
tag = self.get_metacontacts_tag(account, jid) tag = self.get_metacontacts_tag(account, jid)
return self.get_metacontacts_family_from_tag(account, tag)
def get_metacontacts_family_from_tag(self, account, tag):
if not tag: if not tag:
return [] return []
answers = [] answers = []

View File

@ -1908,6 +1908,7 @@ class Interface:
def handle_event_metacontacts(self, account, tags_list): def handle_event_metacontacts(self, account, tags_list):
gajim.contacts.define_metacontacts(account, tags_list) gajim.contacts.define_metacontacts(account, tags_list)
self.roster.redraw_metacontacts(account)
def handle_atom_entry(self, account, data): def handle_atom_entry(self, account, data):
atom_entry, = data atom_entry, = data

View File

@ -565,8 +565,10 @@ class RosterWindow:
brothers = [] brothers = []
nearby_family, big_brother_jid, big_brother_account = \ nearby_family, big_brother_jid, big_brother_account = \
self._get_nearby_family_and_big_brother(family, account) self._get_nearby_family_and_big_brother(family, account)
big_brother_contact = gajim.contacts.get_contact(big_brother_account,
big_brother_jid)
child_iters = self._get_contact_iter(big_brother_jid, big_brother_account, child_iters = self._get_contact_iter(big_brother_jid, big_brother_account,
model = self.model) model=self.model)
parent_iter = self.model.iter_parent(child_iters[0]) parent_iter = self.model.iter_parent(child_iters[0])
parent_type = self.model[parent_iter][C_TYPE] parent_type = self.model[parent_iter][C_TYPE]
@ -583,6 +585,23 @@ class RosterWindow:
for c, acc in brothers: for c, acc in brothers:
self.draw_completely(c.jid, acc) self.draw_completely(c.jid, acc)
# Check is small brothers are under the big brother
for child in nearby_family:
_jid = child['jid']
_account = child['account']
if _account == big_brother_account and _jid == big_brother_jid:
continue
child_iters = self._get_contact_iter(_jid, _account, model=self.model)
if not child_iters:
continue
parent_iter = self.model.iter_parent(child_iters[0])
parent_type = self.model[parent_iter][C_TYPE]
if parent_type != 'contact':
_contact = gajim.contacts.get_contact(_account, _jid)
self._remove_entity(_contact, _account)
self._add_entity(_contact, _account, groups=None,
big_brother_contact=big_brother_contact,
big_brother_account=big_brother_account)
def _get_nearby_family_and_big_brother(self, family, account): def _get_nearby_family_and_big_brother(self, family, account):
'''Return the nearby family and its Big Brother '''Return the nearby family and its Big Brother
@ -631,6 +650,11 @@ class RosterWindow:
return contact return contact
def redraw_metacontacts(self, account):
for tag in gajim.contacts.get_metacontacts_tags(account):
family = gajim.contacts.get_metacontacts_family_from_tag(account, tag)
self._recalibrate_metacontact_family(family, account)
def add_contact(self, jid, account): def add_contact(self, jid, account):
'''Add contact to roster and draw him. '''Add contact to roster and draw him.