Mercurial > libervia-desktop-kivy
comparison cagou/plugins/plugin_wid_chat.py @ 443:61322ff8090b
chat: fixed handling of attachments without URL
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 07 Mar 2020 00:05:50 +0100 |
parents | c2b63d3bb088 |
children | ffdf2390ea56 |
comparison
equal
deleted
inserted
replaced
442:c2b63d3bb088 | 443:61322ff8090b |
---|---|
162 | 162 |
163 def on_kv_post(self, __): | 163 def on_kv_post(self, __): |
164 attachments = self.attachments | 164 attachments = self.attachments |
165 self.clear_widgets() | 165 self.clear_widgets() |
166 for idx, attachment in enumerate(attachments): | 166 for idx, attachment in enumerate(attachments): |
167 url = attachment['url'] | 167 try: |
168 if url.startswith("aesgcm:"): | 168 url = attachment['url'] |
169 del attachment['url'] | 169 except KeyError: |
170 # if the file is encrypted, we need to download it for decryption | 170 url = None |
171 to_download = True | 171 to_download = False |
172 else: | 172 else: |
173 to_download = False | 173 if url.startswith("aesgcm:"): |
174 del attachment['url'] | |
175 # if the file is encrypted, we need to download it for decryption | |
176 to_download = True | |
177 else: | |
178 to_download = False | |
174 | 179 |
175 if idx < 3 or len(attachments) <= 4: | 180 if idx < 3 or len(attachments) <= 4: |
176 if ((self.mess_data.own_mess | 181 if ((self.mess_data.own_mess |
177 or self.chat.contact_list.isInRoster(self.mess_data.from_jid))): | 182 or self.chat.contact_list.isInRoster(self.mess_data.from_jid))): |
178 wid = AsyncImage(size_hint=(1, 1), source="data/images/image-loading.gif") | 183 wid = AsyncImage(size_hint=(1, 1), source="data/images/image-loading.gif") |
182 G.host.bridge.imageGeneratePreview( | 187 G.host.bridge.imageGeneratePreview( |
183 attachment['path'], | 188 attachment['path'], |
184 self.chat.profile, | 189 self.chat.profile, |
185 callback=partial(self._setPreview, attachment, wid), | 190 callback=partial(self._setPreview, attachment, wid), |
186 ) | 191 ) |
192 elif url is None: | |
193 log.warning(f"Can't find any source for {attachment}") | |
187 else: | 194 else: |
188 # we'll download the file, the preview will then be generated | 195 # we'll download the file, the preview will then be generated |
189 to_download = True | 196 to_download = True |
190 else: | 197 else: |
191 # we don't download automatically the image if the contact is not | 198 # we don't download automatically the image if the contact is not |
344 attachment = image_attachments[0] | 351 attachment = image_attachments[0] |
345 # to avoid leaking IP address, we only display image if the contact is in | 352 # to avoid leaking IP address, we only display image if the contact is in |
346 # roster | 353 # roster |
347 if ((self.mess_data.own_mess | 354 if ((self.mess_data.own_mess |
348 or self.chat.contact_list.isInRoster(self.mess_data.from_jid))): | 355 or self.chat.contact_list.isInRoster(self.mess_data.from_jid))): |
349 url = urlparse(attachment['url']) | 356 try: |
350 if url.scheme == "aesgcm": | 357 url = urlparse(attachment['url']) |
351 # we remove the URL now, we'll replace it by | 358 except KeyError: |
352 # the local decrypted version | |
353 del attachment['url'] | |
354 item = AttachmentImageItem(data=attachment) | 359 item = AttachmentImageItem(data=attachment) |
355 G.host.downloadURL( | |
356 url.geturl(), | |
357 callback=partial(self._setPath, item.data), | |
358 dest=C.FILE_DEST_CACHE, | |
359 profile=self.chat.profile, | |
360 ) | |
361 else: | 360 else: |
362 item = AttachmentImageItem(data=attachment) | 361 if url.scheme == "aesgcm": |
362 # we remove the URL now, we'll replace it by | |
363 # the local decrypted version | |
364 del attachment['url'] | |
365 item = AttachmentImageItem(data=attachment) | |
366 G.host.downloadURL( | |
367 url.geturl(), | |
368 callback=partial(self._setPath, item.data), | |
369 dest=C.FILE_DEST_CACHE, | |
370 profile=self.chat.profile, | |
371 ) | |
372 else: | |
373 item = AttachmentImageItem(data=attachment) | |
363 else: | 374 else: |
364 item = AttachmentItem(data=attachment) | 375 item = AttachmentItem(data=attachment) |
365 | 376 |
366 layout.add_widget(item) | 377 layout.add_widget(item) |
367 | 378 |