diff options
-rw-r--r-- | slixmpp/plugins/xep_0030/disco.py | 27 | ||||
-rw-r--r-- | slixmpp/plugins/xep_0363/http_upload.py | 14 |
2 files changed, 30 insertions, 11 deletions
diff --git a/slixmpp/plugins/xep_0030/disco.py b/slixmpp/plugins/xep_0030/disco.py index b1c261a9..daeee879 100644 --- a/slixmpp/plugins/xep_0030/disco.py +++ b/slixmpp/plugins/xep_0030/disco.py @@ -124,6 +124,8 @@ class XEP_0030(BasePlugin): for op in self._disco_ops: self.api.register(getattr(self.static, op), op, default=True) + self.domain_infos = {} + def session_bind(self, jid): self.add_feature('http://jabber.org/protocol/disco#info') @@ -296,6 +298,31 @@ class XEP_0030(BasePlugin): 'cached': cached} return self.api['has_identity'](jid, node, ifrom, data) + async def find_identities(category, type_, domain=None, timeout=None): + if domain is None: + domain = self.xmpp.boundjid.domain + + if domain not in self.domain_infos: + infos = [self.xmpp['xep_0030'].get_info( + domain, timeout=timeout)] + iq_items = await self.xmpp['xep_0030'].get_items( + domain, timeout=timeout) + items = iq_items['disco_items']['items'] + infos += [ + self.xmpp['xep_0030'].get_info(item[0], timeout=timeout) + for item in items] + info_futures, _ = await asyncio.wait(infos, timeout=timeout) + + self.domain_infos[domain] = [ + future.result() for future in info_futures] + + results = [] + for info in self.domain_infos[domain]: + for identity in info['disco_info']['identities']: + if identity[0] == category and identity[1] == type_: + results.append(info) + return results + @future_wrapper def get_info(self, jid=None, node=None, local=None, cached=None, **kwargs): diff --git a/slixmpp/plugins/xep_0363/http_upload.py b/slixmpp/plugins/xep_0363/http_upload.py index 073b3fc0..3c0f2b3e 100644 --- a/slixmpp/plugins/xep_0363/http_upload.py +++ b/slixmpp/plugins/xep_0363/http_upload.py @@ -69,17 +69,9 @@ class XEP_0363(BasePlugin): self.xmpp.event('http_upload_request', iq) async def find_upload_service(self, timeout=None): - infos = [self.xmpp['xep_0030'].get_info(self.xmpp.boundjid.domain)] - iq_items = await self.xmpp['xep_0030'].get_items( - self.xmpp.boundjid.domain, timeout=timeout) - items = iq_items['disco_items']['items'] - infos += [self.xmpp['xep_0030'].get_info(item[0]) for item in items] - info_futures, _ = await asyncio.wait(infos, timeout=timeout) - for future in info_futures: - info = future.result() - for identity in info['disco_info']['identities']: - if identity[0] == 'store' and identity[1] == 'file': - return info + results = await self.xmpp['xep_0030'].find_identities('store', 'file') + if results: + return results[0] def request_slot(self, jid, filename, size, content_type=None, ifrom=None, timeout=None, callback=None, timeout_callback=None): |