fix /list with new SleekXMPP xep_0030 version. Also add some error handling...

fix /list with new SleekXMPP xep_0030 version. Also add some error handling and a '(loading)' information while waiting for the answer
parent 15f73406
......@@ -890,11 +890,7 @@ class Core(object):
server = arg.strip()
list_tab = tabs.MucListTab(self, server)
self.add_tab(list_tab, True)
res = self.xmpp.plugin['xep_0030'].getItems(server)
items = [{'node-part':JID(item[0]).user,
'jid': item[0],
'name': item[2]} for item in res['disco_items'].getItems()]
list_tab.listview.add_lines(items)
self.xmpp.plugin['xep_0030'].get_items(jid=server, block=False, callback=list_tab.on_muc_list_item_received)
def command_whois(self, arg):
"""
......
......@@ -1010,6 +1010,7 @@ class MucListTab(Tab):
self._color_state = theme.COLOR_TAB_NORMAL
self.name = server
self.upper_message = windows.Topic()
self.upper_message.set_message('Chatroom list on server %s (Loading)' % self.name)
columns = ('node-part','name', 'users')
self.list_header = windows.ColumnHeaderWin(columns)
self.listview = windows.ListWin(columns)
......@@ -1026,7 +1027,7 @@ class MucListTab(Tab):
self.resize()
def refresh(self, tabs, informations, roster):
self.upper_message.refresh('Chatroom list on server %s' % self.name)
self.upper_message.refresh()
self.list_header.refresh()
self.listview.refresh()
self.tab_win.refresh(tabs, tabs[0])
......@@ -1057,6 +1058,32 @@ class MucListTab(Tab):
def join_selected_no_focus(self):
return
def set_error(self, msg, code, body):
"""
If there's an error (retrieving the values etc)
"""
self._error_message = _('Error: %(code)s - %(msg)s: %(body)s') % {'msg':msg, 'body':body, 'code':code}
self.upper_message.set_message(self._error_message)
self.upper_message.refresh()
curses.doupdate()
def on_muc_list_item_received(self, iq):
"""
Callback called when a disco#items result is received
Used with command_list
"""
log.debug('res: %s\n\n' % iq)
if iq['type'] == 'error':
self.set_error(iq['error']['type'], iq['error']['code'], iq['error']['text'])
return
items = [{'node-part':JID(item[0]).user,
'jid': item[0],
'name': item[2]} for item in iq['disco_items'].get_items()]
self.listview.add_lines(items)
self.upper_message.set_message('Chatroom list on server %s' % self.name)
self.upper_message.refresh()
curses.doupdate()
def join_selected(self):
row = self.listview.get_selected_row()
if not row:
......
......@@ -154,14 +154,19 @@ class UserList(Win):
class Topic(Win):
def __init__(self):
Win.__init__(self)
self._message = ''
def resize(self, height, width, y, x, stdscr):
self._resize(height, width, y, x, stdscr)
def refresh(self, topic):
def refresh(self, topic=None):
with g_lock:
self._win.erase()
self.addstr(0, 0, topic[:self.width-1], curses.color_pair(theme.COLOR_TOPIC_BAR))
if topic:
msg = topic[:self.width-1]
else:
msg = self._message[:self.width-1]
self.addstr(0, 0, msg, curses.color_pair(theme.COLOR_TOPIC_BAR))
(y, x) = self._win.getyx()
remaining_size = self.width - x
if remaining_size:
......@@ -169,6 +174,9 @@ class Topic(Win):
curses.color_pair(theme.COLOR_INFORMATION_BAR))
self._refresh()
def set_message(self, message):
self._message = message
class GlobalInfoBar(Win):
def __init__(self):
Win.__init__(self)
......@@ -1362,12 +1370,13 @@ class ListWin(Win):
return
self.lines += lines
self.refresh()
curses.doupdate()
def get_selected_row(self):
"""
Return the tuple representing the selected row
"""
if self._selected_row is not None:
if self._selected_row is not None and self.lines:
return self.lines[self._selected_row]
return None
......
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