component AP gateway: handle attachments
This commit is contained in:
parent
072f0cc723
commit
c3f97ec712
1 changed files with 168 additions and 97 deletions
|
|
@ -821,7 +821,7 @@ class SatXMPPEntity(core_types.SatXMPPEntity):
|
|||
"""Return True if a message contain payload to show in frontends"""
|
||||
return (
|
||||
mess_data["message"] or mess_data["subject"]
|
||||
or mess_data["extra"].get(C.MESS_KEY_ATTACHMENTS)
|
||||
or mess_data["extra"].get(C.KEY_ATTACHMENTS)
|
||||
or mess_data["type"] == C.MESS_TYPE_INFO
|
||||
)
|
||||
|
||||
|
|
@ -1361,16 +1361,16 @@ class SatMessageProtocol(xmppim.MessageProtocol):
|
|||
|
||||
def completeAttachments(self, data):
|
||||
"""Complete missing metadata of attachments"""
|
||||
for attachment in data['extra'].get(C.MESS_KEY_ATTACHMENTS, []):
|
||||
for attachment in data['extra'].get(C.KEY_ATTACHMENTS, []):
|
||||
if "name" not in attachment and "url" in attachment:
|
||||
name = (Path(unquote(urlparse(attachment['url']).path)).name
|
||||
or C.FILE_DEFAULT_NAME)
|
||||
attachment["name"] = name
|
||||
if ((C.MESS_KEY_ATTACHMENTS_MEDIA_TYPE not in attachment
|
||||
if ((C.KEY_ATTACHMENTS_MEDIA_TYPE not in attachment
|
||||
and "name" in attachment)):
|
||||
media_type = mimetypes.guess_type(attachment['name'], strict=False)[0]
|
||||
if media_type:
|
||||
attachment[C.MESS_KEY_ATTACHMENTS_MEDIA_TYPE] = media_type
|
||||
attachment[C.KEY_ATTACHMENTS_MEDIA_TYPE] = media_type
|
||||
|
||||
return data
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue