summaryrefslogtreecommitdiff
path: root/src/user.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2014-12-20 23:13:26 +0100
committermathieui <mathieui@mathieui.net>2014-12-20 23:13:26 +0100
commit2452706b909364178655c6c918a0348fb4298fb2 (patch)
treef7d8a3ed6134c7d1a784ec6d50748d2ffc18c903 /src/user.py
parent030b4d7bcd101bbd5efddfefa73f633540b42312 (diff)
downloadpoezio-2452706b909364178655c6c918a0348fb4298fb2.tar.gz
poezio-2452706b909364178655c6c918a0348fb4298fb2.tar.bz2
poezio-2452706b909364178655c6c918a0348fb4298fb2.tar.xz
poezio-2452706b909364178655c6c918a0348fb4298fb2.zip
Add a deterministic_nick_colors option (default: true)
Diffstat (limited to 'src/user.py')
-rw-r--r--src/user.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/user.py b/src/user.py
index 0d29569f..8b4ad94b 100644
--- a/src/user.py
+++ b/src/user.py
@@ -12,6 +12,7 @@ An user is a MUC participant, not a roster contact (see contact.py)
from random import choice
from datetime import timedelta, datetime
+from hashlib import md5
from theming import get_theme
@@ -27,14 +28,23 @@ class User(object):
"""
keep trace of an user in a Room
"""
- def __init__(self, nick, affiliation, show, status, role, jid):
+ def __init__(self, nick, affiliation, show, status, role, jid, deterministic=True):
self.last_talked = datetime(1, 1, 1) # The oldest possible time
self.update(affiliation, show, status, role)
self.change_nick(nick)
- self.color = choice(get_theme().LIST_COLOR_NICKNAMES)
+ if deterministic:
+ self.set_deterministic_color()
+ else:
+ self.color = choice(get_theme().LIST_COLOR_NICKNAMES)
self.jid = jid
self.chatstate = None
+ def set_deterministic_color(self):
+ theme = get_theme()
+ mod = len(theme.LIST_COLOR_NICKNAMES)
+ nick_pos = int(md5(self.nick.encode('utf-8')).hexdigest(), 16) % mod
+ self.color = theme.LIST_COLOR_NICKNAMES[nick_pos]
+
def update(self, affiliation, show, status, role):
self.affiliation = affiliation
self.show = show