component AP gateway: handle attachments

This commit is contained in:
Goffi 2023-03-23 15:42:21 +01:00
commit c3f97ec712
2 changed files with 168 additions and 97 deletions

View file

@ -145,7 +145,7 @@ class Send(base.CommandBase):
to_send.append(msg)
if self.args.attachments:
attachments = extra[C.MESS_KEY_ATTACHMENTS] = []
attachments = extra[C.KEY_ATTACHMENTS] = []
for attachment in self.args.attachments:
try:
file_path = str(Path(attachment).resolve(strict=True))
@ -155,10 +155,10 @@ class Send(base.CommandBase):
attachments.append({"path": file_path})
for idx, msg in enumerate(to_send):
if idx > 0 and C.MESS_KEY_ATTACHMENTS in extra:
if idx > 0 and C.KEY_ATTACHMENTS in extra:
# if we send several messages, we only want to send attachments with the
# first one
del extra[C.MESS_KEY_ATTACHMENTS]
del extra[C.KEY_ATTACHMENTS]
try:
await self.host.bridge.messageSend(
dest_jid,

View file

@ -223,7 +223,7 @@ class Message:
@property
def attachments(self):
return self.extra.get(C.MESS_KEY_ATTACHMENTS)
return self.extra.get(C.KEY_ATTACHMENTS)
class MessageWidget:
@ -733,7 +733,7 @@ class QuickChat(quick_widgets.QuickWidget):
)
return
if ((not msg and not subject and not extra[C.MESS_KEY_ATTACHMENTS]
if ((not msg and not subject and not extra[C.KEY_ATTACHMENTS]
and type_ != C.MESS_TYPE_INFO)):
log.warning("Received an empty message for uid {}".format(uid))
return