Compute metacontact big brother by comparing them instead of computing an absolute score for each one
This commit is contained in:
parent
908d4f17e7
commit
833f58754a
|
@ -420,51 +420,55 @@ class Contacts:
|
||||||
answers.append(data)
|
answers.append(data)
|
||||||
return answers
|
return answers
|
||||||
|
|
||||||
def _get_data_score(self, data):
|
def compare_metacontacts(self, data1, data2):
|
||||||
'''compute thescore of a gived data
|
'''compare 2 metacontacts.
|
||||||
data is {'jid': jid, 'account': account, 'order': order}
|
Data is {'jid': jid, 'account': account, 'order': order}
|
||||||
order is optional
|
order is optional'''
|
||||||
score = (max_order - order)*10000 + is_jabber*priority*10 + status'''
|
if 'order' in data1 and 'order' in data2:
|
||||||
jid = data['jid']
|
if data1['order'] > data2['order']:
|
||||||
account = data['account']
|
return 1
|
||||||
max_order = 0
|
if data1['order'] < data2['order']:
|
||||||
order = 0
|
return -1
|
||||||
if data.has_key('order'):
|
jid1 = data1['jid']
|
||||||
order = data['order']
|
jid2 = data2['jid']
|
||||||
if order:
|
transport1 = common.gajim.get_transport_name_from_jid(jid1)
|
||||||
family = self.get_metacontacts_family(account, jid)
|
transport2 = common.gajim.get_transport_name_from_jid(jid2)
|
||||||
for data_ in family:
|
if transport2 and not transport1:
|
||||||
if data_.has_key('order') and data_['order'] > max_order:
|
return 1
|
||||||
max_order = data_['order']
|
if transport1 and not transport2:
|
||||||
score = (max_order - order)*10000
|
return -1
|
||||||
|
contact1 = self.get_contact_with_highest_priority(data1['account'], jid1)
|
||||||
contact = self.get_contact_with_highest_priority(account, jid)
|
contact2 = self.get_contact_with_highest_priority(data2['account'], jid2)
|
||||||
if not contact:
|
if contact1.priority > contact2.priority:
|
||||||
return score
|
return 1
|
||||||
|
if contact2.priority > contact1.priority:
|
||||||
if common.gajim.get_transport_name_from_jid(jid) is None and \
|
return -1
|
||||||
contact.show not in ('error', 'offline'):
|
show_list = ['not in roster', 'error', 'offline', 'invisible', 'dnd',
|
||||||
score += 10
|
'xa', 'away', 'chat', 'online', 'requested', 'message']
|
||||||
if contact.priority > 0:
|
show1 = show_list.index(contact1.show)
|
||||||
score += contact.priority * 10
|
show2 = show_list.index(contact2.show)
|
||||||
score += ['not in roster', 'error', 'offline', 'invisible', 'dnd', 'xa',
|
if show1 > show2:
|
||||||
'away', 'chat', 'online', 'requested', 'message'].index(contact.show)
|
return 1
|
||||||
if contact.show == 'offline' and contact.status:
|
if show2 > show1:
|
||||||
# Offline contacts with a status message have highest score
|
return -1
|
||||||
score += 1
|
if jid1 > jid2:
|
||||||
return score
|
return 1
|
||||||
|
if jid2 > jid1:
|
||||||
|
return -1
|
||||||
|
# If all is the same, compare accounts, they can't be the same
|
||||||
|
account1 = data1['account']
|
||||||
|
account2 = data2['account']
|
||||||
|
if account1 > account2:
|
||||||
|
return 1
|
||||||
|
if account2 > account1:
|
||||||
|
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 ?'''
|
||||||
max_score = 0
|
family.sort(cmp=self.compare_metacontacts)
|
||||||
max_data = family[0]
|
return family[-1]
|
||||||
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'''
|
||||||
|
|
Loading…
Reference in New Issue