Account data : define 2 services
This commit is contained in:
parent
8b138e8ff4
commit
0c6506da8c
|
@ -178,9 +178,9 @@ class RxSession(private val session: Session) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun liveUserAccountData(types: Set<String>): Observable<List<AccountDataEvent>> {
|
fun liveUserAccountData(types: Set<String>): Observable<List<AccountDataEvent>> {
|
||||||
return session.userAccountDataService().getLiveAccountDataEvents(types).asObservable()
|
return session.accountDataService().getLiveUserAccountDataEvents(types).asObservable()
|
||||||
.startWithCallable {
|
.startWithCallable {
|
||||||
session.userAccountDataService().getAccountDataEvents(types)
|
session.accountDataService().getUserAccountDataEvents(types)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ class QuadSTests : InstrumentedTest {
|
||||||
var accountData: AccountDataEvent? = null
|
var accountData: AccountDataEvent? = null
|
||||||
|
|
||||||
val liveAccountData = runBlocking(Dispatchers.Main) {
|
val liveAccountData = runBlocking(Dispatchers.Main) {
|
||||||
aliceSession.userAccountDataService().getLiveAccountDataEvent("${DefaultSharedSecretStorageService.KEY_ID_BASE}.$TEST_KEY_ID")
|
aliceSession.accountDataService().getLiveUserAccountDataEvent("${DefaultSharedSecretStorageService.KEY_ID_BASE}.$TEST_KEY_ID")
|
||||||
}
|
}
|
||||||
val accountDataObserver = Observer<Optional<AccountDataEvent>?> { t ->
|
val accountDataObserver = Observer<Optional<AccountDataEvent>?> { t ->
|
||||||
if (t?.getOrNull()?.type == "${DefaultSharedSecretStorageService.KEY_ID_BASE}.$TEST_KEY_ID") {
|
if (t?.getOrNull()?.type == "${DefaultSharedSecretStorageService.KEY_ID_BASE}.$TEST_KEY_ID") {
|
||||||
|
@ -104,7 +104,7 @@ class QuadSTests : InstrumentedTest {
|
||||||
val defaultDataLock = CountDownLatch(1)
|
val defaultDataLock = CountDownLatch(1)
|
||||||
|
|
||||||
val liveDefAccountData = runBlocking(Dispatchers.Main) {
|
val liveDefAccountData = runBlocking(Dispatchers.Main) {
|
||||||
aliceSession.userAccountDataService().getLiveAccountDataEvent(DefaultSharedSecretStorageService.DEFAULT_KEY_ID)
|
aliceSession.accountDataService().getLiveUserAccountDataEvent(DefaultSharedSecretStorageService.DEFAULT_KEY_ID)
|
||||||
}
|
}
|
||||||
val accountDefDataObserver = Observer<Optional<AccountDataEvent>?> { t ->
|
val accountDefDataObserver = Observer<Optional<AccountDataEvent>?> { t ->
|
||||||
if (t?.getOrNull()?.type == DefaultSharedSecretStorageService.DEFAULT_KEY_ID) {
|
if (t?.getOrNull()?.type == DefaultSharedSecretStorageService.DEFAULT_KEY_ID) {
|
||||||
|
@ -206,7 +206,7 @@ class QuadSTests : InstrumentedTest {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val accountDataEvent = aliceSession.userAccountDataService().getAccountDataEvent("my.secret")
|
val accountDataEvent = aliceSession.accountDataService().getUserAccountDataEvent("my.secret")
|
||||||
val encryptedContent = accountDataEvent?.content?.get("encrypted") as? Map<*, *>
|
val encryptedContent = accountDataEvent?.content?.get("encrypted") as? Map<*, *>
|
||||||
|
|
||||||
assertEquals("Content should contains two encryptions", 2, encryptedContent?.keys?.size ?: 0)
|
assertEquals("Content should contains two encryptions", 2, encryptedContent?.keys?.size ?: 0)
|
||||||
|
@ -280,7 +280,7 @@ class QuadSTests : InstrumentedTest {
|
||||||
var accountData: AccountDataEvent? = null
|
var accountData: AccountDataEvent? = null
|
||||||
|
|
||||||
val liveAccountData = runBlocking(Dispatchers.Main) {
|
val liveAccountData = runBlocking(Dispatchers.Main) {
|
||||||
session.userAccountDataService().getLiveAccountDataEvent(type)
|
session.accountDataService().getLiveUserAccountDataEvent(type)
|
||||||
}
|
}
|
||||||
val accountDataObserver = Observer<Optional<AccountDataEvent>?> { t ->
|
val accountDataObserver = Observer<Optional<AccountDataEvent>?> { t ->
|
||||||
if (t?.getOrNull()?.type == type) {
|
if (t?.getOrNull()?.type == type) {
|
||||||
|
|
|
@ -24,7 +24,7 @@ import org.matrix.android.sdk.api.failure.GlobalError
|
||||||
import org.matrix.android.sdk.api.federation.FederationService
|
import org.matrix.android.sdk.api.federation.FederationService
|
||||||
import org.matrix.android.sdk.api.pushrules.PushRuleService
|
import org.matrix.android.sdk.api.pushrules.PushRuleService
|
||||||
import org.matrix.android.sdk.api.session.account.AccountService
|
import org.matrix.android.sdk.api.session.account.AccountService
|
||||||
import org.matrix.android.sdk.api.session.accountdata.AccountDataService
|
import org.matrix.android.sdk.api.session.accountdata.SessionAccountDataService
|
||||||
import org.matrix.android.sdk.api.session.cache.CacheService
|
import org.matrix.android.sdk.api.session.cache.CacheService
|
||||||
import org.matrix.android.sdk.api.session.call.CallSignalingService
|
import org.matrix.android.sdk.api.session.call.CallSignalingService
|
||||||
import org.matrix.android.sdk.api.session.content.ContentUploadStateTracker
|
import org.matrix.android.sdk.api.session.content.ContentUploadStateTracker
|
||||||
|
@ -239,9 +239,9 @@ interface Session :
|
||||||
fun openIdService(): OpenIdService
|
fun openIdService(): OpenIdService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the user account data service associated with the session
|
* Returns the account data service associated with the session
|
||||||
*/
|
*/
|
||||||
fun userAccountDataService(): AccountDataService
|
fun accountDataService(): SessionAccountDataService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a listener to the session.
|
* Add a listener to the session.
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||||
|
*
|
||||||
|
* 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.api.session.accountdata
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import org.matrix.android.sdk.api.session.events.model.Content
|
||||||
|
import org.matrix.android.sdk.api.util.Optional
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This service is attached globally to the session.
|
||||||
|
*/
|
||||||
|
interface SessionAccountDataService {
|
||||||
|
/**
|
||||||
|
* Retrieve the account data with the provided type or null if not found
|
||||||
|
*/
|
||||||
|
fun getUserAccountDataEvent(type: String): AccountDataEvent?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Observe the account data with the provided type
|
||||||
|
*/
|
||||||
|
fun getLiveUserAccountDataEvent(type: String): LiveData<Optional<AccountDataEvent>>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the account data with the provided types. The return list can have a different size that
|
||||||
|
* the size of the types set, because some AccountData may not exist.
|
||||||
|
* If an empty set is provided, all the AccountData are retrieved
|
||||||
|
*/
|
||||||
|
fun getUserAccountDataEvents(types: Set<String>): List<AccountDataEvent>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Observe the account data with the provided types. If an empty set is provided, all the AccountData are observed
|
||||||
|
*/
|
||||||
|
fun getLiveUserAccountDataEvents(types: Set<String>): LiveData<List<AccountDataEvent>>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the account data with the provided type and the provided account data content
|
||||||
|
*/
|
||||||
|
suspend fun updateUserAccountData(type: String, content: Content)
|
||||||
|
}
|
|
@ -17,7 +17,8 @@
|
||||||
package org.matrix.android.sdk.api.session.room
|
package org.matrix.android.sdk.api.session.room
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import org.matrix.android.sdk.api.session.accountdata.AccountDataService
|
import org.matrix.android.sdk.api.session.accountdata.SessionAccountDataService
|
||||||
|
import org.matrix.android.sdk.api.session.room.accountdata.RoomAccountDataService
|
||||||
import org.matrix.android.sdk.api.session.room.alias.AliasService
|
import org.matrix.android.sdk.api.session.room.alias.AliasService
|
||||||
import org.matrix.android.sdk.api.session.room.call.RoomCallService
|
import org.matrix.android.sdk.api.session.room.call.RoomCallService
|
||||||
import org.matrix.android.sdk.api.session.room.crypto.RoomCryptoService
|
import org.matrix.android.sdk.api.session.room.crypto.RoomCryptoService
|
||||||
|
@ -57,7 +58,7 @@ interface Room :
|
||||||
RelationService,
|
RelationService,
|
||||||
RoomCryptoService,
|
RoomCryptoService,
|
||||||
RoomPushRuleService,
|
RoomPushRuleService,
|
||||||
AccountDataService {
|
RoomAccountDataService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The roomId of this room
|
* The roomId of this room
|
||||||
|
|
|
@ -14,16 +14,17 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.matrix.android.sdk.api.session.accountdata
|
package org.matrix.android.sdk.api.session.room.accountdata
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
|
import org.matrix.android.sdk.api.session.accountdata.AccountDataEvent
|
||||||
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.util.Optional
|
import org.matrix.android.sdk.api.util.Optional
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This service can be attached globally to the session so it represents user data or attached to a single room.
|
* This service is attached to a single room.
|
||||||
*/
|
*/
|
||||||
interface AccountDataService {
|
interface RoomAccountDataService {
|
||||||
/**
|
/**
|
||||||
* Retrieve the account data with the provided type or null if not found
|
* Retrieve the account data with the provided type or null if not found
|
||||||
*/
|
*/
|
|
@ -18,7 +18,7 @@ package org.matrix.android.sdk.internal.crypto.secrets
|
||||||
|
|
||||||
import org.matrix.android.sdk.api.extensions.orFalse
|
import org.matrix.android.sdk.api.extensions.orFalse
|
||||||
import org.matrix.android.sdk.api.listeners.ProgressListener
|
import org.matrix.android.sdk.api.listeners.ProgressListener
|
||||||
import org.matrix.android.sdk.api.session.accountdata.AccountDataService
|
import org.matrix.android.sdk.api.session.accountdata.SessionAccountDataService
|
||||||
import org.matrix.android.sdk.api.session.events.model.toContent
|
import org.matrix.android.sdk.api.session.events.model.toContent
|
||||||
import org.matrix.android.sdk.api.session.securestorage.EncryptedSecretContent
|
import org.matrix.android.sdk.api.session.securestorage.EncryptedSecretContent
|
||||||
import org.matrix.android.sdk.api.session.securestorage.IntegrityResult
|
import org.matrix.android.sdk.api.session.securestorage.IntegrityResult
|
||||||
|
@ -56,7 +56,7 @@ import kotlin.experimental.and
|
||||||
|
|
||||||
internal class DefaultSharedSecretStorageService @Inject constructor(
|
internal class DefaultSharedSecretStorageService @Inject constructor(
|
||||||
@UserId private val userId: String,
|
@UserId private val userId: String,
|
||||||
private val accountDataService: AccountDataService,
|
private val accountDataService: SessionAccountDataService,
|
||||||
private val outgoingGossipingRequestManager: OutgoingGossipingRequestManager,
|
private val outgoingGossipingRequestManager: OutgoingGossipingRequestManager,
|
||||||
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
||||||
private val cryptoCoroutineScope: CoroutineScope
|
private val cryptoCoroutineScope: CoroutineScope
|
||||||
|
@ -84,7 +84,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
|
||||||
)
|
)
|
||||||
} ?: storageKeyContent
|
} ?: storageKeyContent
|
||||||
|
|
||||||
accountDataService.updateAccountData("$KEY_ID_BASE.$keyId", signedContent.toContent())
|
accountDataService.updateUserAccountData("$KEY_ID_BASE.$keyId", signedContent.toContent())
|
||||||
SsssKeyCreationInfo(
|
SsssKeyCreationInfo(
|
||||||
keyId = keyId,
|
keyId = keyId,
|
||||||
content = storageKeyContent,
|
content = storageKeyContent,
|
||||||
|
@ -113,7 +113,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
|
||||||
)
|
)
|
||||||
} ?: storageKeyContent
|
} ?: storageKeyContent
|
||||||
|
|
||||||
accountDataService.updateAccountData(
|
accountDataService.updateUserAccountData(
|
||||||
"$KEY_ID_BASE.$keyId",
|
"$KEY_ID_BASE.$keyId",
|
||||||
signedContent.toContent()
|
signedContent.toContent()
|
||||||
)
|
)
|
||||||
|
@ -127,11 +127,11 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hasKey(keyId: String): Boolean {
|
override fun hasKey(keyId: String): Boolean {
|
||||||
return accountDataService.getAccountDataEvent("$KEY_ID_BASE.$keyId") != null
|
return accountDataService.getUserAccountDataEvent("$KEY_ID_BASE.$keyId") != null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getKey(keyId: String): KeyInfoResult {
|
override fun getKey(keyId: String): KeyInfoResult {
|
||||||
val accountData = accountDataService.getAccountDataEvent("$KEY_ID_BASE.$keyId")
|
val accountData = accountDataService.getUserAccountDataEvent("$KEY_ID_BASE.$keyId")
|
||||||
?: return KeyInfoResult.Error(SharedSecretStorageError.UnknownKey(keyId))
|
?: return KeyInfoResult.Error(SharedSecretStorageError.UnknownKey(keyId))
|
||||||
return SecretStorageKeyContent.fromJson(accountData.content)?.let {
|
return SecretStorageKeyContent.fromJson(accountData.content)?.let {
|
||||||
KeyInfoResult.Success(
|
KeyInfoResult.Success(
|
||||||
|
@ -143,14 +143,14 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
|
||||||
override suspend fun setDefaultKey(keyId: String) {
|
override suspend fun setDefaultKey(keyId: String) {
|
||||||
val existingKey = getKey(keyId)
|
val existingKey = getKey(keyId)
|
||||||
if (existingKey is KeyInfoResult.Success) {
|
if (existingKey is KeyInfoResult.Success) {
|
||||||
accountDataService.updateAccountData(DEFAULT_KEY_ID, mapOf("key" to keyId))
|
accountDataService.updateUserAccountData(DEFAULT_KEY_ID, mapOf("key" to keyId))
|
||||||
} else {
|
} else {
|
||||||
throw SharedSecretStorageError.UnknownKey(keyId)
|
throw SharedSecretStorageError.UnknownKey(keyId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getDefaultKey(): KeyInfoResult {
|
override fun getDefaultKey(): KeyInfoResult {
|
||||||
val accountData = accountDataService.getAccountDataEvent(DEFAULT_KEY_ID)
|
val accountData = accountDataService.getUserAccountDataEvent(DEFAULT_KEY_ID)
|
||||||
?: return KeyInfoResult.Error(SharedSecretStorageError.UnknownKey(DEFAULT_KEY_ID))
|
?: return KeyInfoResult.Error(SharedSecretStorageError.UnknownKey(DEFAULT_KEY_ID))
|
||||||
val keyId = accountData.content["key"] as? String
|
val keyId = accountData.content["key"] as? String
|
||||||
?: return KeyInfoResult.Error(SharedSecretStorageError.UnknownKey(DEFAULT_KEY_ID))
|
?: return KeyInfoResult.Error(SharedSecretStorageError.UnknownKey(DEFAULT_KEY_ID))
|
||||||
|
@ -178,7 +178,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
accountDataService.updateAccountData(
|
accountDataService.updateUserAccountData(
|
||||||
type = name,
|
type = name,
|
||||||
content = mapOf("encrypted" to encryptedContents)
|
content = mapOf("encrypted" to encryptedContents)
|
||||||
)
|
)
|
||||||
|
@ -288,7 +288,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAlgorithmsForSecret(name: String): List<KeyInfoResult> {
|
override fun getAlgorithmsForSecret(name: String): List<KeyInfoResult> {
|
||||||
val accountData = accountDataService.getAccountDataEvent(name)
|
val accountData = accountDataService.getUserAccountDataEvent(name)
|
||||||
?: return listOf(KeyInfoResult.Error(SharedSecretStorageError.UnknownSecret(name)))
|
?: return listOf(KeyInfoResult.Error(SharedSecretStorageError.UnknownSecret(name)))
|
||||||
val encryptedContent = accountData.content[ENCRYPTED] as? Map<*, *>
|
val encryptedContent = accountData.content[ENCRYPTED] as? Map<*, *>
|
||||||
?: return listOf(KeyInfoResult.Error(SharedSecretStorageError.SecretNotEncrypted(name)))
|
?: return listOf(KeyInfoResult.Error(SharedSecretStorageError.SecretNotEncrypted(name)))
|
||||||
|
@ -303,7 +303,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getSecret(name: String, keyId: String?, secretKey: SsssKeySpec): String {
|
override suspend fun getSecret(name: String, keyId: String?, secretKey: SsssKeySpec): String {
|
||||||
val accountData = accountDataService.getAccountDataEvent(name) ?: throw SharedSecretStorageError.UnknownSecret(name)
|
val accountData = accountDataService.getUserAccountDataEvent(name) ?: throw SharedSecretStorageError.UnknownSecret(name)
|
||||||
val encryptedContent = accountData.content[ENCRYPTED] as? Map<*, *> ?: throw SharedSecretStorageError.SecretNotEncrypted(name)
|
val encryptedContent = accountData.content[ENCRYPTED] as? Map<*, *> ?: throw SharedSecretStorageError.SecretNotEncrypted(name)
|
||||||
val key = keyId?.let { getKey(it) } as? KeyInfoResult.Success ?: getDefaultKey() as? KeyInfoResult.Success
|
val key = keyId?.let { getKey(it) } as? KeyInfoResult.Success ?: getDefaultKey() as? KeyInfoResult.Success
|
||||||
?: throw SharedSecretStorageError.UnknownKey(name)
|
?: throw SharedSecretStorageError.UnknownKey(name)
|
||||||
|
@ -368,7 +368,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
secretNames.forEach { secretName ->
|
secretNames.forEach { secretName ->
|
||||||
val secretEvent = accountDataService.getAccountDataEvent(secretName)
|
val secretEvent = accountDataService.getUserAccountDataEvent(secretName)
|
||||||
?: return IntegrityResult.Error(SharedSecretStorageError.UnknownSecret(secretName))
|
?: return IntegrityResult.Error(SharedSecretStorageError.UnknownSecret(secretName))
|
||||||
if ((secretEvent.content["encrypted"] as? Map<*, *>)?.get(keyInfo.id) == null) {
|
if ((secretEvent.content["encrypted"] as? Map<*, *>)?.get(keyInfo.id) == null) {
|
||||||
return IntegrityResult.Error(SharedSecretStorageError.SecretNotEncryptedWithKey(secretName, keyInfo.id))
|
return IntegrityResult.Error(SharedSecretStorageError.SecretNotEncryptedWithKey(secretName, keyInfo.id))
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.matrix.android.sdk.api.pushrules.PushRuleService
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.SessionLifecycleObserver
|
import org.matrix.android.sdk.api.session.SessionLifecycleObserver
|
||||||
import org.matrix.android.sdk.api.session.account.AccountService
|
import org.matrix.android.sdk.api.session.account.AccountService
|
||||||
import org.matrix.android.sdk.api.session.accountdata.AccountDataService
|
import org.matrix.android.sdk.api.session.accountdata.SessionAccountDataService
|
||||||
import org.matrix.android.sdk.api.session.cache.CacheService
|
import org.matrix.android.sdk.api.session.cache.CacheService
|
||||||
import org.matrix.android.sdk.api.session.call.CallSignalingService
|
import org.matrix.android.sdk.api.session.call.CallSignalingService
|
||||||
import org.matrix.android.sdk.api.session.content.ContentUploadStateTracker
|
import org.matrix.android.sdk.api.session.content.ContentUploadStateTracker
|
||||||
|
@ -74,7 +74,6 @@ import org.matrix.android.sdk.internal.session.identity.DefaultIdentityService
|
||||||
import org.matrix.android.sdk.internal.session.sync.SyncTokenStore
|
import org.matrix.android.sdk.internal.session.sync.SyncTokenStore
|
||||||
import org.matrix.android.sdk.internal.session.sync.job.SyncThread
|
import org.matrix.android.sdk.internal.session.sync.job.SyncThread
|
||||||
import org.matrix.android.sdk.internal.session.sync.job.SyncWorker
|
import org.matrix.android.sdk.internal.session.sync.job.SyncWorker
|
||||||
import org.matrix.android.sdk.internal.session.user.accountdata.UserAccountDataService
|
|
||||||
import org.matrix.android.sdk.internal.util.createUIHandler
|
import org.matrix.android.sdk.internal.util.createUIHandler
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -118,7 +117,7 @@ internal class DefaultSession @Inject constructor(
|
||||||
private val contentDownloadStateTracker: ContentDownloadStateTracker,
|
private val contentDownloadStateTracker: ContentDownloadStateTracker,
|
||||||
private val initialSyncProgressService: Lazy<InitialSyncProgressService>,
|
private val initialSyncProgressService: Lazy<InitialSyncProgressService>,
|
||||||
private val homeServerCapabilitiesService: Lazy<HomeServerCapabilitiesService>,
|
private val homeServerCapabilitiesService: Lazy<HomeServerCapabilitiesService>,
|
||||||
private val accountDataService: Lazy<UserAccountDataService>,
|
private val accountDataService: Lazy<SessionAccountDataService>,
|
||||||
private val _sharedSecretStorageService: Lazy<SharedSecretStorageService>,
|
private val _sharedSecretStorageService: Lazy<SharedSecretStorageService>,
|
||||||
private val accountService: Lazy<AccountService>,
|
private val accountService: Lazy<AccountService>,
|
||||||
private val eventService: Lazy<EventService>,
|
private val eventService: Lazy<EventService>,
|
||||||
|
@ -293,7 +292,7 @@ internal class DefaultSession @Inject constructor(
|
||||||
|
|
||||||
override fun openIdService(): OpenIdService = openIdService.get()
|
override fun openIdService(): OpenIdService = openIdService.get()
|
||||||
|
|
||||||
override fun userAccountDataService(): AccountDataService = accountDataService.get()
|
override fun accountDataService(): SessionAccountDataService = accountDataService.get()
|
||||||
|
|
||||||
override fun getOkHttpClient(): OkHttpClient {
|
override fun getOkHttpClient(): OkHttpClient {
|
||||||
return unauthenticatedWithCertificateOkHttpClient.get()
|
return unauthenticatedWithCertificateOkHttpClient.get()
|
||||||
|
|
|
@ -34,7 +34,7 @@ import org.matrix.android.sdk.api.auth.data.sessionId
|
||||||
import org.matrix.android.sdk.api.crypto.MXCryptoConfig
|
import org.matrix.android.sdk.api.crypto.MXCryptoConfig
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.SessionLifecycleObserver
|
import org.matrix.android.sdk.api.session.SessionLifecycleObserver
|
||||||
import org.matrix.android.sdk.api.session.accountdata.AccountDataService
|
import org.matrix.android.sdk.api.session.accountdata.SessionAccountDataService
|
||||||
import org.matrix.android.sdk.api.session.events.EventService
|
import org.matrix.android.sdk.api.session.events.EventService
|
||||||
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilitiesService
|
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilitiesService
|
||||||
import org.matrix.android.sdk.api.session.initsync.InitialSyncProgressService
|
import org.matrix.android.sdk.api.session.initsync.InitialSyncProgressService
|
||||||
|
@ -93,7 +93,7 @@ import org.matrix.android.sdk.internal.session.room.send.queue.EventSenderProces
|
||||||
import org.matrix.android.sdk.internal.session.room.tombstone.RoomTombstoneEventProcessor
|
import org.matrix.android.sdk.internal.session.room.tombstone.RoomTombstoneEventProcessor
|
||||||
import org.matrix.android.sdk.internal.session.securestorage.DefaultSecureStorageService
|
import org.matrix.android.sdk.internal.session.securestorage.DefaultSecureStorageService
|
||||||
import org.matrix.android.sdk.internal.session.typing.DefaultTypingUsersTracker
|
import org.matrix.android.sdk.internal.session.typing.DefaultTypingUsersTracker
|
||||||
import org.matrix.android.sdk.internal.session.user.accountdata.UserAccountDataService
|
import org.matrix.android.sdk.internal.session.user.accountdata.DefaultSessionAccountDataService
|
||||||
import org.matrix.android.sdk.internal.session.widgets.DefaultWidgetURLFormatter
|
import org.matrix.android.sdk.internal.session.widgets.DefaultWidgetURLFormatter
|
||||||
import org.matrix.android.sdk.internal.util.md5
|
import org.matrix.android.sdk.internal.util.md5
|
||||||
import retrofit2.Retrofit
|
import retrofit2.Retrofit
|
||||||
|
@ -364,7 +364,7 @@ internal abstract class SessionModule {
|
||||||
abstract fun bindHomeServerCapabilitiesService(service: DefaultHomeServerCapabilitiesService): HomeServerCapabilitiesService
|
abstract fun bindHomeServerCapabilitiesService(service: DefaultHomeServerCapabilitiesService): HomeServerCapabilitiesService
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
abstract fun bindAccountDataService(service: UserAccountDataService): AccountDataService
|
abstract fun bindSessionAccountDataService(service: DefaultSessionAccountDataService): SessionAccountDataService
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
abstract fun bindEventService(service: DefaultEventService): EventService
|
abstract fun bindEventService(service: DefaultEventService): EventService
|
||||||
|
|
|
@ -17,10 +17,11 @@
|
||||||
package org.matrix.android.sdk.internal.session.room
|
package org.matrix.android.sdk.internal.session.room
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import org.matrix.android.sdk.api.session.accountdata.AccountDataService
|
import org.matrix.android.sdk.api.session.accountdata.SessionAccountDataService
|
||||||
import org.matrix.android.sdk.api.session.crypto.CryptoService
|
import org.matrix.android.sdk.api.session.crypto.CryptoService
|
||||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||||
import org.matrix.android.sdk.api.session.room.Room
|
import org.matrix.android.sdk.api.session.room.Room
|
||||||
|
import org.matrix.android.sdk.api.session.room.accountdata.RoomAccountDataService
|
||||||
import org.matrix.android.sdk.api.session.room.alias.AliasService
|
import org.matrix.android.sdk.api.session.room.alias.AliasService
|
||||||
import org.matrix.android.sdk.api.session.room.call.RoomCallService
|
import org.matrix.android.sdk.api.session.room.call.RoomCallService
|
||||||
import org.matrix.android.sdk.api.session.room.members.MembershipService
|
import org.matrix.android.sdk.api.session.room.members.MembershipService
|
||||||
|
@ -42,7 +43,6 @@ import org.matrix.android.sdk.api.session.space.Space
|
||||||
import org.matrix.android.sdk.api.util.Optional
|
import org.matrix.android.sdk.api.util.Optional
|
||||||
import org.matrix.android.sdk.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM
|
import org.matrix.android.sdk.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM
|
||||||
import org.matrix.android.sdk.internal.session.permalinks.ViaParameterFinder
|
import org.matrix.android.sdk.internal.session.permalinks.ViaParameterFinder
|
||||||
import org.matrix.android.sdk.internal.session.room.accountdata.RoomAccountDataService
|
|
||||||
import org.matrix.android.sdk.internal.session.room.state.SendStateTask
|
import org.matrix.android.sdk.internal.session.room.state.SendStateTask
|
||||||
import org.matrix.android.sdk.internal.session.room.summary.RoomSummaryDataSource
|
import org.matrix.android.sdk.internal.session.room.summary.RoomSummaryDataSource
|
||||||
import org.matrix.android.sdk.internal.session.search.SearchTask
|
import org.matrix.android.sdk.internal.session.search.SearchTask
|
||||||
|
@ -86,7 +86,7 @@ internal class DefaultRoom(override val roomId: String,
|
||||||
RelationService by relationService,
|
RelationService by relationService,
|
||||||
MembershipService by roomMembersService,
|
MembershipService by roomMembersService,
|
||||||
RoomPushRuleService by roomPushRuleService,
|
RoomPushRuleService by roomPushRuleService,
|
||||||
AccountDataService by roomAccountDataService {
|
RoomAccountDataService by roomAccountDataService {
|
||||||
|
|
||||||
override fun getRoomSummaryLive(): LiveData<Optional<RoomSummary>> {
|
override fun getRoomSummaryLive(): LiveData<Optional<RoomSummary>> {
|
||||||
return roomSummaryDataSource.getRoomSummaryLive(roomId)
|
return roomSummaryDataSource.getRoomSummaryLive(roomId)
|
||||||
|
|
|
@ -19,8 +19,8 @@ package org.matrix.android.sdk.internal.session.room
|
||||||
import org.matrix.android.sdk.api.session.crypto.CryptoService
|
import org.matrix.android.sdk.api.session.crypto.CryptoService
|
||||||
import org.matrix.android.sdk.api.session.room.Room
|
import org.matrix.android.sdk.api.session.room.Room
|
||||||
import org.matrix.android.sdk.internal.session.SessionScope
|
import org.matrix.android.sdk.internal.session.SessionScope
|
||||||
import org.matrix.android.sdk.internal.session.room.accountdata.RoomAccountDataService
|
|
||||||
import org.matrix.android.sdk.internal.session.permalinks.ViaParameterFinder
|
import org.matrix.android.sdk.internal.session.permalinks.ViaParameterFinder
|
||||||
|
import org.matrix.android.sdk.internal.session.room.accountdata.DefaultRoomAccountDataService
|
||||||
import org.matrix.android.sdk.internal.session.room.alias.DefaultAliasService
|
import org.matrix.android.sdk.internal.session.room.alias.DefaultAliasService
|
||||||
import org.matrix.android.sdk.internal.session.room.call.DefaultRoomCallService
|
import org.matrix.android.sdk.internal.session.room.call.DefaultRoomCallService
|
||||||
import org.matrix.android.sdk.internal.session.room.draft.DefaultDraftService
|
import org.matrix.android.sdk.internal.session.room.draft.DefaultDraftService
|
||||||
|
@ -61,7 +61,7 @@ internal class DefaultRoomFactory @Inject constructor(private val cryptoService:
|
||||||
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 roomAccountDataServiceFactory: RoomAccountDataService.Factory,
|
private val roomAccountDataServiceFactory: DefaultRoomAccountDataService.Factory,
|
||||||
private val sendStateTask: SendStateTask,
|
private val sendStateTask: SendStateTask,
|
||||||
private val viaParameterFinder: ViaParameterFinder,
|
private val viaParameterFinder: ViaParameterFinder,
|
||||||
private val searchTask: SearchTask) :
|
private val searchTask: SearchTask) :
|
||||||
|
|
|
@ -21,18 +21,19 @@ import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import org.matrix.android.sdk.api.session.accountdata.AccountDataEvent
|
import org.matrix.android.sdk.api.session.accountdata.AccountDataEvent
|
||||||
import org.matrix.android.sdk.api.session.accountdata.AccountDataService
|
import org.matrix.android.sdk.api.session.accountdata.SessionAccountDataService
|
||||||
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.room.accountdata.RoomAccountDataService
|
||||||
import org.matrix.android.sdk.api.util.Optional
|
import org.matrix.android.sdk.api.util.Optional
|
||||||
|
|
||||||
internal class RoomAccountDataService @AssistedInject constructor(@Assisted private val roomId: String,
|
internal class DefaultRoomAccountDataService @AssistedInject constructor(@Assisted private val roomId: String,
|
||||||
private val dataSource: RoomAccountDataDataSource,
|
private val dataSource: RoomAccountDataDataSource,
|
||||||
private val updateRoomAccountDataTask: UpdateRoomAccountDataTask
|
private val updateRoomAccountDataTask: UpdateRoomAccountDataTask
|
||||||
) : AccountDataService {
|
) : RoomAccountDataService {
|
||||||
|
|
||||||
@AssistedFactory
|
@AssistedFactory
|
||||||
interface Factory {
|
interface Factory {
|
||||||
fun create(roomId: String): RoomAccountDataService
|
fun create(roomId: String): DefaultRoomAccountDataService
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAccountDataEvent(type: String): AccountDataEvent? {
|
override fun getAccountDataEvent(type: String): AccountDataEvent? {
|
||||||
|
|
|
@ -18,7 +18,7 @@ package org.matrix.android.sdk.internal.session.user.accountdata
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import org.matrix.android.sdk.api.session.accountdata.AccountDataService
|
import org.matrix.android.sdk.api.session.accountdata.SessionAccountDataService
|
||||||
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.util.Optional
|
import org.matrix.android.sdk.api.util.Optional
|
||||||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
import org.matrix.android.sdk.internal.di.SessionDatabase
|
||||||
|
@ -29,31 +29,31 @@ import org.matrix.android.sdk.internal.task.configureWith
|
||||||
import org.matrix.android.sdk.internal.util.awaitCallback
|
import org.matrix.android.sdk.internal.util.awaitCallback
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal class UserAccountDataService @Inject constructor(
|
internal class DefaultSessionAccountDataService @Inject constructor(
|
||||||
@SessionDatabase private val monarchy: Monarchy,
|
@SessionDatabase private val monarchy: Monarchy,
|
||||||
private val updateUserAccountDataTask: UpdateUserAccountDataTask,
|
private val updateUserAccountDataTask: UpdateUserAccountDataTask,
|
||||||
private val userAccountDataSyncHandler: UserAccountDataSyncHandler,
|
private val userAccountDataSyncHandler: UserAccountDataSyncHandler,
|
||||||
private val accountDataDataSource: UserAccountDataDataSource,
|
private val accountDataDataSource: UserAccountDataDataSource,
|
||||||
private val taskExecutor: TaskExecutor
|
private val taskExecutor: TaskExecutor
|
||||||
) : AccountDataService {
|
) : SessionAccountDataService {
|
||||||
|
|
||||||
override fun getAccountDataEvent(type: String): AccountDataEvent? {
|
override fun getUserAccountDataEvent(type: String): AccountDataEvent? {
|
||||||
return accountDataDataSource.getAccountDataEvent(type)
|
return accountDataDataSource.getAccountDataEvent(type)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getLiveAccountDataEvent(type: String): LiveData<Optional<AccountDataEvent>> {
|
override fun getLiveUserAccountDataEvent(type: String): LiveData<Optional<AccountDataEvent>> {
|
||||||
return accountDataDataSource.getLiveAccountDataEvent(type)
|
return accountDataDataSource.getLiveAccountDataEvent(type)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAccountDataEvents(types: Set<String>): List<AccountDataEvent> {
|
override fun getUserAccountDataEvents(types: Set<String>): List<AccountDataEvent> {
|
||||||
return accountDataDataSource.getAccountDataEvents(types)
|
return accountDataDataSource.getAccountDataEvents(types)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getLiveAccountDataEvents(types: Set<String>): LiveData<List<AccountDataEvent>> {
|
override fun getLiveUserAccountDataEvents(types: Set<String>): LiveData<List<AccountDataEvent>> {
|
||||||
return accountDataDataSource.getLiveAccountDataEvents(types)
|
return accountDataDataSource.getLiveAccountDataEvents(types)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun updateAccountData(type: String, content: Content) {
|
override suspend fun updateUserAccountData(type: String, content: Content) {
|
||||||
val params = UpdateUserAccountDataTask.AnyParams(type = type, any = content)
|
val params = UpdateUserAccountDataTask.AnyParams(type = type, any = content)
|
||||||
awaitCallback<Unit> { callback ->
|
awaitCallback<Unit> { callback ->
|
||||||
updateUserAccountDataTask.configureWith(params) {
|
updateUserAccountDataTask.configureWith(params) {
|
|
@ -252,7 +252,7 @@ class KeysBackupRestoreSharedViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isBackupKeyInQuadS(): Boolean {
|
private fun isBackupKeyInQuadS(): Boolean {
|
||||||
val sssBackupSecret = session.userAccountDataService().getAccountDataEvent(KEYBACKUP_SECRET_SSSS_NAME)
|
val sssBackupSecret = session.accountDataService().getUserAccountDataEvent(KEYBACKUP_SECRET_SSSS_NAME)
|
||||||
?: return false
|
?: return false
|
||||||
|
|
||||||
// Some sanity ?
|
// Some sanity ?
|
||||||
|
|
|
@ -218,7 +218,7 @@ class SharedSecureStorageViewModel @AssistedInject constructor(
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
args.requestedSecrets.forEach {
|
args.requestedSecrets.forEach {
|
||||||
if (session.userAccountDataService().getAccountDataEvent(it) != null) {
|
if (session.accountDataService().getUserAccountDataEvent(it) != null) {
|
||||||
val res = session.sharedSecretStorageService.getSecret(
|
val res = session.sharedSecretStorageService.getSecret(
|
||||||
name = it,
|
name = it,
|
||||||
keyId = keyInfo.id,
|
keyId = keyInfo.id,
|
||||||
|
@ -287,7 +287,7 @@ class SharedSecureStorageViewModel @AssistedInject constructor(
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
args.requestedSecrets.forEach {
|
args.requestedSecrets.forEach {
|
||||||
if (session.userAccountDataService().getAccountDataEvent(it) != null) {
|
if (session.accountDataService().getUserAccountDataEvent(it) != null) {
|
||||||
val res = session.sharedSecretStorageService.getSecret(
|
val res = session.sharedSecretStorageService.getSecret(
|
||||||
name = it,
|
name = it,
|
||||||
keyId = keyInfo.id,
|
keyId = keyInfo.id,
|
||||||
|
|
|
@ -57,7 +57,7 @@ class AccountDataViewModel @AssistedInject constructor(@Assisted initialState: A
|
||||||
|
|
||||||
private fun handleDeleteAccountData(action: AccountDataAction.DeleteAccountData) {
|
private fun handleDeleteAccountData(action: AccountDataAction.DeleteAccountData) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
session.userAccountDataService().updateAccountData(action.type, emptyMap())
|
session.accountDataService().updateUserAccountData(action.type, emptyMap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -284,7 +284,7 @@ class WidgetPostAPIHandler @AssistedInject constructor(@Assisted private val roo
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
launchWidgetAPIAction(widgetPostAPIMediator, eventData) {
|
launchWidgetAPIAction(widgetPostAPIMediator, eventData) {
|
||||||
session.userAccountDataService().updateAccountData(
|
session.accountDataService().updateUserAccountData(
|
||||||
type = UserAccountDataTypes.TYPE_WIDGETS,
|
type = UserAccountDataTypes.TYPE_WIDGETS,
|
||||||
content = addUserWidgetBody
|
content = addUserWidgetBody
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue