diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/EncryptEventTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/EncryptEventTask.kt index ac49102a07..b582930ab4 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/EncryptEventTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/EncryptEventTask.kt @@ -29,9 +29,7 @@ import javax.inject.Inject internal interface EncryptEventTask : Task { data class Params(val roomId: String, - val event: Event, - /**Do not encrypt these keys, keep them as is in encrypted content (e.g. m.relates_to)*/ - val keepKeys: List? = null + val event: Event ) } @@ -49,22 +47,8 @@ internal class DefaultEncryptEventTask @Inject constructor( localEchoRepository.updateSendState(localEvent.eventId, localEvent.roomId, SendState.ENCRYPTING) - val localMutableContent = localEvent.content?.toMutableMap() ?: mutableMapOf() - params.keepKeys?.forEach { - localMutableContent.remove(it) - } - // let it throws - val result = cryptoService.encryptEventContent(localMutableContent, localEvent.type, params.roomId) - - val modifiedContent = HashMap(result.eventContent) - params.keepKeys?.forEach { toKeep -> - localEvent.content?.get(toKeep)?.let { - // put it back in the encrypted thing - modifiedContent[toKeep] = it - } - } - val safeResult = result.copy(eventContent = modifiedContent) + val result = cryptoService.encryptEventContent(localEvent.content ?: emptyMap(), localEvent.type, params.roomId) // Better handling of local echo, to avoid decrypting transition on remote echo // Should I only do it for text messages? val decryptionLocalEcho = if (result.eventContent["algorithm"] == MXCRYPTO_ALGORITHM_MEGOLM) { @@ -81,17 +65,16 @@ internal class DefaultEncryptEventTask @Inject constructor( } else { null } - localEchoRepository.updateEcho(localEvent.eventId) { _, localEcho -> localEcho.type = EventType.ENCRYPTED - localEcho.content = ContentMapper.map(modifiedContent) + localEcho.content = ContentMapper.map(result.eventContent) decryptionLocalEcho?.also { localEcho.setDecryptionResult(it) } } return localEvent.copy( - type = safeResult.eventType, - content = safeResult.eventContent + type = result.eventType, + content = result.eventContent ) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendEventTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendEventTask.kt index 6620c1c6cc..33d5e5ab79 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendEventTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendEventTask.kt @@ -76,8 +76,7 @@ internal class DefaultSendEventTask @Inject constructor( if (params.encrypt && !params.event.isEncrypted()) { return encryptEventTask.execute(EncryptEventTask.Params( params.event.roomId ?: "", - params.event, - listOf("m.relates_to") + params.event )) } return params.event