diff options
author | Maxime “pep” Buquet <pep@bouah.net> | 2019-09-10 18:25:52 +0200 |
---|---|---|
committer | Maxime “pep” Buquet <pep@bouah.net> | 2019-09-10 18:25:52 +0200 |
commit | d1c239999cc6af702f028141915d20be1b8feac5 (patch) | |
tree | 330e82354318641c4d6d4e00b6870a07584e91df | |
parent | bf37cf5f5ad730496162cf0011dcab7b0ebccfa0 (diff) | |
download | poezio-d1c239999cc6af702f028141915d20be1b8feac5.tar.gz poezio-d1c239999cc6af702f028141915d20be1b8feac5.tar.bz2 poezio-d1c239999cc6af702f028141915d20be1b8feac5.tar.xz poezio-d1c239999cc6af702f028141915d20be1b8feac5.zip |
poezio/mam: style fixes
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
-rw-r--r-- | poezio/mam.py | 21 |
1 files changed, 16 insertions, 5 deletions
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: |