From 7e4735b0ad3a2cc34f69ff4215565721de6e20cd Mon Sep 17 00:00:00 2001 From: Madhur Garg Date: Sat, 17 Aug 2019 14:47:59 +0530 Subject: Added a check on deterministic colors --- poezio/mam.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'poezio/mam.py') diff --git a/poezio/mam.py b/poezio/mam.py index f4adc135..bcb31024 100644 --- a/poezio/mam.py +++ b/poezio/mam.py @@ -12,7 +12,7 @@ from datetime import datetime, timedelta, timezone from slixmpp.exceptions import IqError, IqTimeout from poezio.theming import get_theme from poezio import tabs -from poezio import xhtml +from poezio import xhtml, colors from poezio.config import config from poezio.text_buffer import Message, TextBuffer @@ -23,11 +23,24 @@ 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) if isinstance(tab, tabs.MucTab): nick = nick.split('/')[1] user = tab.get_user_by_name(nick) - if user: - color = user.color + if deterministic: + if user: + color = user.color + else: + theme = get_theme() + if theme.ccg_palette: + fg_color = colors.ccg_text_to_color(theme.ccg_palette, nick) + color = fg_color, -1 + else: + mod = len(theme.LIST_COLOR_NICKNAMES) + 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)) color = xhtml.colors.get(color) -- cgit v1.2.3