From acd7a709de183c114feaeefb9de9a0e050ca4922 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 20 Sep 2019 10:19:56 +0200 Subject: [PATCH] Dagger: create @UserId to inject userId --- .../room/model/create/CreateRoomParams.kt | 5 ++-- .../actions/SetDeviceVerificationAction.kt | 7 ++--- .../algorithms/megolm/MXMegolmDecryption.kt | 7 +++-- .../megolm/MXMegolmDecryptionFactory.kt | 7 ++--- .../crypto/algorithms/olm/MXOlmDecryption.kt | 9 +++---- .../algorithms/olm/MXOlmDecryptionFactory.kt | 7 ++--- .../tasks/DeleteDeviceWithUserPasswordTask.kt | 7 ++--- .../android/internal/di/StringQualifiers.kt | 12 ++++++++- .../internal/session/DefaultFileService.kt | 7 ++--- .../android/internal/session/SessionModule.kt | 11 ++++++-- .../session/filter/DefaultSaveFilterTask.kt | 7 ++--- .../session/group/GroupSummaryUpdater.kt | 8 +++--- .../notification/DefaultPushRuleService.kt | 19 +++++++------- .../notification/ProcessEventForPushTask.kt | 9 ++++--- .../pushers/DefaultConditionResolver.kt | 8 +++--- .../session/pushers/DefaultPusherService.kt | 26 +++++++++---------- .../session/pushers/GetPushRulesTask.kt | 17 ++++++------ .../session/pushers/GetPushersTask.kt | 9 ++++--- .../room/EventRelationsAggregationUpdater.kt | 7 ++--- .../session/room/RoomAvatarResolver.kt | 7 ++--- .../session/room/RoomSummaryUpdater.kt | 9 ++++--- .../membership/RoomDisplayNameResolver.kt | 9 ++++--- .../session/room/prune/EventsPruner.kt | 7 ++--- .../session/room/read/DefaultReadService.kt | 7 ++--- .../session/room/read/SetReadMarkersTask.kt | 7 ++--- .../room/relation/DefaultRelationService.kt | 11 ++++---- .../session/room/send/DefaultSendService.kt | 23 +++++++--------- .../room/send/LocalEchoEventFactory.kt | 13 +++++----- .../internal/session/signout/SignOutTask.kt | 13 ++++------ .../android/internal/session/sync/SyncTask.kt | 7 ++--- .../sync/UserAccountDataSyncHandler.kt | 9 ++++--- .../accountdata/UpdateUserAccountDataTask.kt | 7 ++--- .../crypto/keysrequest/KeyRequestHandler.kt | 2 +- .../IncomingVerificationRequestHandler.kt | 4 +-- 34 files changed, 178 insertions(+), 146 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/create/CreateRoomParams.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/create/CreateRoomParams.kt index cdc1c9527e..c707f3c3ef 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/create/CreateRoomParams.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/create/CreateRoomParams.kt @@ -20,7 +20,6 @@ import android.util.Patterns import com.squareup.moshi.Json import com.squareup.moshi.JsonClass import im.vector.matrix.android.api.MatrixPatterns.isUserId -import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.EventType @@ -219,7 +218,7 @@ class CreateRoomParams { * @param ids the participant ids to add. */ fun addParticipantIds(hsConfig: HomeServerConnectionConfig, - credentials: Credentials, + userId: String, ids: List) { for (id in ids) { if (Patterns.EMAIL_ADDRESS.matcher(id).matches() && hsConfig.identityServerUri != null) { @@ -233,7 +232,7 @@ class CreateRoomParams { invite3pids!!.add(pid) } else if (isUserId(id)) { // do not invite oneself - if (credentials.userId != id) { + if (userId != id) { if (null == invitedUserIds) { invitedUserIds = ArrayList() } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/SetDeviceVerificationAction.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/SetDeviceVerificationAction.kt index d5c41769ef..6cfd398bbc 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/SetDeviceVerificationAction.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/SetDeviceVerificationAction.kt @@ -16,14 +16,15 @@ package im.vector.matrix.android.internal.crypto.actions -import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.internal.crypto.keysbackup.KeysBackup import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore +import im.vector.matrix.android.internal.di.UserId import timber.log.Timber import javax.inject.Inject internal class SetDeviceVerificationAction @Inject constructor(private val cryptoStore: IMXCryptoStore, - private val credentials: Credentials, + @UserId + private val userId: String, private val keysBackup: KeysBackup) { fun handle(verificationStatus: Int, deviceId: String, userId: String) { @@ -39,7 +40,7 @@ internal class SetDeviceVerificationAction @Inject constructor(private val crypt device.verified = verificationStatus cryptoStore.storeUserDevice(userId, device) - if (userId == credentials.userId) { + if (userId == this.userId) { // If one of the user's own devices is being marked as verified / unverified, // check the key backup status, since whether or not we use this depends on // whether it has a signature from a verified device diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt index 47bf9956b9..c518872d44 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt @@ -18,7 +18,6 @@ package im.vector.matrix.android.internal.crypto.algorithms.megolm import android.text.TextUtils -import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.session.crypto.MXCryptoError import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.EventType @@ -40,7 +39,7 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import timber.log.Timber -internal class MXMegolmDecryption(private val credentials: Credentials, +internal class MXMegolmDecryption(private val userId: String, private val olmDevice: MXOlmDevice, private val deviceListManager: DeviceListManager, private val outgoingRoomKeyRequestManager: OutgoingRoomKeyRequestManager, @@ -146,11 +145,11 @@ internal class MXMegolmDecryption(private val credentials: Credentials, val selfMap = HashMap() // TODO Replace this hard coded keys (see OutgoingRoomKeyRequestManager) - selfMap["userId"] = credentials.userId + selfMap["userId"] = userId selfMap["deviceId"] = "*" recipients.add(selfMap) - if (!TextUtils.equals(sender, credentials.userId)) { + if (!TextUtils.equals(sender, userId)) { val senderMap = HashMap() senderMap["userId"] = sender senderMap["deviceId"] = encryptedEventContent.deviceId!! diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryptionFactory.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryptionFactory.kt index 11c43649e9..3231abb125 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryptionFactory.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryptionFactory.kt @@ -16,7 +16,6 @@ package im.vector.matrix.android.internal.crypto.algorithms.megolm -import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.internal.crypto.DeviceListManager import im.vector.matrix.android.internal.crypto.MXOlmDevice import im.vector.matrix.android.internal.crypto.OutgoingRoomKeyRequestManager @@ -24,10 +23,12 @@ import im.vector.matrix.android.internal.crypto.actions.EnsureOlmSessionsForDevi import im.vector.matrix.android.internal.crypto.actions.MessageEncrypter import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore import im.vector.matrix.android.internal.crypto.tasks.SendToDeviceTask +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers import javax.inject.Inject -internal class MXMegolmDecryptionFactory @Inject constructor(private val credentials: Credentials, +internal class MXMegolmDecryptionFactory @Inject constructor(@UserId + private val userId: String, private val olmDevice: MXOlmDevice, private val deviceListManager: DeviceListManager, private val outgoingRoomKeyRequestManager: OutgoingRoomKeyRequestManager, @@ -39,7 +40,7 @@ internal class MXMegolmDecryptionFactory @Inject constructor(private val credent fun create(): MXMegolmDecryption { return MXMegolmDecryption( - credentials, + userId, olmDevice, deviceListManager, outgoingRoomKeyRequestManager, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/olm/MXOlmDecryption.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/olm/MXOlmDecryption.kt index ede99e4b94..9433e364cb 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/olm/MXOlmDecryption.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/olm/MXOlmDecryption.kt @@ -17,7 +17,6 @@ package im.vector.matrix.android.internal.crypto.algorithms.olm -import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.session.crypto.MXCryptoError import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.toModel @@ -35,8 +34,8 @@ import timber.log.Timber internal class MXOlmDecryption( // The olm device interface private val olmDevice: MXOlmDevice, - // the matrix credentials - private val credentials: Credentials) + // the matrix userId + private val userId: String) : IMXDecrypting { override suspend fun decryptEvent(event: Event, timeline: String): MXEventDecryptionResult { @@ -97,9 +96,9 @@ internal class MXOlmDecryption( throw MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_PROPERTY, reason) } - if (olmPayloadContent.recipient != credentials.userId) { + if (olmPayloadContent.recipient != userId) { Timber.e("## decryptEvent() : Event ${event.eventId}:" + - " Intended recipient ${olmPayloadContent.recipient} does not match our id ${credentials.userId}") + " Intended recipient ${olmPayloadContent.recipient} does not match our id $userId") throw MXCryptoError.Base(MXCryptoError.ErrorType.BAD_RECIPIENT, String.format(MXCryptoError.BAD_RECIPIENT_REASON, olmPayloadContent.recipient)) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/olm/MXOlmDecryptionFactory.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/olm/MXOlmDecryptionFactory.kt index afe4b36e97..391e8411bd 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/olm/MXOlmDecryptionFactory.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/olm/MXOlmDecryptionFactory.kt @@ -16,16 +16,17 @@ package im.vector.matrix.android.internal.crypto.algorithms.olm -import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.internal.crypto.MXOlmDevice +import im.vector.matrix.android.internal.di.UserId import javax.inject.Inject internal class MXOlmDecryptionFactory @Inject constructor(private val olmDevice: MXOlmDevice, - private val credentials: Credentials) { + @UserId + private val userId: String) { fun create(): MXOlmDecryption { return MXOlmDecryption( olmDevice, - credentials) + userId) } } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/DeleteDeviceWithUserPasswordTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/DeleteDeviceWithUserPasswordTask.kt index 060b57baa4..21dc18e472 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/DeleteDeviceWithUserPasswordTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/DeleteDeviceWithUserPasswordTask.kt @@ -16,11 +16,11 @@ package im.vector.matrix.android.internal.crypto.tasks -import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.internal.auth.data.LoginFlowTypes import im.vector.matrix.android.internal.crypto.api.CryptoApi import im.vector.matrix.android.internal.crypto.model.rest.DeleteDeviceAuth import im.vector.matrix.android.internal.crypto.model.rest.DeleteDeviceParams +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.task.Task import javax.inject.Inject @@ -34,7 +34,8 @@ internal interface DeleteDeviceWithUserPasswordTask : Task/MF/// val tmpFolderRoot = File(context.cacheDir, "MF") - val tmpFolderUser = File(tmpFolderRoot, sessionParams.credentials.userId.md5()) + val tmpFolderUser = File(tmpFolderRoot, userMd5) File(tmpFolderUser, id.md5()) } FileService.DownloadMode.TO_EXPORT -> { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt index 180cdb6ea2..a08c7e4ab7 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt @@ -67,11 +67,18 @@ internal abstract class SessionModule { return sessionParams.credentials } + @JvmStatic + @UserId + @Provides + fun providesUserId(credentials: Credentials): String { + return credentials.userId + } + @JvmStatic @UserMd5 @Provides - fun providesUserMd5(sessionParams: SessionParams): String { - return sessionParams.credentials.userId.md5() + fun providesUserMd5(@UserId userId: String): String { + return userId.md5() } @JvmStatic diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/filter/DefaultSaveFilterTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/filter/DefaultSaveFilterTask.kt index a5da026aec..b78bc01fc8 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/filter/DefaultSaveFilterTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/filter/DefaultSaveFilterTask.kt @@ -16,7 +16,7 @@ package im.vector.matrix.android.internal.session.filter -import im.vector.matrix.android.api.auth.data.SessionParams +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.task.Task import javax.inject.Inject @@ -33,7 +33,8 @@ internal interface SaveFilterTask : Task { } -internal class DefaultSaveFilterTask @Inject constructor(private val sessionParams: SessionParams, +internal class DefaultSaveFilterTask @Inject constructor(@UserId + private val userId: String, private val filterAPI: FilterApi, private val filterRepository: FilterRepository ) : SaveFilterTask { @@ -41,7 +42,7 @@ internal class DefaultSaveFilterTask @Inject constructor(private val sessionPara override suspend fun execute(params: SaveFilterTask.Params) { val filterResponse = executeRequest { // TODO auto retry - apiCall = filterAPI.uploadFilter(sessionParams.credentials.userId, params.filter) + apiCall = filterAPI.uploadFilter(userId, params.filter) } filterRepository.storeFilterId(params.filter, filterResponse.filterId) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GroupSummaryUpdater.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GroupSummaryUpdater.kt index 5de3a85409..7733b23bbe 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GroupSummaryUpdater.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GroupSummaryUpdater.kt @@ -20,12 +20,12 @@ import android.content.Context import androidx.work.ExistingWorkPolicy import androidx.work.WorkManager import com.zhuinden.monarchy.Monarchy -import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.session.room.model.Membership import im.vector.matrix.android.internal.database.RealmLiveEntityObserver import im.vector.matrix.android.internal.database.model.GroupEntity import im.vector.matrix.android.internal.database.model.GroupSummaryEntity import im.vector.matrix.android.internal.database.query.where +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.worker.WorkManagerUtil import im.vector.matrix.android.internal.worker.WorkManagerUtil.matrixOneTimeWorkRequestBuilder import im.vector.matrix.android.internal.worker.WorkerParamsFactory @@ -36,7 +36,8 @@ import javax.inject.Inject private const val GET_GROUP_DATA_WORKER = "GET_GROUP_DATA_WORKER" internal class GroupSummaryUpdater @Inject constructor(private val context: Context, - private val credentials: Credentials, + @UserId + private val userId: String, private val monarchy: Monarchy) : RealmLiveEntityObserver(monarchy.realmConfiguration) { @@ -60,7 +61,8 @@ internal class GroupSummaryUpdater @Inject constructor(private val context: Cont } private fun fetchGroupsData(groupIds: List) { - val getGroupDataWorkerParams = GetGroupDataWorker.Params(credentials.userId, groupIds) + val getGroupDataWorkerParams = GetGroupDataWorker.Params(userId, groupIds) + val workData = WorkerParamsFactory.toData(getGroupDataWorkerParams) val sendWork = matrixOneTimeWorkRequestBuilder() diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/DefaultPushRuleService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/DefaultPushRuleService.kt index 7cccd0dc3e..f388bf0bd1 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/DefaultPushRuleService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/DefaultPushRuleService.kt @@ -17,7 +17,6 @@ package im.vector.matrix.android.internal.session.notification import com.zhuinden.monarchy.Monarchy import im.vector.matrix.android.api.MatrixCallback -import im.vector.matrix.android.api.auth.data.SessionParams import im.vector.matrix.android.api.pushrules.Action import im.vector.matrix.android.api.pushrules.PushRuleService import im.vector.matrix.android.api.pushrules.rest.PushRule @@ -26,6 +25,7 @@ import im.vector.matrix.android.api.util.Cancelable import im.vector.matrix.android.internal.database.mapper.PushRulesMapper import im.vector.matrix.android.internal.database.model.PushRulesEntity import im.vector.matrix.android.internal.database.query.where +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.session.SessionScope import im.vector.matrix.android.internal.session.pushers.GetPushRulesTask import im.vector.matrix.android.internal.session.pushers.UpdatePushRuleEnableStatusTask @@ -36,8 +36,9 @@ import javax.inject.Inject @SessionScope internal class DefaultPushRuleService @Inject constructor( - private val sessionParams: SessionParams, - private val pushRulesTask: GetPushRulesTask, + @UserId + private val userId: String, + private val getPushRulesTask: GetPushRulesTask, private val updatePushRuleEnableStatusTask: UpdatePushRuleEnableStatusTask, private val taskExecutor: TaskExecutor, private val monarchy: Monarchy @@ -46,7 +47,7 @@ internal class DefaultPushRuleService @Inject constructor( private var listeners = ArrayList() override fun fetchPushRules(scope: String) { - pushRulesTask + getPushRulesTask .configureWith(GetPushRulesTask.Params(scope)) .executeBy(taskExecutor) } @@ -61,19 +62,19 @@ internal class DefaultPushRuleService @Inject constructor( // TODO Create const for ruleSetKey monarchy.doWithRealm { realm -> - PushRulesEntity.where(realm, sessionParams.credentials.userId, scope, "content").findFirst()?.let { re -> + PushRulesEntity.where(realm, userId, scope, "content").findFirst()?.let { re -> contentRules = re.pushRules.map { PushRulesMapper.mapContentRule(it) } } - PushRulesEntity.where(realm, sessionParams.credentials.userId, scope, "override").findFirst()?.let { re -> + PushRulesEntity.where(realm, userId, scope, "override").findFirst()?.let { re -> overrideRules = re.pushRules.map { PushRulesMapper.map(it) } } - PushRulesEntity.where(realm, sessionParams.credentials.userId, scope, "room").findFirst()?.let { re -> + PushRulesEntity.where(realm, userId, scope, "room").findFirst()?.let { re -> roomRules = re.pushRules.map { PushRulesMapper.mapRoomRule(it) } } - PushRulesEntity.where(realm, sessionParams.credentials.userId, scope, "sender").findFirst()?.let { re -> + PushRulesEntity.where(realm, userId, scope, "sender").findFirst()?.let { re -> senderRules = re.pushRules.map { PushRulesMapper.mapSenderRule(it) } } - PushRulesEntity.where(realm, sessionParams.credentials.userId, scope, "underride").findFirst()?.let { re -> + PushRulesEntity.where(realm, userId, scope, "underride").findFirst()?.let { re -> underrideRules = re.pushRules.map { PushRulesMapper.map(it) } } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/ProcessEventForPushTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/ProcessEventForPushTask.kt index 064f1e3f46..226995bc07 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/ProcessEventForPushTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/ProcessEventForPushTask.kt @@ -16,11 +16,11 @@ package im.vector.matrix.android.internal.session.notification -import im.vector.matrix.android.api.auth.data.SessionParams import im.vector.matrix.android.api.pushrules.rest.PushRule import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.room.RoomService +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.session.pushers.DefaultConditionResolver import im.vector.matrix.android.internal.session.sync.model.RoomsSyncResponse import im.vector.matrix.android.internal.task.Task @@ -37,7 +37,8 @@ internal interface ProcessEventForPushTask : Task false } }.filter { - it.senderId != sessionParams.credentials.userId + it.senderId != userId } Timber.v("[PushRules] Found ${allEvents.size} out of ${(newJoinEvents + inviteEvents).size}" + " to check for push rules with ${params.rules.size} rules") @@ -101,7 +102,7 @@ internal class DefaultProcessEventForPushTask @Inject constructor( } private fun fulfilledBingRule(event: Event, rules: List): PushRule? { - val conditionResolver = DefaultConditionResolver(event, roomService, sessionParams) + val conditionResolver = DefaultConditionResolver(event, roomService, userId) rules.filter { it.enabled }.forEach { rule -> val isFullfilled = rule.conditions?.map { it.asExecutableCondition()?.isSatisfied(conditionResolver) ?: false diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/DefaultConditionResolver.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/DefaultConditionResolver.kt index a05cfb6cac..e983f3b96d 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/DefaultConditionResolver.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/DefaultConditionResolver.kt @@ -15,15 +15,16 @@ */ package im.vector.matrix.android.internal.session.pushers -import im.vector.matrix.android.api.auth.data.SessionParams import im.vector.matrix.android.api.pushrules.* import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.room.RoomService +import im.vector.matrix.android.internal.di.UserId import timber.log.Timber internal class DefaultConditionResolver(private val event: Event, private val roomService: RoomService, - private val sessionParams: SessionParams) : ConditionResolver { + @UserId + private val userId: String) : ConditionResolver { override fun resolveEventMatchCondition(eventMatchCondition: EventMatchCondition): Boolean { @@ -45,8 +46,7 @@ internal class DefaultConditionResolver(private val event: Event, override fun resolveContainsDisplayNameCondition(containsDisplayNameCondition: ContainsDisplayNameCondition): Boolean { val roomId = event.roomId ?: return false val room = roomService.getRoom(roomId) ?: return false - val myDisplayName = room.getRoomMember(sessionParams.credentials.userId)?.displayName - ?: return false + val myDisplayName = room.getRoomMember(userId)?.displayName ?: return false return containsDisplayNameCondition.isSatisfied(event, myDisplayName) } } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/DefaultPusherService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/DefaultPusherService.kt index 995d93311d..311dfff608 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/DefaultPusherService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/DefaultPusherService.kt @@ -21,29 +21,29 @@ import androidx.work.BackoffPolicy import androidx.work.WorkManager import com.zhuinden.monarchy.Monarchy import im.vector.matrix.android.api.MatrixCallback -import im.vector.matrix.android.api.auth.data.SessionParams import im.vector.matrix.android.api.session.pushers.Pusher import im.vector.matrix.android.api.session.pushers.PushersService import im.vector.matrix.android.internal.database.mapper.asDomain import im.vector.matrix.android.internal.database.model.PusherEntity import im.vector.matrix.android.internal.database.query.where +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.task.TaskExecutor import im.vector.matrix.android.internal.task.configureWith import im.vector.matrix.android.internal.worker.WorkManagerUtil import im.vector.matrix.android.internal.worker.WorkManagerUtil.matrixOneTimeWorkRequestBuilder import im.vector.matrix.android.internal.worker.WorkerParamsFactory -import java.util.UUID +import java.util.* import java.util.concurrent.TimeUnit import javax.inject.Inject -internal class DefaultPusherService @Inject constructor( - private val context: Context, - private val monarchy: Monarchy, - private val sessionParam: SessionParams, - private val getPusherTask: GetPushersTask, - private val removePusherTask: RemovePusherTask, - private val taskExecutor: TaskExecutor +internal class DefaultPusherService @Inject constructor(private val context: Context, + private val monarchy: Monarchy, + @UserId + private val userId: String, + private val getPusherTask: GetPushersTask, + private val removePusherTask: RemovePusherTask, + private val taskExecutor: TaskExecutor ) : PushersService { @@ -70,7 +70,7 @@ internal class DefaultPusherService @Inject constructor( append = append) - val params = AddHttpPusherWorker.Params(pusher, sessionParam.credentials.userId) + val params = AddHttpPusherWorker.Params(pusher, userId) val request = matrixOneTimeWorkRequestBuilder() .setConstraints(WorkManagerUtil.workConstraints) @@ -82,7 +82,7 @@ internal class DefaultPusherService @Inject constructor( } override fun removeHttpPusher(pushkey: String, appId: String, callback: MatrixCallback) { - val params = RemovePusherTask.Params(sessionParam.credentials.userId, pushkey, appId) + val params = RemovePusherTask.Params(userId, pushkey, appId) removePusherTask .configureWith(params) { this.callback = callback @@ -93,12 +93,12 @@ internal class DefaultPusherService @Inject constructor( override fun livePushers(): LiveData> { return monarchy.findAllMappedWithChanges( - { realm -> PusherEntity.where(realm, sessionParam.credentials.userId) }, + { realm -> PusherEntity.where(realm, userId) }, { it.asDomain() } ) } override fun pushers(): List { - return monarchy.fetchAllCopiedSync { PusherEntity.where(it, sessionParam.credentials.userId) }.map { it.asDomain() } + return monarchy.fetchAllCopiedSync { PusherEntity.where(it, userId) }.map { it.asDomain() } } } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/GetPushRulesTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/GetPushRulesTask.kt index 627c6f89fa..76921fec9f 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/GetPushRulesTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/GetPushRulesTask.kt @@ -16,11 +16,11 @@ package im.vector.matrix.android.internal.session.pushers import com.zhuinden.monarchy.Monarchy -import im.vector.matrix.android.api.auth.data.SessionParams import im.vector.matrix.android.api.pushrules.rest.GetPushRulesResponse import im.vector.matrix.android.internal.database.mapper.PushRulesMapper import im.vector.matrix.android.internal.database.model.PushRulesEntity import im.vector.matrix.android.internal.database.model.PusherEntityFields +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.util.awaitTransaction @@ -36,7 +36,8 @@ internal interface GetPushRulesTask : Task { internal class DefaultGetPushRulesTask @Inject constructor(private val pushRulesApi: PushRulesApi, private val monarchy: Monarchy, - private val sessionParams: SessionParams) : GetPushRulesTask { + @UserId + private val userId: String) : GetPushRulesTask { override suspend fun execute(params: GetPushRulesTask.Params) { val response = executeRequest { @@ -47,10 +48,10 @@ internal class DefaultGetPushRulesTask @Inject constructor(private val pushRules //clear existings? //TODO realm.where(PushRulesEntity::class.java) - .equalTo(PusherEntityFields.USER_ID, sessionParams.credentials.userId) + .equalTo(PusherEntityFields.USER_ID, userId) .findAll().deleteAllFromRealm() - val content = PushRulesEntity(sessionParams.credentials.userId, scope, "content") + val content = PushRulesEntity(userId, scope, "content") response.global.content?.forEach { rule -> PushRulesMapper.map(rule).also { content.pushRules.add(it) @@ -58,7 +59,7 @@ internal class DefaultGetPushRulesTask @Inject constructor(private val pushRules } realm.insertOrUpdate(content) - val override = PushRulesEntity(sessionParams.credentials.userId, scope, "override") + val override = PushRulesEntity(userId, scope, "override") response.global.override?.forEach { rule -> PushRulesMapper.map(rule).also { override.pushRules.add(it) @@ -66,7 +67,7 @@ internal class DefaultGetPushRulesTask @Inject constructor(private val pushRules } realm.insertOrUpdate(override) - val rooms = PushRulesEntity(sessionParams.credentials.userId, scope, "room") + val rooms = PushRulesEntity(userId, scope, "room") response.global.room?.forEach { rule -> PushRulesMapper.map(rule).also { rooms.pushRules.add(it) @@ -74,7 +75,7 @@ internal class DefaultGetPushRulesTask @Inject constructor(private val pushRules } realm.insertOrUpdate(rooms) - val senders = PushRulesEntity(sessionParams.credentials.userId, scope, "sender") + val senders = PushRulesEntity(userId, scope, "sender") response.global.sender?.forEach { rule -> PushRulesMapper.map(rule).also { senders.pushRules.add(it) @@ -82,7 +83,7 @@ internal class DefaultGetPushRulesTask @Inject constructor(private val pushRules } realm.insertOrUpdate(senders) - val underrides = PushRulesEntity(sessionParams.credentials.userId, scope, "underride") + val underrides = PushRulesEntity(userId, scope, "underride") response.global.underride?.forEach { rule -> PushRulesMapper.map(rule).also { underrides.pushRules.add(it) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/GetPushersTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/GetPushersTask.kt index b3199ea370..2e54111fc0 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/GetPushersTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/GetPushersTask.kt @@ -16,11 +16,11 @@ package im.vector.matrix.android.internal.session.pushers import com.zhuinden.monarchy.Monarchy -import im.vector.matrix.android.api.auth.data.SessionParams import im.vector.matrix.android.api.session.pushers.PusherState import im.vector.matrix.android.internal.database.mapper.toEntity import im.vector.matrix.android.internal.database.model.PusherEntity import im.vector.matrix.android.internal.database.model.PusherEntityFields +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.util.awaitTransaction @@ -30,7 +30,8 @@ internal interface GetPushersTask : Task internal class DefaultGetPusherTask @Inject constructor(private val pushersAPI: PushersAPI, private val monarchy: Monarchy, - private val sessionParams: SessionParams) : GetPushersTask { + @UserId + private val userId: String) : GetPushersTask { override suspend fun execute(params: Unit) { val response = executeRequest { @@ -39,10 +40,10 @@ internal class DefaultGetPusherTask @Inject constructor(private val pushersAPI: monarchy.awaitTransaction { realm -> //clear existings? realm.where(PusherEntity::class.java) - .equalTo(PusherEntityFields.USER_ID, sessionParams.credentials.userId) + .equalTo(PusherEntityFields.USER_ID, userId) .findAll().deleteAllFromRealm() response.pushers?.forEach { jsonPusher -> - jsonPusher.toEntity(sessionParams.credentials.userId).also { + jsonPusher.toEntity(userId).also { it.state = PusherState.REGISTERED realm.insertOrUpdate(it) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/EventRelationsAggregationUpdater.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/EventRelationsAggregationUpdater.kt index 9d642d3a89..a5dcb5ef7c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/EventRelationsAggregationUpdater.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/EventRelationsAggregationUpdater.kt @@ -16,13 +16,13 @@ package im.vector.matrix.android.internal.session.room import com.zhuinden.monarchy.Monarchy -import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.internal.database.RealmLiveEntityObserver 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.query.types import im.vector.matrix.android.internal.di.SessionDatabase +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.task.TaskExecutor import im.vector.matrix.android.internal.task.configureWith import io.realm.OrderedCollectionChangeSet @@ -38,7 +38,8 @@ import javax.inject.Inject */ internal class EventRelationsAggregationUpdater @Inject constructor(@SessionDatabase realmConfiguration: RealmConfiguration, - private val credentials: Credentials, + @UserId + private val userId: String, private val task: EventRelationsAggregationTask, private val taskExecutor: TaskExecutor) : RealmLiveEntityObserver(realmConfiguration) { @@ -61,7 +62,7 @@ internal class EventRelationsAggregationUpdater @Inject constructor(@SessionData .toList() val params = EventRelationsAggregationTask.Params( insertedDomains, - credentials.userId + userId ) task.configureWith(params).executeBy(taskExecutor) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomAvatarResolver.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomAvatarResolver.kt index 9161fb25a1..dd986d172d 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomAvatarResolver.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomAvatarResolver.kt @@ -17,7 +17,6 @@ package im.vector.matrix.android.internal.session.room import com.zhuinden.monarchy.Monarchy -import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.events.model.toModel import im.vector.matrix.android.api.session.room.model.RoomAvatarContent @@ -27,11 +26,13 @@ import im.vector.matrix.android.internal.database.model.EventEntity import im.vector.matrix.android.internal.database.model.EventEntityFields import im.vector.matrix.android.internal.database.query.prev import im.vector.matrix.android.internal.database.query.where +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.session.room.membership.RoomMembers import javax.inject.Inject internal class RoomAvatarResolver @Inject constructor(private val monarchy: Monarchy, - private val credentials: Credentials) { + @UserId + private val userId: String) { /** * Compute the room avatar url @@ -52,7 +53,7 @@ internal class RoomAvatarResolver @Inject constructor(private val monarchy: Mona if (members.size == 1) { res = members.firstOrNull()?.toRoomMember()?.avatarUrl } else if (members.size == 2) { - val firstOtherMember = members.where().notEqualTo(EventEntityFields.STATE_KEY, credentials.userId).findFirst() + val firstOtherMember = members.where().notEqualTo(EventEntityFields.STATE_KEY, userId).findFirst() res = firstOtherMember?.toRoomMember()?.avatarUrl } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomSummaryUpdater.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomSummaryUpdater.kt index a8814771cf..8161e3fe1e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomSummaryUpdater.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomSummaryUpdater.kt @@ -17,7 +17,6 @@ package im.vector.matrix.android.internal.session.room import com.zhuinden.monarchy.Monarchy -import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.events.model.toModel import im.vector.matrix.android.api.session.room.model.Membership @@ -31,6 +30,7 @@ import im.vector.matrix.android.internal.database.query.isEventRead import im.vector.matrix.android.internal.database.query.latestEvent import im.vector.matrix.android.internal.database.query.prev import im.vector.matrix.android.internal.database.query.where +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.session.room.membership.RoomDisplayNameResolver import im.vector.matrix.android.internal.session.room.membership.RoomMembers import im.vector.matrix.android.internal.session.sync.model.RoomSyncSummary @@ -39,7 +39,8 @@ import io.realm.Realm import io.realm.kotlin.createObject import javax.inject.Inject -internal class RoomSummaryUpdater @Inject constructor(private val credentials: Credentials, +internal class RoomSummaryUpdater @Inject constructor(@UserId + private val userId: String, private val roomDisplayNameResolver: RoomDisplayNameResolver, private val roomAvatarResolver: RoomAvatarResolver, private val monarchy: Monarchy) { @@ -92,11 +93,11 @@ internal class RoomSummaryUpdater @Inject constructor(private val credentials: C roomSummaryEntity.hasUnreadMessages = roomSummaryEntity.notificationCount > 0 //avoid this call if we are sure there are unread events - || !isEventRead(monarchy, credentials.userId, roomId, latestPreviewableEvent?.eventId) + || !isEventRead(monarchy, userId, roomId, latestPreviewableEvent?.eventId) val otherRoomMembers = RoomMembers(realm, roomId) .queryRoomMembersEvent() - .notEqualTo(EventEntityFields.STATE_KEY, credentials.userId) + .notEqualTo(EventEntityFields.STATE_KEY, userId) .findAll() .asSequence() .map { it.stateKey } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/membership/RoomDisplayNameResolver.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/membership/RoomDisplayNameResolver.kt index 815fc96e8e..1e2e5c920b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/membership/RoomDisplayNameResolver.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/membership/RoomDisplayNameResolver.kt @@ -19,7 +19,6 @@ package im.vector.matrix.android.internal.session.room.membership import android.content.Context import com.zhuinden.monarchy.Monarchy import im.vector.matrix.android.R -import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.events.model.toModel import im.vector.matrix.android.api.session.room.model.* @@ -30,6 +29,7 @@ import im.vector.matrix.android.internal.database.model.RoomEntity import im.vector.matrix.android.internal.database.model.RoomSummaryEntity import im.vector.matrix.android.internal.database.query.prev import im.vector.matrix.android.internal.database.query.where +import im.vector.matrix.android.internal.di.UserId import javax.inject.Inject /** @@ -37,7 +37,8 @@ import javax.inject.Inject */ internal class RoomDisplayNameResolver @Inject constructor(private val context: Context, private val monarchy: Monarchy, - private val credentials: Credentials + @UserId + private val userId: String ) { /** @@ -79,7 +80,7 @@ internal class RoomDisplayNameResolver @Inject constructor(private val context: if (roomEntity?.membership == Membership.INVITE) { - val inviteMeEvent = roomMembers.queryRoomMemberEvent(credentials.userId).findFirst() + val inviteMeEvent = roomMembers.queryRoomMemberEvent(userId).findFirst() val inviterId = inviteMeEvent?.sender name = if (inviterId != null) { val inviterMemberEvent = loadedMembers.where() @@ -97,7 +98,7 @@ internal class RoomDisplayNameResolver @Inject constructor(private val context: } } else { loadedMembers.where() - .notEqualTo(EventEntityFields.STATE_KEY, credentials.userId) + .notEqualTo(EventEntityFields.STATE_KEY, userId) .limit(3) .findAll() } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/prune/EventsPruner.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/prune/EventsPruner.kt index c63733f3d2..389f8e129c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/prune/EventsPruner.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/prune/EventsPruner.kt @@ -17,13 +17,13 @@ package im.vector.matrix.android.internal.session.room.prune import com.zhuinden.monarchy.Monarchy -import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.internal.database.RealmLiveEntityObserver 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.query.types import im.vector.matrix.android.internal.di.SessionDatabase +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.task.TaskExecutor import im.vector.matrix.android.internal.task.configureWith import io.realm.OrderedCollectionChangeSet @@ -37,7 +37,8 @@ import javax.inject.Inject * As it will actually delete the content, it should be called last in the list of listener. */ internal class EventsPruner @Inject constructor(@SessionDatabase realmConfiguration: RealmConfiguration, - private val credentials: Credentials, + @UserId + private val userId: String, private val pruneEventTask: PruneEventTask, private val taskExecutor: TaskExecutor) : RealmLiveEntityObserver(realmConfiguration) { @@ -54,7 +55,7 @@ internal class EventsPruner @Inject constructor(@SessionDatabase realmConfigurat val params = PruneEventTask.Params( insertedDomains, - credentials.userId + userId ) pruneEventTask.configureWith(params).executeBy(taskExecutor) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/read/DefaultReadService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/read/DefaultReadService.kt index 11dfee5f81..79ea93a06d 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/read/DefaultReadService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/read/DefaultReadService.kt @@ -22,7 +22,6 @@ import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject import com.zhuinden.monarchy.Monarchy import im.vector.matrix.android.api.MatrixCallback -import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.session.room.model.ReadReceipt import im.vector.matrix.android.api.session.room.read.ReadService import im.vector.matrix.android.internal.database.RealmLiveData @@ -30,6 +29,7 @@ import im.vector.matrix.android.internal.database.mapper.ReadReceiptsSummaryMapp import im.vector.matrix.android.internal.database.model.ReadReceiptsSummaryEntity import im.vector.matrix.android.internal.database.query.isEventRead import im.vector.matrix.android.internal.database.query.where +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.task.TaskExecutor import im.vector.matrix.android.internal.task.configureWith @@ -38,7 +38,8 @@ internal class DefaultReadService @AssistedInject constructor(@Assisted private private val taskExecutor: TaskExecutor, private val setReadMarkersTask: SetReadMarkersTask, private val readReceiptsSummaryMapper: ReadReceiptsSummaryMapper, - private val credentials: Credentials + @UserId + private val userId: String ) : ReadService { @AssistedInject.Factory @@ -75,7 +76,7 @@ internal class DefaultReadService @AssistedInject constructor(@Assisted private override fun isEventRead(eventId: String): Boolean { - return isEventRead(monarchy, credentials.userId, roomId, eventId) + return isEventRead(monarchy, userId, roomId, eventId) } override fun getEventReadReceiptsLive(eventId: String): LiveData> { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/read/SetReadMarkersTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/read/SetReadMarkersTask.kt index 4fa365bb66..dc61f4786a 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/read/SetReadMarkersTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/read/SetReadMarkersTask.kt @@ -17,7 +17,6 @@ package im.vector.matrix.android.internal.session.room.read import com.zhuinden.monarchy.Monarchy -import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.internal.database.model.ChunkEntity import im.vector.matrix.android.internal.database.model.ReadReceiptEntity import im.vector.matrix.android.internal.database.model.RoomSummaryEntity @@ -26,6 +25,7 @@ import im.vector.matrix.android.internal.database.query.find import im.vector.matrix.android.internal.database.query.findLastLiveChunkFromRoom import im.vector.matrix.android.internal.database.query.latestEvent import im.vector.matrix.android.internal.database.query.where +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.session.room.RoomAPI import im.vector.matrix.android.internal.session.room.send.LocalEchoEventFactory @@ -48,7 +48,8 @@ private const val READ_MARKER = "m.fully_read" private const val READ_RECEIPT = "m.read" internal class DefaultSetReadMarkersTask @Inject constructor(private val roomAPI: RoomAPI, - private val credentials: Credentials, + @UserId + private val userId: String, private val monarchy: Monarchy ) : SetReadMarkersTask { @@ -109,7 +110,7 @@ internal class DefaultSetReadMarkersTask @Inject constructor(private val roomAPI private fun isEventRead(roomId: String, eventId: String): Boolean { var isEventRead = false monarchy.doWithRealm { - val readReceipt = ReadReceiptEntity.where(it, roomId, credentials.userId).findFirst() + val readReceipt = ReadReceiptEntity.where(it, roomId, userId).findFirst() ?: return@doWithRealm val liveChunk = ChunkEntity.findLastLiveChunkFromRoom(it, roomId) ?: return@doWithRealm diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/DefaultRelationService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/DefaultRelationService.kt index 0c8695cbcf..32acdc2620 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/DefaultRelationService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/DefaultRelationService.kt @@ -23,7 +23,6 @@ import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject import com.zhuinden.monarchy.Monarchy import im.vector.matrix.android.api.MatrixCallback -import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.session.crypto.CryptoService import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.room.model.EventAnnotationsSummary @@ -37,6 +36,7 @@ import im.vector.matrix.android.internal.database.mapper.asDomain import im.vector.matrix.android.internal.database.model.EventAnnotationsSummaryEntity import im.vector.matrix.android.internal.database.model.RoomEntity import im.vector.matrix.android.internal.database.query.where +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.session.room.send.EncryptEventWorker import im.vector.matrix.android.internal.session.room.send.LocalEchoEventFactory import im.vector.matrix.android.internal.session.room.send.RedactEventWorker @@ -50,7 +50,8 @@ import timber.log.Timber internal class DefaultRelationService @AssistedInject constructor(@Assisted private val roomId: String, private val context: Context, - private val credentials: Credentials, + @UserId + private val userId: String, private val eventFactory: LocalEchoEventFactory, private val cryptoService: CryptoService, private val findReactionEventForUndoTask: FindReactionEventForUndoTask, @@ -111,7 +112,7 @@ internal class DefaultRelationService @AssistedInject constructor(@Assisted priv //TODO duplicate with send service? private fun createRedactEventWork(localEvent: Event, eventId: String, reason: String?): OneTimeWorkRequest { val sendContentWorkerParams = RedactEventWorker.Params( - credentials.userId, + userId, localEvent.eventId!!, roomId, eventId, @@ -199,13 +200,13 @@ internal class DefaultRelationService @AssistedInject constructor(@Assisted priv private fun createEncryptEventWork(event: Event, keepKeys: List?): OneTimeWorkRequest { // Same parameter - val params = EncryptEventWorker.Params(credentials.userId, roomId, event, keepKeys) + val params = EncryptEventWorker.Params(userId, roomId, event, keepKeys) val sendWorkData = WorkerParamsFactory.toData(params) return TimelineSendEventWorkCommon.createWork(sendWorkData, true) } private fun createSendEventWork(event: Event, startChain: Boolean): OneTimeWorkRequest { - val sendContentWorkerParams = SendEventWorker.Params(credentials.userId, roomId, event) + val sendContentWorkerParams = SendEventWorker.Params(userId, roomId, event) val sendWorkData = WorkerParamsFactory.toData(sendContentWorkerParams) return TimelineSendEventWorkCommon.createWork(sendWorkData, startChain) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/DefaultSendService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/DefaultSendService.kt index a97d03d734..dbcedc1ebc 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/DefaultSendService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/DefaultSendService.kt @@ -17,14 +17,10 @@ package im.vector.matrix.android.internal.session.room.send import android.content.Context -import androidx.lifecycle.LiveData -import androidx.lifecycle.Transformations import androidx.work.* import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject import com.zhuinden.monarchy.Monarchy -import im.vector.matrix.android.BuildConfig -import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.session.content.ContentAttachmentData import im.vector.matrix.android.api.session.crypto.CryptoService import im.vector.matrix.android.api.session.events.model.* @@ -32,16 +28,16 @@ import im.vector.matrix.android.api.session.room.model.message.MessageContent import im.vector.matrix.android.api.session.room.model.message.MessageType import im.vector.matrix.android.api.session.room.send.SendService import im.vector.matrix.android.api.session.room.send.SendState -import im.vector.matrix.android.api.session.room.send.UserDraft import im.vector.matrix.android.api.session.room.timeline.TimelineEvent import im.vector.matrix.android.api.util.Cancelable import im.vector.matrix.android.api.util.CancelableBag -import im.vector.matrix.android.internal.database.RealmLiveData -import im.vector.matrix.android.internal.database.mapper.DraftMapper import im.vector.matrix.android.internal.database.mapper.asDomain -import im.vector.matrix.android.internal.database.model.* +import im.vector.matrix.android.internal.database.model.EventEntity +import im.vector.matrix.android.internal.database.model.RoomEntity +import im.vector.matrix.android.internal.database.model.TimelineEventEntity import im.vector.matrix.android.internal.database.query.findAllInRoomWithSendStates import im.vector.matrix.android.internal.database.query.where +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.session.content.UploadContentWorker import im.vector.matrix.android.internal.session.room.timeline.TimelineSendEventWorkCommon import im.vector.matrix.android.internal.util.CancelableWork @@ -59,7 +55,8 @@ private const val BACKOFF_DELAY = 10_000L internal class DefaultSendService @AssistedInject constructor(@Assisted private val roomId: String, private val context: Context, - private val credentials: Credentials, + @UserId + private val userId: String, private val localEchoEventFactory: LocalEchoEventFactory, private val cryptoService: CryptoService, private val monarchy: Monarchy @@ -292,7 +289,7 @@ internal class DefaultSendService @AssistedInject constructor(@Assisted private private fun createEncryptEventWork(event: Event, startChain: Boolean): OneTimeWorkRequest { // Same parameter - val params = EncryptEventWorker.Params(credentials.userId, roomId, event) + val params = EncryptEventWorker.Params(userId, roomId, event) val sendWorkData = WorkerParamsFactory.toData(params) return matrixOneTimeWorkRequestBuilder() @@ -304,7 +301,7 @@ internal class DefaultSendService @AssistedInject constructor(@Assisted private } private fun createSendEventWork(event: Event, startChain: Boolean): OneTimeWorkRequest { - val sendContentWorkerParams = SendEventWorker.Params(credentials.userId, roomId, event) + val sendContentWorkerParams = SendEventWorker.Params(userId, roomId, event) val sendWorkData = WorkerParamsFactory.toData(sendContentWorkerParams) return TimelineSendEventWorkCommon.createWork(sendWorkData, startChain) @@ -314,7 +311,7 @@ internal class DefaultSendService @AssistedInject constructor(@Assisted private val redactEvent = localEchoEventFactory.createRedactEvent(roomId, event.eventId!!, reason).also { saveLocalEcho(it) } - val sendContentWorkerParams = RedactEventWorker.Params(credentials.userId, redactEvent.eventId!!, roomId, event.eventId, reason) + val sendContentWorkerParams = RedactEventWorker.Params(userId, redactEvent.eventId!!, roomId, event.eventId, reason) val redactWorkData = WorkerParamsFactory.toData(sendContentWorkerParams) return TimelineSendEventWorkCommon.createWork(redactWorkData, true) } @@ -323,7 +320,7 @@ internal class DefaultSendService @AssistedInject constructor(@Assisted private attachment: ContentAttachmentData, isRoomEncrypted: Boolean, startChain: Boolean): OneTimeWorkRequest { - val uploadMediaWorkerParams = UploadContentWorker.Params(credentials.userId, roomId, event, attachment, isRoomEncrypted) + val uploadMediaWorkerParams = UploadContentWorker.Params(userId, roomId, event, attachment, isRoomEncrypted) val uploadWorkData = WorkerParamsFactory.toData(uploadMediaWorkerParams) return matrixOneTimeWorkRequestBuilder() diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt index b0351dca4f..7965717d0b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt @@ -19,7 +19,6 @@ package im.vector.matrix.android.internal.session.room.send import android.media.MediaMetadataRetriever import com.zhuinden.monarchy.Monarchy import im.vector.matrix.android.R -import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.permalinks.PermalinkFactory import im.vector.matrix.android.api.session.content.ContentAttachmentData import im.vector.matrix.android.api.session.events.model.* @@ -33,12 +32,13 @@ import im.vector.matrix.android.api.session.room.timeline.getLastMessageContent import im.vector.matrix.android.internal.database.helper.addSendingEvent import im.vector.matrix.android.internal.database.model.RoomEntity import im.vector.matrix.android.internal.database.query.where +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.session.content.ThumbnailExtractor import im.vector.matrix.android.internal.session.room.RoomSummaryUpdater import im.vector.matrix.android.internal.util.StringProvider import org.commonmark.parser.Parser import org.commonmark.renderer.html.HtmlRenderer -import java.util.UUID +import java.util.* import javax.inject.Inject /** @@ -50,7 +50,8 @@ import javax.inject.Inject * * The transactionID is used as loc */ -internal class LocalEchoEventFactory @Inject constructor(private val credentials: Credentials, +internal class LocalEchoEventFactory @Inject constructor(@UserId + private val userId: String, private val stringProvider: StringProvider, private val roomSummaryUpdater: RoomSummaryUpdater) { // TODO Inject @@ -163,7 +164,7 @@ internal class LocalEchoEventFactory @Inject constructor(private val credentials return Event( roomId = roomId, originServerTs = dummyOriginServerTs(), - senderId = credentials.userId, + senderId = userId, eventId = localId, type = EventType.REACTION, content = content.toContent(), @@ -255,7 +256,7 @@ internal class LocalEchoEventFactory @Inject constructor(private val credentials return Event( roomId = roomId, originServerTs = dummyOriginServerTs(), - senderId = credentials.userId, + senderId = userId, eventId = localID, type = EventType.MESSAGE, content = content.toContent(), @@ -373,7 +374,7 @@ internal class LocalEchoEventFactory @Inject constructor(private val credentials return Event( roomId = roomId, originServerTs = dummyOriginServerTs(), - senderId = credentials.userId, + senderId = userId, eventId = localID, type = EventType.REDACTION, redacts = eventId, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/signout/SignOutTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/signout/SignOutTask.kt index 18c2de71d3..96bfbeef70 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/signout/SignOutTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/signout/SignOutTask.kt @@ -17,15 +17,11 @@ package im.vector.matrix.android.internal.session.signout import android.content.Context -import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.internal.SessionManager import im.vector.matrix.android.internal.auth.SessionParamsStore import im.vector.matrix.android.internal.crypto.CryptoModule import im.vector.matrix.android.internal.database.RealmKeysUtils -import im.vector.matrix.android.internal.di.CryptoDatabase -import im.vector.matrix.android.internal.di.SessionDatabase -import im.vector.matrix.android.internal.di.UserCacheDirectory -import im.vector.matrix.android.internal.di.UserMd5 +import im.vector.matrix.android.internal.di.* import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.session.SessionModule import im.vector.matrix.android.internal.session.cache.ClearCacheTask @@ -38,7 +34,8 @@ import javax.inject.Inject internal interface SignOutTask : Task internal class DefaultSignOutTask @Inject constructor(private val context: Context, - private val credentials: Credentials, + @UserId + private val userId: String, private val signOutAPI: SignOutAPI, private val sessionManager: SessionManager, private val sessionParamsStore: SessionParamsStore, @@ -55,13 +52,13 @@ internal class DefaultSignOutTask @Inject constructor(private val context: Conte } Timber.d("SignOut: release session...") - sessionManager.releaseSession(credentials.userId) + sessionManager.releaseSession(userId) Timber.d("SignOut: cancel pending works...") WorkManagerUtil.cancelAllWorks(context) Timber.d("SignOut: delete session params...") - sessionParamsStore.delete(credentials.userId) + sessionParamsStore.delete(userId) Timber.d("SignOut: clear session data...") clearSessionDataTask.execute(Unit) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTask.kt index ea4efa4740..6035eb17bd 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTask.kt @@ -18,10 +18,10 @@ package im.vector.matrix.android.internal.session.sync import com.zhuinden.monarchy.Monarchy import im.vector.matrix.android.R -import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.failure.Failure import im.vector.matrix.android.api.failure.MatrixError import im.vector.matrix.android.internal.auth.SessionParamsStore +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.session.DefaultInitialSyncProgressService import im.vector.matrix.android.internal.session.filter.FilterRepository @@ -36,7 +36,8 @@ internal interface SyncTask : Task { } internal class DefaultSyncTask @Inject constructor(private val syncAPI: SyncAPI, - private val credentials: Credentials, + @UserId + private val userId: String, private val filterRepository: FilterRepository, private val syncResponseHandler: SyncResponseHandler, private val sessionParamsStore: SessionParamsStore, @@ -70,7 +71,7 @@ internal class DefaultSyncTask @Inject constructor(private val syncAPI: SyncAPI, // Intercept 401 if (throwable is Failure.ServerError && throwable.error.code == MatrixError.UNKNOWN_TOKEN) { - sessionParamsStore.delete(credentials.userId) + sessionParamsStore.delete(userId) } throw throwable } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/UserAccountDataSyncHandler.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/UserAccountDataSyncHandler.kt index 6ea4693168..df05bb281d 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/UserAccountDataSyncHandler.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/UserAccountDataSyncHandler.kt @@ -17,13 +17,13 @@ package im.vector.matrix.android.internal.session.sync import com.zhuinden.monarchy.Monarchy -import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.session.events.model.toModel import im.vector.matrix.android.api.session.room.model.RoomMember import im.vector.matrix.android.internal.database.mapper.asDomain import im.vector.matrix.android.internal.database.model.RoomSummaryEntity import im.vector.matrix.android.internal.database.query.getDirectRooms import im.vector.matrix.android.internal.database.query.where +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.session.room.membership.RoomMembers import im.vector.matrix.android.internal.session.sync.model.InvitedRoomSync import im.vector.matrix.android.internal.session.sync.model.UserAccountDataDirectMessages @@ -37,7 +37,8 @@ import timber.log.Timber import javax.inject.Inject internal class UserAccountDataSyncHandler @Inject constructor(private val monarchy: Monarchy, - private val credentials: Credentials, + @UserId + private val userId: String, private val directChatsHelper: DirectChatsHelper, private val updateUserAccountDataTask: UpdateUserAccountDataTask, private val taskExecutor: TaskExecutor) { @@ -81,11 +82,11 @@ internal class UserAccountDataSyncHandler @Inject constructor(private val monarc val directChats = directChatsHelper.getLocalUserAccount() var hasUpdate = false invites.forEach { (roomId, _) -> - val myUserStateEvent = RoomMembers(realm, roomId).getStateEvent(credentials.userId) + val myUserStateEvent = RoomMembers(realm, roomId).getStateEvent(userId) val inviterId = myUserStateEvent?.sender val myUserRoomMember: RoomMember? = myUserStateEvent?.let { it.asDomain().content?.toModel() } val isDirect = myUserRoomMember?.isDirect - if (inviterId != null && inviterId != credentials.userId && isDirect == true) { + if (inviterId != null && inviterId != userId && isDirect == true) { directChats .getOrPut(inviterId, { arrayListOf() }) .apply { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/UpdateUserAccountDataTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/UpdateUserAccountDataTask.kt index 80fc4cc3b1..cbfde3cd8c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/UpdateUserAccountDataTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/UpdateUserAccountDataTask.kt @@ -16,7 +16,7 @@ package im.vector.matrix.android.internal.session.user.accountdata -import im.vector.matrix.android.api.auth.data.Credentials +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.session.sync.model.UserAccountData import im.vector.matrix.android.internal.task.Task @@ -42,11 +42,12 @@ internal interface UpdateUserAccountDataTask : Task