Commit a155f633 authored by Yann Leboulanger's avatar Yann Leboulanger

support direct invitation (XEP-0249). Fixes #7581

parent ba25709c
......@@ -1383,8 +1383,7 @@ def connection_accepted(self, con, con_type):
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 @@ def connection_accepted(self, con, con_type):
fingerprint=con.Connection.ssl_fingerprint_sha1[i],
certificate=con.Connection.ssl_certificate[i]))
return True
i += 1
if con.Connection.ssl_fingerprint_sha1:
saved_fingerprint = gajim.config.get_per('accounts', self.name,
'ssl_fingerprint_sha1')
......@@ -2846,6 +2844,19 @@ def send_invite(self, room, to, reason='', continue_tag=False):
"""
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})
......
......@@ -1078,10 +1078,15 @@ def generate(self):
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)
......@@ -1195,25 +1200,46 @@ class GcInvitationReceivedEvent(nec.NetworkIncomingEvent):
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 = invite_tag.getTag('invite')
try:
self.jid_from = helpers.parse_jid(item.getAttr('from'))
except helpers.InvalidFormat:
log.warn('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.warn('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
'ignore_unknown_contacts') and not gajim.contacts.get_contacts(
self.conn.name, jid):
return
return True
......
......@@ -484,6 +484,7 @@ def get_contact(self, jid, resource=None):
for c in self._contacts[jid]:
if c.resource == resource:
return c
return self._contacts[jid][0]
def iter_contacts(self):
for jid in self._contacts.keys():
......
......@@ -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 = {}
......
......@@ -3317,7 +3317,7 @@ def on_invite_to_new_room(self, widget, list_, resource=None):
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
"""
......
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