improve new gmail e-mail popup window. Fixes #3252
This commit is contained in:
		
							parent
							
								
									da2ca25d5f
								
							
						
					
					
						commit
						d1762dd9a0
					
				
					 2 changed files with 46 additions and 12 deletions
				
			
		| 
						 | 
					@ -1371,6 +1371,9 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
 | 
				
			||||||
		except:
 | 
							except:
 | 
				
			||||||
			HAS_IDLE = False
 | 
								HAS_IDLE = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							self.gmail_last_tid = None
 | 
				
			||||||
 | 
							self.gmail_last_time = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	def build_http_auth_answer(self, iq_obj, answer):
 | 
						def build_http_auth_answer(self, iq_obj, answer):
 | 
				
			||||||
		if answer == 'yes':
 | 
							if answer == 'yes':
 | 
				
			||||||
			self.connection.send(iq_obj.buildReply('result'))
 | 
								self.connection.send(iq_obj.buildReply('result'))
 | 
				
			||||||
| 
						 | 
					@ -1582,9 +1585,14 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
 | 
				
			||||||
			jid = gajim.get_jid_from_account(self.name)
 | 
								jid = gajim.get_jid_from_account(self.name)
 | 
				
			||||||
			gajim.log.debug('Got notification of new gmail e-mail on %s. Asking the server for more info.' % jid)
 | 
								gajim.log.debug('Got notification of new gmail e-mail on %s. Asking the server for more info.' % jid)
 | 
				
			||||||
			iq = common.xmpp.Iq(typ = 'get')
 | 
								iq = common.xmpp.Iq(typ = 'get')
 | 
				
			||||||
			iq.setAttr('id', '13')
 | 
								iq.setID(self.connection.getAnID())
 | 
				
			||||||
			query = iq.setTag('query')
 | 
								query = iq.setTag('query')
 | 
				
			||||||
			query.setNamespace(common.xmpp.NS_GMAILNOTIFY)
 | 
								query.setNamespace(common.xmpp.NS_GMAILNOTIFY)
 | 
				
			||||||
 | 
								# we want only be notified about newer mails
 | 
				
			||||||
 | 
								if self.gmail_last_tid:
 | 
				
			||||||
 | 
									query.setAttr('newer-than-tid', self.gmail_last_tid)
 | 
				
			||||||
 | 
								if self.gmail_last_time:
 | 
				
			||||||
 | 
									query.setAttr('newer-than-time', self.gmail_last_time)
 | 
				
			||||||
			self.connection.send(iq)
 | 
								self.connection.send(iq)
 | 
				
			||||||
			raise common.xmpp.NodeProcessed
 | 
								raise common.xmpp.NodeProcessed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1601,16 +1609,34 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
 | 
				
			||||||
				if gm.getTag('mailbox').getTag('mail-thread-info'):
 | 
									if gm.getTag('mailbox').getTag('mail-thread-info'):
 | 
				
			||||||
					gmail_messages = gm.getTag('mailbox').getTags('mail-thread-info')
 | 
										gmail_messages = gm.getTag('mailbox').getTags('mail-thread-info')
 | 
				
			||||||
					for gmessage in gmail_messages:
 | 
										for gmessage in gmail_messages:
 | 
				
			||||||
						sender = gmessage.getTag('senders').getTag('sender')
 | 
											unread_senders = []
 | 
				
			||||||
						if not sender:
 | 
											for sender in gmessage.getTag('senders').getTags('sender'):
 | 
				
			||||||
 | 
												if sender.getAttr('unread') != '1':
 | 
				
			||||||
 | 
													continue
 | 
				
			||||||
 | 
												if sender.getAttr('name'):
 | 
				
			||||||
 | 
													unread_senders.append(sender.getAttr('name') + '< ' + \
 | 
				
			||||||
 | 
														sender.getAttr('address') + '>')
 | 
				
			||||||
 | 
												else:
 | 
				
			||||||
 | 
													unread_senders.append(sender.getAttr('address'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
											if not unread_senders:
 | 
				
			||||||
							continue
 | 
												continue
 | 
				
			||||||
						gmail_from = sender.getAttr('address')
 | 
					 | 
				
			||||||
						gmail_subject = gmessage.getTag('subject').getData()
 | 
											gmail_subject = gmessage.getTag('subject').getData()
 | 
				
			||||||
						gmail_snippet = gmessage.getTag('snippet').getData()
 | 
											gmail_snippet = gmessage.getTag('snippet').getData()
 | 
				
			||||||
 | 
											tid = int(gmessage.getAttr('tid'))
 | 
				
			||||||
 | 
											if not self.gmail_last_tid or tid > self.gmail_last_tid:
 | 
				
			||||||
 | 
												self.gmail_last_tid = tid
 | 
				
			||||||
						gmail_messages_list.append({ \
 | 
											gmail_messages_list.append({ \
 | 
				
			||||||
							'From': gmail_from, \
 | 
												'From': unread_senders, \
 | 
				
			||||||
							'Subject': gmail_subject, \
 | 
												'Subject': gmail_subject, \
 | 
				
			||||||
							'Snippet': gmail_snippet})
 | 
												'Snippet': gmail_snippet, \
 | 
				
			||||||
 | 
												'url': gmessage.getAttr('url'), \
 | 
				
			||||||
 | 
												'participation': gmessage.getAttr('participation'), \
 | 
				
			||||||
 | 
												'messages': gmessage.getAttr('messages'), \
 | 
				
			||||||
 | 
												'date': gmessage.getAttr('date')})
 | 
				
			||||||
 | 
										self.gmail_last_time = int(gm.getTag('mailbox').getAttr(
 | 
				
			||||||
 | 
											'result-time'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				jid = gajim.get_jid_from_account(self.name)
 | 
									jid = gajim.get_jid_from_account(self.name)
 | 
				
			||||||
				gajim.log.debug(('You have %s new gmail e-mails on %s.') % (newmsgs, jid))
 | 
									gajim.log.debug(('You have %s new gmail e-mails on %s.') % (newmsgs, jid))
 | 
				
			||||||
				self.dispatch('GMAIL_NOTIFY', (jid, newmsgs, gmail_messages_list))
 | 
									self.dispatch('GMAIL_NOTIFY', (jid, newmsgs, gmail_messages_list))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										20
									
								
								src/gajim.py
									
										
									
									
									
								
							
							
						
						
									
										20
									
								
								src/gajim.py
									
										
									
									
									
								
							| 
						 | 
					@ -1648,18 +1648,26 @@ class Interface:
 | 
				
			||||||
				gmail_new_messages, gmail_new_messages)
 | 
									gmail_new_messages, gmail_new_messages)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if gajim.config.get('notify_on_new_gmail_email_extra'):
 | 
								if gajim.config.get('notify_on_new_gmail_email_extra'):
 | 
				
			||||||
 | 
									cnt = 0
 | 
				
			||||||
				for gmessage in gmail_messages_list:
 | 
									for gmessage in gmail_messages_list:
 | 
				
			||||||
					#FIXME: emulate Gtalk client popups. find out what they parse and how
 | 
										#FIXME: emulate Gtalk client popups. find out what they parse and
 | 
				
			||||||
					#they decide what to show
 | 
										# how they decide what to show each message has a 'From',
 | 
				
			||||||
					# each message has a 'From', 'Subject' and 'Snippet' field
 | 
										# 'Subject' and 'Snippet' field
 | 
				
			||||||
					text += _('\nFrom: %(from_address)s') % \
 | 
										if cnt >=5:
 | 
				
			||||||
						{'from_address': gmessage['From']}
 | 
											break
 | 
				
			||||||
 | 
										senders = reduce(lambda b, a: a + ',\n     ' + b,
 | 
				
			||||||
 | 
											gmessage['From'])
 | 
				
			||||||
 | 
										text += _('\n\nFrom: %(from_address)s\nSubject: %(subject)s\n%(snippet)s') % \
 | 
				
			||||||
 | 
											{'from_address': senders, 'subject': gmessage['Subject'],
 | 
				
			||||||
 | 
											'snippet': gmessage['Snippet']} 
 | 
				
			||||||
 | 
										cnt += 1 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if gajim.config.get_per('soundevents', 'gmail_received', 'enabled'):
 | 
								if gajim.config.get_per('soundevents', 'gmail_received', 'enabled'):
 | 
				
			||||||
				helpers.play_sound('gmail_received')
 | 
									helpers.play_sound('gmail_received')
 | 
				
			||||||
			path = gtkgui_helpers.get_path_to_generic_or_avatar(img)
 | 
								path = gtkgui_helpers.get_path_to_generic_or_avatar(img)
 | 
				
			||||||
			notify.popup(_('New E-mail'), jid, account, 'gmail',
 | 
								notify.popup(_('New E-mail'), jid, account, 'gmail',
 | 
				
			||||||
				path_to_image = path, title = title, text = text)
 | 
									path_to_image=path, title=title,
 | 
				
			||||||
 | 
									text=gobject.markup_escape_text(text))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if self.remote_ctrl:
 | 
							if self.remote_ctrl:
 | 
				
			||||||
			self.remote_ctrl.raise_signal('NewGmail', (account, array))
 | 
								self.remote_ctrl.raise_signal('NewGmail', (account, array))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue