comparison sat/plugins/plugin_xep_0448.py @ 4023:78b5f356900c

component AP gateway: handle attachments
author Goffi <goffi@goffi.org>
date Thu, 23 Mar 2023 15:42:21 +0100
parents e345d93fb6e5
children 524856bd7b19
comparison
equal deleted inserted replaced
4022:cdb7de398c85 4023:78b5f356900c
261 261
262 async def attach(self, client, data): 262 async def attach(self, client, data):
263 # XXX: for now, XEP-0447/XEP-0448 only allow to send one file per <message/>, thus 263 # XXX: for now, XEP-0447/XEP-0448 only allow to send one file per <message/>, thus
264 # we need to send each file in a separate message, in the same way as for 264 # we need to send each file in a separate message, in the same way as for
265 # plugin_sec_aesgcm. 265 # plugin_sec_aesgcm.
266 attachments = data["extra"][C.MESS_KEY_ATTACHMENTS] 266 attachments = data["extra"][C.KEY_ATTACHMENTS]
267 if not data['message'] or data['message'] == {'': ''}: 267 if not data['message'] or data['message'] == {'': ''}:
268 extra_attachments = attachments[1:] 268 extra_attachments = attachments[1:]
269 del attachments[1:] 269 del attachments[1:]
270 else: 270 else:
271 # we have a message, we must send first attachment separately 271 # we have a message, we must send first attachment separately
272 extra_attachments = attachments[:] 272 extra_attachments = attachments[:]
273 attachments.clear() 273 attachments.clear()
274 del data["extra"][C.MESS_KEY_ATTACHMENTS] 274 del data["extra"][C.KEY_ATTACHMENTS]
275 275
276 if attachments: 276 if attachments:
277 if len(attachments) > 1: 277 if len(attachments) > 1:
278 raise exceptions.InternalError( 278 raise exceptions.InternalError(
279 "There should not be more that one attachment at this point" 279 "There should not be more that one attachment at this point"
317 await client.sendMessage( 317 await client.sendMessage(
318 to_jid=data['to'], 318 to_jid=data['to'],
319 message={'': ''}, 319 message={'': ''},
320 subject=data['subject'], 320 subject=data['subject'],
321 mess_type=data['type'], 321 mess_type=data['type'],
322 extra={C.MESS_KEY_ATTACHMENTS: [attachment]}, 322 extra={C.KEY_ATTACHMENTS: [attachment]},
323 ) 323 )
324 324
325 if ((not data['extra'] 325 if ((not data['extra']
326 and (not data['message'] or data['message'] == {'': ''}) 326 and (not data['message'] or data['message'] == {'': ''})
327 and not data['subject'])): 327 and not data['subject'])):