Commit 592932f7 authored by Madhur Garg's avatar Madhur Garg

Changed the querry from timestamp to stanza-id based.

parent 06eeda02
...@@ -49,35 +49,35 @@ async def query(tab, remote_jid, top, start=None, end=None, before=None): ...@@ -49,35 +49,35 @@ async def query(tab, remote_jid, top, start=None, end=None, before=None):
if top: if top:
if isinstance(tab, tabs.MucTab): if isinstance(tab, tabs.MucTab):
try: try:
if before: if before is not None:
results = tab.core.xmpp['xep_0313'].retrieve(jid=remote_jid, results = tab.core.xmpp['xep_0313'].retrieve(jid=remote_jid,
iterator=True, reverse=top, before=before) iterator=True, reverse=top, before=before)
else: else:
results = tab.core.xmpp['xep_0313'].retrieve(jid=remote_jid, results = tab.core.xmpp['xep_0313'].retrieve(jid=remote_jid,
iterator=True, reverse=top, end=end_date) iterator=True, reverse=top, end=end)
except (IqError, IqTimeout): except (IqError, IqTimeout):
return tab.core.information('Failed to retrieve messages', 'Error') return tab.core.information('Failed to retrieve messages', 'Error')
else: else:
try: try:
if before: if before is not None:
results = tab.core.xmpp['xep_0313'].retrieve(with_jid=remote_jid, results = tab.core.xmpp['xep_0313'].retrieve(with_jid=remote_jid,
iterator=True, reverse=top, before=before) iterator=True, reverse=top, before=before)
else: else:
results = tab.core.xmpp['xep_0313'].retrieve(with_jid=remote_jid, results = tab.core.xmpp['xep_0313'].retrieve(with_jid=remote_jid,
iterator=True, reverse=top, end=end_date) iterator=True, reverse=top, end=end)
except (IqError, IqTimeout): except (IqError, IqTimeout):
return tab.core.information('Failed to retrieve messages', 'Error') return tab.core.information('Failed to retrieve messages', 'Error')
else: else:
if 'conference' in list(iq['disco_info']['identities'])[0]: if 'conference' in list(iq['disco_info']['identities'])[0]:
try: try:
results = tab.core.xmpp['xep_0313'].retrieve(jid=remote_jid, results = tab.core.xmpp['xep_0313'].retrieve(jid=remote_jid,
iterator=True, reverse=top, start=start_date, end=end_date) iterator=True, reverse=top, start=start_date, end=end)
except (IqError, IqTimeout): except (IqError, IqTimeout):
return tab.core.information('Failed to retrieve messages', 'Error') return tab.core.information('Failed to retrieve messages', 'Error')
else: else:
try: try:
results = tab.core.xmpp['xep_0313'].retrieve(with_jid=remote_jid, results = tab.core.xmpp['xep_0313'].retrieve(with_jid=remote_jid,
iterator=True, reverse=top, start=start_date, end=end_date) iterator=True, reverse=top, start=start_date, end=end)
except (IqError, IqTimeout): except (IqError, IqTimeout):
return tab.core.information('Failed to retrieve messages', 'Error') return tab.core.information('Failed to retrieve messages', 'Error')
msg_count = 0 msg_count = 0
...@@ -134,17 +134,20 @@ def mam_scroll(tab): ...@@ -134,17 +134,20 @@ def mam_scroll(tab):
try: try:
before = tab.stanza_id before = tab.stanza_id
except: except:
before = False before = None
end = datetime.now() end = datetime.now()
end = end.replace(tzinfo=tzone).astimezone(tz=timezone.utc) tzone = datetime.now().astimezone().tzinfo
end = end.replace(tzinfo=None) end = end.replace(tzinfo=tzone).astimezone(tz=timezone.utc)
end = datetime.strftime(end, '%Y-%m-%dT%H:%M:%SZ') end = end.replace(tzinfo=None)
start = False end = datetime.strftime(end, '%Y-%m-%dT%H:%M:%SZ')
top = True top = True
pos = tab.text_win.pos pos = tab.text_win.pos
tab.text_win.pos += tab.text_win.height - 1 tab.text_win.pos += tab.text_win.height - 1
if tab.text_win.pos + tab.text_win.height > len(tab.text_win.built_lines): if tab.text_win.pos + tab.text_win.height > len(tab.text_win.built_lines):
asyncio.ensure_future(query(tab, remote_jid, top, start, end, before)) if before is None:
asyncio.ensure_future(query(tab, remote_jid, top, end=end))
else:
asyncio.ensure_future(query(tab, remote_jid, top, before=before))
tab.query_id = 1 tab.query_id = 1
tab.text_win.pos = len(tab.text_win.built_lines) - tab.text_win.height tab.text_win.pos = len(tab.text_win.built_lines) - tab.text_win.height
if tab.text_win.pos < 0: if tab.text_win.pos < 0:
......
...@@ -927,9 +927,8 @@ class ChatTab(Tab): ...@@ -927,9 +927,8 @@ class ChatTab(Tab):
return self.text_win.scroll_down(1) return self.text_win.scroll_down(1)
def on_scroll_up(self): def on_scroll_up(self):
tab = self
if self.query_id == 0: if self.query_id == 0:
return mam.mam_scroll(tab) return mam.mam_scroll(tab=self)
else: else:
return self.text_win.scroll_up(self.text_win.height - 1) return self.text_win.scroll_up(self.text_win.height - 1)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment