comparison sat_frontends/jp/cmd_message.py @ 4023:78b5f356900c

component AP gateway: handle attachments
author Goffi <goffi@goffi.org>
date Thu, 23 Mar 2023 15:42:21 +0100
parents 900bf04d87c8
children 524856bd7b19
comparison
equal deleted inserted replaced
4022:cdb7de398c85 4023:78b5f356900c
143 else: 143 else:
144 msg = {} 144 msg = {}
145 to_send.append(msg) 145 to_send.append(msg)
146 146
147 if self.args.attachments: 147 if self.args.attachments:
148 attachments = extra[C.MESS_KEY_ATTACHMENTS] = [] 148 attachments = extra[C.KEY_ATTACHMENTS] = []
149 for attachment in self.args.attachments: 149 for attachment in self.args.attachments:
150 try: 150 try:
151 file_path = str(Path(attachment).resolve(strict=True)) 151 file_path = str(Path(attachment).resolve(strict=True))
152 except FileNotFoundError: 152 except FileNotFoundError:
153 self.disp("file {attachment} doesn't exists, ignoring", error=True) 153 self.disp("file {attachment} doesn't exists, ignoring", error=True)
154 else: 154 else:
155 attachments.append({"path": file_path}) 155 attachments.append({"path": file_path})
156 156
157 for idx, msg in enumerate(to_send): 157 for idx, msg in enumerate(to_send):
158 if idx > 0 and C.MESS_KEY_ATTACHMENTS in extra: 158 if idx > 0 and C.KEY_ATTACHMENTS in extra:
159 # if we send several messages, we only want to send attachments with the 159 # if we send several messages, we only want to send attachments with the
160 # first one 160 # first one
161 del extra[C.MESS_KEY_ATTACHMENTS] 161 del extra[C.KEY_ATTACHMENTS]
162 try: 162 try:
163 await self.host.bridge.messageSend( 163 await self.host.bridge.messageSend(
164 dest_jid, 164 dest_jid,
165 msg, 165 msg,
166 subject, 166 subject,