summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMadhur Garg <madhurgarg96@gmail.com>2019-08-17 14:47:59 +0530
committerMadhur Garg <madhurgarg96@gmail.com>2019-08-22 00:54:25 +0530
commit7e4735b0ad3a2cc34f69ff4215565721de6e20cd (patch)
treed9477bffd7b6a66c9ca5cbb119e546e11f59bf60
parentfe5476a43640cfe5f25670cb62cbf4124d8020e6 (diff)
downloadpoezio-7e4735b0ad3a2cc34f69ff4215565721de6e20cd.tar.gz
poezio-7e4735b0ad3a2cc34f69ff4215565721de6e20cd.tar.bz2
poezio-7e4735b0ad3a2cc34f69ff4215565721de6e20cd.tar.xz
poezio-7e4735b0ad3a2cc34f69ff4215565721de6e20cd.zip
Added a check on deterministic colors
-rw-r--r--poezio/mam.py19
1 files changed, 16 insertions, 3 deletions
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)