From d1c239999cc6af702f028141915d20be1b8feac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Tue, 10 Sep 2019 18:25:52 +0200 Subject: poezio/mam: style fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- poezio/mam.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'poezio/mam.py') diff --git a/poezio/mam.py b/poezio/mam.py index aa87dc4e..95fc6a5e 100644 --- a/poezio/mam.py +++ b/poezio/mam.py @@ -32,8 +32,7 @@ def add_line(tab, text_buffer: TextBuffer, text: str, str_time: str, nick: str, time = datetime.strptime(time, '%Y-%m-%d %H:%M:%S') time = time.replace(tzinfo=timezone.utc).astimezone(tz=None) time = time.replace(tzinfo=None) - deterministic = config.get_by_tabname('deterministic_nick_colors', - tab.jid.bare) + deterministic = config.get_by_tabname('deterministic_nick_colors', tab.jid.bare) if isinstance(tab, tabs.MucTab): nick = nick.split('/')[1] user = tab.get_user_by_name(nick) @@ -47,8 +46,7 @@ def add_line(tab, text_buffer: TextBuffer, text: str, str_time: str, nick: str, color = fg_color, -1 else: mod = len(theme.LIST_COLOR_NICKNAMES) - nick_pos = int(md5(nick.encode('utf-8')).hexdigest(), - 16) % mod + nick_pos = int(md5(nick.encode('utf-8')).hexdigest(), 16) % mod color = theme.LIST_COLOR_NICKNAMES[nick_pos] else: color = random.choice(list(xhtml.colors)) @@ -71,6 +69,7 @@ def add_line(tab, text_buffer: TextBuffer, text: str, str_time: str, nick: str, jid=None, ) + async def query( core, groupchat: bool, @@ -118,6 +117,7 @@ async def query( return results + async def add_messages_to_buffer(tab, top: bool, results, amount: int) -> None: """Prepends or appends messages to the tab text_buffer""" @@ -152,6 +152,7 @@ async def add_messages_to_buffer(tab, top: bool, results, amount: int) -> None: tab.core.refresh_window() return False + async def fetch_history(tab, end: Optional[datetime] = None, amount: Optional[int] = None): remote_jid = tab.jid before = tab.last_stanza_id @@ -167,10 +168,19 @@ async def fetch_history(tab, end: Optional[datetime] = None, amount: Optional[in groupchat = isinstance(tab, tabs.MucTab) - results = await query(tab.core, groupchat, remote_jid, amount, reverse=True, end=end, before=before) + results = await query( + tab.core, + groupchat, + remote_jid, + amount, + reverse=True, + end=end, + before=before, + ) query_status = await add_messages_to_buffer(tab, True, results, amount) tab.query_status = query_status + async def on_tab_open(tab) -> None: amount = 2 * tab.text_win.height end = datetime.now() @@ -184,6 +194,7 @@ async def on_tab_open(tab) -> None: except (NoMAMSupportException, MAMQueryException, DiscoInfoException): return None + async def on_scroll_up(tab) -> None: amount = tab.text_win.height try: -- cgit v1.2.3