summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime “pep” Buquet <pep@bouah.net>2022-03-18 19:54:36 +0100
committerMaxime “pep” Buquet <pep@bouah.net>2022-03-23 16:44:27 +0100
commit3c7961dff769dc2c7d200fae9e89f3a35345c37f (patch)
tree94e7e4931d42258af42e6a5a04447f0e391e3e85
parent5caf2587f6a7654b05c1a9a848ea0c3e4cdd9780 (diff)
downloadpoezio-3c7961dff769dc2c7d200fae9e89f3a35345c37f.tar.gz
poezio-3c7961dff769dc2c7d200fae9e89f3a35345c37f.tar.bz2
poezio-3c7961dff769dc2c7d200fae9e89f3a35345c37f.tar.xz
poezio-3c7961dff769dc2c7d200fae9e89f3a35345c37f.zip
plugins/upload: send encrypted if e2ee enabled on tab
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
-rw-r--r--plugins/upload.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/plugins/upload.py b/plugins/upload.py
index fbf41034..4ca61495 100644
--- a/plugins/upload.py
+++ b/plugins/upload.py
@@ -40,6 +40,12 @@ class Plugin(BasePlugin):
if not self.core.xmpp['xep_0363']:
raise Exception('slixmpp XEP-0363 plugin failed to load')
+ if not self.core.xmpp['xep_0454']:
+ self.api.information(
+ 'slixmpp XEP-0454 plugin failed to load. '
+ 'Will not be able to encrypt uploaded files.',
+ 'Warning',
+ )
for _class in (tabs.PrivateTab, tabs.StaticConversationTab, tabs.DynamicConversationTab, tabs.MucTab):
self.api.add_tab_command(
_class,
@@ -50,9 +56,12 @@ class Plugin(BasePlugin):
short='Upload a file',
completion=self.completion_filename)
- async def upload(self, filename) -> Optional[str]:
+ async def upload(self, filename, encrypted=False) -> Optional[str]:
try:
- url = await self.core.xmpp['xep_0363'].upload_file(filename)
+ upload_file = self.core.xmpp['xep_0363'].upload_file
+ if encrypted:
+ upload_file = self.core.xmpp['xep_0454'].upload_file
+ url = await upload_file(filename)
except UploadServiceNotFound:
self.api.information('HTTP Upload service not found.', 'Error')
return None
@@ -66,8 +75,8 @@ class Plugin(BasePlugin):
return None
return url
- async def send_upload(self, filename, tab):
- url = await self.upload(filename)
+ async def send_upload(self, filename, tab, encrypted=False):
+ url = await self.upload(filename, encrypted)
if url is not None:
self.embed.embed_image_url(url, tab)
@@ -79,7 +88,8 @@ class Plugin(BasePlugin):
filename, = args
filename = expanduser(filename)
tab = self.api.current_tab()
- asyncio.create_task(self.send_upload(filename, tab))
+ encrypted = self.core.xmpp['xep_0454'] and tab.e2e_encrypted is not None
+ asyncio.create_task(self.send_upload(filename, tab, encrypted))
@staticmethod
def completion_filename(the_input):