compute metacontact big brother by comparing them instead of computing an absolute score for each one. fixes #2781 and #2156
This commit is contained in:
		
							parent
							
								
									9994643247
								
							
						
					
					
						commit
						ec2ff7a684
					
				
					 1 changed files with 38 additions and 38 deletions
				
			
		| 
						 | 
					@ -395,48 +395,48 @@ 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:
 | 
				
			||||||
		contact = self.get_contact_with_highest_priority(account, jid)
 | 
								return -1
 | 
				
			||||||
		score = (max_order - order)*10000
 | 
							contact1 = self.get_contact_with_highest_priority(data1['account'], jid1)
 | 
				
			||||||
		
 | 
							contact2 = self.get_contact_with_highest_priority(data2['account'], jid2)
 | 
				
			||||||
		if common.gajim.get_transport_name_from_jid(jid) is None and \
 | 
							if contact1.priority > contact2.priority:
 | 
				
			||||||
		contact.show not in ('error', 'offline'):
 | 
								return 1
 | 
				
			||||||
			score += 10
 | 
							if contact2.priority > contact1.priority:
 | 
				
			||||||
			if contact.priority > 0:
 | 
								return -1
 | 
				
			||||||
				score += contact.priority * 10
 | 
							show_list = ['not in roster', 'error', 'offline', 'invisible', 'dnd',
 | 
				
			||||||
		score += ['not in roster', 'error', 'offline', 'invisible', 'dnd', 'xa',
 | 
								'xa', 'away', 'chat', 'online', 'requested', 'message']
 | 
				
			||||||
		'away', 'chat', 'online', 'requested', 'message'].index(contact.show)
 | 
							show1 = show_list.index(contact1.show)
 | 
				
			||||||
		if contact.show == 'offline' and contact.status:
 | 
							show2 = show_list.index(contact2.show)
 | 
				
			||||||
			# Offline contacts with a status message have highest score
 | 
							if show1 > show2:
 | 
				
			||||||
			score += 1
 | 
								return 1
 | 
				
			||||||
		return score
 | 
							if show2 > show1:
 | 
				
			||||||
 | 
								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 ?'''
 | 
				
			||||||
		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…
	
	Add table
		
		Reference in a new issue