From 9da530f8541ed96fe5fa7e3ff01df5290f511633 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9lestin=20Matte?= <celestin.matte@gmail.com>
Date: Tue, 23 Dec 2014 23:51:04 +0100
Subject: Make it possible to change the nick of a user not in the room, and
 change color of its aliases

---
 src/tabs/muctab.py | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

(limited to 'src/tabs')

diff --git a/src/tabs/muctab.py b/src/tabs/muctab.py
index 7264569a..d567e364 100644
--- a/src/tabs/muctab.py
+++ b/src/tabs/muctab.py
@@ -473,19 +473,27 @@ class MucTab(ChatTab):
         nick = args[0]
         color = args[1].lower()
         user = self.get_user_by_name(nick)
-        if not user:
-            return self.core.information(_("Unknown user: %s") % nick)
         if not color in xhtml.colors and color != 'unset':
             return self.core.information(_("Unknown color: %s") % color, 'Error')
-        if user.nick == self.own_nick:
+        if user and user.nick == self.own_nick:
             return self.core.information(_("You cannot change the color of your"
                                            " own nick.", 'Error'))
         if color == 'unset':
             if config.remove_and_save(nick, 'muc_colors'):
                 self.core.information(_('Color for nick %s unset') % (nick))
         else:
-            user.change_color(color)
+            if user:
+                user.change_color(color)
             config.set_and_save(nick, color, 'muc_colors')
+            nick_color_aliases = config.get_by_tabname('nick_color_aliases', self.name)
+            if nick_color_aliases:
+                # if any user in the room has a nick which is an alias of the
+                # nick, update its color
+                for u in self.users:
+                    nick_alias = re.sub('^_*', '', u.nick)
+                    nick_alias = re.sub('_*$', '', nick_alias)
+                    if nick_alias == nick:
+                        u.change_color(color)
             self.text_win.rebuild_everything(self._text_buffer)
             self.user_win.refresh(self.users)
             self.text_win.refresh()
-- 
cgit v1.2.3