mirror of
https://github.com/element-hq/element-android
synced 2024-11-23 18:05:36 +03:00
Add sendSharedHistoryKeys in crypto service
This commit is contained in:
parent
34713d5023
commit
98b55457b5
2 changed files with 22 additions and 1 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
* ========================================================================================== */
|
||||
|
|
Loading…
Reference in a new issue