diff options
Diffstat (limited to 'src/user.py')
-rw-r--r-- | src/user.py | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/user.py b/src/user.py index 0d29569f..b1796bc3 100644 --- a/src/user.py +++ b/src/user.py @@ -12,9 +12,14 @@ 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 +import xhtml from theming import get_theme +import logging +log = logging.getLogger(__name__) + ROLE_DICT = { '':0, 'none':0, @@ -27,14 +32,26 @@ 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, color=''): 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 color != '': + self.change_color(color, deterministic) + else: + 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 @@ -46,6 +63,17 @@ class User(object): def change_nick(self, nick): self.nick = nick + def change_color(self, color_name, deterministic=False): + color = xhtml.colors.get(color_name) + if color == None: + log.error('Unknown color "%s"' % color_name) + if deterministic: + self.set_deterministic_color() + else: + self.color = choice(get_theme().LIST_COLOR_NICKNAMES) + else: + self.color = (color, -1) + def set_last_talked(self, time): """ time: datetime object |