diff --git a/src/headless/plugins/muc/muc.js b/src/headless/plugins/muc/muc.js index 47af6ff7f..883c00719 100644 --- a/src/headless/plugins/muc/muc.js +++ b/src/headless/plugins/muc/muc.js @@ -1928,7 +1928,14 @@ const ChatRoomMixin = { * @returns {Promise} */ async shouldShowErrorMessage (attrs) { - if (attrs['error_condition'] === 'not-acceptable' && (await this.rejoinIfNecessary())) { + if (attrs.error_type === 'Decryption') { + if (attrs.error_message === "Message key not found. The counter was repeated or the key was not filled.") { + // OMEMO message which we already decrypted before + return false; + } else if ( attrs.error_condition === 'not-encrypted-for-this-device') { + return false; + } + } else if (attrs.error_condition === 'not-acceptable' && (await this.rejoinIfNecessary())) { return false; } return _converse.ChatBox.prototype.shouldShowErrorMessage.call(this, attrs); @@ -2198,7 +2205,10 @@ const ChatRoomMixin = { if (u.isErrorObject(attrs)) { attrs.stanza && log.error(attrs.stanza); return log.error(attrs.message); + } else if (attrs.type === 'error' && !(await this.shouldShowErrorMessage(attrs))) { + return; } + const message = this.getDuplicateMessage(attrs); if (message) { (message.get('type') === 'groupchat') && this.updateMessage(message, attrs); diff --git a/src/plugins/omemo/utils.js b/src/plugins/omemo/utils.js index afd94e074..3a4c8fde2 100644 --- a/src/plugins/omemo/utils.js +++ b/src/plugins/omemo/utils.js @@ -204,12 +204,22 @@ export function handleEncryptedFiles (richtext) { } export function parseEncryptedMessage (stanza, attrs) { - if (attrs.is_encrypted && attrs.encrypted.key) { - // https://xmpp.org/extensions/xep-0384.html#usecases-receiving - if (attrs.encrypted.prekey === true) { - return decryptPrekeyWhisperMessage(attrs); + if (attrs.is_encrypted) { + if (!attrs.encrypted.key) { + return Object.assign(attrs, { + 'error_condition': 'not-encrypted-for-this-device', + 'error_type': 'Decryption', + 'is_ephemeral': true, + 'is_error': true, + 'type': 'error' + }); } else { - return decryptWhisperMessage(attrs); + // https://xmpp.org/extensions/xep-0384.html#usecases-receiving + if (attrs.encrypted.prekey === true) { + return decryptPrekeyWhisperMessage(attrs); + } else { + return decryptWhisperMessage(attrs); + } } } else { return attrs; @@ -287,18 +297,16 @@ async function handleDecryptedWhisperMessage (attrs, key_and_tag) { } function getDecryptionErrorAttributes (e) { - if (api.settings.get('loglevel') === 'debug') { - return { - 'error_text': - __('Sorry, could not decrypt a received OMEMO message due to an error.') + ` ${e.name} ${e.message}`, - 'error_type': 'Decryption', - 'is_ephemeral': true, - 'is_error': true, - 'type': 'error' - }; - } else { - return {}; - } + return { + 'error_text': + __('Sorry, could not decrypt a received OMEMO message due to an error.') + ` ${e.name} ${e.message}`, + 'error_condition': e.name, + 'error_message': e.message, + 'error_type': 'Decryption', + 'is_ephemeral': true, + 'is_error': true, + 'type': 'error' + }; } async function decryptPrekeyWhisperMessage (attrs) {