Mercurial > libervia-backend
comparison sat/core/xmpp.py @ 4023:78b5f356900c
component AP gateway: handle attachments
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 23 Mar 2023 15:42:21 +0100 |
parents | 412b99c29d83 |
children | 524856bd7b19 |
comparison
equal
deleted
inserted
replaced
4022:cdb7de398c85 | 4023:78b5f356900c |
---|---|
819 | 819 |
820 def isMessagePrintable(self, mess_data): | 820 def isMessagePrintable(self, mess_data): |
821 """Return True if a message contain payload to show in frontends""" | 821 """Return True if a message contain payload to show in frontends""" |
822 return ( | 822 return ( |
823 mess_data["message"] or mess_data["subject"] | 823 mess_data["message"] or mess_data["subject"] |
824 or mess_data["extra"].get(C.MESS_KEY_ATTACHMENTS) | 824 or mess_data["extra"].get(C.KEY_ATTACHMENTS) |
825 or mess_data["type"] == C.MESS_TYPE_INFO | 825 or mess_data["type"] == C.MESS_TYPE_INFO |
826 ) | 826 ) |
827 | 827 |
828 async def messageAddToHistory(self, data): | 828 async def messageAddToHistory(self, data): |
829 """Store message into database (for local history) | 829 """Store message into database (for local history) |
1359 | 1359 |
1360 d.addCallback(self._onMessageStartWorkflow, client, message_elt, post_treat) | 1360 d.addCallback(self._onMessageStartWorkflow, client, message_elt, post_treat) |
1361 | 1361 |
1362 def completeAttachments(self, data): | 1362 def completeAttachments(self, data): |
1363 """Complete missing metadata of attachments""" | 1363 """Complete missing metadata of attachments""" |
1364 for attachment in data['extra'].get(C.MESS_KEY_ATTACHMENTS, []): | 1364 for attachment in data['extra'].get(C.KEY_ATTACHMENTS, []): |
1365 if "name" not in attachment and "url" in attachment: | 1365 if "name" not in attachment and "url" in attachment: |
1366 name = (Path(unquote(urlparse(attachment['url']).path)).name | 1366 name = (Path(unquote(urlparse(attachment['url']).path)).name |
1367 or C.FILE_DEFAULT_NAME) | 1367 or C.FILE_DEFAULT_NAME) |
1368 attachment["name"] = name | 1368 attachment["name"] = name |
1369 if ((C.MESS_KEY_ATTACHMENTS_MEDIA_TYPE not in attachment | 1369 if ((C.KEY_ATTACHMENTS_MEDIA_TYPE not in attachment |
1370 and "name" in attachment)): | 1370 and "name" in attachment)): |
1371 media_type = mimetypes.guess_type(attachment['name'], strict=False)[0] | 1371 media_type = mimetypes.guess_type(attachment['name'], strict=False)[0] |
1372 if media_type: | 1372 if media_type: |
1373 attachment[C.MESS_KEY_ATTACHMENTS_MEDIA_TYPE] = media_type | 1373 attachment[C.KEY_ATTACHMENTS_MEDIA_TYPE] = media_type |
1374 | 1374 |
1375 return data | 1375 return data |
1376 | 1376 |
1377 def skipEmptyMessage(self, data): | 1377 def skipEmptyMessage(self, data): |
1378 if not data["message"] and not data["extra"] and not data["subject"]: | 1378 if not data["message"] and not data["extra"] and not data["subject"]: |