split NOTIFY event into NOTIFY and GC_NOTIFY
This commit is contained in:
parent
619ffb95a8
commit
97b75de35b
|
@ -330,25 +330,22 @@ class Connection:
|
||||||
|
|
||||||
def _presenceCB(self, con, prs):
|
def _presenceCB(self, con, prs):
|
||||||
"""Called when we receive a presence"""
|
"""Called when we receive a presence"""
|
||||||
who = unicode(prs.getFrom())
|
|
||||||
prio = prs.getPriority()
|
|
||||||
if not prio:
|
|
||||||
prio = 0
|
|
||||||
ptype = prs.getType()
|
ptype = prs.getType()
|
||||||
if ptype == 'available': ptype = None
|
if ptype == 'available': ptype = None
|
||||||
gajim.log.debug('PresenceCB: %s' % ptype)
|
gajim.log.debug('PresenceCB: %s' % ptype)
|
||||||
xtags = prs.getTags('x')
|
is_gc = False # is it a GC presence ?
|
||||||
sigTag = None
|
sigTag = None
|
||||||
keyID = ''
|
xtags = prs.getTags('x')
|
||||||
status = prs.getStatus()
|
for x in xtags:
|
||||||
for xtag in xtags:
|
if x.getNamespace() == common.xmpp.NS_MUC_USER:
|
||||||
if xtag.getNamespace() == common.xmpp.NS_SIGNED:
|
is_gc = True
|
||||||
|
if x.getNamespace() == common.xmpp.NS_SIGNED:
|
||||||
sigTag = xtag
|
sigTag = xtag
|
||||||
break
|
jid_from = prs.getFrom()
|
||||||
if sigTag and USE_GPG:
|
who = unicode(jid_from)
|
||||||
#verify
|
jid_stripped = jid_from.getStripped()
|
||||||
sigmsg = sigTag.getData()
|
resource = jid_from.getResource()
|
||||||
keyID = self.gpg.verify(status, sigmsg)
|
status = prs.getStatus()
|
||||||
show = prs.getShow()
|
show = prs.getShow()
|
||||||
if not show in STATUS_LIST:
|
if not show in STATUS_LIST:
|
||||||
show = '' # We ignore unknown show
|
show = '' # We ignore unknown show
|
||||||
|
@ -356,7 +353,57 @@ class Connection:
|
||||||
show = 'online'
|
show = 'online'
|
||||||
elif ptype == 'unavailable':
|
elif ptype == 'unavailable':
|
||||||
show = 'offline'
|
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)
|
gajim.log.debug('subscribe request from %s' % who)
|
||||||
if gajim.config.get('alwaysauth') or who.find("@") <= 0:
|
if gajim.config.get('alwaysauth') or who.find("@") <= 0:
|
||||||
if self.connection:
|
if self.connection:
|
||||||
|
@ -365,65 +412,33 @@ class Connection:
|
||||||
self.to_be_sent.append(p)
|
self.to_be_sent.append(p)
|
||||||
if who.find("@") <= 0:
|
if who.find("@") <= 0:
|
||||||
self.dispatch('NOTIFY',
|
self.dispatch('NOTIFY',
|
||||||
(prs.getFrom().getStripped(), 'offline', 'offline',
|
(jid_stripped, 'offline', 'offline', resource, prio, keyID))
|
||||||
prs.getFrom().getResource(), prio, keyID, None, None,
|
|
||||||
None, None, None, None))
|
|
||||||
else:
|
else:
|
||||||
if not status:
|
if not status:
|
||||||
status = _('I would like to add you to my roster.')
|
status = _('I would like to add you to my roster.')
|
||||||
self.dispatch('SUBSCRIBE', (who, status))
|
self.dispatch('SUBSCRIBE', (who, status))
|
||||||
elif ptype == 'subscribed':
|
elif ptype == 'subscribed':
|
||||||
jid = prs.getFrom()
|
self.dispatch('SUBSCRIBED', (jid_stripped, resource))
|
||||||
self.dispatch('SUBSCRIBED', (jid.getStripped(), jid.getResource()))
|
|
||||||
# BE CAREFUL: no con.updateRosterItem() in a callback
|
# BE CAREFUL: no con.updateRosterItem() in a callback
|
||||||
gajim.log.debug(_('we are now subscribed to %s') % who)
|
gajim.log.debug(_('we are now subscribed to %s') % who)
|
||||||
elif ptype == 'unsubscribe':
|
elif ptype == 'unsubscribe':
|
||||||
gajim.log.debug(_('unsubscribe request from %s') % who)
|
gajim.log.debug(_('unsubscribe request from %s') % who)
|
||||||
elif ptype == 'unsubscribed':
|
elif ptype == 'unsubscribed':
|
||||||
gajim.log.debug(_('we are now unsubscribed from %s') % who)
|
gajim.log.debug(_('we are now unsubscribed from %s') % who)
|
||||||
self.dispatch('UNSUBSCRIBED', prs.getFrom().getStripped())
|
self.dispatch('UNSUBSCRIBED', jid_stripped)
|
||||||
elif ptype == 'error':
|
elif ptype == 'error':
|
||||||
errmsg = prs.getError()
|
errmsg = prs.getError()
|
||||||
errcode = prs.getErrorCode()
|
errcode = prs.getErrorCode()
|
||||||
if errcode == '502': # Internal Timeout:
|
if errcode == '502': # Internal Timeout:
|
||||||
self.dispatch('NOTIFY', (prs.getFrom().getStripped(),
|
self.dispatch('NOTIFY', (jid_stripped, 'error', errmsg, resource,
|
||||||
'error', errmsg, prs.getFrom().getResource(),
|
prio, keyID))
|
||||||
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.')))
|
|
||||||
else: # print in the window the error
|
else: # print in the window the error
|
||||||
self.dispatch('ERROR_ANSWER', ('', prs.getFrom().getStripped(),
|
self.dispatch('ERROR_ANSWER', ('', jid_stripped,
|
||||||
errmsg, errcode))
|
errmsg, errcode))
|
||||||
if not ptype or ptype == 'unavailable':
|
if not ptype or ptype == 'unavailable':
|
||||||
jid = unicode(prs.getFrom())
|
gajim.logger.write('status', status, jid_stripped, show)
|
||||||
gajim.logger.write('status', status, jid, show)
|
self.dispatch('NOTIFY', (jid_stripped, show, status, resource, prio,
|
||||||
account = prs.getFrom().getStripped()
|
keyID))
|
||||||
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()))
|
|
||||||
# END presenceCB
|
# END presenceCB
|
||||||
|
|
||||||
def _disconnectedCB(self):
|
def _disconnectedCB(self):
|
||||||
|
|
32
src/gajim.py
32
src/gajim.py
|
@ -163,6 +163,7 @@ class Interface:
|
||||||
gajim.connections[account].build_http_auth_answer(data[2], answer)
|
gajim.connections[account].build_http_auth_answer(data[2], answer)
|
||||||
|
|
||||||
def handle_event_error_answer(self, account, array):
|
def handle_event_error_answer(self, account, array):
|
||||||
|
#('ERROR_ANSWER', account, (id, jid_from. errmsg, errcode))
|
||||||
id, jid_from, errmsg, errcode = array
|
id, jid_from, errmsg, errcode = array
|
||||||
if unicode(errcode) in ['403', '406'] and id:
|
if unicode(errcode) in ['403', '406'] and id:
|
||||||
# show the error dialog
|
# show the error dialog
|
||||||
|
@ -189,7 +190,6 @@ class Interface:
|
||||||
(jid_from, file_props))
|
(jid_from, file_props))
|
||||||
conn.disconnect_transfer(file_props)
|
conn.disconnect_transfer(file_props)
|
||||||
return
|
return
|
||||||
#('ERROR_ANSWER', account, (id, jid_from. errmsg, errcode))
|
|
||||||
if jid_from in self.windows[account]['gc']:
|
if jid_from in self.windows[account]['gc']:
|
||||||
self.windows[account]['gc'][jid_from].print_conversation(
|
self.windows[account]['gc'][jid_from].print_conversation(
|
||||||
'Error %s: %s' % (array[2], array[1]), jid_from)
|
'Error %s: %s' % (array[2], array[1]), jid_from)
|
||||||
|
@ -216,8 +216,7 @@ class Interface:
|
||||||
self.remote.raise_signal('AccountPresence', (status, account))
|
self.remote.raise_signal('AccountPresence', (status, account))
|
||||||
|
|
||||||
def handle_event_notify(self, account, array):
|
def handle_event_notify(self, account, array):
|
||||||
#('NOTIFY', account, (jid, status, message, resource, priority, keyID,
|
#('NOTIFY', account, (jid, status, message, resource, priority, keyID))
|
||||||
# role, affiliation, real_jid, reason, actor, statusCode, new_nick))
|
|
||||||
# if we're here it means contact changed show
|
# if we're here it means contact changed show
|
||||||
statuss = ['offline', 'error', 'online', 'chat', 'away', 'xa', 'dnd',
|
statuss = ['offline', 'error', 'online', 'chat', 'away', 'xa', 'dnd',
|
||||||
'invisible']
|
'invisible']
|
||||||
|
@ -348,16 +347,6 @@ class Interface:
|
||||||
self.remote.raise_signal('ContactAbsence', (account, array))
|
self.remote.raise_signal('ContactAbsence', (account, array))
|
||||||
# stop non active file transfers
|
# 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):
|
def handle_event_msg(self, account, array):
|
||||||
#('MSG', account, (jid, msg, time, encrypted, msg_type, subject, chatstate))
|
#('MSG', account, (jid, msg, time, encrypted, msg_type, subject, chatstate))
|
||||||
jid = gajim.get_jid_without_resource(array[0])
|
jid = gajim.get_jid_without_resource(array[0])
|
||||||
|
@ -637,6 +626,22 @@ class Interface:
|
||||||
if self.remote and self.remote.is_enabled():
|
if self.remote and self.remote.is_enabled():
|
||||||
self.remote.raise_signal('OsInfo', (account, array))
|
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):
|
def handle_event_gc_msg(self, account, array):
|
||||||
#('GC_MSG', account, (jid, msg, time))
|
#('GC_MSG', account, (jid, msg, time))
|
||||||
jids = array[0].split('/', 1)
|
jids = array[0].split('/', 1)
|
||||||
|
@ -999,6 +1004,7 @@ class Interface:
|
||||||
'MYVCARD': self.handle_event_myvcard,
|
'MYVCARD': self.handle_event_myvcard,
|
||||||
'VCARD': self.handle_event_vcard,
|
'VCARD': self.handle_event_vcard,
|
||||||
'OS_INFO': self.handle_event_os_info,
|
'OS_INFO': self.handle_event_os_info,
|
||||||
|
'GC_NOTIFY': self.handle_event_gc_notify,
|
||||||
'GC_MSG': self.handle_event_gc_msg,
|
'GC_MSG': self.handle_event_gc_msg,
|
||||||
'GC_SUBJECT': self.handle_event_gc_subject,
|
'GC_SUBJECT': self.handle_event_gc_subject,
|
||||||
'GC_CONFIG': self.handle_event_gc_config,
|
'GC_CONFIG': self.handle_event_gc_config,
|
||||||
|
|
Loading…
Reference in New Issue