From 97b75de35bbb9ae83ad0ccf2f1c3e28e968d50bd Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Mon, 19 Sep 2005 16:13:45 +0000 Subject: [PATCH] split NOTIFY event into NOTIFY and GC_NOTIFY --- src/common/connection.py | 127 ++++++++++++++++++++++----------------- src/gajim.py | 32 ++++++---- 2 files changed, 90 insertions(+), 69 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index 6acbe0894..678f85a3c 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -330,25 +330,22 @@ class Connection: def _presenceCB(self, con, prs): """Called when we receive a presence""" - who = unicode(prs.getFrom()) - prio = prs.getPriority() - if not prio: - prio = 0 ptype = prs.getType() if ptype == 'available': ptype = None gajim.log.debug('PresenceCB: %s' % ptype) - xtags = prs.getTags('x') + is_gc = False # is it a GC presence ? sigTag = None - keyID = '' - status = prs.getStatus() - for xtag in xtags: - if xtag.getNamespace() == common.xmpp.NS_SIGNED: + xtags = prs.getTags('x') + for x in xtags: + if x.getNamespace() == common.xmpp.NS_MUC_USER: + is_gc = True + if x.getNamespace() == common.xmpp.NS_SIGNED: sigTag = xtag - break - if sigTag and USE_GPG: - #verify - sigmsg = sigTag.getData() - keyID = self.gpg.verify(status, sigmsg) + jid_from = prs.getFrom() + who = unicode(jid_from) + jid_stripped = jid_from.getStripped() + resource = jid_from.getResource() + status = prs.getStatus() show = prs.getShow() if not show in STATUS_LIST: show = '' # We ignore unknown show @@ -356,7 +353,57 @@ class Connection: show = 'online' elif ptype == 'unavailable': show = 'offline' - elif ptype == 'subscribe': + + if is_gc: + if ptype == 'error': + errmsg = prs.getError() + errcode = prs.getErrorCode() + if errcode == '502': # Internal Timeout: + self.dispatch('NOTIFY', (jid_stripped, 'error', errmsg, resource, + prio, keyID)) + elif errcode == '401': # password required to join + self.dispatch('ERROR', (_('Unable to join room'), + _('A password is required to join this room.'))) + elif errcode == '403': # we are banned + self.dispatch('ERROR', (_('Unable to join room'), + _('You are banned from this room.'))) + elif errcode == '404': # room does not exist + self.dispatch('ERROR', (_('Unable to join room'), + _('Such room does not exist.'))) + elif errcode == '405': + self.dispatch('ERROR', (_('Unable to join room'), + _('Room creation is restricted.'))) + elif errcode == '406': + self.dispatch('ERROR', (_('Unable to join room'), + _('Your registered nickname must be used.'))) + elif errcode == '407': + self.dispatch('ERROR', (_('Unable to join room'), + _('You are not in the members list.'))) + elif errcode == '409': # nick conflict + self.dispatch('ERROR', (_('Unable to join room'), + _('Your desired nickname is in use or registered by another user.'))) + else: # print in the window the error + self.dispatch('ERROR_ANSWER', ('', jid_stripped, + errmsg, errcode)) + if not ptype or ptype == 'unavailable': + gajim.logger.write('status', status, who, show) + self.dispatch('GC_NOTIFY', (jid_stripped, show, status, resource, + prs.getRole(), prs.getAffiliation(), prs.getJid(), + prs.getReason(), prs.getActor(), prs.getStatusCode(), + prs.getNewNick())) + return + + prio = prs.getPriority() + try: + prio = int(prio) + except: + prio = 0 + keyID = '' + if sigTag and USE_GPG: + #verify + sigmsg = sigTag.getData() + keyID = self.gpg.verify(status, sigmsg) + if ptype == 'subscribe': gajim.log.debug('subscribe request from %s' % who) if gajim.config.get('alwaysauth') or who.find("@") <= 0: if self.connection: @@ -365,65 +412,33 @@ class Connection: self.to_be_sent.append(p) if who.find("@") <= 0: self.dispatch('NOTIFY', - (prs.getFrom().getStripped(), 'offline', 'offline', - prs.getFrom().getResource(), prio, keyID, None, None, - None, None, None, None)) + (jid_stripped, 'offline', 'offline', resource, prio, keyID)) else: if not status: status = _('I would like to add you to my roster.') self.dispatch('SUBSCRIBE', (who, status)) elif ptype == 'subscribed': - jid = prs.getFrom() - self.dispatch('SUBSCRIBED', (jid.getStripped(), jid.getResource())) + self.dispatch('SUBSCRIBED', (jid_stripped, resource)) # BE CAREFUL: no con.updateRosterItem() in a callback gajim.log.debug(_('we are now subscribed to %s') % who) elif ptype == 'unsubscribe': gajim.log.debug(_('unsubscribe request from %s') % who) elif ptype == 'unsubscribed': gajim.log.debug(_('we are now unsubscribed from %s') % who) - self.dispatch('UNSUBSCRIBED', prs.getFrom().getStripped()) + self.dispatch('UNSUBSCRIBED', jid_stripped) elif ptype == 'error': errmsg = prs.getError() errcode = prs.getErrorCode() if errcode == '502': # Internal Timeout: - self.dispatch('NOTIFY', (prs.getFrom().getStripped(), - 'error', errmsg, prs.getFrom().getResource(), - prio, keyID, prs.getRole(), prs.getAffiliation(), prs.getJid(), - prs.getReason(), prs.getActor(), prs.getStatusCode(), - prs.getNewNick())) - elif errcode == '401': # password required to join - self.dispatch('ERROR', (_('Unable to join room'), - _('A password is required to join this room.'))) - elif errcode == '403': # we are banned - self.dispatch('ERROR', (_('Unable to join room'), - _('You are banned from this room.'))) - elif errcode == '404': # room does not exist - self.dispatch('ERROR', (_('Unable to join room'), - _('Such room does not exist.'))) - elif errcode == '405': - self.dispatch('ERROR', (_('Unable to join room'), - _('Room creation is restricted.'))) - elif errcode == '406': - self.dispatch('ERROR', (_('Unable to join room'), - _('Your registered nickname must be used.'))) - elif errcode == '407': - self.dispatch('ERROR', (_('Unable to join room'), - _('You are not in the members list.'))) - elif errcode == '409': # nick conflict - self.dispatch('ERROR', (_('Unable to join room'), - _('Your desired nickname is in use or registered by another user.'))) + self.dispatch('NOTIFY', (jid_stripped, 'error', errmsg, resource, + prio, keyID)) else: # print in the window the error - self.dispatch('ERROR_ANSWER', ('', prs.getFrom().getStripped(), + self.dispatch('ERROR_ANSWER', ('', jid_stripped, errmsg, errcode)) if not ptype or ptype == 'unavailable': - jid = unicode(prs.getFrom()) - gajim.logger.write('status', status, jid, show) - account = prs.getFrom().getStripped() - resource = prs.getFrom().getResource() - self.dispatch('NOTIFY', ( account, show, status, - resource, prio, keyID, prs.getRole(), - prs.getAffiliation(), prs.getJid(), prs.getReason(), - prs.getActor(), prs.getStatusCode(), prs.getNewNick())) + gajim.logger.write('status', status, jid_stripped, show) + self.dispatch('NOTIFY', (jid_stripped, show, status, resource, prio, + keyID)) # END presenceCB def _disconnectedCB(self): diff --git a/src/gajim.py b/src/gajim.py index 2c6f6d0bc..8275a48a3 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -163,6 +163,7 @@ class Interface: gajim.connections[account].build_http_auth_answer(data[2], answer) def handle_event_error_answer(self, account, array): + #('ERROR_ANSWER', account, (id, jid_from. errmsg, errcode)) id, jid_from, errmsg, errcode = array if unicode(errcode) in ['403', '406'] and id: # show the error dialog @@ -189,7 +190,6 @@ class Interface: (jid_from, file_props)) conn.disconnect_transfer(file_props) return - #('ERROR_ANSWER', account, (id, jid_from. errmsg, errcode)) if jid_from in self.windows[account]['gc']: self.windows[account]['gc'][jid_from].print_conversation( 'Error %s: %s' % (array[2], array[1]), jid_from) @@ -216,8 +216,7 @@ class Interface: self.remote.raise_signal('AccountPresence', (status, account)) def handle_event_notify(self, account, array): - #('NOTIFY', account, (jid, status, message, resource, priority, keyID, - # role, affiliation, real_jid, reason, actor, statusCode, new_nick)) + #('NOTIFY', account, (jid, status, message, resource, priority, keyID)) # if we're here it means contact changed show statuss = ['offline', 'error', 'online', 'chat', 'away', 'xa', 'dnd', 'invisible'] @@ -347,16 +346,6 @@ class Interface: if self.remote and self.remote.is_enabled(): self.remote.raise_signal('ContactAbsence', (account, array)) # stop non active file transfers - - elif self.windows[account]['gc'].has_key(ji): # ji is then room_jid - #it is a groupchat presence - #FIXME: upgrade the chat instances (for pm) - #FIXME: real_jid can be None - self.windows[account]['gc'][ji].chg_contact_status(ji, resource, - array[1], array[2], array[6], array[7], array[8], array[9], - array[10], array[11], array[12], account) - if self.remote and self.remote.is_enabled(): - self.remote.raise_signal('GCPresence', (account, array)) def handle_event_msg(self, account, array): #('MSG', account, (jid, msg, time, encrypted, msg_type, subject, chatstate)) @@ -637,6 +626,22 @@ class Interface: if self.remote and self.remote.is_enabled(): self.remote.raise_signal('OsInfo', (account, array)) + def handle_event_gc_notify(self, account, array): + #('GC_NOTIFY', account, (jid, status, message, resource, + # role, affiliation, jid, reason, actor, statusCode, newNick)) + jid = array[0].split('/')[0] + resource = array[3] + if not resource: + resource = '' + if self.windows[account]['gc'].has_key(jid): # ji is then room_jid + #FIXME: upgrade the chat instances (for pm) + #FIXME: real_jid can be None + self.windows[account]['gc'][jid].chg_contact_status(jid, resource, + array[1], array[2], array[4], array[5], array[6], array[7], + array[8], array[9], array[10], account) + if self.remote and self.remote.is_enabled(): + self.remote.raise_signal('GCPresence', (account, array)) + def handle_event_gc_msg(self, account, array): #('GC_MSG', account, (jid, msg, time)) jids = array[0].split('/', 1) @@ -999,6 +1004,7 @@ class Interface: 'MYVCARD': self.handle_event_myvcard, 'VCARD': self.handle_event_vcard, 'OS_INFO': self.handle_event_os_info, + 'GC_NOTIFY': self.handle_event_gc_notify, 'GC_MSG': self.handle_event_gc_msg, 'GC_SUBJECT': self.handle_event_gc_subject, 'GC_CONFIG': self.handle_event_gc_config,