Add nick_color_aliases (default: true), to look for color of aliases

This commit is contained in:
Célestin Matte 2014-12-23 18:20:33 +01:00
parent 1bbdab7f12
commit 0ae1ee2fbf
4 changed files with 32 additions and 4 deletions

View file

@ -374,6 +374,9 @@ user_list_sort = desc
# If the MUC nicks should receive a fixed color based on their text or not # If the MUC nicks should receive a fixed color based on their text or not
deterministic_nick_colors = true deterministic_nick_colors = true
# If _nick, nick_, _nick_, nick__ etc. should have the same color as nick
nick_color_aliases = true
# The nick of people who join, part, change their status, etc. in a MUC will # The nick of people who join, part, change their status, etc. in a MUC will
# be displayed using their nick color if true. # be displayed using their nick color if true.
display_user_color_in_join_part = true display_user_color_in_join_part = true

View file

@ -528,6 +528,15 @@ or the way messages are displayed.
The value of this option affects the behavior of :term:`/recolor`. The value of this option affects the behavior of :term:`/recolor`.
nick_color_aliases
**Default value:** ``true``
Automatically search for color of nick aliases. For example, if nick is
set to red, _nick, nick_, _nick_, nick__ etc. will have the same color.
Aliases colors are checked first, so that it is still possible to have
different colors for nick_ and nick.
vertical_tab_list_size vertical_tab_list_size
**Default value:** ``20`` **Default value:** ``20``
@ -755,7 +764,6 @@ or the way messages are displayed.
be displayed in that color. This color won't be changed by the recolor be displayed in that color. This color won't be changed by the recolor
command. command.
User Interaction User Interaction
~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~

View file

@ -43,6 +43,7 @@ DEFAULT_CONFIG = {
'custom_port': '', 'custom_port': '',
'default_nick': '', 'default_nick': '',
'deterministic_nick_colors': True, 'deterministic_nick_colors': True,
'nick_color_aliases': True,
'display_activity_notifications': False, 'display_activity_notifications': False,
'display_gaming_notifications': False, 'display_gaming_notifications': False,
'display_mood_notifications': False, 'display_mood_notifications': False,

View file

@ -426,7 +426,7 @@ 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') color = self.search_for_color(user.nick)
if color != '': if color != '':
continue continue
user.set_deterministic_color() user.set_deterministic_color()
@ -444,7 +444,7 @@ class MucTab(ChatTab):
# search our own user, to remove it from the list # search our own user, to remove it from the list
# Also remove users whose color is fixed # Also remove users whose color is fixed
for user in full_sorted_users: for user in full_sorted_users:
color = config.get_by_tabname(user.nick, 'muc_colors') color = self.search_for_color(user.nick)
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
@ -1068,7 +1068,7 @@ 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') color = self.search_for_color(from_nick)
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]
@ -1670,3 +1670,19 @@ class MucTab(ChatTab):
self.core.refresh_window() self.core.refresh_window()
else: # Re-send a self-ping in a few seconds else: # Re-send a self-ping in a few seconds
self.enable_self_ping_event() self.enable_self_ping_event()
def search_for_color(self, nick):
"""
Search for the color of a nick in the config file.
Also, look at the colors of its possible aliases if nick_color_aliases
is set.
"""
color = config.get_by_tabname(nick, 'muc_colors')
if color != '':
return color
nick_color_aliases = config.get_by_tabname('nick_color_aliases', self.name)
if nick_color_aliases:
nick_alias = re.sub('^_*', '', nick)
nick_alias = re.sub('_*$', '', nick_alias)
color = config.get_by_tabname(nick_alias, 'muc_colors')
return color