mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-26 10:58:34 +03:00
Let rust encrypt method handle unencrypted content ( like relates_to)
This commit is contained in:
parent
39755b08ee
commit
5581b82ab4
2 changed files with 6 additions and 24 deletions
|
@ -29,9 +29,7 @@ import javax.inject.Inject
|
|||
|
||||
internal interface EncryptEventTask : Task<EncryptEventTask.Params, Event> {
|
||||
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<String>? = 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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue