mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 17:35:54 +03:00
Merge pull request #955 from vector-im/feature/room_history_in_e2e
Feature/room history in e2e
This commit is contained in:
commit
062c4559a2
16 changed files with 111 additions and 63 deletions
|
@ -12,6 +12,7 @@ Other changes:
|
||||||
|
|
||||||
Bugfix 🐛:
|
Bugfix 🐛:
|
||||||
- Ask for permission before opening the camera (#934)
|
- Ask for permission before opening the camera (#934)
|
||||||
|
- Encrypt for invited users by default, if the room state allows it (#803)
|
||||||
|
|
||||||
Translations 🗣:
|
Translations 🗣:
|
||||||
-
|
-
|
||||||
|
|
|
@ -74,7 +74,7 @@ class CryptoTestHelper(val mTestHelper: CommonTestHelper) {
|
||||||
val room = aliceSession.getRoom(roomId!!)!!
|
val room = aliceSession.getRoom(roomId!!)!!
|
||||||
|
|
||||||
val lock2 = CountDownLatch(1)
|
val lock2 = CountDownLatch(1)
|
||||||
room.enableEncryptionWithAlgorithm(MXCRYPTO_ALGORITHM_MEGOLM, object : TestMatrixCallback<Unit>(lock2) {})
|
room.enableEncryption(callback = TestMatrixCallback(lock2))
|
||||||
mTestHelper.await(lock2)
|
mTestHelper.await(lock2)
|
||||||
|
|
||||||
return CryptoTestData(aliceSession, roomId!!)
|
return CryptoTestData(aliceSession, roomId!!)
|
||||||
|
|
|
@ -23,6 +23,7 @@ import androidx.work.WorkManager
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import im.vector.matrix.android.BuildConfig
|
import im.vector.matrix.android.BuildConfig
|
||||||
import im.vector.matrix.android.api.auth.AuthenticationService
|
import im.vector.matrix.android.api.auth.AuthenticationService
|
||||||
|
import im.vector.matrix.android.api.crypto.MXCryptoConfig
|
||||||
import im.vector.matrix.android.internal.SessionManager
|
import im.vector.matrix.android.internal.SessionManager
|
||||||
import im.vector.matrix.android.internal.crypto.attachments.ElementToDecrypt
|
import im.vector.matrix.android.internal.crypto.attachments.ElementToDecrypt
|
||||||
import im.vector.matrix.android.internal.crypto.attachments.MXEncryptedAttachments
|
import im.vector.matrix.android.internal.crypto.attachments.MXEncryptedAttachments
|
||||||
|
@ -35,7 +36,8 @@ import java.util.concurrent.atomic.AtomicBoolean
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
data class MatrixConfiguration(
|
data class MatrixConfiguration(
|
||||||
val applicationFlavor: String = "Default-application-flavor"
|
val applicationFlavor: String = "Default-application-flavor",
|
||||||
|
val cryptoConfig: MXCryptoConfig = MXCryptoConfig()
|
||||||
) {
|
) {
|
||||||
|
|
||||||
interface Provider {
|
interface Provider {
|
||||||
|
@ -57,12 +59,11 @@ class Matrix private constructor(context: Context, matrixConfiguration: MatrixCo
|
||||||
|
|
||||||
init {
|
init {
|
||||||
Monarchy.init(context)
|
Monarchy.init(context)
|
||||||
DaggerMatrixComponent.factory().create(context).inject(this)
|
DaggerMatrixComponent.factory().create(context, matrixConfiguration).inject(this)
|
||||||
if (context.applicationContext !is Configuration.Provider) {
|
if (context.applicationContext !is Configuration.Provider) {
|
||||||
WorkManager.initialize(context, Configuration.Builder().build())
|
WorkManager.initialize(context, Configuration.Builder().build())
|
||||||
}
|
}
|
||||||
ProcessLifecycleOwner.get().lifecycle.addObserver(backgroundDetectionObserver)
|
ProcessLifecycleOwner.get().lifecycle.addObserver(backgroundDetectionObserver)
|
||||||
userAgentHolder.setApplicationFlavor(matrixConfiguration.applicationFlavor)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getUserAgent() = userAgentHolder.userAgent
|
fun getUserAgent() = userAgentHolder.userAgent
|
||||||
|
|
|
@ -14,14 +14,14 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package im.vector.matrix.android.internal.crypto
|
package im.vector.matrix.android.api.crypto
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to define the parameters used to customize or configure the end-to-end crypto.
|
* Class to define the parameters used to customize or configure the end-to-end crypto.
|
||||||
*/
|
*/
|
||||||
data class MXCryptoConfig(
|
data class MXCryptoConfig(
|
||||||
// Tell whether the encryption of the event content is enabled for the invited members.
|
// Tell whether the encryption of the event content is enabled for the invited members.
|
||||||
// By default, we encrypt messages only for the joined members.
|
// SDK clients can disable this by settings it to false.
|
||||||
// The encryption for the invited members will be blocked if the history visibility is "joined".
|
// Note that the encryption for the invited members will be blocked if the history visibility is "joined".
|
||||||
var enableEncryptionForInvitedMembers: Boolean = false
|
var enableEncryptionForInvitedMembers: Boolean = true
|
||||||
)
|
)
|
|
@ -17,6 +17,7 @@
|
||||||
package im.vector.matrix.android.api.session.room.crypto
|
package im.vector.matrix.android.api.session.room.crypto
|
||||||
|
|
||||||
import im.vector.matrix.android.api.MatrixCallback
|
import im.vector.matrix.android.api.MatrixCallback
|
||||||
|
import im.vector.matrix.android.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM
|
||||||
|
|
||||||
interface RoomCryptoService {
|
interface RoomCryptoService {
|
||||||
|
|
||||||
|
@ -26,5 +27,9 @@ interface RoomCryptoService {
|
||||||
|
|
||||||
fun shouldEncryptForInvitedMembers(): Boolean
|
fun shouldEncryptForInvitedMembers(): Boolean
|
||||||
|
|
||||||
fun enableEncryptionWithAlgorithm(algorithm: String, callback: MatrixCallback<Unit>)
|
/**
|
||||||
|
* Enable encryption of the room
|
||||||
|
*/
|
||||||
|
fun enableEncryption(algorithm: String = MXCRYPTO_ALGORITHM_MEGOLM,
|
||||||
|
callback: MatrixCallback<Unit>)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,28 @@ package im.vector.matrix.android.api.session.room.model
|
||||||
|
|
||||||
import com.squareup.moshi.Json
|
import com.squareup.moshi.Json
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ref: https://matrix.org/docs/spec/client_server/latest#room-history-visibility
|
||||||
|
*/
|
||||||
enum class RoomHistoryVisibility {
|
enum class RoomHistoryVisibility {
|
||||||
|
/**
|
||||||
|
* All events while this is the m.room.history_visibility value may be shared by any
|
||||||
|
* participating homeserver with anyone, regardless of whether they have ever joined the room.
|
||||||
|
*/
|
||||||
|
@Json(name = "world_readable") WORLD_READABLE,
|
||||||
|
/**
|
||||||
|
* Previous events are always accessible to newly joined members. All events in the
|
||||||
|
* room are accessible, even those sent when the member was not a part of the room.
|
||||||
|
*/
|
||||||
@Json(name = "shared") SHARED,
|
@Json(name = "shared") SHARED,
|
||||||
|
/**
|
||||||
|
* Events are accessible to newly joined members from the point they were invited onwards.
|
||||||
|
* Events stop being accessible when the member's state changes to something other than invite or join.
|
||||||
|
*/
|
||||||
@Json(name = "invited") INVITED,
|
@Json(name = "invited") INVITED,
|
||||||
@Json(name = "joined") JOINED,
|
/**
|
||||||
@Json(name = "world_readable") WORLD_READABLE
|
* Events are accessible to newly joined members from the point they joined the room onwards.
|
||||||
|
* Events stop being accessible when the member's state changes to something other than join.
|
||||||
|
*/
|
||||||
|
@Json(name = "joined") JOINED
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,11 +28,6 @@ interface StateService {
|
||||||
*/
|
*/
|
||||||
fun updateTopic(topic: String, callback: MatrixCallback<Unit>)
|
fun updateTopic(topic: String, callback: MatrixCallback<Unit>)
|
||||||
|
|
||||||
/**
|
|
||||||
* Enable encryption of the room
|
|
||||||
*/
|
|
||||||
fun enableEncryption(algorithm: String, callback: MatrixCallback<Unit>)
|
|
||||||
|
|
||||||
fun getStateEvent(eventType: String): Event?
|
fun getStateEvent(eventType: String): Event?
|
||||||
|
|
||||||
fun getStateEventLive(eventType: String): LiveData<Optional<Event>>
|
fun getStateEventLive(eventType: String): LiveData<Optional<Event>>
|
||||||
|
|
|
@ -159,13 +159,6 @@ internal abstract class CryptoModule {
|
||||||
fun providesRoomKeysAPI(retrofit: Retrofit): RoomKeysApi {
|
fun providesRoomKeysAPI(retrofit: Retrofit): RoomKeysApi {
|
||||||
return retrofit.create(RoomKeysApi::class.java)
|
return retrofit.create(RoomKeysApi::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
@Provides
|
|
||||||
@SessionScope
|
|
||||||
fun providesCryptoConfig(): MXCryptoConfig {
|
|
||||||
return MXCryptoConfig()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
|
|
|
@ -27,6 +27,7 @@ import com.zhuinden.monarchy.Monarchy
|
||||||
import dagger.Lazy
|
import dagger.Lazy
|
||||||
import im.vector.matrix.android.api.MatrixCallback
|
import im.vector.matrix.android.api.MatrixCallback
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
import im.vector.matrix.android.api.auth.data.Credentials
|
||||||
|
import im.vector.matrix.android.api.crypto.MXCryptoConfig
|
||||||
import im.vector.matrix.android.api.failure.Failure
|
import im.vector.matrix.android.api.failure.Failure
|
||||||
import im.vector.matrix.android.api.listeners.ProgressListener
|
import im.vector.matrix.android.api.listeners.ProgressListener
|
||||||
import im.vector.matrix.android.api.session.crypto.CryptoService
|
import im.vector.matrix.android.api.session.crypto.CryptoService
|
||||||
|
@ -116,7 +117,7 @@ internal class DefaultCryptoService @Inject constructor(
|
||||||
// Olm device
|
// Olm device
|
||||||
private val olmDevice: MXOlmDevice,
|
private val olmDevice: MXOlmDevice,
|
||||||
// Set of parameters used to configure/customize the end-to-end crypto.
|
// Set of parameters used to configure/customize the end-to-end crypto.
|
||||||
private val cryptoConfig: MXCryptoConfig = MXCryptoConfig(),
|
private val mxCryptoConfig: MXCryptoConfig,
|
||||||
// Device list manager
|
// Device list manager
|
||||||
private val deviceListManager: DeviceListManager,
|
private val deviceListManager: DeviceListManager,
|
||||||
// The key backup service.
|
// The key backup service.
|
||||||
|
@ -399,6 +400,7 @@ internal class DefaultCryptoService @Inject constructor(
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getCryptoDeviceInfo(userId: String): List<CryptoDeviceInfo> {
|
override fun getCryptoDeviceInfo(userId: String): List<CryptoDeviceInfo> {
|
||||||
return cryptoStore.getUserDevices(userId)?.map { it.value } ?: emptyList()
|
return cryptoStore.getUserDevices(userId)?.map { it.value } ?: emptyList()
|
||||||
}
|
}
|
||||||
|
@ -545,8 +547,8 @@ internal class DefaultCryptoService @Inject constructor(
|
||||||
return cryptoStore.getUserDevices(userId)?.values?.toMutableList() ?: ArrayList()
|
return cryptoStore.getUserDevices(userId)?.values?.toMutableList() ?: ArrayList()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isEncryptionEnabledForInvitedUser(): Boolean {
|
private fun isEncryptionEnabledForInvitedUser(): Boolean {
|
||||||
return cryptoConfig.enableEncryptionForInvitedMembers
|
return mxCryptoConfig.enableEncryptionForInvitedMembers
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getEncryptionAlgorithm(roomId: String): String? {
|
override fun getEncryptionAlgorithm(roomId: String): String? {
|
||||||
|
@ -779,7 +781,7 @@ internal class DefaultCryptoService @Inject constructor(
|
||||||
deviceListManager.startTrackingDeviceList(listOf(userId))
|
deviceListManager.startTrackingDeviceList(listOf(userId))
|
||||||
} else if (membership == Membership.INVITE
|
} else if (membership == Membership.INVITE
|
||||||
&& shouldEncryptForInvitedMembers(roomId)
|
&& shouldEncryptForInvitedMembers(roomId)
|
||||||
&& cryptoConfig.enableEncryptionForInvitedMembers) {
|
&& isEncryptionEnabledForInvitedUser()) {
|
||||||
// track the deviceList for this invited user.
|
// track the deviceList for this invited user.
|
||||||
// Caution: there's a big edge case here in that federated servers do not
|
// Caution: there's a big edge case here in that federated servers do not
|
||||||
// know what other servers are in the room at the time they've been invited.
|
// know what other servers are in the room at the time they've been invited.
|
||||||
|
|
|
@ -22,6 +22,7 @@ import com.squareup.moshi.Moshi
|
||||||
import dagger.BindsInstance
|
import dagger.BindsInstance
|
||||||
import dagger.Component
|
import dagger.Component
|
||||||
import im.vector.matrix.android.api.Matrix
|
import im.vector.matrix.android.api.Matrix
|
||||||
|
import im.vector.matrix.android.api.MatrixConfiguration
|
||||||
import im.vector.matrix.android.api.auth.AuthenticationService
|
import im.vector.matrix.android.api.auth.AuthenticationService
|
||||||
import im.vector.matrix.android.internal.SessionManager
|
import im.vector.matrix.android.internal.SessionManager
|
||||||
import im.vector.matrix.android.internal.auth.AuthModule
|
import im.vector.matrix.android.internal.auth.AuthModule
|
||||||
|
@ -48,6 +49,8 @@ internal interface MatrixComponent {
|
||||||
|
|
||||||
fun context(): Context
|
fun context(): Context
|
||||||
|
|
||||||
|
fun matrixConfiguration(): MatrixConfiguration
|
||||||
|
|
||||||
fun resources(): Resources
|
fun resources(): Resources
|
||||||
|
|
||||||
fun olmManager(): OlmManager
|
fun olmManager(): OlmManager
|
||||||
|
@ -66,6 +69,7 @@ internal interface MatrixComponent {
|
||||||
|
|
||||||
@Component.Factory
|
@Component.Factory
|
||||||
interface Factory {
|
interface Factory {
|
||||||
fun create(@BindsInstance context: Context): MatrixComponent
|
fun create(@BindsInstance context: Context,
|
||||||
|
@BindsInstance matrixConfiguration: MatrixConfiguration): MatrixComponent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,18 +18,20 @@ package im.vector.matrix.android.internal.network
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import im.vector.matrix.android.BuildConfig
|
import im.vector.matrix.android.BuildConfig
|
||||||
|
import im.vector.matrix.android.api.MatrixConfiguration
|
||||||
import im.vector.matrix.android.internal.di.MatrixScope
|
import im.vector.matrix.android.internal.di.MatrixScope
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@MatrixScope
|
@MatrixScope
|
||||||
internal class UserAgentHolder @Inject constructor(private val context: Context) {
|
internal class UserAgentHolder @Inject constructor(private val context: Context,
|
||||||
|
matrixConfiguration: MatrixConfiguration) {
|
||||||
|
|
||||||
var userAgent: String = ""
|
var userAgent: String = ""
|
||||||
private set
|
private set
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setApplicationFlavor("NoFlavor")
|
setApplicationFlavor(matrixConfiguration.applicationFlavor)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,7 +40,7 @@ internal class UserAgentHolder @Inject constructor(private val context: Context)
|
||||||
*
|
*
|
||||||
* @param flavorDescription the flavor description
|
* @param flavorDescription the flavor description
|
||||||
*/
|
*/
|
||||||
fun setApplicationFlavor(flavorDescription: String) {
|
private fun setApplicationFlavor(flavorDescription: String) {
|
||||||
var appName = ""
|
var appName = ""
|
||||||
var appVersion = ""
|
var appVersion = ""
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,12 @@ import dagger.Lazy
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import dagger.multibindings.IntoSet
|
import dagger.multibindings.IntoSet
|
||||||
|
import im.vector.matrix.android.api.MatrixConfiguration
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
import im.vector.matrix.android.api.auth.data.Credentials
|
||||||
import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig
|
import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig
|
||||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
import im.vector.matrix.android.api.auth.data.SessionParams
|
||||||
import im.vector.matrix.android.api.auth.data.sessionId
|
import im.vector.matrix.android.api.auth.data.sessionId
|
||||||
|
import im.vector.matrix.android.api.crypto.MXCryptoConfig
|
||||||
import im.vector.matrix.android.api.session.InitialSyncProgressService
|
import im.vector.matrix.android.api.session.InitialSyncProgressService
|
||||||
import im.vector.matrix.android.api.session.Session
|
import im.vector.matrix.android.api.session.Session
|
||||||
import im.vector.matrix.android.api.session.homeserver.HomeServerCapabilitiesService
|
import im.vector.matrix.android.api.session.homeserver.HomeServerCapabilitiesService
|
||||||
|
@ -34,7 +36,15 @@ import im.vector.matrix.android.api.session.securestorage.SecureStorageService
|
||||||
import im.vector.matrix.android.internal.crypto.verification.VerificationMessageLiveObserver
|
import im.vector.matrix.android.internal.crypto.verification.VerificationMessageLiveObserver
|
||||||
import im.vector.matrix.android.internal.database.LiveEntityObserver
|
import im.vector.matrix.android.internal.database.LiveEntityObserver
|
||||||
import im.vector.matrix.android.internal.database.SessionRealmConfigurationFactory
|
import im.vector.matrix.android.internal.database.SessionRealmConfigurationFactory
|
||||||
import im.vector.matrix.android.internal.di.*
|
import im.vector.matrix.android.internal.di.Authenticated
|
||||||
|
import im.vector.matrix.android.internal.di.DeviceId
|
||||||
|
import im.vector.matrix.android.internal.di.SessionCacheDirectory
|
||||||
|
import im.vector.matrix.android.internal.di.SessionDatabase
|
||||||
|
import im.vector.matrix.android.internal.di.SessionFilesDirectory
|
||||||
|
import im.vector.matrix.android.internal.di.SessionId
|
||||||
|
import im.vector.matrix.android.internal.di.Unauthenticated
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
|
import im.vector.matrix.android.internal.di.UserMd5
|
||||||
import im.vector.matrix.android.internal.network.AccessTokenInterceptor
|
import im.vector.matrix.android.internal.network.AccessTokenInterceptor
|
||||||
import im.vector.matrix.android.internal.network.RetrofitFactory
|
import im.vector.matrix.android.internal.network.RetrofitFactory
|
||||||
import im.vector.matrix.android.internal.network.interceptors.CurlLoggingInterceptor
|
import im.vector.matrix.android.internal.network.interceptors.CurlLoggingInterceptor
|
||||||
|
@ -178,6 +188,13 @@ internal abstract class SessionModule {
|
||||||
fun providesEventBus(): EventBus {
|
fun providesEventBus(): EventBus {
|
||||||
return EventBus.builder().build()
|
return EventBus.builder().build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@Provides
|
||||||
|
@SessionScope
|
||||||
|
fun providesMxCryptoConfig(matrixConfiguration: MatrixConfiguration): MXCryptoConfig {
|
||||||
|
return matrixConfiguration.cryptoConfig
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
|
|
|
@ -21,6 +21,7 @@ import androidx.lifecycle.Transformations
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import im.vector.matrix.android.api.MatrixCallback
|
import im.vector.matrix.android.api.MatrixCallback
|
||||||
import im.vector.matrix.android.api.session.crypto.CryptoService
|
import im.vector.matrix.android.api.session.crypto.CryptoService
|
||||||
|
import im.vector.matrix.android.api.session.events.model.EventType
|
||||||
import im.vector.matrix.android.api.session.room.Room
|
import im.vector.matrix.android.api.session.room.Room
|
||||||
import im.vector.matrix.android.api.session.room.members.MembershipService
|
import im.vector.matrix.android.api.session.room.members.MembershipService
|
||||||
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
||||||
|
@ -35,10 +36,15 @@ import im.vector.matrix.android.api.session.room.timeline.TimelineService
|
||||||
import im.vector.matrix.android.api.session.room.typing.TypingService
|
import im.vector.matrix.android.api.session.room.typing.TypingService
|
||||||
import im.vector.matrix.android.api.util.Optional
|
import im.vector.matrix.android.api.util.Optional
|
||||||
import im.vector.matrix.android.api.util.toOptional
|
import im.vector.matrix.android.api.util.toOptional
|
||||||
|
import im.vector.matrix.android.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM
|
||||||
import im.vector.matrix.android.internal.database.mapper.RoomSummaryMapper
|
import im.vector.matrix.android.internal.database.mapper.RoomSummaryMapper
|
||||||
import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
|
import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
|
||||||
import im.vector.matrix.android.internal.database.model.RoomSummaryEntityFields
|
import im.vector.matrix.android.internal.database.model.RoomSummaryEntityFields
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
import im.vector.matrix.android.internal.database.query.where
|
||||||
|
import im.vector.matrix.android.internal.session.room.state.SendStateTask
|
||||||
|
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||||
|
import im.vector.matrix.android.internal.task.configureWith
|
||||||
|
import java.security.InvalidParameterException
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal class DefaultRoom @Inject constructor(override val roomId: String,
|
internal class DefaultRoom @Inject constructor(override val roomId: String,
|
||||||
|
@ -54,7 +60,9 @@ internal class DefaultRoom @Inject constructor(override val roomId: String,
|
||||||
private val cryptoService: CryptoService,
|
private val cryptoService: CryptoService,
|
||||||
private val relationService: RelationService,
|
private val relationService: RelationService,
|
||||||
private val roomMembersService: MembershipService,
|
private val roomMembersService: MembershipService,
|
||||||
private val roomPushRuleService: RoomPushRuleService) :
|
private val roomPushRuleService: RoomPushRuleService,
|
||||||
|
private val taskExecutor: TaskExecutor,
|
||||||
|
private val sendStateTask: SendStateTask) :
|
||||||
Room,
|
Room,
|
||||||
TimelineService by timelineService,
|
TimelineService by timelineService,
|
||||||
SendService by sendService,
|
SendService by sendService,
|
||||||
|
@ -96,11 +104,27 @@ internal class DefaultRoom @Inject constructor(override val roomId: String,
|
||||||
return cryptoService.shouldEncryptForInvitedMembers(roomId)
|
return cryptoService.shouldEncryptForInvitedMembers(roomId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun enableEncryptionWithAlgorithm(algorithm: String, callback: MatrixCallback<Unit>) {
|
override fun enableEncryption(algorithm: String, callback: MatrixCallback<Unit>) {
|
||||||
if (isEncrypted()) {
|
when {
|
||||||
|
isEncrypted() -> {
|
||||||
callback.onFailure(IllegalStateException("Encryption is already enabled for this room"))
|
callback.onFailure(IllegalStateException("Encryption is already enabled for this room"))
|
||||||
} else {
|
}
|
||||||
stateService.enableEncryption(algorithm, callback)
|
algorithm != MXCRYPTO_ALGORITHM_MEGOLM -> {
|
||||||
|
callback.onFailure(InvalidParameterException("Only MXCRYPTO_ALGORITHM_MEGOLM algorithm is supported"))
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
val params = SendStateTask.Params(roomId,
|
||||||
|
EventType.STATE_ROOM_ENCRYPTION,
|
||||||
|
mapOf(
|
||||||
|
"algorithm" to algorithm
|
||||||
|
))
|
||||||
|
|
||||||
|
sendStateTask
|
||||||
|
.configureWith(params) {
|
||||||
|
this.callback = callback
|
||||||
|
}
|
||||||
|
.executeBy(taskExecutor)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,10 @@ import im.vector.matrix.android.internal.session.room.relation.DefaultRelationSe
|
||||||
import im.vector.matrix.android.internal.session.room.reporting.DefaultReportingService
|
import im.vector.matrix.android.internal.session.room.reporting.DefaultReportingService
|
||||||
import im.vector.matrix.android.internal.session.room.send.DefaultSendService
|
import im.vector.matrix.android.internal.session.room.send.DefaultSendService
|
||||||
import im.vector.matrix.android.internal.session.room.state.DefaultStateService
|
import im.vector.matrix.android.internal.session.room.state.DefaultStateService
|
||||||
|
import im.vector.matrix.android.internal.session.room.state.SendStateTask
|
||||||
import im.vector.matrix.android.internal.session.room.timeline.DefaultTimelineService
|
import im.vector.matrix.android.internal.session.room.timeline.DefaultTimelineService
|
||||||
import im.vector.matrix.android.internal.session.room.typing.DefaultTypingService
|
import im.vector.matrix.android.internal.session.room.typing.DefaultTypingService
|
||||||
|
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal interface RoomFactory {
|
internal interface RoomFactory {
|
||||||
|
@ -50,7 +52,9 @@ internal class DefaultRoomFactory @Inject constructor(private val monarchy: Mona
|
||||||
private val typingServiceFactory: DefaultTypingService.Factory,
|
private val typingServiceFactory: DefaultTypingService.Factory,
|
||||||
private val relationServiceFactory: DefaultRelationService.Factory,
|
private val relationServiceFactory: DefaultRelationService.Factory,
|
||||||
private val membershipServiceFactory: DefaultMembershipService.Factory,
|
private val membershipServiceFactory: DefaultMembershipService.Factory,
|
||||||
private val roomPushRuleServiceFactory: DefaultRoomPushRuleService.Factory) :
|
private val roomPushRuleServiceFactory: DefaultRoomPushRuleService.Factory,
|
||||||
|
private val taskExecutor: TaskExecutor,
|
||||||
|
private val sendStateTask: SendStateTask) :
|
||||||
RoomFactory {
|
RoomFactory {
|
||||||
|
|
||||||
override fun create(roomId: String): Room {
|
override fun create(roomId: String): Room {
|
||||||
|
@ -68,7 +72,9 @@ internal class DefaultRoomFactory @Inject constructor(private val monarchy: Mona
|
||||||
cryptoService,
|
cryptoService,
|
||||||
relationServiceFactory.create(roomId),
|
relationServiceFactory.create(roomId),
|
||||||
membershipServiceFactory.create(roomId),
|
membershipServiceFactory.create(roomId),
|
||||||
roomPushRuleServiceFactory.create(roomId)
|
roomPushRuleServiceFactory.create(roomId),
|
||||||
|
taskExecutor,
|
||||||
|
sendStateTask
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ import im.vector.matrix.android.api.session.events.model.EventType
|
||||||
import im.vector.matrix.android.api.session.room.state.StateService
|
import im.vector.matrix.android.api.session.room.state.StateService
|
||||||
import im.vector.matrix.android.api.util.Optional
|
import im.vector.matrix.android.api.util.Optional
|
||||||
import im.vector.matrix.android.api.util.toOptional
|
import im.vector.matrix.android.api.util.toOptional
|
||||||
import im.vector.matrix.android.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM
|
|
||||||
import im.vector.matrix.android.internal.database.mapper.asDomain
|
import im.vector.matrix.android.internal.database.mapper.asDomain
|
||||||
import im.vector.matrix.android.internal.database.model.EventEntity
|
import im.vector.matrix.android.internal.database.model.EventEntity
|
||||||
import im.vector.matrix.android.internal.database.query.descending
|
import im.vector.matrix.android.internal.database.query.descending
|
||||||
|
@ -36,7 +35,6 @@ import im.vector.matrix.android.internal.database.query.where
|
||||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||||
import im.vector.matrix.android.internal.task.configureWith
|
import im.vector.matrix.android.internal.task.configureWith
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
import java.security.InvalidParameterException
|
|
||||||
|
|
||||||
internal class DefaultStateService @AssistedInject constructor(@Assisted private val roomId: String,
|
internal class DefaultStateService @AssistedInject constructor(@Assisted private val roomId: String,
|
||||||
private val monarchy: Monarchy,
|
private val monarchy: Monarchy,
|
||||||
|
@ -78,22 +76,4 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
|
||||||
}
|
}
|
||||||
.executeBy(taskExecutor)
|
.executeBy(taskExecutor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun enableEncryption(algorithm: String, callback: MatrixCallback<Unit>) {
|
|
||||||
if (algorithm != MXCRYPTO_ALGORITHM_MEGOLM) {
|
|
||||||
callback.onFailure(InvalidParameterException("Only MXCRYPTO_ALGORITHM_MEGOLM algorithm is supported"))
|
|
||||||
} else {
|
|
||||||
val params = SendStateTask.Params(roomId,
|
|
||||||
EventType.STATE_ROOM_ENCRYPTION,
|
|
||||||
mapOf(
|
|
||||||
"algorithm" to algorithm
|
|
||||||
))
|
|
||||||
|
|
||||||
sendStateTask
|
|
||||||
.configureWith(params) {
|
|
||||||
this.callback = callback
|
|
||||||
}
|
|
||||||
.executeBy(taskExecutor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ import com.squareup.inject.assisted.Assisted
|
||||||
import com.squareup.inject.assisted.AssistedInject
|
import com.squareup.inject.assisted.AssistedInject
|
||||||
import im.vector.matrix.android.api.MatrixCallback
|
import im.vector.matrix.android.api.MatrixCallback
|
||||||
import im.vector.matrix.android.api.session.Session
|
import im.vector.matrix.android.api.session.Session
|
||||||
import im.vector.matrix.android.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM
|
|
||||||
import im.vector.matrix.rx.rx
|
import im.vector.matrix.rx.rx
|
||||||
import im.vector.matrix.rx.unwrap
|
import im.vector.matrix.rx.unwrap
|
||||||
import im.vector.riotx.core.platform.VectorViewModel
|
import im.vector.riotx.core.platform.VectorViewModel
|
||||||
|
@ -71,7 +70,7 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
|
||||||
copy(isLoading = true)
|
copy(isLoading = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
room.enableEncryption(MXCRYPTO_ALGORITHM_MEGOLM, object : MatrixCallback<Unit> {
|
room.enableEncryption(callback = object : MatrixCallback<Unit> {
|
||||||
override fun onFailure(failure: Throwable) {
|
override fun onFailure(failure: Throwable) {
|
||||||
setState {
|
setState {
|
||||||
copy(isLoading = false)
|
copy(isLoading = false)
|
||||||
|
|
Loading…
Reference in a new issue