Shrink public interface of the MetacontactManager.
This commit is contained in:
		
							parent
							
								
									ee5eb8b546
								
							
						
					
					
						commit
						36fb5def4b
					
				
					 4 changed files with 36 additions and 39 deletions
				
			
		|  | @ -581,11 +581,10 @@ class MetacontactManager(): | |||
| 		#FIXME: can this append ? | ||||
| 		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 iter_metacontacts_families(self, account):		 | ||||
| 		for tag in self._metacontacts_tags[account]: | ||||
| 			family = self._get_metacontacts_family_from_tag(account, tag) | ||||
| 			yield family | ||||
| 
 | ||||
| 	def _get_metacontacts_tag(self, account, jid): | ||||
| 		'''Returns the tag of a jid''' | ||||
|  | @ -643,7 +642,7 @@ class MetacontactManager(): | |||
| 		tag = self._get_metacontacts_tag(account, jid) | ||||
| 		if not tag: | ||||
| 			return False | ||||
| 		meta_jids = self.get_metacontacts_jids(tag, accounts) | ||||
| 		meta_jids = self._get_metacontacts_jids(tag, accounts) | ||||
| 		return len(meta_jids) > 1 or len(meta_jids[account]) > 1 | ||||
| 
 | ||||
| 	def is_big_brother(self, account, jid, accounts): | ||||
|  | @ -651,12 +650,12 @@ class MetacontactManager(): | |||
| 		if family: | ||||
| 			nearby_family = [data for data in family | ||||
| 				if account in accounts] | ||||
| 			bb_data = self.get_metacontacts_big_brother(nearby_family) | ||||
| 			bb_data = self._get_metacontacts_big_brother(nearby_family) | ||||
| 			if bb_data['jid'] == jid and bb_data['account'] == account: | ||||
| 				return True | ||||
| 		return False | ||||
| 
 | ||||
| 	def get_metacontacts_jids(self, tag, accounts): | ||||
| 	def _get_metacontacts_jids(self, tag, accounts): | ||||
| 		'''Returns all jid for the given tag in the form {acct: [jid1, jid2],.}''' | ||||
| 		answers = {} | ||||
| 		for account in self._metacontacts_tags: | ||||
|  | @ -673,9 +672,9 @@ class MetacontactManager(): | |||
| 		[{'account': acct, 'jid': jid, 'order': order}, ] | ||||
| 		'order' is optional''' | ||||
| 		tag = self._get_metacontacts_tag(account, jid) | ||||
| 		return self.get_metacontacts_family_from_tag(account, tag) | ||||
| 		return self._get_metacontacts_family_from_tag(account, tag) | ||||
| 
 | ||||
| 	def get_metacontacts_family_from_tag(self, account, tag): | ||||
| 	def _get_metacontacts_family_from_tag(self, account, tag): | ||||
| 		if not tag: | ||||
| 			return [] | ||||
| 		answers = [] | ||||
|  | @ -765,8 +764,30 @@ class MetacontactManager(): | |||
| 		if account2 > account1: | ||||
| 			return -1 | ||||
| 		return 0 | ||||
| 	 | ||||
| 	def get_nearby_family_and_big_brother(self, family, account): | ||||
| 		'''Return the nearby family and its Big Brother | ||||
| 
 | ||||
| 	def get_metacontacts_big_brother(self, family): | ||||
| 		Nearby family is the part of the family that is grouped with the metacontact. | ||||
| 		A metacontact may be over different accounts. If accounts are not merged | ||||
| 		then the given family is split account wise. | ||||
| 
 | ||||
| 		(nearby_family, big_brother_jid, big_brother_account) | ||||
| 		''' | ||||
| 		if common.gajim.config.get('mergeaccounts'): | ||||
| 			# group all together | ||||
| 			nearby_family = family | ||||
| 		else: | ||||
| 			# we want one nearby_family per account | ||||
| 			nearby_family = [data for data in family if account == data['account']] | ||||
| 
 | ||||
| 		big_brother_data = self._get_metacontacts_big_brother(nearby_family) | ||||
| 		big_brother_jid = big_brother_data['jid'] | ||||
| 		big_brother_account = big_brother_data['account'] | ||||
| 
 | ||||
| 		return (nearby_family, big_brother_jid, big_brother_account) | ||||
| 
 | ||||
| 	def _get_metacontacts_big_brother(self, family): | ||||
| 		'''which of the family will be the big brother under wich all | ||||
| 		others will be ?''' | ||||
| 		family.sort(cmp=self._compare_metacontacts) | ||||
|  |  | |||
|  | @ -2145,7 +2145,7 @@ class Interface: | |||
| 		family = gajim.contacts.get_metacontacts_family(account, jid) | ||||
| 		if family: | ||||
| 			nearby_family, bb_jid, bb_account = \ | ||||
| 				self.roster._get_nearby_family_and_big_brother(family, account) | ||||
| 				gajim.contacts.get_nearby_family_and_big_brother(family, account) | ||||
| 		else: | ||||
| 			bb_jid, bb_account = jid, account | ||||
| 		self.roster.select_contact(bb_jid, bb_account) | ||||
|  |  | |||
|  | @ -604,29 +604,7 @@ class RosterWindow: | |||
| 					big_brother_account=big_brother_account) | ||||
| 
 | ||||
| 	def _get_nearby_family_and_big_brother(self, family, account): | ||||
| 		'''Return the nearby family and its Big Brother | ||||
| 
 | ||||
| 		Nearby family is the part of the family that is grouped with the metacontact. | ||||
| 		A metacontact may be over different accounts. If regroup is s False the | ||||
| 		given family is split account wise. | ||||
| 
 | ||||
| 		(nearby_family, big_brother_jid, big_brother_account) | ||||
| 		''' | ||||
| 		if self.regroup: | ||||
| 			# group all together | ||||
| 			nearby_family = family | ||||
| 		else: | ||||
| 			# we want one nearby_family per account | ||||
| 			nearby_family = [data for data in family | ||||
| 				if account == data['account']] | ||||
| 
 | ||||
| 		big_brother_data = gajim.contacts.get_metacontacts_big_brother( | ||||
| 			nearby_family) | ||||
| 		big_brother_jid = big_brother_data['jid'] | ||||
| 		big_brother_account = big_brother_data['account'] | ||||
| 
 | ||||
| 		return (nearby_family, big_brother_jid, big_brother_account) | ||||
| 
 | ||||
| 		return gajim.contacts.get_nearby_family_and_big_brother(family, account) | ||||
| 
 | ||||
| 	def _add_self_contact(self, account): | ||||
| 		'''Add account's SelfContact to roster and draw it and the account. | ||||
|  | @ -649,10 +627,8 @@ class RosterWindow: | |||
| 
 | ||||
| 		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) | ||||
| 		for family in gajim.contacts.iter_metacontacts_families(account): | ||||
| 			self._recalibrate_metacontact_family(family, account) | ||||
| 
 | ||||
| 	def add_contact(self, jid, account): | ||||
|  |  | |||
|  | @ -382,7 +382,7 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession): | |||
| 		family = gajim.contacts.get_metacontacts_family(self.conn.name, jid) | ||||
| 		if family: | ||||
| 			nearby_family, bb_jid, bb_account = \ | ||||
| 				gajim.interface.roster._get_nearby_family_and_big_brother(family, | ||||
| 				gajim.contacts.get_nearby_family_and_big_brother(family, | ||||
| 				self.conn.name) | ||||
| 		else: | ||||
| 			bb_jid, bb_account = jid, self.conn.name | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue