Commit dfec8bdf authored by Madhur Garg's avatar Madhur Garg

Aligned the timestamp of MAM start/end messages, added info message if no more messages are left.

parent a7530dc3
...@@ -18,14 +18,14 @@ def add_line(self, text_buffer: TextBuffer, text: str, str_time: str, nick: str, ...@@ -18,14 +18,14 @@ def add_line(self, text_buffer: TextBuffer, text: str, str_time: str, nick: str,
time = datetime.strftime(str_time, '%Y-%m-%d %H:%M:%S') time = datetime.strftime(str_time, '%Y-%m-%d %H:%M:%S')
time = datetime.strptime(time, '%Y-%m-%d %H:%M:%S') time = datetime.strptime(time, '%Y-%m-%d %H:%M:%S')
time = time.replace(tzinfo=timezone.utc).astimezone(tz=None)
time = time.replace(tzinfo=None)
if '/' in nick: if '/' in nick:
if isinstance(self, tabs.MucTab): if isinstance(self, tabs.MucTab):
nick = nick.split('/')[1] nick = nick.split('/')[1]
else: else:
nick = nick.split('/')[0] nick = nick.split('/')[0]
color = get_theme().COLOR_OWN_NICK color = get_theme().COLOR_OWN_NICK
time = time.replace(tzinfo=timezone.utc).astimezone(tz=None)
time = time.replace(tzinfo=None)
else: else:
color = get_theme().COLOR_ME_MESSAGE color = get_theme().COLOR_ME_MESSAGE
text_buffer.add_message( text_buffer.add_message(
...@@ -59,30 +59,28 @@ async def query(self, remote_jid, start, end, top): ...@@ -59,30 +59,28 @@ async def query(self, remote_jid, start, end, top):
results = self.core.xmpp['xep_0313'].retrieve(jid=self.remote_jid, results = self.core.xmpp['xep_0313'].retrieve(jid=self.remote_jid,
iterator=True, reverse=top, end=self.end_date) iterator=True, reverse=top, end=self.end_date)
except (IqError, IqTimeout): except (IqError, IqTimeout):
return self.information('Failed to retrieve messages', 'Error') return self.core.information('Failed to retrieve messages', 'Error')
else: else:
try: try:
results = self.core.xmpp['xep_0313'].retrieve(with_jid=self.remote_jid, results = self.core.xmpp['xep_0313'].retrieve(with_jid=self.remote_jid,
iterator=True, reverse=top, end=self.end_date) iterator=True, reverse=top, end=self.end_date)
except (IqError, IqTimeout): except (IqError, IqTimeout):
return self.information('Failed to retrieve messages', 'Error') return self.core.information('Failed to retrieve messages', 'Error')
else: else:
if isinstance(self, tabs.MucTab): if isinstance(self, tabs.MucTab):
try: try:
results = self.core.xmpp['xep_0313'].retrieve(jid=self.remote_jid, results = self.core.xmpp['xep_0313'].retrieve(jid=self.remote_jid,
iterator=True, reverse=top, start=self.start_date, end=self.end_date) iterator=True, reverse=top, start=self.start_date, end=self.end_date)
except (IqError, IqTimeout): except (IqError, IqTimeout):
return self.information('Failed to retrieve messages', 'Error') return self.core.information('Failed to retrieve messages', 'Error')
else: else:
try: try:
results = self.core.xmpp['xep_0313'].retrieve(with_jid=self.remote_jid, results = self.core.xmpp['xep_0313'].retrieve(with_jid=self.remote_jid,
iterator=True, reverse=top, start=self.start_date, end=self.end_date) iterator=True, reverse=top, start=self.start_date, end=self.end_date)
except (IqError, IqTimeout): except (IqError, IqTimeout):
return self.information('Failed to retrieve messages', 'Error') return self.core.information('Failed to retrieve messages', 'Error')
msg_count = 0 msg_count = 0
msgs = [] msgs = []
timestamp = datetime.now()
add_line(self, text_buffer, 'Start of MAM query: ', timestamp, 'MAM', top)
async for rsm in results: async for rsm in results:
if top: if top:
for msg in rsm['mam']['results']: for msg in rsm['mam']['results']:
...@@ -90,17 +88,21 @@ async def query(self, remote_jid, start, end, top): ...@@ -90,17 +88,21 @@ async def query(self, remote_jid, start, end, top):
msgs.append(msg) msgs.append(msg)
if msg_count == 10: if msg_count == 10:
self.query_id = 0 self.query_id = 0
timestamp = datetime.now()
add_line(self, text_buffer, 'End of MAM query: ', timestamp, 'MAM', top)
self.core.refresh_window() self.core.refresh_window()
return return
msg_count += 1 msg_count += 1
msgs.reverse() msgs.reverse()
for msg in msgs: for msg in msgs:
if msg is msgs[0]:
timestamp = msg['mam_result']['forwarded']['delay']['stamp']
add_line(self, text_buffer, 'Start of MAM query: ', timestamp, 'MAM', top)
forwarded = msg['mam_result']['forwarded'] forwarded = msg['mam_result']['forwarded']
timestamp = forwarded['delay']['stamp'] timestamp = forwarded['delay']['stamp']
message = forwarded['stanza'] message = forwarded['stanza']
add_line(self, text_buffer, message['body'], timestamp, str(message['from']), top) add_line(self, text_buffer, message['body'], timestamp, str(message['from']), top)
if msg is msgs[len(msgs)-1]:
timestamp = msg['mam_result']['forwarded']['delay']['stamp']
add_line(self, text_buffer, 'End of MAM query: ', timestamp, 'MAM', top)
self.text_win.scroll_up(len(self.text_win.built_lines)) self.text_win.scroll_up(len(self.text_win.built_lines))
else: else:
for msg in rsm['mam']['results']: for msg in rsm['mam']['results']:
...@@ -109,10 +111,9 @@ async def query(self, remote_jid, start, end, top): ...@@ -109,10 +111,9 @@ async def query(self, remote_jid, start, end, top):
message = forwarded['stanza'] message = forwarded['stanza']
add_line(self, text_buffer, message['body'], timestamp, str(message['from']), top) add_line(self, text_buffer, message['body'], timestamp, str(message['from']), top)
self.core.refresh_window() self.core.refresh_window()
if len(msgs) == 0:
return self.core.information('No more messages left to retrieve', 'Info')
self.query_id = 0 self.query_id = 0
timestamp = datetime.now()
add_line(self, text_buffer, 'End of MAM query: ', timestamp, 'MAM', top)
def mam_scroll(self): def mam_scroll(self):
remote_jid = self.jid remote_jid = self.jid
......
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