diff options
author | louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13> | 2010-03-24 18:01:22 +0000 |
---|---|---|
committer | louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13> | 2010-03-24 18:01:22 +0000 |
commit | 19d86ea5ea5f135c5ad229add1a0d173ac44d2c9 (patch) | |
tree | e8bab31fbb2b75cc31b26cc403183d1f136df152 /src | |
parent | 899a33ae477df3dec4541cb86d65783677d37211 (diff) | |
download | poezio-19d86ea5ea5f135c5ad229add1a0d173ac44d2c9.tar.gz poezio-19d86ea5ea5f135c5ad229add1a0d173ac44d2c9.tar.bz2 poezio-19d86ea5ea5f135c5ad229add1a0d173ac44d2c9.tar.xz poezio-19d86ea5ea5f135c5ad229add1a0d173ac44d2c9.zip |
fixed #1140 (Display the error messages correctly. And also we can provide a password when joining a room)
Diffstat (limited to 'src')
-rw-r--r-- | src/connection.py | 14 | ||||
-rw-r--r-- | src/gui.py | 26 | ||||
-rw-r--r-- | src/handler.py | 4 | ||||
-rw-r--r-- | src/multiuserchat.py | 6 |
4 files changed, 40 insertions, 10 deletions
diff --git a/src/connection.py b/src/connection.py index c514d964..bc4928e7 100644 --- a/src/connection.py +++ b/src/connection.py @@ -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: diff --git a/src/handler.py b/src/handler.py index d651b336..69669af0 100644 --- a/src/handler.py +++ b/src/handler.py @@ -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 diff --git a/src/multiuserchat.py b/src/multiuserchat.py index c8a1aafc..a54874a7 100644 --- a/src/multiuserchat.py +++ b/src/multiuserchat.py @@ -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): |