Don't show unnecessary errors for undecryptable OMEMO messages
As mentioned in the XEP, don't show error messages for OMEMO messages that can't be decrypted because they were already decrypted before or because they weren't encrypted for this device.
This commit is contained in:
parent
d48d748e30
commit
07b2425ff9
@ -1928,7 +1928,14 @@ const ChatRoomMixin = {
|
|||||||
* @returns {Promise<boolean>}
|
* @returns {Promise<boolean>}
|
||||||
*/
|
*/
|
||||||
async shouldShowErrorMessage (attrs) {
|
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 false;
|
||||||
}
|
}
|
||||||
return _converse.ChatBox.prototype.shouldShowErrorMessage.call(this, attrs);
|
return _converse.ChatBox.prototype.shouldShowErrorMessage.call(this, attrs);
|
||||||
@ -2198,7 +2205,10 @@ const ChatRoomMixin = {
|
|||||||
if (u.isErrorObject(attrs)) {
|
if (u.isErrorObject(attrs)) {
|
||||||
attrs.stanza && log.error(attrs.stanza);
|
attrs.stanza && log.error(attrs.stanza);
|
||||||
return log.error(attrs.message);
|
return log.error(attrs.message);
|
||||||
|
} else if (attrs.type === 'error' && !(await this.shouldShowErrorMessage(attrs))) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const message = this.getDuplicateMessage(attrs);
|
const message = this.getDuplicateMessage(attrs);
|
||||||
if (message) {
|
if (message) {
|
||||||
(message.get('type') === 'groupchat') && this.updateMessage(message, attrs);
|
(message.get('type') === 'groupchat') && this.updateMessage(message, attrs);
|
||||||
|
@ -204,12 +204,22 @@ export function handleEncryptedFiles (richtext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function parseEncryptedMessage (stanza, attrs) {
|
export function parseEncryptedMessage (stanza, attrs) {
|
||||||
if (attrs.is_encrypted && attrs.encrypted.key) {
|
if (attrs.is_encrypted) {
|
||||||
// https://xmpp.org/extensions/xep-0384.html#usecases-receiving
|
if (!attrs.encrypted.key) {
|
||||||
if (attrs.encrypted.prekey === true) {
|
return Object.assign(attrs, {
|
||||||
return decryptPrekeyWhisperMessage(attrs);
|
'error_condition': 'not-encrypted-for-this-device',
|
||||||
|
'error_type': 'Decryption',
|
||||||
|
'is_ephemeral': true,
|
||||||
|
'is_error': true,
|
||||||
|
'type': 'error'
|
||||||
|
});
|
||||||
} else {
|
} 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 {
|
} else {
|
||||||
return attrs;
|
return attrs;
|
||||||
@ -287,18 +297,16 @@ async function handleDecryptedWhisperMessage (attrs, key_and_tag) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getDecryptionErrorAttributes (e) {
|
function getDecryptionErrorAttributes (e) {
|
||||||
if (api.settings.get('loglevel') === 'debug') {
|
return {
|
||||||
return {
|
'error_text':
|
||||||
'error_text':
|
__('Sorry, could not decrypt a received OMEMO message due to an error.') + ` ${e.name} ${e.message}`,
|
||||||
__('Sorry, could not decrypt a received OMEMO message due to an error.') + ` ${e.name} ${e.message}`,
|
'error_condition': e.name,
|
||||||
'error_type': 'Decryption',
|
'error_message': e.message,
|
||||||
'is_ephemeral': true,
|
'error_type': 'Decryption',
|
||||||
'is_error': true,
|
'is_ephemeral': true,
|
||||||
'type': 'error'
|
'is_error': true,
|
||||||
};
|
'type': 'error'
|
||||||
} else {
|
};
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function decryptPrekeyWhisperMessage (attrs) {
|
async function decryptPrekeyWhisperMessage (attrs) {
|
||||||
|
Loading…
Reference in New Issue
Block a user