From c988e5fbe0d428cc093be304f87a22f42feeaf68 Mon Sep 17 00:00:00 2001 From: Madhur Garg Date: Mon, 1 Jul 2019 14:04:03 +0530 Subject: Removed MAM class and changed it into function. --- poezio/mam.py | 80 +++++++++++++++++++++++------------------------------------ 1 file changed, 31 insertions(+), 49 deletions(-) diff --git a/poezio/mam.py b/poezio/mam.py index ba669cd2..fea0ffc7 100644 --- a/poezio/mam.py +++ b/poezio/mam.py @@ -6,56 +6,38 @@ XEP-0313: Message Archive Management(MAM). """ -import asyncio from datetime import datetime, timezone from poezio.theming import get_theme from poezio.text_buffer import Message, TextBuffer - -def add_line(text_buffer: TextBuffer, text: str, str_time: str, nick: str): - """Adds a textual entry in the TextBuffer""" - - time = datetime.strftime(str_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) - nick = nick.split('/')[1] - color = get_theme().COLOR_OWN_NICK - text_buffer.add_message( - text, - time, - nick, - color, - True, # History - None, # User - False, # Highlight - None, # Identifier - None, # str_time - None, # Jid - ) - - -class MAM: - """ - A basic client fetching mam archive messages - """ - - def __init__(self, remote_jid, start, end, tab): - self.remote_jid = remote_jid - self.start_date = start - self.end_date = end - self.tab = tab - asyncio.ensure_future(self.start()) - - async def start(self): - text_buffer = self.tab._text_buffer - results = self.tab.core.xmpp.plugin['xep_0313'].retrieve(jid=self.remote_jid, - iterator=True, start=self.start_date, end=self.end_date) - async for rsm in results: - for msg in rsm['mam']['results']: - forwarded = msg['mam_result']['forwarded'] - timestamp = forwarded['delay']['stamp'] - message = forwarded['stanza'] - add_line(text_buffer, '%s' % message['body'], timestamp, str(message['from'])) - - self.tab.text_win.pos = 0 - self.tab.core.refresh_window() +async def MAM(self, remote_jid, start, end): + self.remote_jid = remote_jid + self.start_date = start + self.end_date = end + text_buffer = self._text_buffer + results = self.core.xmpp.plugin['xep_0313'].retrieve(jid=self.remote_jid, + iterator=True, start=self.start_date, end=self.end_date) + async for rsm in results: + for msg in rsm['mam']['results']: + forwarded = msg['mam_result']['forwarded'] + timestamp = forwarded['delay']['stamp'] + message = forwarded['stanza'] + text = str(message['body']) + time = datetime.strftime(timestamp, '%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) + nick = str(message['from']).split('/')[1] + color = get_theme().COLOR_OWN_NICK + text_buffer.add_message( + text, + time, + nick, + color, + True, # History + None, # User + False, # Highlight + None, # Identifier + None, # str_time + None, # Jid + ) + self.core.refresh_window() -- cgit v1.2.3