XEP-0095: API changes
- ``accept`` and ``decline`` are now coroutines.
This commit is contained in:
parent
504067d5a8
commit
f0aec1614f
@ -81,7 +81,7 @@ class XEP_0095(BasePlugin):
|
|||||||
self._methods_order.remove((order, method, plugin_name))
|
self._methods_order.remove((order, method, plugin_name))
|
||||||
self._methods_order.sort()
|
self._methods_order.sort()
|
||||||
|
|
||||||
def _handle_request(self, iq):
|
async def _handle_request(self, iq):
|
||||||
profile = iq['si']['profile']
|
profile = iq['si']['profile']
|
||||||
sid = iq['si']['id']
|
sid = iq['si']['id']
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ class XEP_0095(BasePlugin):
|
|||||||
receiver = iq['to']
|
receiver = iq['to']
|
||||||
sender = iq['from']
|
sender = iq['from']
|
||||||
|
|
||||||
self.api['add_pending'](receiver, sid, sender, {
|
await self.api['add_pending'](receiver, sid, sender, {
|
||||||
'response_id': iq['id'],
|
'response_id': iq['id'],
|
||||||
'method': selected_method,
|
'method': selected_method,
|
||||||
'profile': profile
|
'profile': profile
|
||||||
@ -153,8 +153,13 @@ class XEP_0095(BasePlugin):
|
|||||||
options=methods)
|
options=methods)
|
||||||
return si.send(**iqargs)
|
return si.send(**iqargs)
|
||||||
|
|
||||||
def accept(self, jid, sid, payload=None, ifrom=None, stream_handler=None):
|
async def accept(self, jid, sid, payload=None, ifrom=None, stream_handler=None):
|
||||||
stream = self.api['get_pending'](ifrom, sid, jid)
|
"""Accept a stream initiation.
|
||||||
|
|
||||||
|
.. versionchanged:: 1.8.0
|
||||||
|
This function is now a coroutine.
|
||||||
|
"""
|
||||||
|
stream = await self.api['get_pending'](ifrom, sid, jid)
|
||||||
iq = self.xmpp.Iq()
|
iq = self.xmpp.Iq()
|
||||||
iq['id'] = stream['response_id']
|
iq['id'] = stream['response_id']
|
||||||
iq['to'] = jid
|
iq['to'] = jid
|
||||||
@ -174,16 +179,21 @@ class XEP_0095(BasePlugin):
|
|||||||
method_plugin = self._methods[stream['method']][0]
|
method_plugin = self._methods[stream['method']][0]
|
||||||
self.xmpp[method_plugin].api['preauthorize_sid'](ifrom, sid, jid)
|
self.xmpp[method_plugin].api['preauthorize_sid'](ifrom, sid, jid)
|
||||||
|
|
||||||
self.api['del_pending'](ifrom, sid, jid)
|
await self.api['del_pending'](ifrom, sid, jid)
|
||||||
|
|
||||||
if stream_handler:
|
if stream_handler:
|
||||||
self.xmpp.add_event_handler('stream:%s:%s' % (sid, jid),
|
self.xmpp.add_event_handler('stream:%s:%s' % (sid, jid),
|
||||||
stream_handler,
|
stream_handler,
|
||||||
disposable=True)
|
disposable=True)
|
||||||
return iq.send()
|
return await iq.send()
|
||||||
|
|
||||||
def decline(self, jid, sid, ifrom=None):
|
async def decline(self, jid, sid, ifrom=None):
|
||||||
stream = self.api['get_pending'](ifrom, sid, jid)
|
"""Decline a stream initiation.
|
||||||
|
|
||||||
|
.. versionchanged:: 1.8.0
|
||||||
|
This function is now a coroutine.
|
||||||
|
"""
|
||||||
|
stream = await self.api['get_pending'](ifrom, sid, jid)
|
||||||
if not stream:
|
if not stream:
|
||||||
return
|
return
|
||||||
iq = self.xmpp.Iq()
|
iq = self.xmpp.Iq()
|
||||||
@ -193,8 +203,8 @@ class XEP_0095(BasePlugin):
|
|||||||
iq['type'] = 'error'
|
iq['type'] = 'error'
|
||||||
iq['error']['condition'] = 'forbidden'
|
iq['error']['condition'] = 'forbidden'
|
||||||
iq['error']['text'] = 'Offer declined'
|
iq['error']['text'] = 'Offer declined'
|
||||||
self.api['del_pending'](ifrom, sid, jid)
|
await self.api['del_pending'](ifrom, sid, jid)
|
||||||
return iq.send()
|
return await iq.send()
|
||||||
|
|
||||||
def _add_pending(self, jid, node, ifrom, data):
|
def _add_pending(self, jid, node, ifrom, data):
|
||||||
with self._pending_lock:
|
with self._pending_lock:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user