summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMadhur Garg <madhurgarg96@gmail.com>2019-08-12 03:13:27 +0530
committerMadhur Garg <madhurgarg96@gmail.com>2019-08-22 00:54:25 +0530
commit8a271e6f26b28dadf1b9e4099fc5ed4ba48a61bf (patch)
tree69d09baa1e0d9755b24d966214e3bd74156fc36f
parenta372e5f49fa78692589aad3b121b1059dcc66b77 (diff)
downloadpoezio-8a271e6f26b28dadf1b9e4099fc5ed4ba48a61bf.tar.gz
poezio-8a271e6f26b28dadf1b9e4099fc5ed4ba48a61bf.tar.bz2
poezio-8a271e6f26b28dadf1b9e4099fc5ed4ba48a61bf.tar.xz
poezio-8a271e6f26b28dadf1b9e4099fc5ed4ba48a61bf.zip
Added <before> tag to query messages based on stanza-id
-rw-r--r--poezio/mam.py33
1 files changed, 20 insertions, 13 deletions
diff --git a/poezio/mam.py b/poezio/mam.py
index 3f42cc92..b22e3cd7 100644
--- a/poezio/mam.py
+++ b/poezio/mam.py
@@ -38,7 +38,7 @@ def add_line(text_buffer: TextBuffer, text: str, str_time: str, nick: str, top:
None, # Jid
)
-async def query(tab, remote_jid, start, end, top):
+async def query(tab, remote_jid, top, start=None, end=None, before=None):
tab.remote_jid = remote_jid
tab.start_date = start
tab.end_date = end
@@ -52,14 +52,22 @@ async def query(tab, remote_jid, start, end, top):
if top:
if isinstance(tab, tabs.MucTab):
try:
- results = tab.core.xmpp['xep_0313'].retrieve(jid=tab.remote_jid,
- iterator=True, reverse=top, end=tab.end_date)
+ if before:
+ results = tab.core.xmpp['xep_0313'].retrieve(jid=tab.remote_jid,
+ iterator=True, reverse=top, before=before)
+ else:
+ results = tab.core.xmpp['xep_0313'].retrieve(jid=tab.remote_jid,
+ iterator=True, reverse=top, end=tab.end_date)
except (IqError, IqTimeout):
return tab.core.information('Failed to retrieve messages', 'Error')
else:
try:
- results = tab.core.xmpp['xep_0313'].retrieve(with_jid=tab.remote_jid,
- iterator=True, reverse=top, end=tab.end_date)
+ if before:
+ results = tab.core.xmpp['xep_0313'].retrieve(with_jid=tab.remote_jid,
+ iterator=True, reverse=top, before=before)
+ else:
+ results = tab.core.xmpp['xep_0313'].retrieve(with_jid=tab.remote_jid,
+ iterator=True, reverse=top, end=tab.end_date)
except (IqError, IqTimeout):
return tab.core.information('Failed to retrieve messages', 'Error')
else:
@@ -96,6 +104,7 @@ async def query(tab, remote_jid, start, end, top):
forwarded = msg['mam_result']['forwarded']
timestamp = forwarded['delay']['stamp']
message = forwarded['stanza']
+ tab.stanza_id = msg['mam_result']['id']
nick = str(message['from'])
if isinstance(tab, tabs.MucTab):
nick = nick.split('/')[1]
@@ -125,13 +134,11 @@ async def query(tab, remote_jid, start, end, top):
def mam_scroll(tab):
remote_jid = tab.jid
text_buffer = tab._text_buffer
- end = datetime.now()
- for message in text_buffer.messages:
- time = message.time
- if time < end:
- end = time
- end = end + timedelta(seconds=-1)
- tzone = datetime.now().astimezone().tzinfo
+ try:
+ before = tab.stanza_id
+ except:
+ before = False
+ 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')
@@ -140,7 +147,7 @@ def mam_scroll(tab):
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, start, end, top))
+ asyncio.ensure_future(query(tab, remote_jid, top, start, end, 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: