Add sendSharedHistoryKeys in crypto service

This commit is contained in:
ariskotsomitopoulos 2022-04-21 13:43:41 +03:00 committed by Valere
parent 34713d5023
commit 98b55457b5
2 changed files with 22 additions and 1 deletions

View file

@ -176,4 +176,9 @@ interface CryptoService {
* send, in order to speed up sending of the message.
*/
fun prepareToEncrypt(roomId: String, callback: MatrixCallback<Unit>)
/**
* Share existing inbound sessions with the provided userId devices
*/
fun sendSharedHistoryKeys(roomId: String, userId: String)
}

View file

@ -1334,7 +1334,23 @@ internal class DefaultCryptoService @Inject constructor(
)
}
}
override fun sendSharedHistoryKeys(roomId: String, userId: String) {
cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
val userDevices = cryptoStore.getUserDevices(userId)
userDevices?.forEach {
// Lets share our existing inbound sessions for every user device
val deviceId = it.key
val inboundSessions = cryptoStore.getInboundGroupSessions(roomId)
inboundSessions.forEach { inboundGroupSession ->
// Share the session with the to userId with deviceId
val exportedKeys = inboundGroupSession.exportKeys()
val algorithm = exportedKeys?.algorithm
val decryptor = roomDecryptorProvider.getRoomDecryptor(roomId, algorithm)
decryptor?.shareKeysWithDevice(exportedKeys, deviceId, userId)
}
}
}
}
/* ==========================================================================================
* For test only
* ========================================================================================== */