summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMadhur Garg <madhurgarg96@gmail.com>2019-07-01 14:04:03 +0530
committerMadhur Garg <madhurgarg96@gmail.com>2019-08-22 00:54:25 +0530
commitc988e5fbe0d428cc093be304f87a22f42feeaf68 (patch)
treefa0235da9ad7ff744911c202a28a4995d48e3332
parent6df26dc98d6b21875d56e2b19b082cdaa80dd699 (diff)
downloadpoezio-c988e5fbe0d428cc093be304f87a22f42feeaf68.tar.gz
poezio-c988e5fbe0d428cc093be304f87a22f42feeaf68.tar.bz2
poezio-c988e5fbe0d428cc093be304f87a22f42feeaf68.tar.xz
poezio-c988e5fbe0d428cc093be304f87a22f42feeaf68.zip
Removed MAM class and changed it into function.
-rw-r--r--poezio/mam.py80
1 files 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()