support for one 'chat' session per Contact
This commit is contained in:
		
							parent
							
								
									3bb2eabadb
								
							
						
					
					
						commit
						00209abaf9
					
				
					 4 changed files with 36 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -1815,6 +1815,9 @@ class ChatControl(ChatControlBase):
 | 
			
		|||
				encrypted = data[4], subject = data[1], xhtml = data[7])
 | 
			
		||||
			if len(data) > 6 and isinstance(data[6], int):
 | 
			
		||||
				message_ids.append(data[6])
 | 
			
		||||
 | 
			
		||||
			if len(data) > 8:
 | 
			
		||||
				self.set_thread_id(data[8])
 | 
			
		||||
		if message_ids:
 | 
			
		||||
			gajim.logger.set_read_messages(message_ids)
 | 
			
		||||
		gajim.events.remove_events(self.account, jid_with_resource,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,6 +16,8 @@
 | 
			
		|||
 | 
			
		||||
import common.gajim
 | 
			
		||||
 | 
			
		||||
import random, string
 | 
			
		||||
 | 
			
		||||
class Contact:
 | 
			
		||||
	'''Information concerning each contact'''
 | 
			
		||||
	def __init__(self, jid='', name='', groups=[], show='', status='', sub='',
 | 
			
		||||
| 
						 | 
				
			
			@ -50,6 +52,20 @@ class Contact:
 | 
			
		|||
		self.chatstate = chatstate
 | 
			
		||||
		self.last_status_time = last_status_time
 | 
			
		||||
 | 
			
		||||
		# XEP-0201
 | 
			
		||||
		self.sessions = {}
 | 
			
		||||
 | 
			
		||||
	def new_session(self):
 | 
			
		||||
		thread_id = "".join([random.choice(string.letters) for x in xrange(0,32)])
 | 
			
		||||
		self.sessions[self.get_full_jid()] = thread_id
 | 
			
		||||
		return thread_id
 | 
			
		||||
 | 
			
		||||
	def get_session(self):
 | 
			
		||||
		try:
 | 
			
		||||
			return self.sessions[self.get_full_jid()]
 | 
			
		||||
		except KeyError:
 | 
			
		||||
			return None
 | 
			
		||||
 | 
			
		||||
	def get_full_jid(self):
 | 
			
		||||
		if self.resource:
 | 
			
		||||
			return self.jid + '/' + self.resource
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -37,6 +37,8 @@ class MessageControl:
 | 
			
		|||
		self.hide_chat_buttons_current = False
 | 
			
		||||
		self.resource = resource
 | 
			
		||||
 | 
			
		||||
		self.thread_id = self.contact.get_session()
 | 
			
		||||
 | 
			
		||||
		gajim.last_message_time[self.account][self.get_full_jid()] = 0
 | 
			
		||||
 | 
			
		||||
		self.xml = gtkgui_helpers.get_glade('message_window.glade', widget_name)
 | 
			
		||||
| 
						 | 
				
			
			@ -110,14 +112,26 @@ class MessageControl:
 | 
			
		|||
	def get_specific_unread(self):
 | 
			
		||||
		return len(gajim.events.get_events(self.account, self.contact.jid))
 | 
			
		||||
 | 
			
		||||
	def set_thread_id(self, thread_id):
 | 
			
		||||
		if thread_id == self.thread_id:
 | 
			
		||||
			return
 | 
			
		||||
		if self.thread_id:
 | 
			
		||||
			print "starting a new session, forgetting about the old one!"
 | 
			
		||||
		self.thread_id = thread_id
 | 
			
		||||
		self.contact.sessions[self.contact.get_full_jid()] = thread_id
 | 
			
		||||
 | 
			
		||||
	def send_message(self, message, keyID = '', type = 'chat',
 | 
			
		||||
	chatstate = None, msg_id = None, composing_jep = None, resource = None,
 | 
			
		||||
	user_nick = None):
 | 
			
		||||
		'''Send the given message to the active tab. Doesn't return None if error
 | 
			
		||||
		'''
 | 
			
		||||
		jid = self.contact.jid
 | 
			
		||||
 | 
			
		||||
		if not self.thread_id:
 | 
			
		||||
			self.thread_id = self.contact.new_session()
 | 
			
		||||
 | 
			
		||||
		# Send and update history
 | 
			
		||||
		return gajim.connections[self.account].send_message(jid, message, keyID,
 | 
			
		||||
			type = type, chatstate = chatstate, msg_id = msg_id,
 | 
			
		||||
			composing_jep = composing_jep, resource = self.resource,
 | 
			
		||||
			user_nick = user_nick)
 | 
			
		||||
			user_nick = user_nick, thread = self.thread_id)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3596,6 +3596,8 @@ class RosterWindow:
 | 
			
		|||
			typ = ''
 | 
			
		||||
			if msg_type == 'error':
 | 
			
		||||
				typ = 'status'
 | 
			
		||||
			if thread:
 | 
			
		||||
				ctrl.set_thread_id(thread)
 | 
			
		||||
			ctrl.print_conversation(msg, typ, tim = tim, encrypted = encrypted,
 | 
			
		||||
						subject = subject, xhtml = xhtml)
 | 
			
		||||
			if msg_id:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue