Add sendSharedHistoryKeys in crypto service
This commit is contained in:
parent
34713d5023
commit
98b55457b5
@ -176,4 +176,9 @@ interface CryptoService {
|
|||||||
* send, in order to speed up sending of the message.
|
* send, in order to speed up sending of the message.
|
||||||
*/
|
*/
|
||||||
fun prepareToEncrypt(roomId: String, callback: MatrixCallback<Unit>)
|
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
|
* For test only
|
||||||
* ========================================================================================== */
|
* ========================================================================================== */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user