mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-29 14:38:45 +03:00
Refactor code structure and improve naming
This commit is contained in:
parent
497f7cf044
commit
395d48f946
6 changed files with 41 additions and 17 deletions
|
@ -40,7 +40,7 @@ import org.matrix.android.sdk.api.session.crypto.verification.VerificationServic
|
||||||
import org.matrix.android.sdk.api.session.events.model.Content
|
import org.matrix.android.sdk.api.session.events.model.Content
|
||||||
import org.matrix.android.sdk.api.session.events.model.Event
|
import org.matrix.android.sdk.api.session.events.model.Event
|
||||||
import org.matrix.android.sdk.api.session.events.model.content.RoomKeyWithHeldContent
|
import org.matrix.android.sdk.api.session.events.model.content.RoomKeyWithHeldContent
|
||||||
import org.matrix.android.sdk.internal.database.helper.SessionInfoPair
|
import org.matrix.android.sdk.internal.crypto.model.SessionInfo
|
||||||
|
|
||||||
interface CryptoService {
|
interface CryptoService {
|
||||||
|
|
||||||
|
@ -181,5 +181,5 @@ interface CryptoService {
|
||||||
/**
|
/**
|
||||||
* Share all inbound sessions of the last chunk messages to the provided userId devices
|
* Share all inbound sessions of the last chunk messages to the provided userId devices
|
||||||
*/
|
*/
|
||||||
fun sendSharedHistoryKeysToLastChunk(roomId: String, userId: String, sessionInfoSet: Set<SessionInfoPair>?)
|
fun sendSharedHistoryKeys(roomId: String, userId: String, sessionInfoSet: Set<SessionInfo>?)
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,7 @@ import org.matrix.android.sdk.internal.crypto.algorithms.olm.MXOlmEncryptionFact
|
||||||
import org.matrix.android.sdk.internal.crypto.crosssigning.DefaultCrossSigningService
|
import org.matrix.android.sdk.internal.crypto.crosssigning.DefaultCrossSigningService
|
||||||
import org.matrix.android.sdk.internal.crypto.keysbackup.DefaultKeysBackupService
|
import org.matrix.android.sdk.internal.crypto.keysbackup.DefaultKeysBackupService
|
||||||
import org.matrix.android.sdk.internal.crypto.model.MXKey.Companion.KEY_SIGNED_CURVE_25519_TYPE
|
import org.matrix.android.sdk.internal.crypto.model.MXKey.Companion.KEY_SIGNED_CURVE_25519_TYPE
|
||||||
|
import org.matrix.android.sdk.internal.crypto.model.SessionInfo
|
||||||
import org.matrix.android.sdk.internal.crypto.model.toRest
|
import org.matrix.android.sdk.internal.crypto.model.toRest
|
||||||
import org.matrix.android.sdk.internal.crypto.repository.WarnOnUnknownDeviceRepository
|
import org.matrix.android.sdk.internal.crypto.repository.WarnOnUnknownDeviceRepository
|
||||||
import org.matrix.android.sdk.internal.crypto.store.IMXCryptoStore
|
import org.matrix.android.sdk.internal.crypto.store.IMXCryptoStore
|
||||||
|
@ -968,7 +969,7 @@ internal class DefaultCryptoService @Inject constructor(
|
||||||
eventContent?.historyVisibility?.let {
|
eventContent?.historyVisibility?.let {
|
||||||
cryptoStore.setShouldEncryptForInvitedMembers(roomId, it != RoomHistoryVisibility.JOINED)
|
cryptoStore.setShouldEncryptForInvitedMembers(roomId, it != RoomHistoryVisibility.JOINED)
|
||||||
cryptoStore.setShouldShareHistory(roomId, it.shouldShareHistory())
|
cryptoStore.setShouldShareHistory(roomId, it.shouldShareHistory())
|
||||||
}
|
} ?: cryptoStore.setShouldShareHistory(roomId, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1338,7 +1339,7 @@ internal class DefaultCryptoService @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun sendSharedHistoryKeysToLastChunk(roomId: String, userId: String, sessionInfoSet: Set<SessionInfoPair>?) {
|
override fun sendSharedHistoryKeys(roomId: String, userId: String, sessionInfoSet: Set<SessionInfo>?) {
|
||||||
cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
|
cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
|
||||||
runCatching {
|
runCatching {
|
||||||
deviceListManager.downloadKeys(listOf(userId), false)
|
deviceListManager.downloadKeys(listOf(userId), false)
|
||||||
|
@ -1347,11 +1348,11 @@ internal class DefaultCryptoService @Inject constructor(
|
||||||
userDevices?.forEach {
|
userDevices?.forEach {
|
||||||
// Lets share the provided inbound sessions for every user device
|
// Lets share the provided inbound sessions for every user device
|
||||||
val deviceId = it.key
|
val deviceId = it.key
|
||||||
sessionInfoSet?.mapNotNull { sessionInfoPair ->
|
sessionInfoSet?.mapNotNull { sessionInfo ->
|
||||||
// Get inbound session from sessionId and sessionKey
|
// Get inbound session from sessionId and sessionKey
|
||||||
cryptoStore.getInboundGroupSession(
|
cryptoStore.getInboundGroupSession(
|
||||||
sessionId = sessionInfoPair.first,
|
sessionId = sessionInfo.sessionId,
|
||||||
senderKey = sessionInfoPair.second,
|
senderKey = sessionInfo.senderKey,
|
||||||
sharedHistory = true
|
sharedHistory = true
|
||||||
)
|
)
|
||||||
}?.filter { inboundGroupSession ->
|
}?.filter { inboundGroupSession ->
|
||||||
|
@ -1362,7 +1363,7 @@ internal class DefaultCryptoService @Inject constructor(
|
||||||
val exportedKeys = inboundGroupSession.exportKeys(sharedHistory = true)
|
val exportedKeys = inboundGroupSession.exportKeys(sharedHistory = true)
|
||||||
val algorithm = exportedKeys?.algorithm
|
val algorithm = exportedKeys?.algorithm
|
||||||
val decryptor = roomDecryptorProvider.getRoomDecryptor(roomId, algorithm)
|
val decryptor = roomDecryptorProvider.getRoomDecryptor(roomId, algorithm)
|
||||||
decryptor?.shareKeysWithDevice(exportedKeys, deviceId, userId)
|
decryptor?.shareForwardKeysWithDevice(exportedKeys, deviceId, userId)
|
||||||
Timber.i("## CRYPTO | Sharing inbound session")
|
Timber.i("## CRYPTO | Sharing inbound session")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,5 +45,5 @@ internal interface IMXDecrypting {
|
||||||
*/
|
*/
|
||||||
fun onRoomKeyEvent(event: Event, defaultKeysBackupService: DefaultKeysBackupService) {}
|
fun onRoomKeyEvent(event: Event, defaultKeysBackupService: DefaultKeysBackupService) {}
|
||||||
|
|
||||||
fun shareKeysWithDevice(exportedKeys: MegolmSessionData?, deviceId: String, userId: String) {}
|
fun shareForwardKeysWithDevice(exportedKeys: MegolmSessionData?, deviceId: String, userId: String) {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.matrix.android.sdk.internal.crypto.model
|
||||||
|
|
||||||
|
data class SessionInfo(
|
||||||
|
val sessionId: String,
|
||||||
|
val senderKey: String
|
||||||
|
)
|
|
@ -21,6 +21,7 @@ import io.realm.kotlin.createObject
|
||||||
import org.matrix.android.sdk.api.session.events.model.content.EncryptedEventContent
|
import org.matrix.android.sdk.api.session.events.model.content.EncryptedEventContent
|
||||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomMemberContent
|
import org.matrix.android.sdk.api.session.room.model.RoomMemberContent
|
||||||
|
import org.matrix.android.sdk.internal.crypto.model.SessionInfo
|
||||||
import org.matrix.android.sdk.internal.database.mapper.asDomain
|
import org.matrix.android.sdk.internal.database.mapper.asDomain
|
||||||
import org.matrix.android.sdk.internal.database.model.ChunkEntity
|
import org.matrix.android.sdk.internal.database.model.ChunkEntity
|
||||||
import org.matrix.android.sdk.internal.database.model.CurrentStateEventEntityFields
|
import org.matrix.android.sdk.internal.database.model.CurrentStateEventEntityFields
|
||||||
|
@ -185,13 +186,11 @@ internal fun ChunkEntity.isMoreRecentThan(chunkToCheck: ChunkEntity): Boolean {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun ChunkEntity.Companion.findLatestSessionInfo(realm: Realm, roomId: String): Set<SessionInfoPair>? =
|
internal fun ChunkEntity.Companion.findLatestSessionInfo(realm: Realm, roomId: String): Set<SessionInfo>? =
|
||||||
ChunkEntity.findLastForwardChunkOfRoom(realm, roomId)?.timelineEvents?.mapNotNull { timelineEvent ->
|
ChunkEntity.findLastForwardChunkOfRoom(realm, roomId)?.timelineEvents?.mapNotNull { timelineEvent ->
|
||||||
timelineEvent?.root?.asDomain()?.content?.toModel<EncryptedEventContent>()?.let { content ->
|
timelineEvent?.root?.asDomain()?.content?.toModel<EncryptedEventContent>()?.let { content ->
|
||||||
content.sessionId ?: return@mapNotNull null
|
content.sessionId ?: return@mapNotNull null
|
||||||
content.senderKey ?: return@mapNotNull null
|
content.senderKey ?: return@mapNotNull null
|
||||||
Pair(content.sessionId, content.senderKey)
|
SessionInfo(content.sessionId, content.senderKey)
|
||||||
}
|
}
|
||||||
}?.toSet()
|
}?.toSet()
|
||||||
|
|
||||||
internal typealias SessionInfoPair = Pair<String, String>
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package org.matrix.android.sdk.internal.session.room.membership
|
package org.matrix.android.sdk.internal.session.room.membership
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
|
import com.otaliastudios.opengl.core.use
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
|
@ -44,6 +45,7 @@ import org.matrix.android.sdk.internal.session.room.membership.admin.MembershipA
|
||||||
import org.matrix.android.sdk.internal.session.room.membership.joining.InviteTask
|
import org.matrix.android.sdk.internal.session.room.membership.joining.InviteTask
|
||||||
import org.matrix.android.sdk.internal.session.room.membership.threepid.InviteThreePidTask
|
import org.matrix.android.sdk.internal.session.room.membership.threepid.InviteThreePidTask
|
||||||
import org.matrix.android.sdk.internal.util.fetchCopied
|
import org.matrix.android.sdk.internal.util.fetchCopied
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
internal class DefaultMembershipService @AssistedInject constructor(
|
internal class DefaultMembershipService @AssistedInject constructor(
|
||||||
@Assisted private val roomId: String,
|
@Assisted private val roomId: String,
|
||||||
|
@ -143,10 +145,10 @@ internal class DefaultMembershipService @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun invite(userId: String, reason: String?) {
|
override suspend fun invite(userId: String, reason: String?) {
|
||||||
val sessionInfoSet = Realm.getInstance(monarchy.realmConfiguration).use {
|
val sessionInfo = Realm.getInstance(monarchy.realmConfiguration).use {
|
||||||
ChunkEntity.findLatestSessionInfo(it, roomId)
|
ChunkEntity.findLatestSessionInfo(it, roomId)
|
||||||
}
|
}
|
||||||
cryptoService.sendSharedHistoryKeysToLastChunk(roomId, userId, sessionInfoSet)
|
cryptoService.sendSharedHistoryKeys(roomId, userId, sessionInfo)
|
||||||
val params = InviteTask.Params(roomId, userId, reason)
|
val params = InviteTask.Params(roomId, userId, reason)
|
||||||
inviteTask.execute(params)
|
inviteTask.execute(params)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue