handle GMailNewMailCB with NEC
This commit is contained in:
parent
35039100ff
commit
42591685fc
|
@ -1108,6 +1108,8 @@ ConnectionJingle, ConnectionIBBytestream):
|
||||||
self._nec_roster_received)
|
self._nec_roster_received)
|
||||||
gajim.ged.register_event_handler('error-received', ged.CORE,
|
gajim.ged.register_event_handler('error-received', ged.CORE,
|
||||||
self._nec_error_received)
|
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):
|
def build_http_auth_answer(self, iq_obj, answer):
|
||||||
if not self.connection or self.connected < 2:
|
if not self.connection or self.connected < 2:
|
||||||
|
@ -1321,29 +1323,33 @@ ConnectionJingle, ConnectionIBBytestream):
|
||||||
gajim.nec.push_incoming_event(TimeResultReceivedEvent(None,
|
gajim.nec.push_incoming_event(TimeResultReceivedEvent(None,
|
||||||
conn=self, iq_obj=iq_obj))
|
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
|
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:
|
if not self.connection or self.connected < 2:
|
||||||
return
|
return
|
||||||
if not gm.getTag('new-mail'):
|
# we'll now ask the server for the exact number of new messages
|
||||||
return
|
jid = gajim.get_jid_from_account(self.name)
|
||||||
if gm.getTag('new-mail').getNamespace() == common.xmpp.NS_GMAILNOTIFY:
|
log.debug('Got notification of new gmail e-mail on %s. Asking the '
|
||||||
# we'll now ask the server for the exact number of new messages
|
'server for more info.' % jid)
|
||||||
jid = gajim.get_jid_from_account(self.name)
|
iq = common.xmpp.Iq(typ='get')
|
||||||
log.debug('Got notification of new gmail e-mail on %s. Asking the server for more info.' % jid)
|
query = iq.setTag('query')
|
||||||
iq = common.xmpp.Iq(typ = 'get')
|
query.setNamespace(common.xmpp.NS_GMAILNOTIFY)
|
||||||
iq.setID(self.connection.getAnID())
|
# we want only be notified about newer mails
|
||||||
query = iq.setTag('query')
|
if self.gmail_last_tid:
|
||||||
query.setNamespace(common.xmpp.NS_GMAILNOTIFY)
|
query.setAttr('newer-than-tid', self.gmail_last_tid)
|
||||||
# we want only be notified about newer mails
|
if self.gmail_last_time:
|
||||||
if self.gmail_last_tid:
|
query.setAttr('newer-than-time', self.gmail_last_time)
|
||||||
query.setAttr('newer-than-tid', self.gmail_last_tid)
|
self.connection.send(iq)
|
||||||
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):
|
def _gMailQueryCB(self, con, iq_obj):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -557,4 +557,15 @@ class ErrorReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
||||||
self.get_jid_resource()
|
self.get_jid_resource()
|
||||||
self.errmsg = self.iq_obj.getErrorMsg()
|
self.errmsg = self.iq_obj.getErrorMsg()
|
||||||
self.errcode = self.iq_obj.getErrorCode()
|
self.errcode = self.iq_obj.getErrorCode()
|
||||||
return True
|
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
|
||||||
|
|
Loading…
Reference in New Issue