Skip to content

Commit 8adabb8

Browse files
Add sendSharedHistoryKeys in crypto service
1 parent d250e3d commit 8adabb8

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/CryptoService.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,9 @@ interface CryptoService {
162162
* send, in order to speed up sending of the message.
163163
*/
164164
fun prepareToEncrypt(roomId: String, callback: MatrixCallback<Unit>)
165+
166+
/**
167+
* Share existing inbound sessions with the provided userId devices
168+
*/
169+
fun sendSharedHistoryKeys(roomId: String, userId: String)
165170
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,23 @@ internal class DefaultCryptoService @Inject constructor(
13701370
)
13711371
}
13721372
}
1373-
1373+
override fun sendSharedHistoryKeys(roomId: String, userId: String) {
1374+
cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
1375+
val userDevices = cryptoStore.getUserDevices(userId)
1376+
userDevices?.forEach {
1377+
// Lets share our existing inbound sessions for every user device
1378+
val deviceId = it.key
1379+
val inboundSessions = cryptoStore.getInboundGroupSessions(roomId)
1380+
inboundSessions.forEach { inboundGroupSession ->
1381+
// Share the session with the to userId with deviceId
1382+
val exportedKeys = inboundGroupSession.exportKeys()
1383+
val algorithm = exportedKeys?.algorithm
1384+
val decryptor = roomDecryptorProvider.getRoomDecryptor(roomId, algorithm)
1385+
decryptor?.shareKeysWithDevice(exportedKeys, deviceId, userId)
1386+
}
1387+
}
1388+
}
1389+
}
13741390
/* ==========================================================================================
13751391
* For test only
13761392
* ========================================================================================== */

0 commit comments

Comments
 (0)