fixed gmail new mail notification check
without the tid gmail ignores the query
This commit is contained in:
parent
9165cbf7f6
commit
badd327360
1 changed files with 12 additions and 4 deletions
|
@ -46,6 +46,7 @@ class Gmail(BasePlugin):
|
||||||
self._handle_new_mail))
|
self._handle_new_mail))
|
||||||
|
|
||||||
self._last_result_time = None
|
self._last_result_time = None
|
||||||
|
self._last_result_tid = None
|
||||||
|
|
||||||
def plugin_end(self):
|
def plugin_end(self):
|
||||||
self.xmpp.remove_handler('Gmail New Mail')
|
self.xmpp.remove_handler('Gmail New Mail')
|
||||||
|
@ -57,13 +58,19 @@ class Gmail(BasePlugin):
|
||||||
|
|
||||||
def check(self, block=True, timeout=None, callback=None):
|
def check(self, block=True, timeout=None, callback=None):
|
||||||
last_time = self._last_result_time
|
last_time = self._last_result_time
|
||||||
self._last_result_time = str(int(time.time() * 1000))
|
last_tid = self._last_result_tid
|
||||||
return self.search(newer=last_time,
|
data = self.search(newer_time=last_time,
|
||||||
|
newer_tid=last_tid,
|
||||||
block=block,
|
block=block,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
callback=callback)
|
callback=callback)
|
||||||
|
|
||||||
def search(self, query=None, newer=None, block=True,
|
self._last_result_time = data["gmail_messages"]["result_time"]
|
||||||
|
if data["gmail_messages"]["threads"]:
|
||||||
|
self._last_result_tid = data["gmail_messages"]["threads"][0]["tid"]
|
||||||
|
return data
|
||||||
|
|
||||||
|
def search(self, query=None, newer_time=None, newer_tid=None, block=True,
|
||||||
timeout=None, callback=None):
|
timeout=None, callback=None):
|
||||||
if not query:
|
if not query:
|
||||||
log.info('Gmail: Checking for new email')
|
log.info('Gmail: Checking for new email')
|
||||||
|
@ -73,5 +80,6 @@ class Gmail(BasePlugin):
|
||||||
iq['type'] = 'get'
|
iq['type'] = 'get'
|
||||||
iq['to'] = self.xmpp.boundjid.bare
|
iq['to'] = self.xmpp.boundjid.bare
|
||||||
iq['gmail']['search'] = query
|
iq['gmail']['search'] = query
|
||||||
iq['gmail']['newer_than_time'] = newer
|
iq['gmail']['newer_than_time'] = newer_time
|
||||||
|
iq['gmail']['newer_than_tid'] = newer_tid
|
||||||
return iq.send(block=block, timeout=timeout, callback=callback)
|
return iq.send(block=block, timeout=timeout, callback=callback)
|
||||||
|
|
Loading…
Reference in a new issue