diff options
Diffstat (limited to 'plugins/vcard.py')
-rw-r--r-- | plugins/vcard.py | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/plugins/vcard.py b/plugins/vcard.py index 643dd569..b0c8e396 100644 --- a/plugins/vcard.py +++ b/plugins/vcard.py @@ -25,15 +25,16 @@ Command vcard from the current interlocutor, and in the contact list to do it on the currently selected contact. """ +import asyncio from poezio.decorators import command_args_parser from poezio.plugin import BasePlugin from poezio.roster import roster -from poezio.common import safeJID from poezio.contact import Contact, Resource from poezio.core.structs import Completion from poezio import tabs from slixmpp.jid import JID, InvalidJID +from slixmpp.exceptions import IqTimeout class Plugin(BasePlugin): @@ -61,7 +62,7 @@ class Plugin(BasePlugin): help='Send an XMPP vcard request to jid (see XEP-0054).', short='Send a vcard request.', completion=self.completion_vcard) - for _class in (tabs.PrivateTab, tabs.ConversationTab): + for _class in (tabs.PrivateTab, tabs.DynamicConversationTab, tabs.StaticConversationTab): self.api.add_tab_command( _class, 'vcard', @@ -240,19 +241,18 @@ class Plugin(BasePlugin): on_cancel = lambda form: self.core.close_tab() self.core.open_new_form(form, on_cancel, on_validate) - def _get_vcard(self, jid): + async def _get_vcard(self, jid): '''Send an iq to ask the vCard.''' - - def timeout_cb(iq): + try: + vcard = await self.core.xmpp.plugin['xep_0054'].get_vcard( + jid=jid, + timeout=30, + ) + self._handle_vcard(vcard) + except IqTimeout: self.api.information('Timeout while retrieving vCard for %s' % jid, 'Error') - return - self.core.xmpp.plugin['xep_0054'].get_vcard( - jid=jid, - timeout=30, - callback=self._handle_vcard, - timeout_callback=timeout_cb) @command_args_parser.raw def command_vcard(self, arg): @@ -266,14 +266,16 @@ class Plugin(BasePlugin): self.api.information('Invalid JID: %s' % arg, 'Error') return - self._get_vcard(jid) + asyncio.create_task( + self._get_vcard(jid) + ) @command_args_parser.raw def command_private_vcard(self, arg): if arg: self.command_vcard(arg) return - self.command_vcard(self.api.current_tab().name) + self.command_vcard(self.api.current_tab().jid.full) @command_args_parser.raw def command_muc_vcard(self, arg): @@ -282,11 +284,15 @@ class Plugin(BasePlugin): return user = self.api.current_tab().get_user_by_name(arg) if user: - # No need to use safeJID here, we already know the JID is valid. - jid = JID(self.api.current_tab().name + '/' + user.nick) + jid = self.api.current_tab().jid.bare + '/' + user.nick else: - jid = safeJID(arg) - self._get_vcard(jid) + try: + jid = JID(arg) + except InvalidJID: + return self.api.information('Invalid JID: %s' % arg, 'Error') + asyncio.create_task( + self._get_vcard(jid) + ) @command_args_parser.raw def command_roster_vcard(self, arg): @@ -295,9 +301,13 @@ class Plugin(BasePlugin): return current = self.api.current_tab().selected_row if isinstance(current, Resource): - self._get_vcard(JID(current.jid).bare) + asyncio.create_task( + self._get_vcard(JID(current.jid).bare) + ) elif isinstance(current, Contact): - self._get_vcard(current.bare_jid) + asyncio.create_task( + self._get_vcard(current.bare_jid) + ) def completion_vcard(self, the_input): contacts = [contact.bare_jid for contact in roster.get_contacts()] |