diff options
-rw-r--r-- | poezio/mam.py | 27 | ||||
-rw-r--r-- | poezio/tabs/basetabs.py | 3 |
2 files changed, 16 insertions, 14 deletions
diff --git a/poezio/mam.py b/poezio/mam.py index 44eab3f4..fdbfd2af 100644 --- a/poezio/mam.py +++ b/poezio/mam.py @@ -49,35 +49,35 @@ async def query(tab, remote_jid, top, start=None, end=None, before=None): if top: if isinstance(tab, tabs.MucTab): try: - if before: + if before is not None: results = tab.core.xmpp['xep_0313'].retrieve(jid=remote_jid, iterator=True, reverse=top, before=before) else: 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): return tab.core.information('Failed to retrieve messages', 'Error') else: try: - if before: + if before is not None: results = tab.core.xmpp['xep_0313'].retrieve(with_jid=remote_jid, iterator=True, reverse=top, before=before) else: 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): return tab.core.information('Failed to retrieve messages', 'Error') else: if 'conference' in list(iq['disco_info']['identities'])[0]: try: 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): return tab.core.information('Failed to retrieve messages', 'Error') else: try: 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): return tab.core.information('Failed to retrieve messages', 'Error') msg_count = 0 @@ -134,17 +134,20 @@ def mam_scroll(tab): try: before = tab.stanza_id except: - before = False + before = None end = datetime.now() - end = end.replace(tzinfo=tzone).astimezone(tz=timezone.utc) - end = end.replace(tzinfo=None) - end = datetime.strftime(end, '%Y-%m-%dT%H:%M:%SZ') - start = False + tzone = datetime.now().astimezone().tzinfo + end = end.replace(tzinfo=tzone).astimezone(tz=timezone.utc) + end = end.replace(tzinfo=None) + end = datetime.strftime(end, '%Y-%m-%dT%H:%M:%SZ') top = True pos = tab.text_win.pos tab.text_win.pos += tab.text_win.height - 1 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.text_win.pos = len(tab.text_win.built_lines) - tab.text_win.height if tab.text_win.pos < 0: diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index ae133dfb..12fcd170 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -927,9 +927,8 @@ class ChatTab(Tab): return self.text_win.scroll_down(1) def on_scroll_up(self): - tab = self if self.query_id == 0: - return mam.mam_scroll(tab) + return mam.mam_scroll(tab=self) else: return self.text_win.scroll_up(self.text_win.height - 1) |