poezio/mam: style fixes

Signed-off-by: Maxime Buquet's avatarMaxime “pep” Buquet <pep@bouah.net>
parent bf37cf5f
...@@ -32,8 +32,7 @@ def add_line(tab, text_buffer: TextBuffer, text: str, str_time: str, nick: str, ...@@ -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 = datetime.strptime(time, '%Y-%m-%d %H:%M:%S')
time = time.replace(tzinfo=timezone.utc).astimezone(tz=None) time = time.replace(tzinfo=timezone.utc).astimezone(tz=None)
time = time.replace(tzinfo=None) time = time.replace(tzinfo=None)
deterministic = config.get_by_tabname('deterministic_nick_colors', deterministic = config.get_by_tabname('deterministic_nick_colors', tab.jid.bare)
tab.jid.bare)
if isinstance(tab, tabs.MucTab): if isinstance(tab, tabs.MucTab):
nick = nick.split('/')[1] nick = nick.split('/')[1]
user = tab.get_user_by_name(nick) 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, ...@@ -47,8 +46,7 @@ def add_line(tab, text_buffer: TextBuffer, text: str, str_time: str, nick: str,
color = fg_color, -1 color = fg_color, -1
else: else:
mod = len(theme.LIST_COLOR_NICKNAMES) mod = len(theme.LIST_COLOR_NICKNAMES)
nick_pos = int(md5(nick.encode('utf-8')).hexdigest(), nick_pos = int(md5(nick.encode('utf-8')).hexdigest(), 16) % mod
16) % mod
color = theme.LIST_COLOR_NICKNAMES[nick_pos] color = theme.LIST_COLOR_NICKNAMES[nick_pos]
else: else:
color = random.choice(list(xhtml.colors)) color = random.choice(list(xhtml.colors))
...@@ -71,6 +69,7 @@ def add_line(tab, text_buffer: TextBuffer, text: str, str_time: str, nick: str, ...@@ -71,6 +69,7 @@ def add_line(tab, text_buffer: TextBuffer, text: str, str_time: str, nick: str,
jid=None, jid=None,
) )
async def query( async def query(
core, core,
groupchat: bool, groupchat: bool,
...@@ -118,6 +117,7 @@ async def query( ...@@ -118,6 +117,7 @@ async def query(
return results return results
async def add_messages_to_buffer(tab, top: bool, results, amount: int) -> None: async def add_messages_to_buffer(tab, top: bool, results, amount: int) -> None:
"""Prepends or appends messages to the tab text_buffer""" """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: ...@@ -152,6 +152,7 @@ async def add_messages_to_buffer(tab, top: bool, results, amount: int) -> None:
tab.core.refresh_window() tab.core.refresh_window()
return False return False
async def fetch_history(tab, end: Optional[datetime] = None, amount: Optional[int] = None): async def fetch_history(tab, end: Optional[datetime] = None, amount: Optional[int] = None):
remote_jid = tab.jid remote_jid = tab.jid
before = tab.last_stanza_id before = tab.last_stanza_id
...@@ -167,10 +168,19 @@ async def fetch_history(tab, end: Optional[datetime] = None, amount: Optional[in ...@@ -167,10 +168,19 @@ async def fetch_history(tab, end: Optional[datetime] = None, amount: Optional[in
groupchat = isinstance(tab, tabs.MucTab) 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) query_status = await add_messages_to_buffer(tab, True, results, amount)
tab.query_status = query_status tab.query_status = query_status
async def on_tab_open(tab) -> None: async def on_tab_open(tab) -> None:
amount = 2 * tab.text_win.height amount = 2 * tab.text_win.height
end = datetime.now() end = datetime.now()
...@@ -184,6 +194,7 @@ async def on_tab_open(tab) -> None: ...@@ -184,6 +194,7 @@ async def on_tab_open(tab) -> None:
except (NoMAMSupportException, MAMQueryException, DiscoInfoException): except (NoMAMSupportException, MAMQueryException, DiscoInfoException):
return None return None
async def on_scroll_up(tab) -> None: async def on_scroll_up(tab) -> None:
amount = tab.text_win.height amount = tab.text_win.height
try: try:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment