summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/default_config.cfg4
-rw-r--r--doc/source/configuration.rst9
-rw-r--r--src/config.py2
-rw-r--r--src/tabs/muctab.py30
-rw-r--r--src/user.py26
5 files changed, 60 insertions, 11 deletions
diff --git a/data/default_config.cfg b/data/default_config.cfg
index 95ae1333..08afa452 100644
--- a/data/default_config.cfg
+++ b/data/default_config.cfg
@@ -509,3 +509,7 @@ M-i = ^I
# to save various data across restarts
folded_roster_groups =
info_win_height = 2
+
+[muc_colors]
+# Set color for a nick, under the form
+# nick = color
diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst
index d3d4fb43..8d82f4bd 100644
--- a/doc/source/configuration.rst
+++ b/doc/source/configuration.rst
@@ -747,6 +747,15 @@ or the way messages are displayed.
If the message takes more than one line, the popup will stay visible
two more second per additional lines.
+ muc_colors (section)
+
+ **Default:** ``[empty]``
+
+ Fix a color for a nick. Whenever such a nick appears in a MUC, it will
+ be displayed in that color. This color won't be changed by the recolor
+ command.
+
+
User Interaction
~~~~~~~~~~~~~~~~
diff --git a/src/config.py b/src/config.py
index 339e8a85..068f8325 100644
--- a/src/config.py
+++ b/src/config.py
@@ -135,6 +135,8 @@ DEFAULT_CONFIG = {
'var': {
'folded_roster_groups': '',
'info_win_height': 2
+ },
+ 'muc_colors': {
}
}
diff --git a/src/tabs/muctab.py b/src/tabs/muctab.py
index 160c4b0e..b9dba7ab 100644
--- a/src/tabs/muctab.py
+++ b/src/tabs/muctab.py
@@ -424,6 +424,9 @@ class MucTab(ChatTab):
for user in self.users:
if user.nick == self.own_nick:
continue
+ color = config.get_by_tabname(user.nick, 'muc_colors')
+ if color != '':
+ continue
user.set_deterministic_color()
if args[0] == 'random':
self.core.information(_('"random" was provided, but poezio is '
@@ -435,11 +438,17 @@ class MucTab(ChatTab):
compare_users = lambda x: x.last_talked
users = list(self.users)
sorted_users = sorted(users, key=compare_users, reverse=True)
+ full_sorted_users = sorted_users[:]
# search our own user, to remove it from the list
- for user in sorted_users:
+ # Also remove users whose color is fixed
+ for user in full_sorted_users:
+ color = config.get_by_tabname(user.nick, 'muc_colors')
if user.nick == self.own_nick:
sorted_users.remove(user)
user.color = get_theme().COLOR_OWN_NICK
+ elif color != '':
+ sorted_users.remove(user)
+ user.change_color(color, deterministic)
colors = list(get_theme().LIST_COLOR_NICKNAMES)
if args[0] == 'random':
random.shuffle(colors)
@@ -468,8 +477,8 @@ class MucTab(ChatTab):
if user.nick == self.own_nick:
return self.core.information(_("You cannot change the color of your"
" own nick.", 'Error'))
- colors = list(get_theme().LIST_COLOR_NICKNAMES)
- user.color = (xhtml.colors[color], -1)
+ user.change_color(color)
+ config.write_in_file('muc_colors', nick, color)
self.text_win.rebuild_everything(self._text_buffer)
self.user_win.refresh(self.users)
self.text_win.refresh()
@@ -1052,12 +1061,13 @@ class MucTab(ChatTab):
jid = presence['muc']['jid']
typ = presence['type']
deterministic = config.get_by_tabname('deterministic_nick_colors', self.name)
+ color = config.get_by_tabname(from_nick, 'muc_colors')
if not self.joined: # user in the room BEFORE us.
# ignore redondant presence message, see bug #1509
if (from_nick not in [user.nick for user in self.users]
and typ != "unavailable"):
new_user = User(from_nick, affiliation, show,
- status, role, jid, deterministic)
+ status, role, jid, deterministic, color)
self.users.append(new_user)
self.core.events.trigger('muc_join', presence, self)
if '110' in status_codes or self.own_nick == from_nick:
@@ -1134,7 +1144,7 @@ class MucTab(ChatTab):
if not user:
self.core.events.trigger('muc_join', presence, self)
self.on_user_join(from_nick, affiliation, show, status, role,
- jid)
+ jid, color)
# nick change
elif change_nick:
self.core.events.trigger('muc_nickchange', presence, self)
@@ -1189,13 +1199,13 @@ class MucTab(ChatTab):
typ=2)
self.disconnect()
- def on_user_join(self, from_nick, affiliation, show, status, role, jid):
+ def on_user_join(self, from_nick, affiliation, show, status, role, jid, color):
"""
When a new user joins the groupchat
"""
deterministic = config.get_by_tabname('deterministic_nick_colors', self.name)
user = User(from_nick, affiliation,
- show, status, role, jid, deterministic)
+ show, status, role, jid, deterministic, color)
self.users.append(user)
hide_exit_join = config.get_by_tabname('hide_exit_join',
self.general_jid)
@@ -1236,6 +1246,12 @@ class MucTab(ChatTab):
self.own_nick = new_nick
# also change our nick in all private discussions of this room
self.core.on_muc_own_nickchange(self)
+ else:
+ color = config.get_by_tabname(new_nick, 'muc_colors')
+ if color != '':
+ deterministic = config.get_by_tabname('deterministic_nick_colors',
+ self.name)
+ user.change_color(color, deterministic)
user.change_nick(new_nick)
if config.get_by_tabname('display_user_color_in_join_part',
diff --git a/src/user.py b/src/user.py
index 8b4ad94b..b1796bc3 100644
--- a/src/user.py
+++ b/src/user.py
@@ -13,9 +13,13 @@ 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,
@@ -28,14 +32,17 @@ class User(object):
"""
keep trace of an user in a Room
"""
- def __init__(self, nick, affiliation, show, status, role, jid, deterministic=True):
+ 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)
- if deterministic:
- self.set_deterministic_color()
+ if color != '':
+ self.change_color(color, deterministic)
else:
- 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
@@ -56,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