Commit 251a10ab authored by Célestin Matte's avatar Célestin Matte

Add a muc_color section in the config file to permanently fix a color to a nick

parent f7e7836f
...@@ -509,3 +509,7 @@ M-i = ^I ...@@ -509,3 +509,7 @@ M-i = ^I
# to save various data across restarts # to save various data across restarts
folded_roster_groups = folded_roster_groups =
info_win_height = 2 info_win_height = 2
[muc_colors]
# Set color for a nick, under the form
# nick = color
...@@ -747,6 +747,15 @@ or the way messages are displayed. ...@@ -747,6 +747,15 @@ or the way messages are displayed.
If the message takes more than one line, the popup will stay visible If the message takes more than one line, the popup will stay visible
two more second per additional lines. 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 User Interaction
~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~
......
...@@ -135,6 +135,8 @@ DEFAULT_CONFIG = { ...@@ -135,6 +135,8 @@ DEFAULT_CONFIG = {
'var': { 'var': {
'folded_roster_groups': '', 'folded_roster_groups': '',
'info_win_height': 2 'info_win_height': 2
},
'muc_colors': {
} }
} }
......
...@@ -424,6 +424,9 @@ class MucTab(ChatTab): ...@@ -424,6 +424,9 @@ class MucTab(ChatTab):
for user in self.users: for user in self.users:
if user.nick == self.own_nick: if user.nick == self.own_nick:
continue continue
color = config.get_by_tabname(user.nick, 'muc_colors')
if color != '':
continue
user.set_deterministic_color() user.set_deterministic_color()
if args[0] == 'random': if args[0] == 'random':
self.core.information(_('"random" was provided, but poezio is ' self.core.information(_('"random" was provided, but poezio is '
...@@ -435,11 +438,17 @@ class MucTab(ChatTab): ...@@ -435,11 +438,17 @@ class MucTab(ChatTab):
compare_users = lambda x: x.last_talked compare_users = lambda x: x.last_talked
users = list(self.users) users = list(self.users)
sorted_users = sorted(users, key=compare_users, reverse=True) sorted_users = sorted(users, key=compare_users, reverse=True)
full_sorted_users = sorted_users[:]
# search our own user, to remove it from the list # 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: if user.nick == self.own_nick:
sorted_users.remove(user) sorted_users.remove(user)
user.color = get_theme().COLOR_OWN_NICK 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) colors = list(get_theme().LIST_COLOR_NICKNAMES)
if args[0] == 'random': if args[0] == 'random':
random.shuffle(colors) random.shuffle(colors)
...@@ -468,8 +477,8 @@ class MucTab(ChatTab): ...@@ -468,8 +477,8 @@ class MucTab(ChatTab):
if user.nick == self.own_nick: if user.nick == self.own_nick:
return self.core.information(_("You cannot change the color of your" return self.core.information(_("You cannot change the color of your"
" own nick.", 'Error')) " own nick.", 'Error'))
colors = list(get_theme().LIST_COLOR_NICKNAMES) user.change_color(color)
user.color = (xhtml.colors[color], -1) config.write_in_file('muc_colors', nick, color)
self.text_win.rebuild_everything(self._text_buffer) self.text_win.rebuild_everything(self._text_buffer)
self.user_win.refresh(self.users) self.user_win.refresh(self.users)
self.text_win.refresh() self.text_win.refresh()
...@@ -1052,12 +1061,13 @@ class MucTab(ChatTab): ...@@ -1052,12 +1061,13 @@ class MucTab(ChatTab):
jid = presence['muc']['jid'] jid = presence['muc']['jid']
typ = presence['type'] typ = presence['type']
deterministic = config.get_by_tabname('deterministic_nick_colors', self.name) 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. if not self.joined: # user in the room BEFORE us.
# ignore redondant presence message, see bug #1509 # ignore redondant presence message, see bug #1509
if (from_nick not in [user.nick for user in self.users] if (from_nick not in [user.nick for user in self.users]
and typ != "unavailable"): and typ != "unavailable"):
new_user = User(from_nick, affiliation, show, new_user = User(from_nick, affiliation, show,
status, role, jid, deterministic) status, role, jid, deterministic, color)
self.users.append(new_user) self.users.append(new_user)
self.core.events.trigger('muc_join', presence, self) self.core.events.trigger('muc_join', presence, self)
if '110' in status_codes or self.own_nick == from_nick: if '110' in status_codes or self.own_nick == from_nick:
...@@ -1134,7 +1144,7 @@ class MucTab(ChatTab): ...@@ -1134,7 +1144,7 @@ class MucTab(ChatTab):
if not user: if not user:
self.core.events.trigger('muc_join', presence, self) self.core.events.trigger('muc_join', presence, self)
self.on_user_join(from_nick, affiliation, show, status, role, self.on_user_join(from_nick, affiliation, show, status, role,
jid) jid, color)
# nick change # nick change
elif change_nick: elif change_nick:
self.core.events.trigger('muc_nickchange', presence, self) self.core.events.trigger('muc_nickchange', presence, self)
...@@ -1189,13 +1199,13 @@ class MucTab(ChatTab): ...@@ -1189,13 +1199,13 @@ class MucTab(ChatTab):
typ=2) typ=2)
self.disconnect() 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 When a new user joins the groupchat
""" """
deterministic = config.get_by_tabname('deterministic_nick_colors', self.name) deterministic = config.get_by_tabname('deterministic_nick_colors', self.name)
user = User(from_nick, affiliation, user = User(from_nick, affiliation,
show, status, role, jid, deterministic) show, status, role, jid, deterministic, color)
self.users.append(user) self.users.append(user)
hide_exit_join = config.get_by_tabname('hide_exit_join', hide_exit_join = config.get_by_tabname('hide_exit_join',
self.general_jid) self.general_jid)
...@@ -1236,6 +1246,12 @@ class MucTab(ChatTab): ...@@ -1236,6 +1246,12 @@ class MucTab(ChatTab):
self.own_nick = new_nick self.own_nick = new_nick
# also change our nick in all private discussions of this room # also change our nick in all private discussions of this room
self.core.on_muc_own_nickchange(self) 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) user.change_nick(new_nick)
if config.get_by_tabname('display_user_color_in_join_part', if config.get_by_tabname('display_user_color_in_join_part',
......
...@@ -13,9 +13,13 @@ An user is a MUC participant, not a roster contact (see contact.py) ...@@ -13,9 +13,13 @@ An user is a MUC participant, not a roster contact (see contact.py)
from random import choice from random import choice
from datetime import timedelta, datetime from datetime import timedelta, datetime
from hashlib import md5 from hashlib import md5
import xhtml
from theming import get_theme from theming import get_theme
import logging
log = logging.getLogger(__name__)
ROLE_DICT = { ROLE_DICT = {
'':0, '':0,
'none':0, 'none':0,
...@@ -28,14 +32,17 @@ class User(object): ...@@ -28,14 +32,17 @@ class User(object):
""" """
keep trace of an user in a Room 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.last_talked = datetime(1, 1, 1) # The oldest possible time
self.update(affiliation, show, status, role) self.update(affiliation, show, status, role)
self.change_nick(nick) self.change_nick(nick)
if deterministic: if color != '':
self.set_deterministic_color() self.change_color(color, deterministic)
else: 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.jid = jid
self.chatstate = None self.chatstate = None
...@@ -56,6 +63,17 @@ class User(object): ...@@ -56,6 +63,17 @@ class User(object):
def change_nick(self, nick): def change_nick(self, nick):
self.nick = 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): def set_last_talked(self, time):
""" """
time: datetime object time: datetime object
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment