summaryrefslogtreecommitdiff
path: root/poezio/tabs/muctab.py
diff options
context:
space:
mode:
Diffstat (limited to 'poezio/tabs/muctab.py')
-rw-r--r--poezio/tabs/muctab.py133
1 files changed, 92 insertions, 41 deletions
diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py
index 405c2b1f..80631388 100644
--- a/poezio/tabs/muctab.py
+++ b/poezio/tabs/muctab.py
@@ -52,6 +52,8 @@ class MucTab(ChatTab):
message_type = 'groupchat'
plugin_commands = {} # type: Dict[str, Command]
plugin_keys = {} # type: Dict[str, Callable]
+ additional_information = {} # type: Dict[str, Callable[[str], str]]
+ lagged = False
def __init__(self, core, jid, nick, password=None):
ChatTab.__init__(self, core, jid)
@@ -106,6 +108,20 @@ class MucTab(ChatTab):
return last_message.time
return None
+ @staticmethod
+ def add_information_element(plugin_name: str, callback: Callable[[str], str]) -> None:
+ """
+ Lets a plugin add its own information to the MucInfoWin
+ """
+ MucTab.additional_information[plugin_name] = callback
+
+ @staticmethod
+ def remove_information_element(plugin_name: str) -> None:
+ """
+ Lets a plugin add its own information to the MucInfoWin
+ """
+ del MucTab.additional_information[plugin_name]
+
def cancel_config(self, form):
"""
The user do not want to send his/her config, send an iq cancel
@@ -141,13 +157,14 @@ class MucTab(ChatTab):
def leave_room(self, message: str):
if self.joined:
- info_col = dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
- char_quit = get_theme().CHAR_QUIT
- spec_col = dump_tuple(get_theme().COLOR_QUIT_CHAR)
+ theme = get_theme()
+ info_col = dump_tuple(theme.COLOR_INFORMATION_TEXT)
+ char_quit = theme.CHAR_QUIT
+ spec_col = dump_tuple(theme.COLOR_QUIT_CHAR)
if config.get_by_tabname('display_user_color_in_join_part',
self.general_jid):
- color = dump_tuple(get_theme().COLOR_OWN_NICK)
+ color = dump_tuple(theme.COLOR_OWN_NICK)
else:
color = "3"
@@ -285,8 +302,9 @@ class MucTab(ChatTab):
"""
Print the current topic
"""
- info_text = dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
- norm_text = dump_tuple(get_theme().COLOR_NORMAL_TEXT)
+ theme = get_theme()
+ info_text = dump_tuple(theme.COLOR_INFORMATION_TEXT)
+ norm_text = dump_tuple(theme.COLOR_NORMAL_TEXT)
if self.topic_from:
user = self.get_user_by_name(self.topic_from)
if user:
@@ -396,6 +414,8 @@ class MucTab(ChatTab):
if self.joined:
if self.input.text:
self.state = 'nonempty'
+ elif self.lagged:
+ self.state = 'disconnected'
else:
self.state = 'normal'
else:
@@ -421,13 +441,14 @@ class MucTab(ChatTab):
"""
Handle MUC presence
"""
+ self.reset_lag()
status_codes = set()
for status_code in presence.xml.findall(STATUS_XPATH):
status_codes.add(status_code.attrib['code'])
if presence['type'] == 'error':
self.core.room_error(presence, self.name)
elif not self.joined:
- if '110' in status_codes:
+ if '110' in status_codes or self.own_nick == presence['from'].resource:
self.process_presence_buffer(presence)
else:
self.presence_buffer.append(presence)
@@ -440,7 +461,9 @@ class MucTab(ChatTab):
if self.core.tabs.current_tab is self:
self.text_win.refresh()
self.user_win.refresh_if_changed(self.users)
- self.info_header.refresh(self, self.text_win, user=self.own_user)
+ self.info_header.refresh(
+ self, self.text_win, user=self.own_user,
+ information=MucTab.additional_information)
self.input.refresh()
self.core.doupdate()
@@ -500,7 +523,8 @@ class MucTab(ChatTab):
if (self.core.tabs.current_tab is self
and self.core.status.show not in ('xa', 'away')):
self.send_chat_state('active')
- new_user.color = get_theme().COLOR_OWN_NICK
+ theme = get_theme()
+ new_user.color = theme.COLOR_OWN_NICK
if config.get_by_tabname('display_user_color_in_join_part',
self.general_jid):
@@ -508,14 +532,14 @@ class MucTab(ChatTab):
else:
color = "3"
- info_col = dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
- warn_col = dump_tuple(get_theme().COLOR_WARNING_TEXT)
- spec_col = dump_tuple(get_theme().COLOR_JOIN_CHAR)
+ info_col = dump_tuple(theme.COLOR_INFORMATION_TEXT)
+ warn_col = dump_tuple(theme.COLOR_WARNING_TEXT)
+ spec_col = dump_tuple(theme.COLOR_JOIN_CHAR)
enable_message = ('\x19%(color_spec)s}%(spec)s\x19%(info_col)s} You '
'(\x19%(nick_col)s}%(nick)s\x19%(info_col)s}) joined'
' the room') % {
'nick': from_nick,
- 'spec': get_theme().CHAR_JOIN,
+ 'spec': theme.CHAR_JOIN,
'color_spec': spec_col,
'nick_col': color,
'info_col': info_col,
@@ -630,9 +654,10 @@ class MucTab(ChatTab):
color = dump_tuple(user.color)
else:
color = 3
- info_col = dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
- spec_col = dump_tuple(get_theme().COLOR_JOIN_CHAR)
- char_join = get_theme().CHAR_JOIN
+ theme = get_theme()
+ info_col = dump_tuple(theme.COLOR_INFORMATION_TEXT)
+ spec_col = dump_tuple(theme.COLOR_JOIN_CHAR)
+ char_join = theme.CHAR_JOIN
if not jid.full:
msg = ('\x19%(color_spec)s}%(spec)s \x19%(color)s}%(nick)s'
'\x19%(info_col)s} joined the room') % {
@@ -651,7 +676,7 @@ class MucTab(ChatTab):
'color': color,
'jid': jid.full,
'info_col': info_col,
- 'jid_color': dump_tuple(get_theme().COLOR_MUC_JID),
+ 'jid_color': dump_tuple(theme.COLOR_MUC_JID),
'color_spec': spec_col,
}
self.add_message(msg, typ=2)
@@ -710,8 +735,9 @@ class MucTab(ChatTab):
else:
by = None
- info_col = dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
- char_kick = get_theme().CHAR_KICK
+ theme = get_theme()
+ info_col = dump_tuple(theme.COLOR_INFORMATION_TEXT)
+ char_kick = theme.CHAR_KICK
if from_nick == self.own_nick: # we are banned
if by:
@@ -786,8 +812,9 @@ class MucTab(ChatTab):
reason = presence.xml.find('{%s}x/{%s}item/{%s}reason' %
(NS_MUC_USER, NS_MUC_USER, NS_MUC_USER))
by = None
- info_col = dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
- char_kick = get_theme().CHAR_KICK
+ theme = get_theme()
+ info_col = dump_tuple(theme.COLOR_INFORMATION_TEXT)
+ char_kick = theme.CHAR_KICK
if actor_elem is not None:
by = actor_elem.get('nick') or actor_elem.get('jid')
if from_nick == self.own_nick: # we are kicked
@@ -880,8 +907,9 @@ class MucTab(ChatTab):
color = dump_tuple(user.color)
else:
color = 3
- info_col = dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
- spec_col = dump_tuple(get_theme().COLOR_QUIT_CHAR)
+ theme = get_theme()
+ info_col = dump_tuple(theme.COLOR_INFORMATION_TEXT)
+ spec_col = dump_tuple(theme.COLOR_QUIT_CHAR)
error_leave_txt = ''
if server_initiated:
@@ -893,18 +921,18 @@ class MucTab(ChatTab):
'room%(error_leave)s') % {
'nick': from_nick,
'color': color,
- 'spec': get_theme().CHAR_QUIT,
+ 'spec': theme.CHAR_QUIT,
'info_col': info_col,
'color_spec': spec_col,
'error_leave': error_leave_txt,
}
else:
- jid_col = dump_tuple(get_theme().COLOR_MUC_JID)
+ jid_col = dump_tuple(theme.COLOR_MUC_JID)
leave_msg = ('\x19%(color_spec)s}%(spec)s \x19%(color)s}'
'%(nick)s\x19%(info_col)s} (\x19%(jid_col)s}'
'%(jid)s\x19%(info_col)s}) has left the '
'room%(error_leave)s') % {
- 'spec': get_theme().CHAR_QUIT,
+ 'spec': theme.CHAR_QUIT,
'nick': from_nick,
'color': color,
'jid': jid.full,
@@ -931,16 +959,17 @@ class MucTab(ChatTab):
color = dump_tuple(user.color)
else:
color = 3
+ info_col = dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
if from_nick == self.own_nick:
msg = '\x19%(color)s}You\x19%(info_col)s} changed: ' % {
- 'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT),
+ 'info_col': info_col,
'color': color
}
else:
msg = '\x19%(color)s}%(nick)s\x19%(info_col)s} changed: ' % {
'nick': from_nick,
'color': color,
- 'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
+ 'info_col': info_col
}
if affiliation != user.affiliation:
msg += 'affiliation: %s, ' % affiliation
@@ -1126,6 +1155,7 @@ class MucTab(ChatTab):
self.command_cycle(iq["error"]["text"] or "not in this room")
self.core.refresh_window()
else: # Re-send a self-ping in a few seconds
+ self.reset_lag()
self.enable_self_ping_event()
def search_for_color(self, nick):
@@ -1145,8 +1175,26 @@ class MucTab(ChatTab):
return color
def on_self_ping_failed(self, iq):
- self.command_cycle("the MUC server is not responding")
- self.core.refresh_window()
+ if not self.lagged:
+ self.lagged = True
+ info_text = dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
+ self._text_buffer.add_message(
+ "\x19%s}MUC service not responding." % info_text)
+ self._state = 'disconnected'
+ self.core.refresh_window()
+ self.enable_self_ping_event()
+
+ def reset_lag(self):
+ if self.lagged:
+ self.lagged = False
+ info_text = dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
+ self._text_buffer.add_message(
+ "\x19%s}MUC service is responding again." % info_text)
+ if self != self.core.tabs.current_tab:
+ self._state = 'joined'
+ else:
+ self._state = 'normal'
+ self.core.refresh_window()
########################## UI ONLY #####################################
@@ -1225,7 +1273,9 @@ class MucTab(ChatTab):
if display_user_list:
self.v_separator.refresh()
self.user_win.refresh(self.users)
- self.info_header.refresh(self, self.text_win, user=self.own_user)
+ self.info_header.refresh(
+ self, self.text_win, user=self.own_user,
+ information=MucTab.additional_information)
self.refresh_tab_win()
if display_info_win:
self.info_win.refresh()
@@ -1454,23 +1504,24 @@ class MucTab(ChatTab):
if not self.joined:
return
+ theme = get_theme()
aff = {
- 'owner': get_theme().CHAR_AFFILIATION_OWNER,
- 'admin': get_theme().CHAR_AFFILIATION_ADMIN,
- 'member': get_theme().CHAR_AFFILIATION_MEMBER,
- 'none': get_theme().CHAR_AFFILIATION_NONE,
+ 'owner': theme.CHAR_AFFILIATION_OWNER,
+ 'admin': theme.CHAR_AFFILIATION_ADMIN,
+ 'member': theme.CHAR_AFFILIATION_MEMBER,
+ 'none': theme.CHAR_AFFILIATION_NONE,
}
colors = {}
- colors["visitor"] = dump_tuple(get_theme().COLOR_USER_VISITOR)
- colors["moderator"] = dump_tuple(get_theme().COLOR_USER_MODERATOR)
- colors["participant"] = dump_tuple(get_theme().COLOR_USER_PARTICIPANT)
- color_other = dump_tuple(get_theme().COLOR_USER_NONE)
+ colors["visitor"] = dump_tuple(theme.COLOR_USER_VISITOR)
+ colors["moderator"] = dump_tuple(theme.COLOR_USER_MODERATOR)
+ colors["participant"] = dump_tuple(theme.COLOR_USER_PARTICIPANT)
+ color_other = dump_tuple(theme.COLOR_USER_NONE)
buff = ['Users: %s \n' % len(self.users)]
for user in self.users:
affiliation = aff.get(user.affiliation,
- get_theme().CHAR_AFFILIATION_NONE)
+ theme.CHAR_AFFILIATION_NONE)
color = colors.get(user.role, color_other)
buff.append(
'\x19%s}%s\x19o\x19%s}%s\x19o' %
@@ -1529,7 +1580,7 @@ class MucTab(ChatTab):
@command_args_parser.quoted(2)
def command_affiliation(self, args):
"""
- /affiliation <nick> <role>
+ /affiliation <nick or jid> <affiliation>
Changes the affiliation of an user
affiliations can be: outcast, none, member, admin, owner
"""