fixed #1140 (Display the error messages correctly. And also we can provide a...

fixed #1140 (Display the error messages correctly. And also we can provide a password when joining a room)
parent 899a33ae
......@@ -88,7 +88,7 @@ class Connection(threading.Thread):
self.client.auth(None, "", self.resource)
return True
except TypeError:
self.handler.emit('error', msg=_('Error: Could not authenticate. Please make sure the server you chose (%s) supports anonymous authentication' % (config.get('server', '')))) # TODO msg
self.handler.emit('error', msg=_('Error: Could not authenticate. Please make sure the server you chose (%s) supports anonymous authentication' % (config.get('server', ''))))
return None
else:
log.error('Non-anonymous connections not handled currently')
......@@ -102,9 +102,16 @@ class Connection(threading.Thread):
self.client.RegisterHandler('iq', self.on_get_version, typ='get', ns=xmpp.NS_VERSION)
self.client.RegisterHandler('presence', self.handler_presence)
self.client.RegisterHandler('message', self.handler_message)
# self.client.RegisterHandler('message', self.handler_delayed_message, ns=xmpp.NS_DELAY)
def error_message(self, stanza):
room_name = stanza.getFrom().getStripped()
self.handler.emit('error-message', room=room_name, error=stanza.getTag('error'), msg=stanza.getError())
raise xmpp.protocol.NodeProcessed
def handler_presence(self, connection, presence):
if presence.getType() == 'error':
self.error_message(presence)
return
fro = presence.getFrom()
to = presence.getAttr('to')
if fro == to: # own presence
......@@ -120,6 +127,9 @@ class Connection(threading.Thread):
raise xmpp.protocol.NodeProcessed
def handler_message(self, connection, message):
if message.getType() == 'error':
self.error_message(message)
return
self.handler.emit('room-message', stanza=message)
raise xmpp.protocol.NodeProcessed
......
......@@ -63,7 +63,7 @@ class Gui(object):
self.commands = {
'help': (self.command_help, _('OLOL, this is SOOO recursive')),
'join': (self.command_join, _('Usage: /join [room_name][/nick]\nJoin: Join the specified room. You can specify a nickname after a slash (/). If no nickname is specified, you will use the default_nick in the configuration file. You can omit the room name: you will then join the room you\'re looking at (useful if you were kicked). Examples:\n/join room@server.tld\n/join room@server.tld/John\n/join /me_again\n/join')),
'join': (self.command_join, _('Usage: /join [room_name][/nick] [password]\nJoin: Join the specified room. You can specify a nickname after a slash (/). If no nickname is specified, you will use the default_nick in the configuration file. You can omit the room name: you will then join the room you\'re looking at (useful if you were kicked). You can also provide a password to join the room.\nExamples:\n/join room@server.tld\n/join room@server.tld/John\n/join /me_again\n/join\n/join room@server.tld/my_nick password\n/join / pass')),
'quit': (self.command_quit, _('Usage: /quit\nQuit: Just disconnect from the server and exit poezio.')),
'exit': (self.command_quit, _('Usage: /exit\nExit: Just disconnect from the server and exit poezio.')),
'next': (self.rotate_rooms_right, _('Usage: /next\nNext: Go to the next room.')),
......@@ -106,6 +106,7 @@ class Gui(object):
self.handler.connect('join-room', self.join_room)
self.handler.connect('room-presence', self.room_presence)
self.handler.connect('room-message', self.room_message)
self.handler.connect('error-message', self.room_error)
self.handler.connect('error', self.information)
def main_loop(self, stdscr):
......@@ -219,6 +220,15 @@ class Gui(object):
self.rooms.insert(0, self.rooms.pop())
self.window.refresh(self.rooms)
def room_error(self, room, error, msg):
r = self.get_room_by_name(room)
code = error.getAttr('code')
typ = error.getAttr('type')
body = error.getTag('text').getData()
self.add_info(r, _('Error: %(code)s-%(msg)s: %(body)s' % {'msg':msg, 'code':code, 'body':body}))
if code == '401':
self.add_info(r, _('To provide a password in order to join the room, type "/join / password" (replace "password" by the real password)'))
def room_message(self, stanza, date=None):
delay_tag = stanza.getTag('delay', namespace='urn:xmpp:delay')
if delay_tag and not date:
......@@ -226,8 +236,6 @@ class Gui(object):
date = common.datetime_tuple(delay_tag.getAttr('stamp'))
else:
delayed = False
if len(sys.argv) > 1:
self.information(str(stanza).encode('utf-8'))
if stanza.getType() != 'groupchat':
return # ignore all messages not comming from a MUC
nick_from = stanza.getFrom().getResource()
......@@ -262,8 +270,9 @@ class Gui(object):
room = self.get_room_by_name(from_room)
if not room:
return
if stanza.getType() == 'error':
msg = _("Error: %s") % stanza.getError()
# if stanza.getType() == 'error':
# print stanza
# msg = _("Error: %s") % stanza.getError()
else:
msg = None
affiliation = stanza.getAffiliation()
......@@ -424,6 +433,7 @@ class Gui(object):
self.muc.eject_user(roomname, 'kick', nick, reason)
def command_join(self, args):
password = None
if len(args) == 0:
r = self.current_room()
if r.name == 'Info':
......@@ -441,13 +451,17 @@ class Gui(object):
if r.name == 'Info':
return
room = r.name
if nick == '':
nick = r.own_nick
else:
room = info[0]
r = self.get_room_by_name(room)
if len(args) == 2: # a password is provided
password = args[1]
if r and r.joined: # if we are already in the room
self.information(_("already in room [%s]") % room)
return
self.muc.join_room(room, nick)
self.muc.join_room(room, nick, password)
if not r: # if the room window exists, we don't recreate it.
self.join_room(room, nick)
else:
......
......@@ -58,6 +58,10 @@ class Handler(Singleton):
# We send our time
# Args: the stanza we reply to
'error-message': list(),
# We send our time
# Args: the stanza we reply to
'error': list()
# We send our time
# Args: the stanza we reply to
......
......@@ -152,10 +152,12 @@ class MultiUserChat(object):
"""Join a new room"""
pres = Presence(to='%s/%s' % (room, nick))
pres.setFrom('%s'%self.own_jid)
if password:
if not password:
pres.addChild(name='x', namespace=NS_MUC)
else:
pres.addChild(name='x', namespace=NS_MUC)
item = pres.addChild(name='x', namespace=NS_MUC)
passwd = item.addChild(name='password')
passwd.setData(password)
self.connection.send(pres)
def quit_room(self, room, nick, msg=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