handle GMailNewMailCB with NEC

This commit is contained in:
Yann Leboulanger 2010-09-09 15:21:43 +02:00
parent 35039100ff
commit 42591685fc
2 changed files with 36 additions and 19 deletions

View File

@ -1108,6 +1108,8 @@ ConnectionJingle, ConnectionIBBytestream):
self._nec_roster_received)
gajim.ged.register_event_handler('error-received', ged.CORE,
self._nec_error_received)
gajim.ged.register_event_handler('gmail-new-mail-received', ged.CORE,
self._nec_gmail_new_mail_received)
def build_http_auth_answer(self, iq_obj, answer):
if not self.connection or self.connected < 2:
@ -1321,20 +1323,25 @@ ConnectionJingle, ConnectionIBBytestream):
gajim.nec.push_incoming_event(TimeResultReceivedEvent(None,
conn=self, iq_obj=iq_obj))
def _gMailNewMailCB(self, con, gm):
def _gMailNewMailCB(self, con, iq_obj):
"""
Called when we get notified of new mail messages in gmail account
"""
log.debug('gMailNewMailCB')
gajim.nec.push_incoming_event(GmailNewMailReceivedEvent(None,
conn=self, iq_obj=iq_obj))
raise common.xmpp.NodeProcessed
def _nec_gmail_new_mail_received(self, obj):
if obj.conn.name != self.name:
return
if not self.connection or self.connected < 2:
return
if not gm.getTag('new-mail'):
return
if gm.getTag('new-mail').getNamespace() == common.xmpp.NS_GMAILNOTIFY:
# we'll now ask the server for the exact number of new messages
jid = gajim.get_jid_from_account(self.name)
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.setID(self.connection.getAnID())
log.debug('Got notification of new gmail e-mail on %s. Asking the '
'server for more info.' % jid)
iq = common.xmpp.Iq(typ='get')
query = iq.setTag('query')
query.setNamespace(common.xmpp.NS_GMAILNOTIFY)
# we want only be notified about newer mails
@ -1343,7 +1350,6 @@ ConnectionJingle, ConnectionIBBytestream):
if self.gmail_last_time:
query.setAttr('newer-than-time', self.gmail_last_time)
self.connection.send(iq)
raise common.xmpp.NodeProcessed
def _gMailQueryCB(self, con, iq_obj):
"""

View File

@ -558,3 +558,14 @@ class ErrorReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
self.errmsg = self.iq_obj.getErrorMsg()
self.errcode = self.iq_obj.getErrorCode()
return True
class GmailNewMailReceivedEvent(nec.NetworkIncomingEvent):
name = 'gmail-new-mail-received'
base_network_events = []
def generate(self):
if not self.iq_obj.getTag('new-mail'):
return
if self.iq_obj.getTag('new-mail').getNamespace() != xmpp.NS_GMAILNOTIFY:
return
return True