summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMadhur Garg <madhurgarg96@gmail.com>2019-08-10 15:21:59 +0530
committerMadhur Garg <madhurgarg96@gmail.com>2019-08-22 00:54:25 +0530
commitc5ef5b0421d8fd80a00497f8529bff6304615fbe (patch)
treec935be5eb8740318161e811cc787ea34a7dc7071
parentbb20db0d0a3d0dbe2b3abea10acd15c29f1f61ba (diff)
downloadpoezio-c5ef5b0421d8fd80a00497f8529bff6304615fbe.tar.gz
poezio-c5ef5b0421d8fd80a00497f8529bff6304615fbe.tar.bz2
poezio-c5ef5b0421d8fd80a00497f8529bff6304615fbe.tar.xz
poezio-c5ef5b0421d8fd80a00497f8529bff6304615fbe.zip
Changed the parameter from 'self' to 'tab' where the function is not a method.
-rw-r--r--poezio/mam.py80
-rw-r--r--poezio/tabs/basetabs.py3
2 files changed, 42 insertions, 41 deletions
diff --git a/poezio/mam.py b/poezio/mam.py
index f68ac39d..3f42cc92 100644
--- a/poezio/mam.py
+++ b/poezio/mam.py
@@ -38,43 +38,43 @@ def add_line(text_buffer: TextBuffer, text: str, str_time: str, nick: str, top:
None, # Jid
)
-async def query(self, remote_jid, start, end, top):
- self.remote_jid = remote_jid
- self.start_date = start
- self.end_date = end
- text_buffer = self._text_buffer
+async def query(tab, remote_jid, start, end, top):
+ tab.remote_jid = remote_jid
+ tab.start_date = start
+ tab.end_date = end
+ text_buffer = tab._text_buffer
try:
- iq = await self.core.xmpp.plugin['xep_0030'].get_info(jid=remote_jid)
+ iq = await tab.core.xmpp.plugin['xep_0030'].get_info(jid=remote_jid)
except (IqError, IqTimeout):
- return self.information('Failed to retrieve messages', 'Error')
+ return tab.information('Failed to retrieve messages', 'Error')
if 'urn:xmpp:mam:2' not in iq['disco_info'].get_features():
- return self.core.information("This MUC doesn't support MAM.", "Error")
+ return tab.core.information("This MUC doesn't support MAM.", "Error")
if top:
- if isinstance(self, tabs.MucTab):
+ if isinstance(tab, tabs.MucTab):
try:
- results = self.core.xmpp['xep_0313'].retrieve(jid=self.remote_jid,
- iterator=True, reverse=top, end=self.end_date)
+ results = tab.core.xmpp['xep_0313'].retrieve(jid=tab.remote_jid,
+ iterator=True, reverse=top, end=tab.end_date)
except (IqError, IqTimeout):
- return self.core.information('Failed to retrieve messages', 'Error')
+ return tab.core.information('Failed to retrieve messages', 'Error')
else:
try:
- results = self.core.xmpp['xep_0313'].retrieve(with_jid=self.remote_jid,
- iterator=True, reverse=top, end=self.end_date)
+ results = tab.core.xmpp['xep_0313'].retrieve(with_jid=tab.remote_jid,
+ iterator=True, reverse=top, end=tab.end_date)
except (IqError, IqTimeout):
- return self.core.information('Failed to retrieve messages', 'Error')
+ return tab.core.information('Failed to retrieve messages', 'Error')
else:
if 'conference' in list(iq['disco_info']['identities'])[0]:
try:
- results = self.core.xmpp['xep_0313'].retrieve(jid=self.remote_jid,
- iterator=True, reverse=top, start=self.start_date, end=self.end_date)
+ results = tab.core.xmpp['xep_0313'].retrieve(jid=tab.remote_jid,
+ iterator=True, reverse=top, start=tab.start_date, end=tab.end_date)
except (IqError, IqTimeout):
- return self.core.information('Failed to retrieve messages', 'Error')
+ return tab.core.information('Failed to retrieve messages', 'Error')
else:
try:
- results = self.core.xmpp['xep_0313'].retrieve(with_jid=self.remote_jid,
- iterator=True, reverse=top, start=self.start_date, end=self.end_date)
+ results = tab.core.xmpp['xep_0313'].retrieve(with_jid=tab.remote_jid,
+ iterator=True, reverse=top, start=tab.start_date, end=tab.end_date)
except (IqError, IqTimeout):
- return self.core.information('Failed to retrieve messages', 'Error')
+ return tab.core.information('Failed to retrieve messages', 'Error')
msg_count = 0
msgs = []
async for rsm in results:
@@ -84,8 +84,8 @@ async def query(self, remote_jid, start, end, top):
'{%s}%s' % ('jabber:client', 'body')) is not None:
msgs.append(msg)
if msg_count == 10:
- self.query_id = 0
- self.core.refresh_window()
+ tab.query_id = 0
+ tab.core.refresh_window()
return
msg_count += 1
msgs.reverse()
@@ -97,7 +97,7 @@ async def query(self, remote_jid, start, end, top):
timestamp = forwarded['delay']['stamp']
message = forwarded['stanza']
nick = str(message['from'])
- if isinstance(self, tabs.MucTab):
+ if isinstance(tab, tabs.MucTab):
nick = nick.split('/')[1]
else:
nick = nick.split('/')[0]
@@ -105,7 +105,7 @@ async def query(self, remote_jid, start, end, top):
if msg is msgs[len(msgs)-1]:
timestamp = msg['mam_result']['forwarded']['delay']['stamp']
add_line(text_buffer, 'End of MAM query: ', timestamp, 'MAM', top)
- self.text_win.scroll_up(len(self.text_win.built_lines))
+ tab.text_win.scroll_up(len(tab.text_win.built_lines))
else:
for msg in rsm['mam']['results']:
forwarded = msg['mam_result']['forwarded']
@@ -117,14 +117,14 @@ async def query(self, remote_jid, start, end, top):
else:
nick = nick.split('/')[0]
add_line(text_buffer, message['body'], timestamp, nick, top)
- self.core.refresh_window()
+ tab.core.refresh_window()
if len(msgs) == 0:
- return self.core.information('No more messages left to retrieve', 'Info')
- self.query_id = 0
+ return tab.core.information('No more messages left to retrieve', 'Info')
+ tab.query_id = 0
-def mam_scroll(self):
- remote_jid = self.jid
- text_buffer = self._text_buffer
+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
@@ -137,12 +137,12 @@ def mam_scroll(self):
end = datetime.strftime(end, '%Y-%m-%dT%H:%M:%SZ')
start = False
top = True
- pos = self.text_win.pos
- self.text_win.pos += self.text_win.height - 1
- if self.text_win.pos + self.text_win.height > len(self.text_win.built_lines):
- asyncio.ensure_future(query(self, remote_jid, start, end, top))
- self.query_id = 1
- self.text_win.pos = len(self.text_win.built_lines) - self.text_win.height
- if self.text_win.pos < 0:
- self.text_win.pos = 0
- return self.text_win.pos != pos
+ 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))
+ tab.query_id = 1
+ tab.text_win.pos = len(tab.text_win.built_lines) - tab.text_win.height
+ if tab.text_win.pos < 0:
+ tab.text_win.pos = 0
+ return tab.text_win.pos != pos
diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py
index 9ee71070..ae133dfb 100644
--- a/poezio/tabs/basetabs.py
+++ b/poezio/tabs/basetabs.py
@@ -927,8 +927,9 @@ 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(self)
+ return mam.mam_scroll(tab)
else:
return self.text_win.scroll_up(self.text_win.height - 1)