reverting [8388] for the moment

This commit is contained in:
Yann Leboulanger 2007-07-12 20:45:43 +00:00
parent 59aa2cf87d
commit 2af509d005
1 changed files with 38 additions and 38 deletions

View File

@ -395,48 +395,48 @@ class Contacts:
answers.append(data) answers.append(data)
return answers return answers
def compare_metacontacts(self, data1, data2): def _get_data_score(self, data):
'''compare 2 metacontacts. '''compute thescore of a gived data
Data is {'jid': jid, 'account': account, 'order': order} data is {'jid': jid, 'account': account, 'order': order}
order is optional''' order is optional
if 'order' in data1 and 'order' in data2: score = (max_order - order)*10000 + is_jabber*priority*10 + status'''
if data1['order'] > data2['order']: jid = data['jid']
return 1 account = data['account']
if data1['order'] < data2['order']: max_order = 0
return -1 order = 0
jid1 = data1['jid'] if data.has_key('order'):
jid2 = data2['jid'] order = data['order']
transport1 = common.gajim.get_transport_name_from_jid(jid1) if order:
transport2 = common.gajim.get_transport_name_from_jid(jid2) family = self.get_metacontacts_family(account, jid)
if transport2 and not transport1: for data_ in family:
return 1 if data_.has_key('order') and data_['order'] > max_order:
if transport1 and not transport2: max_order = data_['order']
return -1 contact = self.get_contact_with_highest_priority(account, jid)
contact1 = self.get_contact_with_highest_priority(data1['account'], jid1) score = (max_order - order)*10000
contact2 = self.get_contact_with_highest_priority(data2['account'], jid2)
if contact1.priority > contact2.priority: if common.gajim.get_transport_name_from_jid(jid) is None and \
return 1 contact.show not in ('error', 'offline'):
if contact2.priority > contact1.priority: score += 10
return -1 if contact.priority > 0:
show_list = ['not in roster', 'error', 'offline', 'invisible', 'dnd', score += contact.priority * 10
'xa', 'away', 'chat', 'online', 'requested', 'message'] score += ['not in roster', 'error', 'offline', 'invisible', 'dnd', 'xa',
show1 = show_list.index(contact1.show) 'away', 'chat', 'online', 'requested', 'message'].index(contact.show)
show2 = show_list.index(contact2.show) if contact.show == 'offline' and contact.status:
if show1 > show2: # Offline contacts with a status message have highest score
return 1 score += 1
if show2 > show1: return score
return -1
if jid1 > jid2:
return 1
if jid2 > jid1:
return -1
return 0
def get_metacontacts_big_brother(self, family): def get_metacontacts_big_brother(self, family):
'''which of the family will be the big brother under wich all '''which of the family will be the big brother under wich all
others will be ?''' others will be ?'''
family.sort(cmp=self.compare_metacontacts) max_score = 0
return family[-1] max_data = family[0]
for data in family:
score = self._get_data_score(data)
if score > max_score:
max_score = score
max_data = data
return max_data
def is_pm_from_jid(self, account, jid): def is_pm_from_jid(self, account, jid):
'''Returns True if the given jid is a private message jid''' '''Returns True if the given jid is a private message jid'''