# HG changeset patch # User Goffi # Date 1583535950 -3600 # Node ID 61322ff8090b65a5a3cdec80a3555cf51ea5a8dc # Parent c2b63d3bb088e1c5d4acf11597d888a6517798d8 chat: fixed handling of attachments without URL diff -r c2b63d3bb088 -r 61322ff8090b cagou/plugins/plugin_wid_chat.py --- a/cagou/plugins/plugin_wid_chat.py Sat Mar 07 00:05:50 2020 +0100 +++ b/cagou/plugins/plugin_wid_chat.py Sat Mar 07 00:05:50 2020 +0100 @@ -164,13 +164,18 @@ attachments = self.attachments self.clear_widgets() for idx, attachment in enumerate(attachments): - url = attachment['url'] - if url.startswith("aesgcm:"): - del attachment['url'] - # if the file is encrypted, we need to download it for decryption - to_download = True + try: + url = attachment['url'] + except KeyError: + url = None + to_download = False else: - to_download = False + if url.startswith("aesgcm:"): + del attachment['url'] + # if the file is encrypted, we need to download it for decryption + to_download = True + else: + to_download = False if idx < 3 or len(attachments) <= 4: if ((self.mess_data.own_mess @@ -184,6 +189,8 @@ self.chat.profile, callback=partial(self._setPreview, attachment, wid), ) + elif url is None: + log.warning(f"Can't find any source for {attachment}") else: # we'll download the file, the preview will then be generated to_download = True @@ -346,20 +353,24 @@ # roster if ((self.mess_data.own_mess or self.chat.contact_list.isInRoster(self.mess_data.from_jid))): - url = urlparse(attachment['url']) - if url.scheme == "aesgcm": - # we remove the URL now, we'll replace it by - # the local decrypted version - del attachment['url'] + try: + url = urlparse(attachment['url']) + except KeyError: item = AttachmentImageItem(data=attachment) - G.host.downloadURL( - url.geturl(), - callback=partial(self._setPath, item.data), - dest=C.FILE_DEST_CACHE, - profile=self.chat.profile, - ) else: - item = AttachmentImageItem(data=attachment) + if url.scheme == "aesgcm": + # we remove the URL now, we'll replace it by + # the local decrypted version + del attachment['url'] + item = AttachmentImageItem(data=attachment) + G.host.downloadURL( + url.geturl(), + callback=partial(self._setPath, item.data), + dest=C.FILE_DEST_CACHE, + profile=self.chat.profile, + ) + else: + item = AttachmentImageItem(data=attachment) else: item = AttachmentItem(data=attachment)