summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2017-10-15 14:09:40 +0200
committermathieui <mathieui@mathieui.net>2017-10-15 14:09:40 +0200
commit9844f288de27dac7095c82832ad51c75ede7a362 (patch)
tree7afa7b1f662f7ac0ca0940786f9ae70ba57f44ac
parentdb69afc1714f98726cfb336d54dec947b77a90a1 (diff)
downloadpoezio-9844f288de27dac7095c82832ad51c75ede7a362.tar.gz
poezio-9844f288de27dac7095c82832ad51c75ede7a362.tar.bz2
poezio-9844f288de27dac7095c82832ad51c75ede7a362.tar.xz
poezio-9844f288de27dac7095c82832ad51c75ede7a362.zip
Always refresh the MUC when setting or unsetting a user color
Fixes #3213
-rw-r--r--poezio/tabs/muctab.py60
1 files changed, 33 insertions, 27 deletions
diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py
index 966ba9d4..4438e015 100644
--- a/poezio/tabs/muctab.py
+++ b/poezio/tabs/muctab.py
@@ -311,6 +311,35 @@ class MucTab(ChatTab):
user.color = colors[i % len(colors)]
self.text_win.rebuild_everything(self._text_buffer)
+ @refresh_wrapper.conditional
+ def set_nick_color(self, nick, color):
+ "Set a custom color for a nick, permanently"
+ user = self.get_user_by_name(nick)
+ if color not in xhtml.colors and color not in ('unset', 'random'):
+ return False
+ if nick == self.own_nick:
+ return False
+ if color == 'unset':
+ if config.remove_and_save(nick, 'muc_colors'):
+ self.core.information('Color for nick %s unset' % (nick), 'Info')
+ else:
+ if color == 'random':
+ color = random.choice(list(xhtml.colors))
+ 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 tab in self.core.get_tabs(MucTab):
+ for u in tab.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)
+ return True
def on_input(self, key, raw):
if not raw and key in self.key_func:
@@ -1213,35 +1242,12 @@ class MucTab(ChatTab):
return self.core.command.help('color')
nick = args[0]
color = args[1].lower()
- user = self.get_user_by_name(nick)
- if color not in xhtml.colors and color not in ('unset', 'random'):
- return self.core.information("Unknown color: %s" % color, 'Error')
- if user and user.nick == self.own_nick:
+ if 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:
- if color == 'random':
- color = random.choice(list(xhtml.colors))
- 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 tab in self.core.get_tabs(MucTab):
- for u in tab.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()
- self.input.refresh()
+ elif color not in xhtml.colors and color not in ('unset', 'random'):
+ return self.core.information("Unknown color: %s" % color, 'Error')
+ self.set_nick_color(nick, color)
@command_args_parser.quoted(1)
def command_version(self, args):