when new_chat give the oontact with higher priority not the first resource
This commit is contained in:
		
							parent
							
								
									11e85d4984
								
							
						
					
					
						commit
						de46aeaa08
					
				
					 5 changed files with 37 additions and 22 deletions
				
			
		| 
						 | 
				
			
			@ -100,7 +100,18 @@ def get_first_contact_instance_from_jid(account, jid):
 | 
			
		|||
			contact = gc_contacts[account][room][nick] 
 | 
			
		||||
	return contact
 | 
			
		||||
 | 
			
		||||
def get_contact_instance_with_highest_priority(account, jid):
 | 
			
		||||
	contact_instances = contacts[account][jid]
 | 
			
		||||
	which_has_highest_prio = 0 # which resource has highest priority?
 | 
			
		||||
	which = 0
 | 
			
		||||
	for c in contact_instances[1:]:
 | 
			
		||||
		which += 1
 | 
			
		||||
		if c.priority > which_has_highest_prio:
 | 
			
		||||
			which_has_highest_prio = which
 | 
			
		||||
	return contacts[account][jid][which_has_highest_prio]
 | 
			
		||||
 | 
			
		||||
def get_contact_name_from_jid(account, jid):
 | 
			
		||||
	print `contacts[account][jid]`
 | 
			
		||||
	return contacts[account][jid][0].name
 | 
			
		||||
 | 
			
		||||
def get_jid_without_resource(jid):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -516,8 +516,8 @@ class PreferencesWindow:
 | 
			
		|||
			#open new tabbed chat windows
 | 
			
		||||
			for jid in jids:
 | 
			
		||||
				if kind == 'chats':
 | 
			
		||||
					user = gajim.contacts[acct][jid][0]
 | 
			
		||||
					self.plugin.roster.new_chat(user, acct)
 | 
			
		||||
					c = gajim.get_contact_instance_with_highest_priority(acct, jid)
 | 
			
		||||
					self.plugin.roster.new_chat(c, acct)
 | 
			
		||||
				if kind == 'gc':
 | 
			
		||||
					self.plugin.roster.new_room(jid, saved_var[jid]['nick'], acct)
 | 
			
		||||
				window = windows[jid]
 | 
			
		||||
| 
						 | 
				
			
			@ -549,8 +549,8 @@ class PreferencesWindow:
 | 
			
		|||
			#open new tabbed chat windows
 | 
			
		||||
			for jid in jids:
 | 
			
		||||
				if kind == 'chats':
 | 
			
		||||
					user = gajim.contacts[acct][jid][0]
 | 
			
		||||
					self.plugin.roster.new_chat(user, acct)
 | 
			
		||||
					c = gajim.get_contact_instance_with_highest_priority(acct, jid)
 | 
			
		||||
					self.plugin.roster.new_chat(c, acct)
 | 
			
		||||
				if kind == 'gc':
 | 
			
		||||
					self.plugin.roster.new_room(jid, saved_var[jid]['nick'], acct)
 | 
			
		||||
				window = windows[jid]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1135,7 +1135,8 @@ class PopupNotificationWindow:
 | 
			
		|||
		# use Contact class, new_chat expects it that way
 | 
			
		||||
		# is it in the roster?
 | 
			
		||||
		if gajim.contacts[self.account].has_key(self.jid):
 | 
			
		||||
			contact = gajim.contacts[self.account][self.jid][0]
 | 
			
		||||
			contact = gajim.get_contact_instance_with_highest_priority(
 | 
			
		||||
				self.account, self.jid)
 | 
			
		||||
		else:
 | 
			
		||||
			keyID = ''
 | 
			
		||||
			attached_keys = gajim.config.get_per('accounts', self.account,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -472,12 +472,12 @@ class Interface:
 | 
			
		|||
					model = tv.get_model()
 | 
			
		||||
					i = gc.get_contact_iter(jid, nick)
 | 
			
		||||
					if i:
 | 
			
		||||
						show = model.get_value(i, 3)
 | 
			
		||||
						show = model[i][3]
 | 
			
		||||
					else:
 | 
			
		||||
						show = 'offline'
 | 
			
		||||
					u = Contact(jid = fjid, name = nick, groups = ['none'],
 | 
			
		||||
					c = Contact(jid = fjid, name = nick, groups = ['none'],
 | 
			
		||||
						show = show, ask = 'none')
 | 
			
		||||
					self.roster.new_chat(u, account)
 | 
			
		||||
					self.roster.new_chat(c, account)
 | 
			
		||||
				self.windows[account]['chats'][fjid].print_conversation(
 | 
			
		||||
					'Error %s: %s' % (array[1], array[2]), fjid, 'status')
 | 
			
		||||
				return
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1147,7 +1147,8 @@ _('If "%s" accepts this request you will know his status.') %jid).get_response()
 | 
			
		|||
				if self.plugin.windows[account]['chats'].has_key(jid):
 | 
			
		||||
					self.plugin.windows[account]['chats'][jid].set_active_tab(jid)
 | 
			
		||||
				elif gajim.contacts[account].has_key(jid):
 | 
			
		||||
					self.new_chat(gajim.contacts[account][jid][0], account)
 | 
			
		||||
					c = gajim.get_contact_instance_with_highest_priority(account, jid)
 | 
			
		||||
					self.new_chat(c, account)
 | 
			
		||||
					self.plugin.windows[account]['chats'][jid].set_active_tab(jid)
 | 
			
		||||
				self.plugin.windows[account]['chats'][jid].window.present()
 | 
			
		||||
			return True
 | 
			
		||||
| 
						 | 
				
			
			@ -1346,37 +1347,37 @@ _('If "%s" accepts this request you will know his status.') %jid).get_response()
 | 
			
		|||
		self.update_status_comboxbox()
 | 
			
		||||
		self.make_menu()
 | 
			
		||||
	
 | 
			
		||||
	def new_chat(self, user, account):
 | 
			
		||||
	def new_chat(self, contact, account):
 | 
			
		||||
		if gajim.config.get('usetabbedchat'):
 | 
			
		||||
			if not self.plugin.windows[account]['chats'].has_key('tabbed'):
 | 
			
		||||
				self.plugin.windows[account]['chats']['tabbed'] = \
 | 
			
		||||
					tabbed_chat_window.TabbedChatWindow(user, self.plugin, account)
 | 
			
		||||
					tabbed_chat_window.TabbedChatWindow(contact, self.plugin, account)
 | 
			
		||||
			else:
 | 
			
		||||
				self.plugin.windows[account]['chats']['tabbed'].new_user(user)
 | 
			
		||||
				self.plugin.windows[account]['chats']['tabbed'].new_user(contact)
 | 
			
		||||
				
 | 
			
		||||
			self.plugin.windows[account]['chats'][user.jid] = \
 | 
			
		||||
			self.plugin.windows[account]['chats'][contact.jid] = \
 | 
			
		||||
				self.plugin.windows[account]['chats']['tabbed']
 | 
			
		||||
		else:
 | 
			
		||||
			self.plugin.windows[account]['chats'][user.jid] = \
 | 
			
		||||
				tabbed_chat_window.TabbedChatWindow(user, self.plugin, account)
 | 
			
		||||
			self.plugin.windows[account]['chats'][contact.jid] = \
 | 
			
		||||
				tabbed_chat_window.TabbedChatWindow(contact, self.plugin, account)
 | 
			
		||||
 | 
			
		||||
	def new_chat_from_jid(self, account, jid):
 | 
			
		||||
		if gajim.contacts[account].has_key(jid):
 | 
			
		||||
			user = gajim.contacts[account][jid][0]
 | 
			
		||||
			contact = gajim.get_contact_instance_with_highest_priority(account, jid)
 | 
			
		||||
		else:
 | 
			
		||||
			keyID = ''
 | 
			
		||||
			attached_keys = gajim.config.get_per('accounts', account,
 | 
			
		||||
				'attached_gpg_keys').split()
 | 
			
		||||
			if jid in attached_keys:
 | 
			
		||||
				keyID = attached_keys[attached_keys.index(jid) + 1]
 | 
			
		||||
			user = Contact(jid = jid, name = jid.split('@')[0],
 | 
			
		||||
			contact = Contact(jid = jid, name = jid.split('@')[0],
 | 
			
		||||
				groups = [_('not in the roster')], show = 'not in the roster',
 | 
			
		||||
				status = '', sub = 'none', keyID = keyID)
 | 
			
		||||
			gajim.contacts[account][jid] = [user]
 | 
			
		||||
			self.add_contact_to_roster(user.jid, account)			
 | 
			
		||||
			gajim.contacts[account][jid] = [contact]
 | 
			
		||||
			self.add_contact_to_roster(contact.jid, account)			
 | 
			
		||||
 | 
			
		||||
		if not self.plugin.windows[account]['chats'].has_key(jid):
 | 
			
		||||
			self.new_chat(user, account)
 | 
			
		||||
			self.new_chat(contact, account)
 | 
			
		||||
		self.plugin.windows[account]['chats'][jid].set_active_tab(jid)
 | 
			
		||||
		self.plugin.windows[account]['chats'][jid].window.present()
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1460,7 +1461,8 @@ _('If "%s" accepts this request you will know his status.') %jid).get_response()
 | 
			
		|||
			self.tree.set_cursor(path)
 | 
			
		||||
		else:
 | 
			
		||||
			if not self.plugin.windows[account]['chats'].has_key(jid):
 | 
			
		||||
				self.new_chat(gajim.contacts[account][jid][0], account)
 | 
			
		||||
				c = gajim.get_contact_instance_with_highest_priority(account, jid)
 | 
			
		||||
				self.new_chat(c, account)
 | 
			
		||||
				if path:
 | 
			
		||||
					self.tree.expand_row(path[0:1], False)
 | 
			
		||||
					self.tree.expand_row(path[0:2], False)
 | 
			
		||||
| 
						 | 
				
			
			@ -1621,7 +1623,8 @@ _('If "%s" accepts this request you will know his status.') %jid).get_response()
 | 
			
		|||
			if self.plugin.windows[account]['chats'].has_key(jid):
 | 
			
		||||
				self.plugin.windows[account]['chats'][jid].set_active_tab(jid)
 | 
			
		||||
			elif gajim.contacts[account].has_key(jid):
 | 
			
		||||
				self.new_chat(gajim.contacts[account][jid][0], account)
 | 
			
		||||
				c = gajim.get_contact_instance_with_highest_priority(account, jid)
 | 
			
		||||
				self.new_chat(c, account)
 | 
			
		||||
				self.plugin.windows[account]['chats'][jid].set_active_tab(jid)
 | 
			
		||||
			self.plugin.windows[account]['chats'][jid].window.present()
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue