changeset 207a253a058f in /home/hg/repos/gajim
author: Yann Leboulanger asterix@lagaule.org branches: gtk3 details:http://hg.gajim.org/gajim?cmd=changeset;node=207a253a058f description: support direct invitation (XEP-0249). Fixes #7581
diffstat:
src/common/connection.py | 17 +++++++- src/common/connection_handlers_events.py | 57 +++++++++++++++++++++++-------- src/common/contacts.py | 1 + src/common/gajim.py | 2 +- src/roster_window.py | 2 +- 5 files changed, 59 insertions(+), 20 deletions(-)
diffs (158 lines):
diff -r 4c59a680b4c5 -r 207a253a058f src/common/connection.py --- a/src/common/connection.py Wed Nov 27 18:20:49 2013 +0100 +++ b/src/common/connection.py Thu Nov 28 21:24:17 2013 +0100 @@ -1383,8 +1383,7 @@ errnum = con.Connection.ssl_errnum except AttributeError: errnum = [] # we don't have an errnum - i = 0 - for er in errnum: + for i, er in enumerate(errnum): if er > 0 and str(er) not in gajim.config.get_per('accounts', self.name, 'ignore_ssl_errors').split(): text = _('The authenticity of the %s certificate could be ' @@ -1399,7 +1398,6 @@ fingerprint=con.Connection.ssl_fingerprint_sha1[i], certificate=con.Connection.ssl_certificate[i])) return True - i += 1 if len(con.Connection.ssl_fingerprint_sha1): saved_fingerprint = gajim.config.get_per('accounts', self.name, 'ssl_fingerprint_sha1') @@ -2846,6 +2844,19 @@ """ Send invitation """ + contact = gajim.contacts.get_contact_from_full_jid(self.name, to) + if contact and contact.supports(nbxmpp.NS_CONFERENCE): + # send direct invite + message=nbxmpp.Message(to=to) + attrs = {'jid': room} + if reason: + attrs['reason'] = reason + if continue_tag: + attrs['continue'] = 'true' + c = message.addChild(name='x', attrs=attrs, + namespace=nbxmpp.NS_CONFERENCE) + self.connection.send(message) + return message=nbxmpp.Message(to=room) c = message.addChild(name='x', namespace=nbxmpp.NS_MUC_USER) c = c.addChild(name='invite', attrs={'to': to}) diff -r 4c59a680b4c5 -r 207a253a058f src/common/connection_handlers_events.py --- a/src/common/connection_handlers_events.py Wed Nov 27 18:20:49 2013 +0100 +++ b/src/common/connection_handlers_events.py Thu Nov 28 21:24:17 2013 +0100 @@ -1077,10 +1077,15 @@ self.invite_tag = None self.decline_tag = None if not self.enc_tag: + # Direct invitation? self.invite_tag = self.stanza.getTag('x', - namespace=nbxmpp.NS_MUC_USER) - if self.invite_tag and not self.invite_tag.getTag('invite'): - self.invite_tag = None + namespace=nbxmpp.NS_CONFERENCE) + # Mediated invitation? + if not self.invite_tag: + self.invite_tag = self.stanza.getTag('x', + namespace=nbxmpp.NS_MUC_USER) + if self.invite_tag and not self.invite_tag.getTag('invite'): + self.invite_tag = None
self.decline_tag = self.stanza.getTag('x', namespace=nbxmpp.NS_MUC_USER) @@ -1193,25 +1198,47 @@ base_network_events = []
def generate(self): - self.room_jid = self.msg_obj.fjid + invite_tag = self.msg_obj.invite_tag + if invite_tag.getNamespace() == nbxmpp.NS_CONFERENCE: + # direct invitation + try: + self.room_jid = helpers.parse_jid(invite_tag.getAttr('jid')) + except helpers.InvalidFormat: + log.warn('Invalid JID: %s, ignoring it' % invite_tag.getAttr( + 'jid')) + return + self.jid_from = self.msg_obj.fjid + self.reason = invite_tag.getAttr('reason') + self.password = invite_tag.getAttr('password') + self.is_continued = False + if invite_tag.getAttr('continue') == 'true': + self.is_continued = True + else + self.room_jid = self.msg_obj.fjid + item = self.msg_obj.invite_tag.getTag('invite') + try: + self.jid_from = helpers.parse_jid(item.getAttr('from')) + except helpers.InvalidFormat: + log.warning('Invalid JID: %s, ignoring it' % item.getAttr( + 'from')) + return
- item = self.msg_obj.invite_tag.getTag('invite') - try: - self.jid_from = helpers.parse_jid(item.getAttr('from')) - except helpers.InvalidFormat: - log.warning('Invalid JID: %s, ignoring it' % item.getAttr('from')) + self.reason = item.getTagData('reason') + self.password = invite_tag.getTagData('password') + + self.is_continued = False + if item.getTag('continue'): + self.is_continued = True + + if self.room_jid in gajim.gc_connected[self.conn.name] and \ + gajim.gc_connected[self.conn.name][self.room_jid]: + # We are already in groupchat. Ignore invitation return jid = gajim.get_jid_without_resource(self.jid_from) if gajim.config.get_per('accounts', self.conn.name, 'ignore_unknown_contacts') and not gajim.contacts.get_contacts( self.conn.name, jid): return - self.reason = item.getTagData('reason') - self.password = self.msg_obj.invite_tag.getTagData('password') - - self.is_continued = False - if item.getTag('continue'): - self.is_continued = True
return True
diff -r 4c59a680b4c5 -r 207a253a058f src/common/contacts.py --- a/src/common/contacts.py Wed Nov 27 18:20:49 2013 +0100 +++ b/src/common/contacts.py Thu Nov 28 21:24:17 2013 +0100 @@ -488,6 +488,7 @@ for c in self._contacts[jid]: if c.resource == resource: return c + return self._contacts[jid][0]
def iter_contacts(self): for jid in list(self._contacts.keys()): diff -r 4c59a680b4c5 -r 207a253a058f src/common/gajim.py --- a/src/common/gajim.py Wed Nov 27 18:20:49 2013 +0100 +++ b/src/common/gajim.py Thu Nov 28 21:24:17 2013 +0100 @@ -212,7 +212,7 @@ nbxmpp.NS_SSN, nbxmpp.NS_MOOD, nbxmpp.NS_ACTIVITY, nbxmpp.NS_NICK, nbxmpp.NS_ROSTERX, nbxmpp.NS_SECLABEL, nbxmpp.NS_HASHES, nbxmpp.NS_HASHES_MD5, nbxmpp.NS_HASHES_SHA1, nbxmpp.NS_HASHES_SHA256, - nbxmpp.NS_HASHES_SHA512, nbxmpp.NS_CORRECT] + nbxmpp.NS_HASHES_SHA512, nbxmpp.NS_CORRECT, nbxmpp.NS_CONFERENCE]
# Optional features gajim supports per account gajim_optional_features = {} diff -r 4c59a680b4c5 -r 207a253a058f src/roster_window.py --- a/src/roster_window.py Wed Nov 27 18:20:49 2013 +0100 +++ b/src/roster_window.py Thu Nov 28 21:24:17 2013 +0100 @@ -3335,7 +3335,7 @@ break
def on_invite_to_room(self, widget, list_, room_jid, room_account, - resource=None): + resource=None): """ Resource parameter MUST NOT be used if more than one contact in list """