From 07fee8ed3d24670fbad13c15e1d6c3c8c9f2cdc7 Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 20 Jun 2019 19:26:59 +0200 Subject: [PATCH] Dagger: continue reworking on app and sdk [WIP] --- matrix-sdk-android-rx/build.gradle | 5 +- matrix-sdk-android/build.gradle | 2 +- .../matrix/android/auth/AuthenticatorTest.kt | 12 +--- .../src/main/AndroidManifest.xml | 8 ++- .../im/vector/matrix/android/api/Matrix.kt | 50 ++++++++++----- .../android/internal/MatrixInitProvider.kt | 52 --------------- .../matrix/android/internal/SessionManager.kt | 4 ++ .../android/internal/auth/AuthModule.kt | 3 - .../internal/auth/DefaultAuthenticator.kt | 1 - .../auth/db/RealmSessionParamsStore.kt | 1 - .../internal/auth/db/SessionParamsMapper.kt | 1 - .../android/internal/crypto/CryptoManager.kt | 4 +- .../android/internal/crypto/CryptoModule.kt | 26 +------- .../internal/crypto/DeviceListManager.kt | 1 - .../android/internal/crypto/ObjectSigner.kt | 1 - .../EnsureOlmSessionsForDevicesAction.kt | 1 - .../EnsureOlmSessionsForUsersAction.kt | 1 - .../actions/MegolmSessionDataImporter.kt | 1 - .../crypto/actions/MessageEncrypter.kt | 1 - .../actions/SetDeviceVerificationAction.kt | 1 - .../megolm/MXMegolmDecryptionFactory.kt | 1 - .../megolm/MXMegolmEncryptionFactory.kt | 1 - .../algorithms/olm/MXOlmDecryptionFactory.kt | 1 - .../algorithms/olm/MXOlmEncryptionFactory.kt | 1 - .../tasks/CreateKeysBackupVersionTask.kt | 2 - .../keysbackup/tasks/DeleteBackupTask.kt | 1 - .../tasks/DeleteRoomSessionDataTask.kt | 1 - .../tasks/DeleteRoomSessionsDataTask.kt | 1 - .../tasks/DeleteSessionsDataTask.kt | 1 - .../tasks/GetKeysBackupLastVersionTask.kt | 2 - .../tasks/GetKeysBackupVersionTask.kt | 2 - .../tasks/GetRoomSessionDataTask.kt | 1 - .../tasks/GetRoomSessionsDataTask.kt | 1 - .../keysbackup/tasks/GetSessionsDataTask.kt | 1 - .../tasks/StoreRoomSessionDataTask.kt | 1 - .../tasks/StoreRoomSessionsDataTask.kt | 1 - .../keysbackup/tasks/StoreSessionsDataTask.kt | 1 - .../tasks/UpdateKeysBackupVersionTask.kt | 2 - .../WarnOnUnknownDeviceRepository.kt | 2 +- .../crypto/store/db/RealmCryptoStore.kt | 2 + .../ClaimOneTimeKeysForUsersDeviceTask.kt | 1 - .../internal/crypto/tasks/DeleteDeviceTask.kt | 1 - .../crypto/tasks/DownloadKeysForUsersTask.kt | 1 - .../internal/crypto/tasks/GetDevicesTask.kt | 1 - .../crypto/tasks/GetKeyChangesTask.kt | 1 - .../internal/crypto/tasks/SendToDeviceTask.kt | 1 - .../crypto/tasks/SetDeviceNameTask.kt | 1 - .../internal/crypto/tasks/UploadKeysTask.kt | 1 - .../android/internal/di/MatrixComponent.kt | 6 +- .../android/internal/di/MatrixModule.kt | 2 - .../android/internal/di/NetworkModule.kt | 6 -- .../network/AccessTokenInterceptor.kt | 1 - .../internal/network/UserAgentInterceptor.kt | 1 - .../internal/session/DefaultSession.kt | 8 +-- .../internal/session/SessionComponent.kt | 23 ++++++- .../android/internal/session/SessionModule.kt | 9 +-- .../internal/session/cache/CacheModule.kt | 2 - .../internal/session/cache/ClearCacheTask.kt | 1 - .../session/cache/DefaultCacheService.kt | 1 - .../internal/session/content/ContentModule.kt | 2 - .../DefaultContentUploadStateTracker.kt | 1 + .../content/DefaultContentUrlResolver.kt | 1 - .../internal/session/content/FileUploader.kt | 1 - .../session/content/UploadContentWorker.kt | 27 ++++---- .../session/filter/DefaultFilterRepository.kt | 1 - .../session/filter/DefaultFilterService.kt | 1 - .../session/filter/DefaultSaveFilterTask.kt | 1 - .../internal/session/filter/FilterModule.kt | 5 +- .../session/group/DefaultGetGroupDataTask.kt | 1 - .../session/group/DefaultGroupService.kt | 1 - .../session/group/GetGroupDataWorker.kt | 20 +++--- .../internal/session/group/GroupModule.kt | 4 +- .../session/group/GroupSummaryUpdater.kt | 12 ++-- .../internal/session/room/DefaultRoom.kt | 34 +++++----- .../session/room/DefaultRoomService.kt | 1 - .../session/room/EventRelationExtractor.kt | 1 - .../room/EventRelationsAggregationTask.kt | 1 - .../room/EventRelationsAggregationUpdater.kt | 1 - .../session/room/RoomAvatarResolver.kt | 1 - .../internal/session/room/RoomFactory.kt | 12 ++-- .../internal/session/room/RoomModule.kt | 25 +------- .../session/room/RoomSummaryUpdater.kt | 1 - .../session/room/create/CreateRoomTask.kt | 1 - .../room/directory/GetPublicRoomTask.kt | 1 - .../directory/GetThirdPartyProtocolsTask.kt | 1 - .../membership/DefaultMembershipService.kt | 1 - .../room/membership/LoadRoomMembersTask.kt | 1 - .../membership/SenderRoomMemberExtractor.kt | 3 +- .../room/membership/joining/InviteTask.kt | 1 - .../room/membership/joining/JoinRoomTask.kt | 1 - .../room/membership/leaving/LeaveRoomTask.kt | 1 - .../session/room/prune/EventsPruner.kt | 1 - .../session/room/prune/PruneEventTask.kt | 1 - .../session/room/read/DefaultReadService.kt | 1 - .../session/room/read/SetReadMarkersTask.kt | 1 - .../room/relation/DefaultRelationService.kt | 34 +++++----- .../relation/FindReactionEventForUndoTask.kt | 1 - .../room/relation/SendRelationWorker.kt | 23 +++---- .../room/relation/UpdateQuickReactionTask.kt | 1 - .../session/room/send/DefaultSendService.kt | 49 ++++++++------ .../session/room/send/EncryptEventWorker.kt | 25 ++++---- .../session/room/send/EventFactory.kt | 1 - .../room/send/LocalEchoEventFactory.kt | 1 - .../session/room/send/LocalEchoUpdater.kt | 1 - .../session/room/send/RedactEventWorker.kt | 45 ++++++------- .../session/room/send/SendEventWorker.kt | 27 ++++---- .../session/room/state/DefaultStateService.kt | 1 - .../session/room/state/SendStateTask.kt | 1 - .../timeline/DefaultGetContextOfEventTask.kt | 1 - .../room/timeline/DefaultPaginationTask.kt | 1 - .../room/timeline/DefaultTimelineService.kt | 24 +++---- .../session/room/timeline/GetEventTask.kt | 1 - .../timeline/TimelineSendEventWorkCommon.kt | 11 ++-- .../room/timeline/TokenChunkEventPersistor.kt | 13 ++-- .../session/signout/DefaultSignOutService.kt | 1 - .../internal/session/signout/SignOutModule.kt | 4 +- .../internal/session/signout/SignOutTask.kt | 1 - .../session/sync/CryptoSyncHandler.kt | 1 - .../internal/session/sync/GroupSyncHandler.kt | 1 - .../session/sync/ReadReceiptHandler.kt | 1 - .../internal/session/sync/RoomSyncHandler.kt | 8 ++- .../internal/session/sync/RoomTagHandler.kt | 1 - .../internal/session/sync/SyncModule.kt | 2 +- .../session/sync/SyncResponseHandler.kt | 1 - .../android/internal/session/sync/SyncTask.kt | 1 - .../internal/session/sync/SyncTokenStore.kt | 4 +- .../sync/UserAccountDataSyncHandler.kt | 1 - .../internal/session/sync/job/SyncThread.kt | 1 - .../session/user/DefaultUserService.kt | 1 - .../internal/session/user/UpdateUserTask.kt | 1 - .../session/user/UserEntityUpdater.kt | 1 - .../internal/session/user/UserModule.kt | 3 - .../android/internal/task/TaskExecutor.kt | 1 - .../android/internal/util/CancelableWork.kt | 6 +- .../SessionWorkerParams.kt} | 11 ++-- .../matrix/android/internal/worker/Worker.kt | 25 ++++++++ .../internal/worker/WorkerBindingModule.kt | 64 ------------------- vector/build.gradle | 2 +- .../fcm/VectorFirebaseMessagingService.kt | 3 +- .../riotredesign/EmojiCompatFontProvider.kt | 2 + .../vector/riotredesign/VectorApplication.kt | 9 ++- .../riotredesign/core/di/ScreenComponent.kt | 8 ++- .../riotredesign/core/di/VectorComponent.kt | 6 ++ .../riotredesign/core/di/VectorModule.kt | 11 +++- .../riotredesign/features/MainActivity.kt | 15 +++-- .../IncomingVerificationRequestHandler.kt | 2 +- .../features/home/AvatarRenderer.kt | 7 +- .../features/home/HomeActivity.kt | 2 +- .../home/room/detail/RoomDetailViewModel.kt | 5 ++ .../helper/ContentUploadStateTrackerBinder.kt | 6 +- .../helper/TimelineMediaSizeProvider.kt | 2 + .../timeline/item/MessageImageVideoItem.kt | 2 +- .../features/login/LoginActivity.kt | 11 +++- .../features/media/ImageContentRenderer.kt | 4 +- .../features/media/VideoContentRenderer.kt | 2 +- .../features/rageshake/BugReporter.kt | 4 +- 156 files changed, 393 insertions(+), 552 deletions(-) delete mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/MatrixInitProvider.kt rename matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/{di/MatrixAssistedModule.kt => worker/SessionWorkerParams.kt} (71%) create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/Worker.kt delete mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/WorkerBindingModule.kt diff --git a/matrix-sdk-android-rx/build.gradle b/matrix-sdk-android-rx/build.gradle index 26d141c3..183f3be1 100644 --- a/matrix-sdk-android-rx/build.gradle +++ b/matrix-sdk-android-rx/build.gradle @@ -37,10 +37,7 @@ dependencies { implementation project(":matrix-sdk-android") implementation 'androidx.appcompat:appcompat:1.1.0-alpha01' implementation 'io.reactivex.rxjava2:rxkotlin:2.3.0' - implementation 'io.reactivex.rxjava2:rxandroid:2.0.2' - - // Paging - implementation 'androidx.paging:paging-runtime:2.0.0' + implementation 'io.reactivex.rxjava2:rxandroid:2.1.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.1' diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index 4119c03c..0bb1dbfb 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -120,7 +120,7 @@ dependencies { kapt 'dk.ilios:realmfieldnameshelper:1.1.1' // Work - implementation "android.arch.work:work-runtime-ktx:1.0.0" + implementation "androidx.work:work-runtime-ktx:2.1.0-beta01" // FP implementation "io.arrow-kt:arrow-core:$arrow_version" diff --git a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/auth/AuthenticatorTest.kt b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/auth/AuthenticatorTest.kt index 27c1c4da..398507fa 100644 --- a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/auth/AuthenticatorTest.kt +++ b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/auth/AuthenticatorTest.kt @@ -39,16 +39,8 @@ import org.koin.test.KoinTest @RunWith(AndroidJUnit4::class) internal class AuthenticatorTest : InstrumentedTest, KoinTest { - init { - Monarchy.init(context()) - val matrixModule = MatrixModule(context()).definition - val networkModule = NetworkModule().definition - val authModule = AuthModule().definition - loadKoinModules(listOf(matrixModule, networkModule, authModule)) - } - - private val authenticator: Authenticator by inject() - private val okReplayInterceptor: OkReplayInterceptor by inject() + lateinit var authenticator: Authenticator + lateinit var okReplayInterceptor: OkReplayInterceptor private val okReplayConfig = OkReplayConfig.Builder() .tapeRoot(AndroidTapeRoot( diff --git a/matrix-sdk-android/src/main/AndroidManifest.xml b/matrix-sdk-android/src/main/AndroidManifest.xml index f4e0e50f..7191d9c8 100644 --- a/matrix-sdk-android/src/main/AndroidManifest.xml +++ b/matrix-sdk-android/src/main/AndroidManifest.xml @@ -1,4 +1,5 @@ @@ -7,9 +8,10 @@ - + diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Matrix.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Matrix.kt index c4d128ea..3ea61119 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Matrix.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Matrix.kt @@ -18,10 +18,13 @@ package im.vector.matrix.android.api import android.content.Context import androidx.lifecycle.ProcessLifecycleOwner +import androidx.work.Configuration +import androidx.work.WorkManager import com.zhuinden.monarchy.Monarchy import im.vector.matrix.android.api.auth.Authenticator import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.sync.FilterService +import im.vector.matrix.android.internal.SessionManager import im.vector.matrix.android.internal.di.DaggerMatrixComponent import im.vector.matrix.android.internal.network.UserAgentHolder import im.vector.matrix.android.internal.util.BackgroundDetectionObserver @@ -29,23 +32,37 @@ import org.matrix.olm.OlmManager import java.util.concurrent.atomic.AtomicBoolean import javax.inject.Inject +data class MatrixConfiguration( + val applicationFlavor: String = "Default-application-flavor" +) { + + interface Provider { + fun providesMatrixConfiguration(): MatrixConfiguration + } + +} + /** * This is the main entry point to the matrix sdk. - * This class is automatically init by a provider. * To get the singleton instance, use getInstance static method. */ -class Matrix private constructor(context: Context) { +class Matrix private constructor(context: Context, matrixConfiguration: MatrixConfiguration) { - @Inject internal lateinit var olmManager: OlmManager @Inject internal lateinit var authenticator: Authenticator @Inject internal lateinit var userAgentHolder: UserAgentHolder @Inject internal lateinit var backgroundDetectionObserver: BackgroundDetectionObserver + @Inject internal lateinit var olmManager: OlmManager + @Inject internal lateinit var sessionManager: SessionManager var currentSession: Session? = null init { Monarchy.init(context) DaggerMatrixComponent.factory().create(context).inject(this) + if (context.applicationContext !is Configuration.Provider) { + WorkManager.initialize(context, Configuration.Builder().build()) + } ProcessLifecycleOwner.get().lifecycle.addObserver(backgroundDetectionObserver) + userAgentHolder.setApplicationFlavor(matrixConfiguration.applicationFlavor) authenticator.getLastActiveSession()?.also { currentSession = it it.open() @@ -54,30 +71,33 @@ class Matrix private constructor(context: Context) { } } + fun getUserAgent() = userAgentHolder.userAgent + fun authenticator(): Authenticator { return authenticator } - /** - * Set application flavor, to alter user agent. - */ - fun setApplicationFlavor(flavor: String) { - userAgentHolder.setApplicationFlavor(flavor) - } - - fun getUserAgent() = userAgentHolder.userAgent - companion object { + private lateinit var instance: Matrix private val isInit = AtomicBoolean(false) - internal fun initialize(context: Context) { + fun initialize(context: Context, matrixConfiguration: MatrixConfiguration) { if (isInit.compareAndSet(false, true)) { - instance = Matrix(context.applicationContext) + instance = Matrix(context.applicationContext, matrixConfiguration) } } - fun getInstance(): Matrix { + fun getInstance(context: Context): Matrix { + if (isInit.compareAndSet(false, true)) { + val appContext = context.applicationContext + if (appContext is MatrixConfiguration.Provider) { + val matrixConfiguration = (appContext as MatrixConfiguration.Provider).providesMatrixConfiguration() + instance = Matrix(appContext, matrixConfiguration) + } else { + throw IllegalStateException("Matrix is not initialized properly. You should call Matrix.initialize or let your application implements MatrixConfiguration.Provider.") + } + } return instance } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/MatrixInitProvider.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/MatrixInitProvider.kt deleted file mode 100644 index 9167cbc5..00000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/MatrixInitProvider.kt +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2019 New Vector Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package im.vector.matrix.android.internal - -import android.content.ContentProvider -import android.content.ContentValues -import android.database.Cursor -import android.net.Uri -import im.vector.matrix.android.api.Matrix - -internal class MatrixInitProvider : ContentProvider() { - - override fun onCreate(): Boolean { - Matrix.initialize(context!!) - return true - } - - override fun insert(uri: Uri, values: ContentValues?): Uri? { - return null - } - - override fun query(uri: Uri, projection: Array?, selection: String?, selectionArgs: Array?, sortOrder: String?): Cursor? { - return null - } - - override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array?): Int { - return 0 - } - - override fun delete(uri: Uri, selection: String?, selectionArgs: Array?): Int { - return 0 - } - - override fun getType(uri: Uri): String? { - return null - } - -} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/SessionManager.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/SessionManager.kt index 74124bba..d70052ef 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/SessionManager.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/SessionManager.kt @@ -31,6 +31,10 @@ internal class SessionManager @Inject constructor(private val matrixComponent: M private val sessionComponents = HashMap() + fun getSessionComponent(userId: String): SessionComponent? { + return sessionComponents[userId] + } + fun createSession(sessionParams: SessionParams): Session { val userId = sessionParams.credentials.userId if (sessionComponents.containsKey(userId)) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/AuthModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/AuthModule.kt index 2f774647..71e7d371 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/AuthModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/AuthModule.kt @@ -35,7 +35,6 @@ internal abstract class AuthModule { companion object { @JvmStatic @Provides - @MatrixScope @AuthDatabase fun providesRealmConfiguration(context: Context): RealmConfiguration { val old = File(context.filesDir, "matrix-sdk-auth") @@ -51,11 +50,9 @@ internal abstract class AuthModule { } @Binds - @MatrixScope abstract fun bindSessionParamsStore(sessionParamsStore: RealmSessionParamsStore): SessionParamsStore @Binds - @MatrixScope abstract fun bindAuthenticator(authenticator: DefaultAuthenticator): Authenticator } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticator.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticator.kt index 56571fa8..c19ec005 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticator.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticator.kt @@ -37,7 +37,6 @@ import kotlinx.coroutines.withContext import retrofit2.Retrofit import javax.inject.Inject -@MatrixScope internal class DefaultAuthenticator @Inject constructor(private val retrofitBuilder: Retrofit.Builder, private val coroutineDispatchers: MatrixCoroutineDispatchers, private val sessionParamsStore: SessionParamsStore, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/RealmSessionParamsStore.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/RealmSessionParamsStore.kt index 3b742e65..4a202e3a 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/RealmSessionParamsStore.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/RealmSessionParamsStore.kt @@ -25,7 +25,6 @@ import io.realm.Realm import io.realm.RealmConfiguration import javax.inject.Inject -@MatrixScope internal class RealmSessionParamsStore @Inject constructor(private val mapper: SessionParamsMapper, @AuthDatabase private val realmConfiguration: RealmConfiguration ) : SessionParamsStore { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/SessionParamsMapper.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/SessionParamsMapper.kt index 53e3a98a..a8738cb4 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/SessionParamsMapper.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/SessionParamsMapper.kt @@ -23,7 +23,6 @@ import im.vector.matrix.android.api.auth.data.SessionParams import im.vector.matrix.android.internal.di.MatrixScope import javax.inject.Inject -@MatrixScope internal class SessionParamsMapper @Inject constructor(moshi: Moshi) { private val credentialsAdapter = moshi.adapter(Credentials::class.java) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoManager.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoManager.kt index 4c011bfd..5213b6c7 100755 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoManager.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoManager.kt @@ -93,6 +93,8 @@ import kotlin.coroutines.EmptyCoroutineContext */ @SessionScope internal class CryptoManager @Inject constructor( + // Olm Manager + private val olmManager: OlmManager, // The credentials, private val credentials: Credentials, private val myDeviceInfoHolder: MyDeviceInfoHolder, @@ -118,8 +120,6 @@ internal class CryptoManager @Inject constructor( private val incomingRoomKeyRequestManager: IncomingRoomKeyRequestManager, // private val outgoingRoomKeyRequestManager: OutgoingRoomKeyRequestManager, - // Olm Manager - private val olmManager: OlmManager, // Actions private val setDeviceVerificationAction: SetDeviceVerificationAction, private val megolmSessionDataImporter: MegolmSessionDataImporter, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoModule.kt index ccaa6c56..f5ed61b6 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoModule.kt @@ -88,8 +88,8 @@ internal abstract class CryptoModule { // Realm configuration, named to avoid clash with main cache realm configuration @JvmStatic @Provides - @SessionScope @CryptoDatabase + @SessionScope fun providesRealmConfiguration(context: Context, credentials: Credentials): RealmConfiguration { return RealmConfiguration.Builder() .directory(File(context.filesDir, credentials.userId.hash())) @@ -102,7 +102,6 @@ internal abstract class CryptoModule { @JvmStatic @Provides - @SessionScope @CryptoDatabase fun providesClearCacheTask(@CryptoDatabase realmConfiguration: RealmConfiguration): ClearCacheTask { return RealmClearCacheTask(realmConfiguration) @@ -111,7 +110,6 @@ internal abstract class CryptoModule { @JvmStatic @Provides - @SessionScope fun providesCryptoStore(@CryptoDatabase realmConfiguration: RealmConfiguration, credentials: Credentials): IMXCryptoStore { return RealmCryptoStore(false /* TODO*/, realmConfiguration, @@ -142,91 +140,69 @@ internal abstract class CryptoModule { } @Binds - @SessionScope abstract fun bindCryptoService(cryptoManager: CryptoManager): CryptoService @Binds - @SessionScope abstract fun bindDeleteDeviceTask(deleteDeviceTask: DefaultDeleteDeviceTask): DeleteDeviceTask @Binds - @SessionScope abstract fun bindGetDevicesTask(getDevicesTask: DefaultGetDevicesTask): GetDevicesTask @Binds - @SessionScope abstract fun bindSetDeviceNameTask(getDevicesTask: DefaultSetDeviceNameTask): SetDeviceNameTask @Binds - @SessionScope abstract fun bindUploadKeysTask(getDevicesTask: DefaultUploadKeysTask): UploadKeysTask @Binds - @SessionScope abstract fun bindDownloadKeysForUsersTask(downloadKeysForUsers: DefaultDownloadKeysForUsers): DownloadKeysForUsersTask @Binds - @SessionScope abstract fun bindCreateKeysBackupVersionTask(createKeysBackupVersionTask: DefaultCreateKeysBackupVersionTask): CreateKeysBackupVersionTask @Binds - @SessionScope abstract fun bindDeleteBackupTask(deleteBackupTask: DefaultDeleteBackupTask): DeleteBackupTask @Binds - @SessionScope abstract fun bindDeleteRoomSessionDataTask(deleteRoomSessionDataTask: DefaultDeleteRoomSessionDataTask): DeleteRoomSessionDataTask @Binds - @SessionScope abstract fun bindDeleteRoomSessionsDataTask(deleteRoomSessionDataTask: DefaultDeleteRoomSessionsDataTask): DeleteRoomSessionsDataTask @Binds - @SessionScope abstract fun bindDeleteSessionsDataTask(deleteRoomSessionDataTask: DefaultDeleteSessionsDataTask): DeleteSessionsDataTask @Binds - @SessionScope abstract fun bindGetKeysBackupLastVersionTask(getKeysBackupLastVersionTask: DefaultGetKeysBackupLastVersionTask): GetKeysBackupLastVersionTask @Binds - @SessionScope abstract fun bindGetKeysBackupVersionTask(getKeysBackupVersionTask: DefaultGetKeysBackupVersionTask) : GetKeysBackupVersionTask @Binds - @SessionScope abstract fun bindGetRoomSessionDataTask(getRoomSessionDataTask: DefaultGetRoomSessionDataTask) : GetRoomSessionDataTask @Binds - @SessionScope abstract fun bindGetRoomSessionsDataTask(getRoomSessionDataTask: DefaultGetRoomSessionsDataTask) : GetRoomSessionsDataTask @Binds - @SessionScope abstract fun bindGetSessionsDataTask(getRoomSessionDataTask: DefaultGetSessionsDataTask) : GetSessionsDataTask @Binds - @SessionScope abstract fun bindStoreRoomSessionDataTask(storeRoomSessionDataTask: DefaultStoreRoomSessionDataTask) : StoreRoomSessionDataTask @Binds - @SessionScope abstract fun bindStoreRoomSessionsDataTask(storeRoomSessionDataTask: DefaultStoreRoomSessionsDataTask) : StoreRoomSessionsDataTask @Binds - @SessionScope abstract fun bindStoreSessionsDataTask(storeRoomSessionDataTask: DefaultStoreSessionsDataTask) : StoreSessionsDataTask @Binds - @SessionScope abstract fun bindUpdateKeysBackupVersionTask(updateKeysBackupVersionTask: DefaultUpdateKeysBackupVersionTask) : UpdateKeysBackupVersionTask @Binds - @SessionScope abstract fun bindSendToDeviceTask(sendToDeviceTask: DefaultSendToDeviceTask) : SendToDeviceTask @Binds - @SessionScope abstract fun bindClaimOneTimeKeysForUsersDeviceTask(claimOneTimeKeysForUsersDevice: DefaultClaimOneTimeKeysForUsersDevice) : ClaimOneTimeKeysForUsersDeviceTask diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DeviceListManager.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DeviceListManager.kt index f58901d1..d6450f9c 100755 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DeviceListManager.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DeviceListManager.kt @@ -33,7 +33,6 @@ import java.util.* import javax.inject.Inject // Legacy name: MXDeviceList - @SessionScope internal class DeviceListManager @Inject constructor(private val cryptoStore: IMXCryptoStore, private val olmDevice: MXOlmDevice, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/ObjectSigner.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/ObjectSigner.kt index 2e91cb7a..8ca33ea4 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/ObjectSigner.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/ObjectSigner.kt @@ -21,7 +21,6 @@ import im.vector.matrix.android.internal.session.SessionScope import java.util.* import javax.inject.Inject -@SessionScope internal class ObjectSigner @Inject constructor(private val credentials: Credentials, private val olmDevice: MXOlmDevice) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/EnsureOlmSessionsForDevicesAction.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/EnsureOlmSessionsForDevicesAction.kt index 6ea04594..36a5b5cd 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/EnsureOlmSessionsForDevicesAction.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/EnsureOlmSessionsForDevicesAction.kt @@ -29,7 +29,6 @@ import timber.log.Timber import java.util.* import javax.inject.Inject -@SessionScope internal class EnsureOlmSessionsForDevicesAction @Inject constructor(private val olmDevice: MXOlmDevice, private val oneTimeKeysForUsersDeviceTask: ClaimOneTimeKeysForUsersDeviceTask) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/EnsureOlmSessionsForUsersAction.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/EnsureOlmSessionsForUsersAction.kt index 0f784b69..f6817e14 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/EnsureOlmSessionsForUsersAction.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/EnsureOlmSessionsForUsersAction.kt @@ -29,7 +29,6 @@ import timber.log.Timber import java.util.* import javax.inject.Inject -@SessionScope internal class EnsureOlmSessionsForUsersAction @Inject constructor(private val olmDevice: MXOlmDevice, private val cryptoStore: IMXCryptoStore, private val ensureOlmSessionsForDevicesAction: EnsureOlmSessionsForDevicesAction) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/MegolmSessionDataImporter.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/MegolmSessionDataImporter.kt index a311ee0a..34124cec 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/MegolmSessionDataImporter.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/MegolmSessionDataImporter.kt @@ -30,7 +30,6 @@ import im.vector.matrix.android.internal.session.SessionScope import timber.log.Timber import javax.inject.Inject -@SessionScope internal class MegolmSessionDataImporter @Inject constructor(private val olmDevice: MXOlmDevice, private val roomDecryptorProvider: RoomDecryptorProvider, private val outgoingRoomKeyRequestManager: OutgoingRoomKeyRequestManager, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/MessageEncrypter.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/MessageEncrypter.kt index fd063df9..4703237e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/MessageEncrypter.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/MessageEncrypter.kt @@ -29,7 +29,6 @@ import timber.log.Timber import java.util.* import javax.inject.Inject -@SessionScope internal class MessageEncrypter @Inject constructor(private val credentials: Credentials, private val olmDevice: MXOlmDevice) { 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 d5450077..dfc54ffe 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 @@ -23,7 +23,6 @@ import im.vector.matrix.android.internal.session.SessionScope import timber.log.Timber import javax.inject.Inject -@SessionScope internal class SetDeviceVerificationAction @Inject constructor(private val cryptoStore: IMXCryptoStore, private val credentials: Credentials, private val keysBackup: KeysBackup) { 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 2f9a61cf..43c485df 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 @@ -28,7 +28,6 @@ import im.vector.matrix.android.internal.session.SessionScope import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers import javax.inject.Inject -@SessionScope internal class MXMegolmDecryptionFactory @Inject constructor(private val credentials: Credentials, private val olmDevice: MXOlmDevice, private val deviceListManager: DeviceListManager, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmEncryptionFactory.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmEncryptionFactory.kt index 0fad79a6..2807863e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmEncryptionFactory.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmEncryptionFactory.kt @@ -29,7 +29,6 @@ import im.vector.matrix.android.internal.session.SessionScope import im.vector.matrix.android.internal.task.TaskExecutor import javax.inject.Inject -@SessionScope internal class MXMegolmEncryptionFactory @Inject constructor( private val olmDevice: MXOlmDevice, private val keysBackup: KeysBackup, 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 4fbf88bf..a8b4b1a0 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 @@ -21,7 +21,6 @@ import im.vector.matrix.android.internal.crypto.MXOlmDevice import im.vector.matrix.android.internal.session.SessionScope import javax.inject.Inject -@SessionScope internal class MXOlmDecryptionFactory @Inject constructor(private val olmDevice: MXOlmDevice, private val credentials: Credentials) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/olm/MXOlmEncryptionFactory.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/olm/MXOlmEncryptionFactory.kt index ef047d6c..99ab8eda 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/olm/MXOlmEncryptionFactory.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/olm/MXOlmEncryptionFactory.kt @@ -25,7 +25,6 @@ import im.vector.matrix.android.internal.session.SessionScope import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers import javax.inject.Inject -@SessionScope internal class MXOlmEncryptionFactory @Inject constructor(private val olmDevice: MXOlmDevice, private val cryptoStore: IMXCryptoStore, private val messageEncrypter: MessageEncrypter, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/tasks/CreateKeysBackupVersionTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/tasks/CreateKeysBackupVersionTask.kt index feb4a189..f0c5037f 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/tasks/CreateKeysBackupVersionTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/tasks/CreateKeysBackupVersionTask.kt @@ -21,13 +21,11 @@ import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.CreateKeysBackupVersionBody import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeysVersion import im.vector.matrix.android.internal.network.executeRequest -import im.vector.matrix.android.internal.session.SessionScope import im.vector.matrix.android.internal.task.Task import javax.inject.Inject internal interface CreateKeysBackupVersionTask : Task -@SessionScope internal class DefaultCreateKeysBackupVersionTask @Inject constructor(private val roomKeysApi: RoomKeysApi) : CreateKeysBackupVersionTask { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/tasks/DeleteBackupTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/tasks/DeleteBackupTask.kt index 6d857636..a1ad84ab 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/tasks/DeleteBackupTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/tasks/DeleteBackupTask.kt @@ -30,7 +30,6 @@ internal interface DeleteBackupTask : Task { ) } -@SessionScope internal class DefaultDeleteBackupTask @Inject constructor(private val roomKeysApi: RoomKeysApi) : DeleteBackupTask { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/tasks/DeleteRoomSessionDataTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/tasks/DeleteRoomSessionDataTask.kt index 3edd90a8..c24d314c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/tasks/DeleteRoomSessionDataTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/tasks/DeleteRoomSessionDataTask.kt @@ -31,7 +31,6 @@ internal interface DeleteRoomSessionDataTask : Task -@SessionScope internal class DefaultGetKeysBackupLastVersionTask @Inject constructor(private val roomKeysApi: RoomKeysApi) : GetKeysBackupLastVersionTask { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/tasks/GetKeysBackupVersionTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/tasks/GetKeysBackupVersionTask.kt index 0016a01b..dfaeafa1 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/tasks/GetKeysBackupVersionTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/tasks/GetKeysBackupVersionTask.kt @@ -20,13 +20,11 @@ import arrow.core.Try import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeysVersionResult import im.vector.matrix.android.internal.network.executeRequest -import im.vector.matrix.android.internal.session.SessionScope import im.vector.matrix.android.internal.task.Task import javax.inject.Inject internal interface GetKeysBackupVersionTask : Task -@SessionScope internal class DefaultGetKeysBackupVersionTask @Inject constructor(private val roomKeysApi: RoomKeysApi) : GetKeysBackupVersionTask { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/tasks/GetRoomSessionDataTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/tasks/GetRoomSessionDataTask.kt index 05aee672..253a2a5a 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/tasks/GetRoomSessionDataTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/tasks/GetRoomSessionDataTask.kt @@ -32,7 +32,6 @@ internal interface GetRoomSessionDataTask : Task { ) } -@SessionScope internal class DefaultDeleteDeviceTask @Inject constructor(private val cryptoApi: CryptoApi) : DeleteDeviceTask { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/DownloadKeysForUsersTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/DownloadKeysForUsersTask.kt index 09539ade..00ea7178 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/DownloadKeysForUsersTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/DownloadKeysForUsersTask.kt @@ -35,7 +35,6 @@ internal interface DownloadKeysForUsersTask : Task -@SessionScope internal class DefaultGetDevicesTask @Inject constructor(private val cryptoApi: CryptoApi) : GetDevicesTask { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/GetKeyChangesTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/GetKeyChangesTask.kt index a89dabea..21eabc22 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/GetKeyChangesTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/GetKeyChangesTask.kt @@ -33,7 +33,6 @@ internal interface GetKeyChangesTask : Task { ) } -@SessionScope internal class DefaultSendToDeviceTask @Inject constructor(private val cryptoApi: CryptoApi) : SendToDeviceTask { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/SetDeviceNameTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/SetDeviceNameTask.kt index 0997a4b2..04613ddd 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/SetDeviceNameTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/SetDeviceNameTask.kt @@ -34,7 +34,6 @@ internal interface SetDeviceNameTask : Task { ) } -@SessionScope internal class DefaultSetDeviceNameTask @Inject constructor(private val cryptoApi: CryptoApi) : SetDeviceNameTask { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/UploadKeysTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/UploadKeysTask.kt index 434803c2..96c3a558 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/UploadKeysTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/UploadKeysTask.kt @@ -38,7 +38,6 @@ internal interface UploadKeysTask : Task -@SessionScope internal class RealmClearCacheTask @Inject constructor(private val realmConfiguration: RealmConfiguration) : ClearCacheTask { override suspend fun execute(params: Unit): Try { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/cache/DefaultCacheService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/cache/DefaultCacheService.kt index d38e7cb2..34c5c5be 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/cache/DefaultCacheService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/cache/DefaultCacheService.kt @@ -24,7 +24,6 @@ import im.vector.matrix.android.internal.task.TaskExecutor import im.vector.matrix.android.internal.task.configureWith import javax.inject.Inject -@SessionScope internal class DefaultCacheService @Inject constructor(@SessionDatabase private val clearCacheTask: ClearCacheTask, private val taskExecutor: TaskExecutor) : CacheService { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/ContentModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/ContentModule.kt index 66b75a54..f87d0fd6 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/ContentModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/ContentModule.kt @@ -26,10 +26,8 @@ import im.vector.matrix.android.internal.session.SessionScope internal abstract class ContentModule { @Binds - @SessionScope abstract fun bindContentUploadStateTracker(contentUploadStateTracker: DefaultContentUploadStateTracker): ContentUploadStateTracker @Binds - @SessionScope abstract fun bindContentUrlResolver(contentUrlResolver: DefaultContentUrlResolver): ContentUrlResolver } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/DefaultContentUploadStateTracker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/DefaultContentUploadStateTracker.kt index fbd7983d..33941729 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/DefaultContentUploadStateTracker.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/DefaultContentUploadStateTracker.kt @@ -19,6 +19,7 @@ package im.vector.matrix.android.internal.session.content import android.os.Handler import android.os.Looper import im.vector.matrix.android.api.session.content.ContentUploadStateTracker +import im.vector.matrix.android.internal.di.MatrixScope import im.vector.matrix.android.internal.session.SessionScope import javax.inject.Inject diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/DefaultContentUrlResolver.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/DefaultContentUrlResolver.kt index bfba5bb7..50fe285a 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/DefaultContentUrlResolver.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/DefaultContentUrlResolver.kt @@ -25,7 +25,6 @@ import javax.inject.Inject private const val MATRIX_CONTENT_URI_SCHEME = "mxc://" private const val URI_PREFIX_CONTENT_API = "_matrix/media/v1/" -@SessionScope internal class DefaultContentUrlResolver @Inject constructor(private val homeServerConnectionConfig: HomeServerConnectionConfig) : ContentUrlResolver { companion object { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/FileUploader.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/FileUploader.kt index 71906b11..217c06ba 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/FileUploader.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/FileUploader.kt @@ -29,7 +29,6 @@ import java.io.IOException import javax.inject.Inject -@SessionScope internal class FileUploader @Inject constructor(private val okHttpClient: OkHttpClient, private val sessionParams: SessionParams, private val moshi: Moshi) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/UploadContentWorker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/UploadContentWorker.kt index 30c4b629..80b9b0a2 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/UploadContentWorker.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/UploadContentWorker.kt @@ -19,7 +19,6 @@ package im.vector.matrix.android.internal.session.content import android.content.Context import androidx.work.CoroutineWorker import androidx.work.WorkerParameters -import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject import com.squareup.moshi.JsonClass import im.vector.matrix.android.api.session.content.ContentAttachmentData @@ -31,32 +30,37 @@ import im.vector.matrix.android.api.session.room.model.message.MessageContent import im.vector.matrix.android.api.session.room.model.message.MessageFileContent import im.vector.matrix.android.api.session.room.model.message.MessageImageContent import im.vector.matrix.android.api.session.room.model.message.MessageVideoContent -import im.vector.matrix.android.internal.worker.DelegateWorkerFactory import im.vector.matrix.android.internal.network.ProgressRequestBody import im.vector.matrix.android.internal.session.room.send.SendEventWorker +import im.vector.matrix.android.internal.worker.DelegateWorkerFactory +import im.vector.matrix.android.internal.worker.SessionWorkerParams import im.vector.matrix.android.internal.worker.WorkerParamsFactory +import im.vector.matrix.android.internal.worker.getSessionComponent import timber.log.Timber import java.io.File +import javax.inject.Inject -internal class UploadContentWorker @AssistedInject constructor( - @Assisted context: Context, - @Assisted params: WorkerParameters, - private val fileUploader: FileUploader, - private val contentUploadStateTracker: DefaultContentUploadStateTracker) - : CoroutineWorker(context, params) { +internal class UploadContentWorker(context: Context, params: WorkerParameters) : CoroutineWorker(context, params) { @JsonClass(generateAdapter = true) internal data class Params( + override val userId: String, val roomId: String, val event: Event, val attachment: ContentAttachmentData - ) + ) : SessionWorkerParams + + @Inject lateinit var fileUploader: FileUploader + @Inject lateinit var contentUploadStateTracker: DefaultContentUploadStateTracker override suspend fun doWork(): Result { val params = WorkerParamsFactory.fromData(inputData) ?: return Result.success() + val sessionComponent = getSessionComponent(params.userId) ?: return Result.success() + sessionComponent.inject(this) + val eventId = params.event.eventId ?: return Result.success() val attachment = params.attachment @@ -105,7 +109,7 @@ internal class UploadContentWorker @AssistedInject constructor( thumbnailUrl: String?): Result { contentUploadStateTracker.setSuccess(params.event.eventId!!) val event = updateEvent(params.event, attachmentUrl, thumbnailUrl) - val sendParams = SendEventWorker.Params(params.roomId, event) + val sendParams = SendEventWorker.Params(params.userId, params.roomId, event) return Result.success(WorkerParamsFactory.toData(sendParams)) } @@ -137,8 +141,5 @@ internal class UploadContentWorker @AssistedInject constructor( return copy(url = url) } - @AssistedInject.Factory - interface Factory : DelegateWorkerFactory - } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/filter/DefaultFilterRepository.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/filter/DefaultFilterRepository.kt index f08c769f..f6a0a13b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/filter/DefaultFilterRepository.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/filter/DefaultFilterRepository.kt @@ -26,7 +26,6 @@ import io.realm.RealmConfiguration import io.realm.kotlin.where import javax.inject.Inject -@SessionScope internal class DefaultFilterRepository @Inject constructor( @SessionDatabase private val realmConfiguration: RealmConfiguration ) : FilterRepository { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/filter/DefaultFilterService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/filter/DefaultFilterService.kt index 033838ee..e64bce19 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/filter/DefaultFilterService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/filter/DefaultFilterService.kt @@ -22,7 +22,6 @@ import im.vector.matrix.android.internal.task.TaskExecutor import im.vector.matrix.android.internal.task.configureWith import javax.inject.Inject -@SessionScope internal class DefaultFilterService @Inject constructor(private val filterRepository: FilterRepository, private val saveFilterTask: SaveFilterTask, private val taskExecutor: TaskExecutor) : FilterService { 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 a3c7fea8..26612b23 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 @@ -35,7 +35,6 @@ internal interface SaveFilterTask : Task { } -@SessionScope internal class DefaultSaveFilterTask @Inject constructor(private val sessionParams: SessionParams, private val filterAPI: FilterApi, private val filterRepository: FilterRepository diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/filter/FilterModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/filter/FilterModule.kt index fed83d87..a43e19bd 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/filter/FilterModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/filter/FilterModule.kt @@ -30,24 +30,21 @@ internal abstract class FilterModule { @Module companion object { - @SessionScope @Provides @JvmStatic + @SessionScope fun providesFilterApi(retrofit: Retrofit): FilterApi { return retrofit.create(FilterApi::class.java) } } @Binds - @SessionScope abstract fun bindFilterRepository(filterRepository: DefaultFilterRepository): FilterRepository @Binds - @SessionScope abstract fun bindFilterService(filterService: DefaultFilterService): FilterService @Binds - @SessionScope abstract fun bindSaveFilterTask(saveFilterTask_Factory: DefaultSaveFilterTask): SaveFilterTask diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/DefaultGetGroupDataTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/DefaultGetGroupDataTask.kt index 15d4d55f..3c763d98 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/DefaultGetGroupDataTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/DefaultGetGroupDataTask.kt @@ -39,7 +39,6 @@ internal interface GetGroupDataTask : Task { } -@SessionScope internal class DefaultGetGroupDataTask @Inject constructor( private val groupAPI: GroupAPI, private val monarchy: Monarchy diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/DefaultGroupService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/DefaultGroupService.kt index 90ee7d58..ed0552da 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/DefaultGroupService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/DefaultGroupService.kt @@ -28,7 +28,6 @@ import im.vector.matrix.android.internal.database.query.where import im.vector.matrix.android.internal.session.SessionScope import javax.inject.Inject -@SessionScope internal class DefaultGroupService @Inject constructor(private val monarchy: Monarchy) : GroupService { override fun getGroup(groupId: String): Group? { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GetGroupDataWorker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GetGroupDataWorker.kt index 1a07fd93..4b3d6453 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GetGroupDataWorker.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GetGroupDataWorker.kt @@ -24,26 +24,28 @@ import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject import com.squareup.moshi.JsonClass import im.vector.matrix.android.internal.worker.DelegateWorkerFactory +import im.vector.matrix.android.internal.worker.SessionWorkerParams import im.vector.matrix.android.internal.worker.WorkerParamsFactory +import im.vector.matrix.android.internal.worker.getSessionComponent +import javax.inject.Inject -internal class GetGroupDataWorker @AssistedInject constructor( - @Assisted context: Context, - @Assisted params: WorkerParameters, - private val getGroupDataTask: GetGroupDataTask -) : CoroutineWorker(context, params) { - - @AssistedInject.Factory - interface Factory : DelegateWorkerFactory +internal class GetGroupDataWorker (context: Context, params: WorkerParameters) : CoroutineWorker(context, params) { @JsonClass(generateAdapter = true) internal data class Params( + override val userId: String, val groupIds: List - ) + ): SessionWorkerParams + + @Inject lateinit var getGroupDataTask: GetGroupDataTask override suspend fun doWork(): Result { val params = WorkerParamsFactory.fromData(inputData) ?: return Result.failure() + val sessionComponent = getSessionComponent(params.userId) ?: return Result.success() + sessionComponent.inject(this) + val results = params.groupIds.map { groupId -> fetchGroupData(groupId) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GroupModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GroupModule.kt index 518585d3..cdb698b0 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GroupModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GroupModule.kt @@ -28,19 +28,17 @@ internal abstract class GroupModule { @Module companion object { - @SessionScope @Provides @JvmStatic + @SessionScope fun providesGroupAPI(retrofit: Retrofit): GroupAPI { return retrofit.create(GroupAPI::class.java) } } @Binds - @SessionScope abstract fun bindGetGroupDataTask(getGroupDataTask: DefaultGetGroupDataTask): GetGroupDataTask @Binds - @SessionScope abstract fun bindGroupService(groupService: DefaultGroupService): GroupService } \ No newline at end of file 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 81b56c08..43bad2bc 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 @@ -16,23 +16,25 @@ package im.vector.matrix.android.internal.session.group +import android.content.Context import androidx.work.Constraints import androidx.work.ExistingWorkPolicy import androidx.work.NetworkType import androidx.work.OneTimeWorkRequestBuilder import androidx.work.WorkManager import com.zhuinden.monarchy.Monarchy +import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.internal.database.RealmLiveEntityObserver import im.vector.matrix.android.internal.database.model.GroupEntity import im.vector.matrix.android.internal.database.query.where -import im.vector.matrix.android.internal.session.SessionScope import im.vector.matrix.android.internal.worker.WorkerParamsFactory import javax.inject.Inject private const val GET_GROUP_DATA_WORKER = "GET_GROUP_DATA_WORKER" -@SessionScope -internal class GroupSummaryUpdater @Inject constructor(monarchy: Monarchy) : RealmLiveEntityObserver(monarchy) { +internal class GroupSummaryUpdater @Inject constructor(private val context: Context, + private val credentials: Credentials, + monarchy: Monarchy) : RealmLiveEntityObserver(monarchy) { override val query = Monarchy.Query { GroupEntity.where(it) } @@ -42,7 +44,7 @@ internal class GroupSummaryUpdater @Inject constructor(monarchy: Monarchy) : Rea override fun processChanges(inserted: List, updated: List, deleted: List) { val newGroupIds = inserted.map { it.groupId } - val getGroupDataWorkerParams = GetGroupDataWorker.Params(newGroupIds) + val getGroupDataWorkerParams = GetGroupDataWorker.Params(credentials.userId, newGroupIds) val workData = WorkerParamsFactory.toData(getGroupDataWorkerParams) val sendWork = OneTimeWorkRequestBuilder() @@ -50,7 +52,7 @@ internal class GroupSummaryUpdater @Inject constructor(monarchy: Monarchy) : Rea .setConstraints(workConstraints) .build() - WorkManager.getInstance() + WorkManager.getInstance(context) .beginUniqueWork(GET_GROUP_DATA_WORKER, ExistingWorkPolicy.APPEND, sendWork) .enqueue() } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoom.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoom.kt index 51f93873..44249c59 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoom.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoom.kt @@ -18,6 +18,7 @@ package im.vector.matrix.android.internal.session.room import androidx.lifecycle.LiveData import androidx.lifecycle.Transformations +import com.squareup.inject.assisted.AssistedInject import com.zhuinden.monarchy.Monarchy import im.vector.matrix.android.api.session.crypto.CryptoService import im.vector.matrix.android.api.session.room.Room @@ -33,27 +34,24 @@ 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.model.RoomSummaryEntityFields import im.vector.matrix.android.internal.database.query.where -import im.vector.matrix.android.internal.session.SessionScope import javax.inject.Inject -@SessionScope -internal class DefaultRoom @Inject constructor( - override val roomId: String, - private val monarchy: Monarchy, - private val timelineService: TimelineService, - private val sendService: SendService, - private val stateService: StateService, - private val readService: ReadService, - private val cryptoService: CryptoService, - private val relationService: RelationService, - private val roomMembersService: MembershipService +internal class DefaultRoom @Inject constructor(override val roomId: String, + private val monarchy: Monarchy, + private val timelineService: TimelineService, + private val sendService: SendService, + private val stateService: StateService, + private val readService: ReadService, + private val cryptoService: CryptoService, + private val relationService: RelationService, + private val roomMembersService: MembershipService ) : Room, - TimelineService by timelineService, - SendService by sendService, - StateService by stateService, - ReadService by readService, - RelationService by relationService, - MembershipService by roomMembersService { + TimelineService by timelineService, + SendService by sendService, + StateService by stateService, + ReadService by readService, + RelationService by relationService, + MembershipService by roomMembersService { override val roomSummary: LiveData by lazy { val liveRealmData = RealmLiveData(monarchy.realmConfiguration) { realm -> diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoomService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoomService.kt index 571a50d2..cd729c93 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoomService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoomService.kt @@ -35,7 +35,6 @@ import im.vector.matrix.android.internal.task.configureWith import im.vector.matrix.android.internal.util.fetchManaged import javax.inject.Inject -@SessionScope internal class DefaultRoomService @Inject constructor(private val monarchy: Monarchy, private val createRoomTask: CreateRoomTask, private val roomFactory: RoomFactory, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/EventRelationExtractor.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/EventRelationExtractor.kt index 78e24b2d..147726b1 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/EventRelationExtractor.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/EventRelationExtractor.kt @@ -28,7 +28,6 @@ import javax.inject.Inject * Fetches annotations (reactions, edits...) associated to a given eventEntity from the data layer. */ -@SessionScope internal class EventRelationExtractor @Inject constructor() { fun extractFrom(event: EventEntity, realm: Realm = event.realm): EventAnnotationsSummary? { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/EventRelationsAggregationTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/EventRelationsAggregationTask.kt index 18d0896e..2ed98f92 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/EventRelationsAggregationTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/EventRelationsAggregationTask.kt @@ -44,7 +44,6 @@ internal interface EventRelationsAggregationTask : Task -@SessionScope internal class DefaultCreateRoomTask @Inject constructor(private val roomAPI: RoomAPI, @SessionDatabase private val realmConfiguration: RealmConfiguration) : CreateRoomTask { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/directory/GetPublicRoomTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/directory/GetPublicRoomTask.kt index e3fbed1e..b2cc1a74 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/directory/GetPublicRoomTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/directory/GetPublicRoomTask.kt @@ -32,7 +32,6 @@ internal interface GetPublicRoomTask : Task { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/directory/GetThirdPartyProtocolsTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/directory/GetThirdPartyProtocolsTask.kt index d72c3b5a..cd53c92d 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/directory/GetThirdPartyProtocolsTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/directory/GetThirdPartyProtocolsTask.kt @@ -26,7 +26,6 @@ import javax.inject.Inject internal interface GetThirdPartyProtocolsTask : Task> -@SessionScope internal class DefaultGetThirdPartyProtocolsTask @Inject constructor (private val roomAPI: RoomAPI) : GetThirdPartyProtocolsTask { override suspend fun execute(params: Unit): Try> { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/membership/DefaultMembershipService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/membership/DefaultMembershipService.kt index 9f51ade0..a64071a5 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/membership/DefaultMembershipService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/membership/DefaultMembershipService.kt @@ -36,7 +36,6 @@ import im.vector.matrix.android.internal.task.configureWith import im.vector.matrix.android.internal.util.fetchCopied import javax.inject.Inject -@SessionScope internal class DefaultMembershipService @Inject constructor(private val roomId: String, private val monarchy: Monarchy, private val taskExecutor: TaskExecutor, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/membership/LoadRoomMembersTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/membership/LoadRoomMembersTask.kt index d49448a0..4dbb60b8 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/membership/LoadRoomMembersTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/membership/LoadRoomMembersTask.kt @@ -40,7 +40,6 @@ internal interface LoadRoomMembersTask : Task { ) } -@SessionScope internal class DefaultInviteTask @Inject constructor(private val roomAPI: RoomAPI) : InviteTask { override suspend fun execute(params: InviteTask.Params): Try { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/membership/joining/JoinRoomTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/membership/joining/JoinRoomTask.kt index 37f4a2fa..96454cbf 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/membership/joining/JoinRoomTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/membership/joining/JoinRoomTask.kt @@ -29,7 +29,6 @@ internal interface JoinRoomTask : Task { ) } -@SessionScope internal class DefaultJoinRoomTask @Inject constructor(private val roomAPI: RoomAPI) : JoinRoomTask { override suspend fun execute(params: JoinRoomTask.Params): Try { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/membership/leaving/LeaveRoomTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/membership/leaving/LeaveRoomTask.kt index 30c73035..fe055e99 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/membership/leaving/LeaveRoomTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/membership/leaving/LeaveRoomTask.kt @@ -29,7 +29,6 @@ internal interface LeaveRoomTask : Task { ) } -@SessionScope internal class DefaultLeaveRoomTask @Inject constructor(private val roomAPI: RoomAPI) : LeaveRoomTask { override suspend fun execute(params: LeaveRoomTask.Params): Try { 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 a1bb65af..456cbde7 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 @@ -33,7 +33,6 @@ import javax.inject.Inject * Listens to the database for the insertion of any redaction event. * As it will actually delete the content, it should be called last in the list of listener. */ -@SessionScope internal class EventsPruner @Inject constructor(monarchy: Monarchy, private val credentials: Credentials, private val pruneEventTask: PruneEventTask, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/prune/PruneEventTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/prune/PruneEventTask.kt index 08d52e24..56b40f2d 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/prune/PruneEventTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/prune/PruneEventTask.kt @@ -43,7 +43,6 @@ internal interface PruneEventTask : Task { } -@SessionScope internal class DefaultPruneEventTask @Inject constructor(private val monarchy: Monarchy) : PruneEventTask { override suspend fun execute(params: PruneEventTask.Params): Try { 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 ad3ad3b6..321e9890 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 @@ -27,7 +27,6 @@ import im.vector.matrix.android.internal.task.configureWith import im.vector.matrix.android.internal.util.fetchCopied import javax.inject.Inject -@SessionScope internal class DefaultReadService @Inject constructor(private val roomId: String, private val monarchy: Monarchy, private val taskExecutor: TaskExecutor, 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 aef52f5f..2146fdf0 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 @@ -47,7 +47,6 @@ internal interface SetReadMarkersTask : Task { private const val READ_MARKER = "m.fully_read" private const val READ_RECEIPT = "m.read" -@SessionScope internal class DefaultSetReadMarkersTask @Inject constructor(private val roomAPI: RoomAPI, private val credentials: Credentials, private val monarchy: Monarchy 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 7ae4e5df..bbac2d0a 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 @@ -15,10 +15,12 @@ */ package im.vector.matrix.android.internal.session.room.relation +import android.content.Context import androidx.lifecycle.LiveData import androidx.work.OneTimeWorkRequest 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.events.model.Event import im.vector.matrix.android.api.session.room.model.EventAnnotationsSummary import im.vector.matrix.android.api.session.room.model.message.MessageType @@ -38,11 +40,14 @@ import im.vector.matrix.android.internal.session.room.timeline.TimelineSendEvent import im.vector.matrix.android.internal.task.TaskExecutor import im.vector.matrix.android.internal.task.configureWith import im.vector.matrix.android.internal.util.CancelableWork -import im.vector.matrix.android.internal.worker.WorkerParamsFactory import im.vector.matrix.android.internal.util.tryTransactionAsync +import im.vector.matrix.android.internal.worker.WorkerParamsFactory import timber.log.Timber +import javax.inject.Inject -internal class DefaultRelationService constructor(private val roomId: String, +internal class DefaultRelationService @Inject constructor(private val context: Context, + private val credentials: Credentials, + private val roomId: String, private val eventFactory: LocalEchoEventFactory, private val findReactionEventForUndoTask: FindReactionEventForUndoTask, private val updateQuickReactionTask: UpdateQuickReactionTask, @@ -57,14 +62,13 @@ internal class DefaultRelationService constructor(private val roomId: String, saveLocalEcho(it) } val sendRelationWork = createSendRelationWork(event) - TimelineSendEventWorkCommon.postWork(roomId, sendRelationWork) - return CancelableWork(sendRelationWork.id) + TimelineSendEventWorkCommon.postWork(context, roomId, sendRelationWork) + return CancelableWork(context, sendRelationWork.id) } private fun createSendRelationWork(event: Event): OneTimeWorkRequest { - val sendContentWorkerParams = SendEventWorker.Params( - roomId, event) + val sendContentWorkerParams = SendEventWorker.Params(credentials.userId,roomId, event) val sendWorkData = WorkerParamsFactory.toData(sendContentWorkerParams) return TimelineSendEventWorkCommon.createWork(sendWorkData) @@ -94,7 +98,7 @@ internal class DefaultRelationService constructor(private val roomId: String, } val redactWork = createRedactEventWork(redactEvent, toRedact, null) - TimelineSendEventWorkCommon.postWork(roomId, redactWork) + TimelineSendEventWorkCommon.postWork(context, roomId, redactWork) } } @@ -123,7 +127,7 @@ internal class DefaultRelationService constructor(private val roomId: String, saveLocalEcho(it) } val redactWork = createRedactEventWork(redactEvent, it, null) - TimelineSendEventWorkCommon.postWork(roomId, redactWork) + TimelineSendEventWorkCommon.postWork(context, roomId, redactWork) } } }) @@ -137,7 +141,7 @@ internal class DefaultRelationService constructor(private val roomId: String, //TODO duplicate with send service? private fun createRedactEventWork(localEvent: Event, eventId: String, reason: String?): OneTimeWorkRequest { - val sendContentWorkerParams = RedactEventWorker.Params(localEvent.eventId!!, + val sendContentWorkerParams = RedactEventWorker.Params(credentials.userId ,localEvent.eventId!!, roomId, eventId, reason) val redactWorkData = WorkerParamsFactory.toData(sendContentWorkerParams) return TimelineSendEventWorkCommon.createWork(redactWorkData) @@ -147,14 +151,14 @@ internal class DefaultRelationService constructor(private val roomId: String, val event = eventFactory.createReplaceTextEvent(roomId, targetEventId, newBodyText, newBodyAutoMarkdown, MessageType.MSGTYPE_TEXT, compatibilityBodyText).also { saveLocalEcho(it) } - val sendContentWorkerParams = SendEventWorker.Params(roomId, event) + val sendContentWorkerParams = SendEventWorker.Params(credentials.userId ,roomId, event) val sendWorkData = WorkerParamsFactory.toData(sendContentWorkerParams) //TODO use relation API? val workRequest = TimelineSendEventWorkCommon.createWork(sendWorkData) - TimelineSendEventWorkCommon.postWork(roomId, workRequest) - return CancelableWork(workRequest.id) + TimelineSendEventWorkCommon.postWork(context, roomId, workRequest) + return CancelableWork(context, workRequest.id) } @@ -163,13 +167,13 @@ internal class DefaultRelationService constructor(private val roomId: String, val event = eventFactory.createReplyTextEvent(roomId, eventReplied, replyText)?.also { saveLocalEcho(it) } ?: return null - val sendContentWorkerParams = SendEventWorker.Params(roomId, event) + val sendContentWorkerParams = SendEventWorker.Params(credentials.userId ,roomId, event) val sendWorkData = WorkerParamsFactory.toData(sendContentWorkerParams) val workRequest = TimelineSendEventWorkCommon.createWork(sendWorkData) - TimelineSendEventWorkCommon.postWork(roomId, workRequest) - return CancelableWork(workRequest.id) + TimelineSendEventWorkCommon.postWork(context, roomId, workRequest) + return CancelableWork(context, workRequest.id) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/FindReactionEventForUndoTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/FindReactionEventForUndoTask.kt index 7a7abdbe..8841819e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/FindReactionEventForUndoTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/FindReactionEventForUndoTask.kt @@ -42,7 +42,6 @@ internal interface FindReactionEventForUndoTask : Task { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/SendRelationWorker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/SendRelationWorker.kt index dbd97714..b269f161 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/SendRelationWorker.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/SendRelationWorker.kt @@ -18,7 +18,6 @@ package im.vector.matrix.android.internal.session.room.relation import android.content.Context import androidx.work.Worker import androidx.work.WorkerParameters -import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject import com.squareup.moshi.JsonClass import im.vector.matrix.android.api.failure.Failure @@ -26,30 +25,34 @@ import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.toModel import im.vector.matrix.android.api.session.room.model.relation.ReactionContent import im.vector.matrix.android.api.session.room.model.relation.ReactionInfo -import im.vector.matrix.android.internal.worker.DelegateWorkerFactory 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.SendResponse +import im.vector.matrix.android.internal.worker.DelegateWorkerFactory +import im.vector.matrix.android.internal.worker.SessionWorkerParams import im.vector.matrix.android.internal.worker.WorkerParamsFactory +import im.vector.matrix.android.internal.worker.getSessionComponent +import javax.inject.Inject -internal class SendRelationWorker @AssistedInject constructor( - @Assisted context: Context, - @Assisted params: WorkerParameters, - private val roomAPI: RoomAPI) - : Worker(context, params) { - +internal class SendRelationWorker(context: Context, params: WorkerParameters): Worker(context, params) { @JsonClass(generateAdapter = true) internal data class Params( + override val userId: String, val roomId: String, val event: Event, val relationType: String? = null - ) + ): SessionWorkerParams + + @Inject lateinit var roomAPI: RoomAPI override fun doWork(): Result { val params = WorkerParamsFactory.fromData(inputData) ?: return Result.failure() + val sessionComponent = getSessionComponent(params.userId) ?: return Result.success() + sessionComponent.inject(this) + val localEvent = params.event if (localEvent.eventId == null) { return Result.failure() @@ -81,6 +84,4 @@ internal class SendRelationWorker @AssistedInject constructor( }, { Result.success() }) } - @AssistedInject.Factory - interface Factory : DelegateWorkerFactory } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/UpdateQuickReactionTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/UpdateQuickReactionTask.kt index 2169adeb..66e02ce9 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/UpdateQuickReactionTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/UpdateQuickReactionTask.kt @@ -43,7 +43,6 @@ internal interface UpdateQuickReactionTask : Task { return Try { 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 12fee962..c5a775b7 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 @@ -16,8 +16,16 @@ package im.vector.matrix.android.internal.session.room.send -import androidx.work.* +import android.content.Context +import androidx.work.BackoffPolicy +import androidx.work.Constraints +import androidx.work.ExistingWorkPolicy +import androidx.work.NetworkType +import androidx.work.OneTimeWorkRequest +import androidx.work.OneTimeWorkRequestBuilder +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.content.ContentAttachmentData import im.vector.matrix.android.api.session.crypto.CryptoService import im.vector.matrix.android.api.session.events.model.Event @@ -31,6 +39,7 @@ import im.vector.matrix.android.internal.util.CancelableWork import im.vector.matrix.android.internal.worker.WorkerParamsFactory import timber.log.Timber import java.util.concurrent.TimeUnit +import javax.inject.Inject private const val UPLOAD_WORK = "UPLOAD_WORK" private const val BACKOFF_DELAY = 10_000L @@ -39,10 +48,12 @@ private val WORK_CONSTRAINTS = Constraints.Builder() .setRequiredNetworkType(NetworkType.CONNECTED) .build() -internal class DefaultSendService(private val roomId: String, - private val localEchoEventFactory: LocalEchoEventFactory, - private val cryptoService: CryptoService, - private val monarchy: Monarchy) +internal class DefaultSendService @Inject constructor(private val context: Context, + private val credentials: Credentials, + private val roomId: String, + private val localEchoEventFactory: LocalEchoEventFactory, + private val cryptoService: CryptoService, + private val monarchy: Monarchy) : SendService { override fun sendTextMessage(text: String, msgType: String, autoMarkdown: Boolean): Cancelable { @@ -54,8 +65,8 @@ internal class DefaultSendService(private val roomId: String, Timber.v("Send event in encrypted room") val encryptWork = createEncryptEventWork(event) val sendWork = createSendEventWork(event) - TimelineSendEventWorkCommon.postSequentialWorks(roomId, encryptWork, sendWork) - CancelableWork(encryptWork.id) + TimelineSendEventWorkCommon.postSequentialWorks(context, roomId, encryptWork, sendWork) + CancelableWork(context, encryptWork.id) } else { sendEvent(event) } @@ -63,8 +74,8 @@ internal class DefaultSendService(private val roomId: String, private fun sendEvent(event: Event): Cancelable { val sendWork = createSendEventWork(event) - TimelineSendEventWorkCommon.postWork(roomId, sendWork) - return CancelableWork(sendWork.id) + TimelineSendEventWorkCommon.postWork(context, roomId, sendWork) + return CancelableWork(context, sendWork.id) } override fun sendFormattedTextMessage(text: String, formattedText: String): Cancelable { @@ -72,8 +83,8 @@ internal class DefaultSendService(private val roomId: String, saveLocalEcho(it) } val sendWork = createSendEventWork(event) - TimelineSendEventWorkCommon.postWork(roomId, sendWork) - return CancelableWork(sendWork.id) + TimelineSendEventWorkCommon.postWork(context, roomId, sendWork) + return CancelableWork(context, sendWork.id) } override fun sendMedias(attachments: List): Cancelable { @@ -87,8 +98,8 @@ internal class DefaultSendService(private val roomId: String, override fun redactEvent(event: Event, reason: String?): Cancelable { //TODO manage media/attachements? val redactWork = createRedactEventWork(event, reason) - TimelineSendEventWorkCommon.postWork(roomId, redactWork) - return CancelableWork(redactWork.id) + TimelineSendEventWorkCommon.postWork(context, roomId, redactWork) + return CancelableWork(context, redactWork.id) } override fun sendMedia(attachment: ContentAttachmentData): Cancelable { @@ -99,12 +110,12 @@ internal class DefaultSendService(private val roomId: String, val uploadWork = createUploadMediaWork(event, attachment) val sendWork = createSendEventWork(event) - WorkManager.getInstance() + WorkManager.getInstance(context) .beginUniqueWork(buildWorkIdentifier(UPLOAD_WORK), ExistingWorkPolicy.APPEND, uploadWork) .then(sendWork) .enqueue() - return CancelableWork(sendWork.id) + return CancelableWork(context, sendWork.id) } private fun saveLocalEcho(event: Event) { @@ -117,7 +128,7 @@ internal class DefaultSendService(private val roomId: String, private fun createEncryptEventWork(event: Event): OneTimeWorkRequest { // Same parameter - val params = EncryptEventWorker.Params(roomId, event) + val params = EncryptEventWorker.Params(credentials.userId ,roomId, event) val sendWorkData = WorkerParamsFactory.toData(params) return OneTimeWorkRequestBuilder() @@ -128,7 +139,7 @@ internal class DefaultSendService(private val roomId: String, } private fun createSendEventWork(event: Event): OneTimeWorkRequest { - val sendContentWorkerParams = SendEventWorker.Params(roomId, event) + val sendContentWorkerParams = SendEventWorker.Params(credentials.userId ,roomId, event) val sendWorkData = WorkerParamsFactory.toData(sendContentWorkerParams) return TimelineSendEventWorkCommon.createWork(sendWorkData) @@ -138,13 +149,13 @@ internal class DefaultSendService(private val roomId: String, val redactEvent = localEchoEventFactory.createRedactEvent(roomId, event.eventId!!, reason).also { saveLocalEcho(it) } - val sendContentWorkerParams = RedactEventWorker.Params(redactEvent.eventId!!, roomId, event.eventId, reason) + val sendContentWorkerParams = RedactEventWorker.Params(credentials.userId ,redactEvent.eventId!!, roomId, event.eventId, reason) val redactWorkData = WorkerParamsFactory.toData(sendContentWorkerParams) return TimelineSendEventWorkCommon.createWork(redactWorkData) } private fun createUploadMediaWork(event: Event, attachment: ContentAttachmentData): OneTimeWorkRequest { - val uploadMediaWorkerParams = UploadContentWorker.Params(roomId, event, attachment) + val uploadMediaWorkerParams = UploadContentWorker.Params(credentials.userId ,roomId, event, attachment) val uploadWorkData = WorkerParamsFactory.toData(uploadMediaWorkerParams) return OneTimeWorkRequestBuilder() diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/EncryptEventWorker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/EncryptEventWorker.kt index 256f3d16..4e6537b7 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/EncryptEventWorker.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/EncryptEventWorker.kt @@ -30,27 +30,32 @@ import im.vector.matrix.android.api.session.room.send.SendState import im.vector.matrix.android.internal.crypto.model.MXEncryptEventContentResult import im.vector.matrix.android.internal.worker.WorkerParamsFactory import im.vector.matrix.android.internal.worker.DelegateWorkerFactory +import im.vector.matrix.android.internal.worker.SessionWorkerParams +import im.vector.matrix.android.internal.worker.getSessionComponent import java.util.concurrent.CountDownLatch +import javax.inject.Inject -internal class EncryptEventWorker @AssistedInject constructor( - @Assisted context: Context, - @Assisted params: WorkerParameters, - private val crypto: CryptoService, - private val localEchoUpdater: LocalEchoUpdater) +internal class EncryptEventWorker(context: Context, params: WorkerParameters) : Worker(context, params) { - @JsonClass(generateAdapter = true) internal data class Params( + override val userId: String, val roomId: String, val event: Event - ) + ): SessionWorkerParams + + @Inject lateinit var crypto: CryptoService + @Inject lateinit var localEchoUpdater: LocalEchoUpdater override fun doWork(): Result { val params = WorkerParamsFactory.fromData(inputData) ?: return Result.success() + val sessionComponent = getSessionComponent(params.userId) ?: return Result.success() + sessionComponent.inject(this) + val localEvent = params.event if (localEvent.eventId == null) { return Result.success() @@ -87,7 +92,7 @@ internal class EncryptEventWorker @AssistedInject constructor( type = safeResult.eventType, content = safeResult.eventContent ) - val nextWorkerParams = SendEventWorker.Params(params.roomId, encryptedEvent) + val nextWorkerParams = SendEventWorker.Params(params.userId, params.roomId, encryptedEvent) return Result.success(WorkerParamsFactory.toData(nextWorkerParams)) } val safeError = error @@ -99,8 +104,4 @@ internal class EncryptEventWorker @AssistedInject constructor( //always return success, or the chain will be stuck for ever! return Result.success() } - - @AssistedInject.Factory - interface Factory : DelegateWorkerFactory - } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/EventFactory.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/EventFactory.kt index 7ebab9d6..d76b730e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/EventFactory.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/EventFactory.kt @@ -25,7 +25,6 @@ import im.vector.matrix.android.internal.di.MoshiProvider import im.vector.matrix.android.internal.session.SessionScope import javax.inject.Inject -@SessionScope internal class EventFactory @Inject constructor(private val credentials: Credentials) { private val moshi = MoshiProvider.providesMoshi() 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 585b925a..924025f3 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 @@ -52,7 +52,6 @@ import javax.inject.Inject * The transactionID is used as loc */ -@SessionScope internal class LocalEchoEventFactory @Inject constructor(private val credentials: Credentials, private val stringProvider: StringProvider) { fun createTextEvent(roomId: String, msgType: String, text: String, autoMarkdown: Boolean): Event { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoUpdater.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoUpdater.kt index 689d2b48..ec063f3a 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoUpdater.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoUpdater.kt @@ -26,7 +26,6 @@ import im.vector.matrix.android.internal.session.SessionScope import im.vector.matrix.android.internal.util.tryTransactionAsync import javax.inject.Inject -@SessionScope internal class LocalEchoUpdater @Inject constructor(private val monarchy: Monarchy) { fun updateSendState(eventId: String, sendState: SendState) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/RedactEventWorker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/RedactEventWorker.kt index 7d45a2a6..23e1d92d 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/RedactEventWorker.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/RedactEventWorker.kt @@ -18,33 +18,37 @@ package im.vector.matrix.android.internal.session.room.send import android.content.Context import androidx.work.Worker import androidx.work.WorkerParameters -import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject import com.squareup.moshi.JsonClass import im.vector.matrix.android.api.failure.Failure import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.session.room.RoomAPI -import im.vector.matrix.android.internal.worker.WorkerParamsFactory import im.vector.matrix.android.internal.worker.DelegateWorkerFactory +import im.vector.matrix.android.internal.worker.SessionWorkerParams +import im.vector.matrix.android.internal.worker.WorkerParamsFactory +import im.vector.matrix.android.internal.worker.getSessionComponent +import javax.inject.Inject -internal class RedactEventWorker @AssistedInject constructor( - @Assisted context: Context, - @Assisted params: WorkerParameters, - private val roomAPI: RoomAPI) - : Worker(context, params) { +internal class RedactEventWorker(context: Context, params: WorkerParameters) : Worker(context, params) { @JsonClass(generateAdapter = true) internal data class Params( + override val userId: String, val txID: String, val roomId: String, val eventId: String, val reason: String? - ) + ) : SessionWorkerParams + + @Inject lateinit var roomAPI: RoomAPI override fun doWork(): Result { val params = WorkerParamsFactory.fromData(inputData) ?: return Result.failure() + val sessionComponent = getSessionComponent(params.userId) ?: return Result.success() + sessionComponent.inject(this) + val eventId = params.eventId val result = executeRequest { apiCall = roomAPI.redactEvent( @@ -55,20 +59,17 @@ internal class RedactEventWorker @AssistedInject constructor( ) } return result.fold({ - when (it) { - is Failure.NetworkConnection -> Result.retry() - else -> { - //TODO mark as failed to send? - //always return success, or the chain will be stuck for ever! - Result.success() - } - } - }, { - Result.success() - }) + when (it) { + is Failure.NetworkConnection -> Result.retry() + else -> { + //TODO mark as failed to send? + //always return success, or the chain will be stuck for ever! + Result.success() + } + } + }, { + Result.success() + }) } - @AssistedInject.Factory - interface Factory : DelegateWorkerFactory - } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/SendEventWorker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/SendEventWorker.kt index 6ff60da0..948eb25b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/SendEventWorker.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/SendEventWorker.kt @@ -19,36 +19,40 @@ package im.vector.matrix.android.internal.session.room.send import android.content.Context import androidx.work.Worker import androidx.work.WorkerParameters -import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject import com.squareup.moshi.JsonClass +import im.vector.matrix.android.api.Matrix import im.vector.matrix.android.api.failure.Failure import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.room.send.SendState -import im.vector.matrix.android.internal.worker.DelegateWorkerFactory import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.session.room.RoomAPI +import im.vector.matrix.android.internal.worker.DelegateWorkerFactory +import im.vector.matrix.android.internal.worker.SessionWorkerParams import im.vector.matrix.android.internal.worker.WorkerParamsFactory +import im.vector.matrix.android.internal.worker.getSessionComponent +import javax.inject.Inject -internal class SendEventWorker @AssistedInject constructor( - @Assisted context: Context, - @Assisted params: WorkerParameters, - private val roomAPI: RoomAPI, - private val localEchoUpdater: LocalEchoUpdater) +internal class SendEventWorker constructor(context: Context, params: WorkerParameters) : Worker(context, params) { - @JsonClass(generateAdapter = true) internal data class Params( + override val userId: String, val roomId: String, val event: Event - ) + ) : SessionWorkerParams + + @Inject lateinit var localEchoUpdater: LocalEchoUpdater + @Inject lateinit var roomAPI: RoomAPI override fun doWork(): Result { - val params = WorkerParamsFactory.fromData(inputData) ?: return Result.success() + val sessionComponent = getSessionComponent(params.userId) ?: return Result.success() + sessionComponent.inject(this) + val event = params.event if (event.eventId == null) { return Result.success() @@ -75,7 +79,4 @@ internal class SendEventWorker @AssistedInject constructor( }, { Result.success() }) } - @AssistedInject.Factory - interface Factory : DelegateWorkerFactory - } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/state/DefaultStateService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/state/DefaultStateService.kt index 6988b6f8..b3ae4442 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/state/DefaultStateService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/state/DefaultStateService.kt @@ -24,7 +24,6 @@ import im.vector.matrix.android.internal.task.TaskExecutor import im.vector.matrix.android.internal.task.configureWith import javax.inject.Inject -@SessionScope internal class DefaultStateService @Inject constructor(private val roomId: String, private val taskExecutor: TaskExecutor, private val sendStateTask: SendStateTask) : StateService { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/state/SendStateTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/state/SendStateTask.kt index 45e714e1..085340e6 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/state/SendStateTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/state/SendStateTask.kt @@ -31,7 +31,6 @@ internal interface SendStateTask : Task { ) } -@SessionScope internal class DefaultSendStateTask @Inject constructor(private val roomAPI: RoomAPI) : SendStateTask { override suspend fun execute(params: SendStateTask.Params): Try { return executeRequest { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/DefaultGetContextOfEventTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/DefaultGetContextOfEventTask.kt index 49c69a00..a47bab62 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/DefaultGetContextOfEventTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/DefaultGetContextOfEventTask.kt @@ -33,7 +33,6 @@ internal interface GetContextOfEventTask : Task?): Timeline { @@ -38,11 +39,12 @@ internal class DefaultTimelineService(private val roomId: String, } override fun getTimeLineEvent(eventId: String): TimelineEvent? { - return monarchy.fetchCopyMap({ - EventEntity.where(it, eventId = eventId).findFirst() - }, { entity, realm -> - timelineEventFactory.create(entity, realm) - }) + return monarchy + .fetchCopyMap({ + EventEntity.where(it, eventId = eventId).findFirst() + }, { entity, realm -> + timelineEventFactory.create(entity, realm) + }) } } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/GetEventTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/GetEventTask.kt index e791ba76..5ce58e02 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/GetEventTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/GetEventTask.kt @@ -24,7 +24,6 @@ import im.vector.matrix.android.internal.session.SessionScope import im.vector.matrix.android.internal.session.room.RoomAPI import javax.inject.Inject -@SessionScope internal class GetEventTask @Inject constructor(private val roomAPI: RoomAPI ) : Task { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TimelineSendEventWorkCommon.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TimelineSendEventWorkCommon.kt index b47fad21..ca2007a1 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TimelineSendEventWorkCommon.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TimelineSendEventWorkCommon.kt @@ -15,6 +15,7 @@ */ package im.vector.matrix.android.internal.session.room.timeline +import android.content.Context import androidx.work.* import java.util.concurrent.TimeUnit @@ -35,13 +36,13 @@ private val WORK_CONSTRAINTS = Constraints.Builder() */ internal object TimelineSendEventWorkCommon { - fun postSequentialWorks(roomId: String, vararg workRequests: OneTimeWorkRequest) { + fun postSequentialWorks(context: Context, roomId: String, vararg workRequests: OneTimeWorkRequest) { when { workRequests.isEmpty() -> return - workRequests.size == 1 -> postWork(roomId, workRequests.first()) + workRequests.size == 1 -> postWork(context, roomId, workRequests.first()) else -> { val firstWork = workRequests.first() - var continuation = WorkManager.getInstance() + var continuation = WorkManager.getInstance(context) .beginUniqueWork(buildWorkIdentifier(roomId), ExistingWorkPolicy.APPEND, firstWork) for (i in 1 until workRequests.size) { val workRequest = workRequests[i] @@ -52,8 +53,8 @@ internal object TimelineSendEventWorkCommon { } } - fun postWork(roomId: String, workRequest: OneTimeWorkRequest) { - WorkManager.getInstance() + fun postWork(context: Context, roomId: String, workRequest: OneTimeWorkRequest) { + WorkManager.getInstance(context) .beginUniqueWork(buildWorkIdentifier(roomId), ExistingWorkPolicy.APPEND, workRequest) .enqueue() } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TokenChunkEventPersistor.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TokenChunkEventPersistor.kt index 3aa07b00..50881854 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TokenChunkEventPersistor.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TokenChunkEventPersistor.kt @@ -18,14 +18,18 @@ package im.vector.matrix.android.internal.session.room.timeline import arrow.core.Try import com.zhuinden.monarchy.Monarchy -import im.vector.matrix.android.internal.database.helper.* +import im.vector.matrix.android.internal.database.helper.addAll +import im.vector.matrix.android.internal.database.helper.addOrUpdate +import im.vector.matrix.android.internal.database.helper.addStateEvents +import im.vector.matrix.android.internal.database.helper.deleteOnCascade +import im.vector.matrix.android.internal.database.helper.isUnlinked +import im.vector.matrix.android.internal.database.helper.merge import im.vector.matrix.android.internal.database.model.ChunkEntity import im.vector.matrix.android.internal.database.model.RoomEntity import im.vector.matrix.android.internal.database.query.create import im.vector.matrix.android.internal.database.query.find import im.vector.matrix.android.internal.database.query.findAllIncludingEvents import im.vector.matrix.android.internal.database.query.where -import im.vector.matrix.android.internal.session.SessionScope import im.vector.matrix.android.internal.util.tryTransactionSync import io.realm.kotlin.createObject import timber.log.Timber @@ -34,7 +38,6 @@ import javax.inject.Inject /** * Insert Chunk in DB, and eventually merge with existing chunk event */ -@SessionScope internal class TokenChunkEventPersistor @Inject constructor(private val monarchy: Monarchy) { /** @@ -114,7 +117,7 @@ internal class TokenChunkEventPersistor @Inject constructor(private val monarchy Timber.v("Start persisting ${receivedChunk.events.size} events in $roomId towards $direction") val roomEntity = RoomEntity.where(realm, roomId).findFirst() - ?: realm.createObject(roomId) + ?: realm.createObject(roomId) val nextToken: String? val prevToken: String? @@ -137,7 +140,7 @@ internal class TokenChunkEventPersistor @Inject constructor(private val monarchy } else { nextChunk?.apply { this.prevToken = prevToken } } - ?: ChunkEntity.create(realm, prevToken, nextToken) + ?: ChunkEntity.create(realm, prevToken, nextToken) if (receivedChunk.events.isEmpty() && receivedChunk.end == receivedChunk.start) { Timber.v("Reach end of $roomId") diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/signout/DefaultSignOutService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/signout/DefaultSignOutService.kt index 3589df3d..2b240ff9 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/signout/DefaultSignOutService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/signout/DefaultSignOutService.kt @@ -23,7 +23,6 @@ import im.vector.matrix.android.internal.task.TaskExecutor import im.vector.matrix.android.internal.task.configureWith import javax.inject.Inject -@SessionScope internal class DefaultSignOutService @Inject constructor(private val signOutTask: SignOutTask, private val taskExecutor: TaskExecutor) : SignOutService { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/signout/SignOutModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/signout/SignOutModule.kt index 63df5a03..b4863090 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/signout/SignOutModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/signout/SignOutModule.kt @@ -30,20 +30,18 @@ internal abstract class SignOutModule { @Module companion object { - @SessionScope @Provides @JvmStatic + @SessionScope fun providesSignOutAPI(retrofit: Retrofit): SignOutAPI { return retrofit.create(SignOutAPI::class.java) } } @Binds - @SessionScope abstract fun bindSignOutTask(signOutTask: DefaultSignOutTask): SignOutTask @Binds - @SessionScope abstract fun bindSignOutService(signOutService: DefaultSignOutService): SignOutService } \ No newline at end of file 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 ab34e0f8..b627ebd6 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 @@ -25,7 +25,6 @@ import javax.inject.Inject internal interface SignOutTask : Task -@SessionScope internal class DefaultSignOutTask @Inject constructor(private val signOutAPI: SignOutAPI, private val sessionParamsStore: SessionParamsStore) : SignOutTask { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/CryptoSyncHandler.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/CryptoSyncHandler.kt index 5930d861..8992091b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/CryptoSyncHandler.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/CryptoSyncHandler.kt @@ -32,7 +32,6 @@ import timber.log.Timber import javax.inject.Inject -@SessionScope internal class CryptoSyncHandler @Inject constructor(private val cryptoManager: CryptoManager, private val sasVerificationService: DefaultSasVerificationService) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/GroupSyncHandler.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/GroupSyncHandler.kt index 7c9248c9..d7b8328c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/GroupSyncHandler.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/GroupSyncHandler.kt @@ -26,7 +26,6 @@ import im.vector.matrix.android.internal.session.sync.model.InvitedGroupSync import io.realm.Realm import javax.inject.Inject -@SessionScope internal class GroupSyncHandler @Inject constructor(private val monarchy: Monarchy) { sealed class HandlingStrategy { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/ReadReceiptHandler.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/ReadReceiptHandler.kt index fafc75f0..930f20f2 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/ReadReceiptHandler.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/ReadReceiptHandler.kt @@ -30,7 +30,6 @@ import javax.inject.Inject // dict value ts value typealias ReadReceiptContent = Map>>> -@SessionScope internal class ReadReceiptHandler @Inject constructor() { fun handle(realm: Realm, roomId: String, content: ReadReceiptContent?) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/RoomSyncHandler.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/RoomSyncHandler.kt index f8fb285d..4c80fbcc 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/RoomSyncHandler.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/RoomSyncHandler.kt @@ -32,16 +32,18 @@ import im.vector.matrix.android.internal.database.model.RoomEntity 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.where -import im.vector.matrix.android.internal.session.SessionScope import im.vector.matrix.android.internal.session.room.RoomSummaryUpdater import im.vector.matrix.android.internal.session.room.timeline.PaginationDirection -import im.vector.matrix.android.internal.session.sync.model.* +import im.vector.matrix.android.internal.session.sync.model.InvitedRoomSync +import im.vector.matrix.android.internal.session.sync.model.RoomSync +import im.vector.matrix.android.internal.session.sync.model.RoomSyncAccountData +import im.vector.matrix.android.internal.session.sync.model.RoomSyncEphemeral +import im.vector.matrix.android.internal.session.sync.model.RoomsSyncResponse import io.realm.Realm import io.realm.kotlin.createObject import timber.log.Timber import javax.inject.Inject -@SessionScope internal class RoomSyncHandler @Inject constructor(private val monarchy: Monarchy, private val readReceiptHandler: ReadReceiptHandler, private val roomSummaryUpdater: RoomSummaryUpdater, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/RoomTagHandler.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/RoomTagHandler.kt index 9bec48dd..49038eed 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/RoomTagHandler.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/RoomTagHandler.kt @@ -25,7 +25,6 @@ import io.realm.Realm import java.util.* import javax.inject.Inject -@SessionScope internal class RoomTagHandler @Inject constructor() { fun handle(realm: Realm, roomId: String, content: RoomTagContent?) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncModule.kt index cd8b7605..3d84d63e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncModule.kt @@ -29,9 +29,9 @@ internal abstract class SyncModule { @Module companion object { - @SessionScope @Provides @JvmStatic + @SessionScope fun providesSyncAPI(retrofit: Retrofit): SyncAPI { return retrofit.create(SyncAPI::class.java) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncResponseHandler.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncResponseHandler.kt index 174f2de9..593bb924 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncResponseHandler.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncResponseHandler.kt @@ -24,7 +24,6 @@ import timber.log.Timber import javax.inject.Inject import kotlin.system.measureTimeMillis -@SessionScope internal class SyncResponseHandler @Inject constructor(private val roomSyncHandler: RoomSyncHandler, private val userAccountDataSyncHandler: UserAccountDataSyncHandler, private val groupSyncHandler: GroupSyncHandler, 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 920fb389..6acd82c9 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 @@ -35,7 +35,6 @@ internal interface SyncTask : Task { } -@SessionScope internal class DefaultSyncTask @Inject constructor(private val syncAPI: SyncAPI, private val filterRepository: FilterRepository, private val syncResponseHandler: SyncResponseHandler, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTokenStore.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTokenStore.kt index 17ca1680..8823f2e3 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTokenStore.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTokenStore.kt @@ -16,14 +16,12 @@ package im.vector.matrix.android.internal.session.sync -import im.vector.matrix.android.internal.di.SessionDatabase import im.vector.matrix.android.internal.database.model.SyncEntity -import im.vector.matrix.android.internal.session.SessionScope +import im.vector.matrix.android.internal.di.SessionDatabase import io.realm.Realm import io.realm.RealmConfiguration import javax.inject.Inject -@SessionScope internal class SyncTokenStore @Inject constructor(@SessionDatabase private val realmConfiguration: RealmConfiguration) { fun getLastToken(): String? { 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 db377599..52f66fa4 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 @@ -25,7 +25,6 @@ import im.vector.matrix.android.internal.session.sync.model.UserAccountDataDirec import im.vector.matrix.android.internal.session.sync.model.UserAccountDataSync import javax.inject.Inject -@SessionScope internal class UserAccountDataSyncHandler @Inject constructor(private val monarchy: Monarchy) { fun handle(accountData: UserAccountDataSync) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/job/SyncThread.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/job/SyncThread.kt index db79d392..8825c4f4 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/job/SyncThread.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/job/SyncThread.kt @@ -40,7 +40,6 @@ import javax.inject.Inject private const val RETRY_WAIT_TIME_MS = 10_000L -@SessionScope internal class SyncThread @Inject constructor(private val syncTask: SyncTask, private val networkConnectivityChecker: NetworkConnectivityChecker, private val syncTokenStore: SyncTokenStore, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/DefaultUserService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/DefaultUserService.kt index 4f79a9f1..cb1bcdce 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/DefaultUserService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/DefaultUserService.kt @@ -31,7 +31,6 @@ import im.vector.matrix.android.internal.session.SessionScope import im.vector.matrix.android.internal.util.fetchCopied import javax.inject.Inject -@SessionScope internal class DefaultUserService @Inject constructor(private val monarchy: Monarchy) : UserService { override fun getUser(userId: String): User? { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/UpdateUserTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/UpdateUserTask.kt index b653e48f..eb331e41 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/UpdateUserTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/UpdateUserTask.kt @@ -35,7 +35,6 @@ internal interface UpdateUserTask : Task { } -@SessionScope internal class DefaultUpdateUserTask @Inject constructor(private val monarchy: Monarchy) : UpdateUserTask { override suspend fun execute(params: UpdateUserTask.Params): Try { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/UserEntityUpdater.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/UserEntityUpdater.kt index 40998d04..df9dc277 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/UserEntityUpdater.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/UserEntityUpdater.kt @@ -31,7 +31,6 @@ import im.vector.matrix.android.internal.task.configureWith import io.realm.Sort import javax.inject.Inject -@SessionScope internal class UserEntityUpdater @Inject constructor(monarchy: Monarchy, private val updateUserTask: UpdateUserTask, private val taskExecutor: TaskExecutor) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/UserModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/UserModule.kt index 00714c77..b3af7e45 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/UserModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/UserModule.kt @@ -21,17 +21,14 @@ package im.vector.matrix.android.internal.session.user import dagger.Binds import dagger.Module import im.vector.matrix.android.api.session.user.UserService -import im.vector.matrix.android.internal.session.SessionScope @Module internal abstract class UserModule { @Binds - @SessionScope abstract fun bindUserService(userService: DefaultUserService): UserService @Binds - @SessionScope abstract fun bindUpdateUserTask(updateUserTask: DefaultUpdateUserTask): UpdateUserTask } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/task/TaskExecutor.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/task/TaskExecutor.kt index 944b62ee..cfab8ef4 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/task/TaskExecutor.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/task/TaskExecutor.kt @@ -30,7 +30,6 @@ import timber.log.Timber import javax.inject.Inject import kotlin.coroutines.EmptyCoroutineContext -@MatrixScope internal class TaskExecutor @Inject constructor(private val coroutineDispatchers: MatrixCoroutineDispatchers) { fun execute(task: ConfigurableTask): Cancelable { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/CancelableWork.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/CancelableWork.kt index f144ed5c..ebd20ec6 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/CancelableWork.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/CancelableWork.kt @@ -16,14 +16,16 @@ package im.vector.matrix.android.internal.util +import android.content.Context import androidx.work.WorkManager import im.vector.matrix.android.api.util.Cancelable import java.util.* -internal class CancelableWork(private val workId: UUID) : Cancelable { +internal class CancelableWork(private val context: Context, + private val workId: UUID) : Cancelable { override fun cancel() { - WorkManager.getInstance().cancelWorkById(workId) + WorkManager.getInstance(context).cancelWorkById(workId) } } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixAssistedModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/SessionWorkerParams.kt similarity index 71% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixAssistedModule.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/SessionWorkerParams.kt index ce1804cb..874254cc 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixAssistedModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/SessionWorkerParams.kt @@ -14,11 +14,8 @@ * limitations under the License. */ -package im.vector.matrix.android.internal.di +package im.vector.matrix.android.internal.worker -import com.squareup.inject.assisted.dagger2.AssistedModule -import dagger.Module - -@Module(includes = [AssistedInject_MatrixAssistedModule::class]) -@AssistedModule -internal class MatrixAssistedModule \ No newline at end of file +interface SessionWorkerParams { + val userId: String +} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/Worker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/Worker.kt new file mode 100644 index 00000000..4a4b5e3b --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/Worker.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.matrix.android.internal.worker + +import androidx.work.ListenableWorker +import im.vector.matrix.android.api.Matrix +import im.vector.matrix.android.internal.session.SessionComponent + +internal fun ListenableWorker.getSessionComponent(userId: String): SessionComponent? { + return Matrix.getInstance(applicationContext).sessionManager.getSessionComponent(userId) +} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/WorkerBindingModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/WorkerBindingModule.kt deleted file mode 100644 index 20e75a8d..00000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/WorkerBindingModule.kt +++ /dev/null @@ -1,64 +0,0 @@ -/* - * - * * Copyright 2019 New Vector Ltd - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * - */ - -package im.vector.matrix.android.internal.worker - -import dagger.Binds -import dagger.Module -import dagger.multibindings.IntoMap -import im.vector.matrix.android.internal.session.content.UploadContentWorker -import im.vector.matrix.android.internal.session.group.GetGroupDataWorker -import im.vector.matrix.android.internal.session.room.relation.SendRelationWorker -import im.vector.matrix.android.internal.session.room.send.EncryptEventWorker -import im.vector.matrix.android.internal.session.room.send.RedactEventWorker -import im.vector.matrix.android.internal.session.room.send.SendEventWorker - - -@Module -internal interface WorkerBindingModule { - - @Binds - @IntoMap - @WorkerKey(SendEventWorker::class) - fun bindSendEventWorker(factory: SendEventWorker.Factory): DelegateWorkerFactory - - @Binds - @IntoMap - @WorkerKey(SendRelationWorker::class) - fun bindSendRelationWorker(factory: SendRelationWorker.Factory): DelegateWorkerFactory - - @Binds - @IntoMap - @WorkerKey(EncryptEventWorker::class) - fun bindEncryptEventWorker(factory: EncryptEventWorker.Factory): DelegateWorkerFactory - - @Binds - @IntoMap - @WorkerKey(RedactEventWorker::class) - fun bindRedactEventWorker(factory: RedactEventWorker.Factory): DelegateWorkerFactory - - @Binds - @IntoMap - @WorkerKey(GetGroupDataWorker::class) - fun bindGetGroupDataWorker(factory: GetGroupDataWorker.Factory): DelegateWorkerFactory - - @Binds - @IntoMap - @WorkerKey(UploadContentWorker::class) - fun bindUploadContentWorker(factory: UploadContentWorker.Factory): DelegateWorkerFactory -} \ No newline at end of file diff --git a/vector/build.gradle b/vector/build.gradle index 3754ceee..2d773481 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -173,7 +173,7 @@ dependencies { implementation 'com.airbnb.android:mvrx:1.0.1' // Work - implementation "android.arch.work:work-runtime-ktx:1.0.0" + implementation "androidx.work:work-runtime-ktx:2.1.0-beta01" // FP implementation "io.arrow-kt:arrow-core:$arrow_version" diff --git a/vector/src/gplay/java/im/vector/riotredesign/push/fcm/VectorFirebaseMessagingService.kt b/vector/src/gplay/java/im/vector/riotredesign/push/fcm/VectorFirebaseMessagingService.kt index 47d4c1b1..1387e865 100755 --- a/vector/src/gplay/java/im/vector/riotredesign/push/fcm/VectorFirebaseMessagingService.kt +++ b/vector/src/gplay/java/im/vector/riotredesign/push/fcm/VectorFirebaseMessagingService.kt @@ -34,7 +34,6 @@ import im.vector.riotredesign.features.notifications.NotifiableEventResolver import im.vector.riotredesign.features.notifications.NotifiableMessageEvent import im.vector.riotredesign.features.notifications.NotificationDrawerManager import im.vector.riotredesign.features.notifications.SimpleNotifiableEvent -import org.koin.android.ext.android.inject import timber.log.Timber /** @@ -42,7 +41,7 @@ import timber.log.Timber */ class VectorFirebaseMessagingService : FirebaseMessagingService() { - val notificationDrawerManager by inject() + @Inject lateinit var notificationDrawerManager: NotificationDrawerManager private val notifiableEventResolver by lazy { NotifiableEventResolver(this) diff --git a/vector/src/main/java/im/vector/riotredesign/EmojiCompatFontProvider.kt b/vector/src/main/java/im/vector/riotredesign/EmojiCompatFontProvider.kt index c7fc7a95..6647cbea 100644 --- a/vector/src/main/java/im/vector/riotredesign/EmojiCompatFontProvider.kt +++ b/vector/src/main/java/im/vector/riotredesign/EmojiCompatFontProvider.kt @@ -4,7 +4,9 @@ import android.graphics.Typeface import androidx.core.provider.FontsContractCompat import timber.log.Timber import javax.inject.Inject +import javax.inject.Singleton +@Singleton class EmojiCompatFontProvider @Inject constructor(): FontsContractCompat.FontRequestCallback() { var typeface: Typeface? = null diff --git a/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt b/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt index f740bec0..b2ce3c8a 100644 --- a/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt +++ b/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt @@ -31,6 +31,7 @@ import com.github.piasy.biv.BigImageViewer import com.github.piasy.biv.loader.glide.GlideImageLoader import com.jakewharton.threetenabp.AndroidThreeTen import im.vector.matrix.android.api.Matrix +import im.vector.matrix.android.api.MatrixConfiguration import im.vector.riotredesign.core.di.DaggerVectorComponent import im.vector.riotredesign.core.di.HasInjector import im.vector.riotredesign.core.di.VectorComponent @@ -42,7 +43,7 @@ import timber.log.Timber import javax.inject.Inject -class VectorApplication : Application(), HasInjector { +class VectorApplication : Application(), HasInjector, MatrixConfiguration.Provider, androidx.work.Configuration.Provider { lateinit var appContext: Context //font thread handler @@ -67,8 +68,6 @@ class VectorApplication : Application(), HasInjector { BigImageViewer.initialize(GlideImageLoader.with(applicationContext)) EpoxyController.defaultDiffingHandler = EpoxyAsyncUtil.getAsyncBackgroundHandler() EpoxyController.defaultModelBuildingHandler = EpoxyAsyncUtil.getAsyncBackgroundHandler() - - Matrix.getInstance().setApplicationFlavor(BuildConfig.FLAVOR_DESCRIPTION) registerActivityLifecycleCallbacks(VectorActivityLifecycleCallbacks()) val fontRequest = FontRequest( "com.google.android.gms.fonts", @@ -80,6 +79,10 @@ class VectorApplication : Application(), HasInjector { vectorConfiguration.initConfiguration() } + override fun providesMatrixConfiguration() = MatrixConfiguration(BuildConfig.FLAVOR_DESCRIPTION) + + override fun getWorkManagerConfiguration() = androidx.work.Configuration.Builder().build() + override fun injector(): VectorComponent { return vectorComponent } diff --git a/vector/src/main/java/im/vector/riotredesign/core/di/ScreenComponent.kt b/vector/src/main/java/im/vector/riotredesign/core/di/ScreenComponent.kt index 46320f4e..1c28b8ef 100644 --- a/vector/src/main/java/im/vector/riotredesign/core/di/ScreenComponent.kt +++ b/vector/src/main/java/im/vector/riotredesign/core/di/ScreenComponent.kt @@ -22,6 +22,7 @@ import dagger.BindsInstance import dagger.Component import im.vector.fragments.keysbackup.restore.KeysBackupRestoreFromPassphraseFragment import im.vector.riotredesign.core.platform.SimpleFragmentActivity +import im.vector.riotredesign.features.MainActivity import im.vector.riotredesign.features.crypto.keysbackup.restore.KeysBackupRestoreFromKeyFragment import im.vector.riotredesign.features.crypto.keysbackup.restore.KeysBackupRestoreSuccessFragment import im.vector.riotredesign.features.crypto.keysbackup.settings.KeysBackupSettingsFragment @@ -40,6 +41,7 @@ import im.vector.riotredesign.features.home.room.detail.timeline.action.MessageM import im.vector.riotredesign.features.home.room.detail.timeline.action.QuickReactionFragment import im.vector.riotredesign.features.home.room.detail.timeline.action.ViewReactionBottomSheet import im.vector.riotredesign.features.home.room.list.RoomListFragment +import im.vector.riotredesign.features.login.LoginActivity import im.vector.riotredesign.features.reactions.EmojiReactionPickerActivity import im.vector.riotredesign.features.roomdirectory.PublicRoomsFragment import im.vector.riotredesign.features.roomdirectory.createroom.CreateRoomFragment @@ -66,7 +68,7 @@ interface ScreenComponent { fun inject(roomDirectoryPickerFragment: RoomDirectoryPickerFragment) fun inject(roomPreviewNoPreviewFragment: RoomPreviewNoPreviewFragment) - + fun inject(keysBackupSettingsFragment: KeysBackupSettingsFragment) fun inject(homeDrawerFragment: HomeDrawerFragment) @@ -103,6 +105,10 @@ interface ScreenComponent { fun inject(emojiReactionPickerActivity: EmojiReactionPickerActivity) + fun inject(loginActivity: LoginActivity) + + fun inject(mainActivity: MainActivity) + @Component.Factory interface Factory { diff --git a/vector/src/main/java/im/vector/riotredesign/core/di/VectorComponent.kt b/vector/src/main/java/im/vector/riotredesign/core/di/VectorComponent.kt index 100716f6..3e21cbac 100644 --- a/vector/src/main/java/im/vector/riotredesign/core/di/VectorComponent.kt +++ b/vector/src/main/java/im/vector/riotredesign/core/di/VectorComponent.kt @@ -21,7 +21,9 @@ import android.content.res.Resources import dagger.BindsInstance import dagger.Component import im.vector.matrix.android.api.Matrix +import im.vector.matrix.android.api.auth.Authenticator import im.vector.matrix.android.api.session.Session +import im.vector.riotredesign.EmojiCompatFontProvider import im.vector.riotredesign.VectorApplication import im.vector.riotredesign.features.configuration.VectorConfiguration import im.vector.riotredesign.features.crypto.keysrequest.KeyRequestHandler @@ -49,6 +51,8 @@ interface VectorComponent { fun vectorConfiguration(): VectorConfiguration + fun emojiCompatFontProvider(): EmojiCompatFontProvider + fun navigator(): Navigator fun homeNavigator(): HomeNavigator @@ -63,6 +67,8 @@ interface VectorComponent { fun inject(vectorApplication: VectorApplication) + fun authenticator(): Authenticator + @Component.Factory interface Factory { fun create(@BindsInstance context: Context): VectorComponent diff --git a/vector/src/main/java/im/vector/riotredesign/core/di/VectorModule.kt b/vector/src/main/java/im/vector/riotredesign/core/di/VectorModule.kt index 4b4f4467..ec8db244 100644 --- a/vector/src/main/java/im/vector/riotredesign/core/di/VectorModule.kt +++ b/vector/src/main/java/im/vector/riotredesign/core/di/VectorModule.kt @@ -24,6 +24,7 @@ import dagger.Binds import dagger.Module import dagger.Provides import im.vector.matrix.android.api.Matrix +import im.vector.matrix.android.api.auth.Authenticator import im.vector.matrix.android.api.session.Session import im.vector.riotredesign.features.navigation.DefaultNavigator import im.vector.riotredesign.features.navigation.Navigator @@ -48,8 +49,8 @@ abstract class VectorModule { @Provides @JvmStatic - fun providesMatrix(): Matrix { - return Matrix.getInstance() + fun providesMatrix(context: Context): Matrix { + return Matrix.getInstance(context) } @Provides @@ -58,6 +59,12 @@ abstract class VectorModule { //TODO: handle session injection better return matrix.currentSession!! } + + @Provides + @JvmStatic + fun providesAuthenticator(matrix: Matrix): Authenticator{ + return matrix.authenticator() + } } @Binds diff --git a/vector/src/main/java/im/vector/riotredesign/features/MainActivity.kt b/vector/src/main/java/im/vector/riotredesign/features/MainActivity.kt index 2cc31dff..a87753e6 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/MainActivity.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/MainActivity.kt @@ -21,10 +21,13 @@ import android.content.Intent import android.os.Bundle import im.vector.matrix.android.api.Matrix import im.vector.matrix.android.api.MatrixCallback +import im.vector.matrix.android.api.auth.Authenticator +import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.platform.VectorBaseActivity import im.vector.riotredesign.features.home.HomeActivity import im.vector.riotredesign.features.login.LoginActivity import timber.log.Timber +import javax.inject.Inject class MainActivity : VectorBaseActivity() { @@ -44,16 +47,18 @@ class MainActivity : VectorBaseActivity() { } } - private val authenticator = Matrix.getInstance().authenticator() + @Inject lateinit var matrix: Matrix + @Inject lateinit var authenticator: Authenticator + + override fun injectWith(injector: ScreenComponent) { + injector.inject(this) + } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - - val session = Matrix.getInstance().currentSession - val clearCache = intent.getBooleanExtra(EXTRA_CLEAR_CACHE, false) val clearCredentials = intent.getBooleanExtra(EXTRA_CLEAR_CREDENTIALS, false) - + val session = matrix.currentSession if (session == null) { start() } else { diff --git a/vector/src/main/java/im/vector/riotredesign/features/crypto/verification/IncomingVerificationRequestHandler.kt b/vector/src/main/java/im/vector/riotredesign/features/crypto/verification/IncomingVerificationRequestHandler.kt index f670a599..6349534f 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/crypto/verification/IncomingVerificationRequestHandler.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/crypto/verification/IncomingVerificationRequestHandler.kt @@ -44,7 +44,7 @@ class IncomingVerificationRequestHandler @Inject constructor(val context: Contex when (tx.state) { SasVerificationTxState.OnStarted -> { //Add a notification for every incoming request - val session = Matrix.getInstance().currentSession!! + val session = Matrix.getInstance(context).currentSession!! val name = session.getUser(tx.otherUserId)?.displayName ?: tx.otherUserId diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/AvatarRenderer.kt b/vector/src/main/java/im/vector/riotredesign/features/home/AvatarRenderer.kt index 84d61fe6..451a49c2 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/AvatarRenderer.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/AvatarRenderer.kt @@ -20,7 +20,6 @@ import android.content.Context import android.graphics.drawable.Drawable import android.widget.ImageView import androidx.annotation.AnyThread -import androidx.annotation.ColorRes import androidx.annotation.UiThread import androidx.core.content.ContextCompat import com.amulyakhare.textdrawable.TextDrawable @@ -79,7 +78,7 @@ object AvatarRenderer { name } val placeholder = getPlaceholderDrawable(context, identifier, displayName) - buildGlideRequest(glideRequest, avatarUrl) + buildGlideRequest(context, glideRequest, avatarUrl) .placeholder(placeholder) .into(target) } @@ -116,8 +115,8 @@ object AvatarRenderer { // return AVATAR_COLOR_LIST[colorIndex.toInt()] // } - private fun buildGlideRequest(glideRequest: GlideRequests, avatarUrl: String?): GlideRequest { - val resolvedUrl = Matrix.getInstance().currentSession!!.contentUrlResolver() + private fun buildGlideRequest(context: Context, glideRequest: GlideRequests, avatarUrl: String?): GlideRequest { + val resolvedUrl = Matrix.getInstance(context).currentSession!!.contentUrlResolver() .resolveThumbnail(avatarUrl, THUMBNAIL_SIZE, THUMBNAIL_SIZE, ContentUrlResolver.ThumbnailMethod.SCALE) return glideRequest diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt b/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt index 497d108b..d0e05f87 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt @@ -140,7 +140,7 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.sliding_menu_sign_out -> { - SignOutUiWorker(this).perform(Matrix.getInstance().currentSession!!) + SignOutUiWorker(this).perform(Matrix.getInstance(this).currentSession!!) return true } } diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailViewModel.kt index f78efbff..cf678897 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailViewModel.kt @@ -78,6 +78,11 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro val fragment: RoomDetailFragment = (viewModelContext as FragmentViewModelContext).fragment() return fragment.roomDetailViewModelFactory.create(state) } + + override fun initialState(viewModelContext: ViewModelContext): RoomDetailViewState? { + + return super.initialState(viewModelContext) + } } init { diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/helper/ContentUploadStateTrackerBinder.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/helper/ContentUploadStateTrackerBinder.kt index 8d395668..93b567b1 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/helper/ContentUploadStateTrackerBinder.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/helper/ContentUploadStateTrackerBinder.kt @@ -36,7 +36,7 @@ object ContentUploadStateTrackerBinder { mediaData: ImageContentRenderer.Data, progressLayout: ViewGroup) { - Matrix.getInstance().currentSession?.also { session -> + Matrix.getInstance(progressLayout.context).currentSession?.also { session -> val uploadStateTracker = session.contentUploadProgressTracker() val updateListener = ContentMediaProgressUpdater(progressLayout, mediaData) updateListeners[eventId] = updateListener @@ -44,8 +44,8 @@ object ContentUploadStateTrackerBinder { } } - fun unbind(eventId: String) { - Matrix.getInstance().currentSession?.also { session -> + fun unbind(eventId: String, progressLayout: ViewGroup) { + Matrix.getInstance(progressLayout.context).currentSession?.also { session -> val uploadStateTracker = session.contentUploadProgressTracker() updateListeners[eventId]?.also { uploadStateTracker.untrack(eventId, it) diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/helper/TimelineMediaSizeProvider.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/helper/TimelineMediaSizeProvider.kt index 4f509798..6d985ae6 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/helper/TimelineMediaSizeProvider.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/helper/TimelineMediaSizeProvider.kt @@ -17,8 +17,10 @@ package im.vector.riotredesign.features.home.room.detail.timeline.helper import androidx.recyclerview.widget.RecyclerView +import im.vector.riotredesign.core.di.ScreenScope import javax.inject.Inject +@ScreenScope class TimelineMediaSizeProvider @Inject constructor() { lateinit var recyclerView: RecyclerView diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/item/MessageImageVideoItem.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/item/MessageImageVideoItem.kt index b1c884fd..25eb8bca 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/item/MessageImageVideoItem.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/item/MessageImageVideoItem.kt @@ -50,7 +50,7 @@ abstract class MessageImageVideoItem : AbsMessageItem { override fun onSuccess(data: Session) { - Matrix.getInstance().currentSession = data + Matrix.getInstance(this@LoginActivity).currentSession = data data.open() data.setFilter(FilterService.FilterPreset.RiotFilter) data.startSync() diff --git a/vector/src/main/java/im/vector/riotredesign/features/media/ImageContentRenderer.kt b/vector/src/main/java/im/vector/riotredesign/features/media/ImageContentRenderer.kt index fcd7cab1..e02536a0 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/media/ImageContentRenderer.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/media/ImageContentRenderer.kt @@ -57,7 +57,7 @@ object ImageContentRenderer { val (width, height) = processSize(data, mode) imageView.layoutParams.height = height imageView.layoutParams.width = width - val contentUrlResolver = Matrix.getInstance().currentSession!!.contentUrlResolver() + val contentUrlResolver = Matrix.getInstance(imageView.context).currentSession!!.contentUrlResolver() val resolvedUrl = when (mode) { Mode.FULL_SIZE -> contentUrlResolver.resolveFullSize(data.url) Mode.THUMBNAIL -> contentUrlResolver.resolveThumbnail(data.url, width, height, ContentUrlResolver.ThumbnailMethod.SCALE) @@ -76,7 +76,7 @@ object ImageContentRenderer { fun render(data: Data, imageView: BigImageView) { val (width, height) = processSize(data, Mode.THUMBNAIL) - val contentUrlResolver = Matrix.getInstance().currentSession!!.contentUrlResolver() + val contentUrlResolver = Matrix.getInstance(imageView.context).currentSession!!.contentUrlResolver() val fullSize = contentUrlResolver.resolveFullSize(data.url) val thumbnail = contentUrlResolver.resolveThumbnail(data.url, width, height, ContentUrlResolver.ThumbnailMethod.SCALE) imageView.showImage( diff --git a/vector/src/main/java/im/vector/riotredesign/features/media/VideoContentRenderer.kt b/vector/src/main/java/im/vector/riotredesign/features/media/VideoContentRenderer.kt index 577b6570..54a91ed5 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/media/VideoContentRenderer.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/media/VideoContentRenderer.kt @@ -32,7 +32,7 @@ object VideoContentRenderer { ) : Parcelable fun render(data: Data, thumbnailView: ImageView, videoView: VideoView) { - val contentUrlResolver = Matrix.getInstance().currentSession!!.contentUrlResolver() + val contentUrlResolver = Matrix.getInstance(videoView.context).currentSession!!.contentUrlResolver() val resolvedUrl = contentUrlResolver.resolveFullSize(data.videoUrl) videoView.setVideoPath(resolvedUrl) videoView.start() diff --git a/vector/src/main/java/im/vector/riotredesign/features/rageshake/BugReporter.kt b/vector/src/main/java/im/vector/riotredesign/features/rageshake/BugReporter.kt index f755f433..59bf5c0a 100755 --- a/vector/src/main/java/im/vector/riotredesign/features/rageshake/BugReporter.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/rageshake/BugReporter.kt @@ -195,7 +195,7 @@ object BugReporter { var matrixSdkVersion = "undefined" var olmVersion = "undefined" - Matrix.getInstance().currentSession?.let { session -> + Matrix.getInstance(context).currentSession?.let { session -> userId = session.sessionParams.credentials.userId deviceId = session.sessionParams.credentials.deviceId ?: "undefined" // TODO matrixSdkVersion = session.getVersion(true); @@ -207,7 +207,7 @@ object BugReporter { val builder = BugReporterMultipartBody.Builder() .addFormDataPart("text", "[RiotX] $bugDescription") .addFormDataPart("app", "riot-android") - .addFormDataPart("user_agent", Matrix.getInstance().getUserAgent()) + .addFormDataPart("user_agent", Matrix.getInstance(context).getUserAgent()) .addFormDataPart("user_id", userId) .addFormDataPart("device_id", deviceId) // TODO .addFormDataPart("version", Matrix.getInstance(context).getVersion(true, false))