Dagger: continue reworking on app and sdk [WIP]

This commit is contained in:
ganfra 2019-06-20 19:26:59 +02:00
parent ee87c253fe
commit 07fee8ed3d
156 changed files with 393 additions and 552 deletions

View File

@ -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'

View File

@ -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"

View File

@ -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(

View File

@ -1,4 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="im.vector.matrix.android">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
@ -7,9 +8,10 @@

<application>

<provider
android:name=".internal.MatrixInitProvider"
android:authorities="im.vector.matrix.android.MatrixInitProvider" />
<provider android:name="androidx.work.impl.WorkManagerInitializer"
android:authorities="${applicationId}.workmanager-init"
android:exported="false"
tools:node="remove" />

</application>


View File

@ -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
}


View File

@ -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<String>?, selection: String?, selectionArgs: Array<String>?, sortOrder: String?): Cursor? {
return null
}

override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<String>?): Int {
return 0
}

override fun delete(uri: Uri, selection: String?, selectionArgs: Array<String>?): Int {
return 0
}

override fun getType(uri: Uri): String? {
return null
}

}

View File

@ -31,6 +31,10 @@ internal class SessionManager @Inject constructor(private val matrixComponent: M

private val sessionComponents = HashMap<String, SessionComponent>()

fun getSessionComponent(userId: String): SessionComponent? {
return sessionComponents[userId]
}

fun createSession(sessionParams: SessionParams): Session {
val userId = sessionParams.credentials.userId
if (sessionComponents.containsKey(userId)) {

View File

@ -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

}

View File

@ -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,

View File

@ -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 {

View File

@ -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)

View File

@ -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,

View File

@ -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



View File

@ -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,

View File

@ -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) {


View File

@ -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) {


View File

@ -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) {

View File

@ -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,

View File

@ -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) {


View File

@ -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) {

View File

@ -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,

View File

@ -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,

View File

@ -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) {


View File

@ -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,

View File

@ -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<CreateKeysBackupVersionBody, KeysVersion>

@SessionScope
internal class DefaultCreateKeysBackupVersionTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: CreateKeysBackupVersionTask {


View File

@ -30,7 +30,6 @@ internal interface DeleteBackupTask : Task<DeleteBackupTask.Params, Unit> {
)
}

@SessionScope
internal class DefaultDeleteBackupTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: DeleteBackupTask {


View File

@ -31,7 +31,6 @@ internal interface DeleteRoomSessionDataTask : Task<DeleteRoomSessionDataTask.Pa
)
}

@SessionScope
internal class DefaultDeleteRoomSessionDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: DeleteRoomSessionDataTask {


View File

@ -30,7 +30,6 @@ internal interface DeleteRoomSessionsDataTask : Task<DeleteRoomSessionsDataTask.
)
}

@SessionScope
internal class DefaultDeleteRoomSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: DeleteRoomSessionsDataTask {


View File

@ -29,7 +29,6 @@ internal interface DeleteSessionsDataTask : Task<DeleteSessionsDataTask.Params,
)
}

@SessionScope
internal class DefaultDeleteSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: DeleteSessionsDataTask {


View File

@ -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 GetKeysBackupLastVersionTask : Task<Unit, KeysVersionResult>

@SessionScope
internal class DefaultGetKeysBackupLastVersionTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: GetKeysBackupLastVersionTask {


View File

@ -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<String, KeysVersionResult>

@SessionScope
internal class DefaultGetKeysBackupVersionTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: GetKeysBackupVersionTask {


View File

@ -32,7 +32,6 @@ internal interface GetRoomSessionDataTask : Task<GetRoomSessionDataTask.Params,
)
}

@SessionScope
internal class DefaultGetRoomSessionDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: GetRoomSessionDataTask {


View File

@ -32,7 +32,6 @@ internal interface GetRoomSessionsDataTask : Task<GetRoomSessionsDataTask.Params
)
}

@SessionScope
internal class DefaultGetRoomSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: GetRoomSessionsDataTask {


View File

@ -30,7 +30,6 @@ internal interface GetSessionsDataTask : Task<GetSessionsDataTask.Params, KeysBa
)
}

@SessionScope
internal class DefaultGetSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: GetSessionsDataTask {


View File

@ -34,7 +34,6 @@ internal interface StoreRoomSessionDataTask : Task<StoreRoomSessionDataTask.Para
)
}

@SessionScope
internal class DefaultStoreRoomSessionDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: StoreRoomSessionDataTask {


View File

@ -33,7 +33,6 @@ internal interface StoreRoomSessionsDataTask : Task<StoreRoomSessionsDataTask.Pa
)
}

@SessionScope
internal class DefaultStoreRoomSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: StoreRoomSessionsDataTask {


View File

@ -32,7 +32,6 @@ internal interface StoreSessionsDataTask : Task<StoreSessionsDataTask.Params, Ba
)
}

@SessionScope
internal class DefaultStoreSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: StoreSessionsDataTask {


View File

@ -20,7 +20,6 @@ import arrow.core.Try
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.UpdateKeysBackupVersionBody
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

@ -31,7 +30,6 @@ internal interface UpdateKeysBackupVersionTask : Task<UpdateKeysBackupVersionTas
)
}

@SessionScope
internal class DefaultUpdateKeysBackupVersionTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: UpdateKeysBackupVersionTask {


View File

@ -20,7 +20,7 @@ import im.vector.matrix.android.internal.session.SessionScope
import javax.inject.Inject

@SessionScope
internal class WarnOnUnknownDeviceRepository @Inject constructor(){
internal class WarnOnUnknownDeviceRepository @Inject constructor() {

// TODO: set it back to true by default. Need UI
// Warn the user if some new devices are detected while encrypting a message.

View File

@ -29,6 +29,7 @@ import im.vector.matrix.android.internal.crypto.store.db.model.*
import im.vector.matrix.android.internal.crypto.store.db.query.delete
import im.vector.matrix.android.internal.crypto.store.db.query.getById
import im.vector.matrix.android.internal.crypto.store.db.query.getOrCreate
import im.vector.matrix.android.internal.session.SessionScope
import io.realm.RealmConfiguration
import io.realm.Sort
import io.realm.kotlin.where
@ -38,6 +39,7 @@ import timber.log.Timber
import kotlin.collections.set

// enableFileEncryption is used to migrate the previous store
@SessionScope
internal class RealmCryptoStore(private val enableFileEncryption: Boolean = false,
private val realmConfiguration: RealmConfiguration,
private val credentials: Credentials) : IMXCryptoStore {

View File

@ -36,7 +36,6 @@ internal interface ClaimOneTimeKeysForUsersDeviceTask : Task<ClaimOneTimeKeysFor
)
}

@SessionScope
internal class DefaultClaimOneTimeKeysForUsersDevice @Inject constructor(private val cryptoApi: CryptoApi)
: ClaimOneTimeKeysForUsersDeviceTask {


View File

@ -31,7 +31,6 @@ internal interface DeleteDeviceTask : Task<DeleteDeviceTask.Params, Unit> {
)
}

@SessionScope
internal class DefaultDeleteDeviceTask @Inject constructor(private val cryptoApi: CryptoApi)
: DeleteDeviceTask {


View File

@ -35,7 +35,6 @@ internal interface DownloadKeysForUsersTask : Task<DownloadKeysForUsersTask.Para
val token: String?)
}

@SessionScope
internal class DefaultDownloadKeysForUsers @Inject constructor(private val cryptoApi: CryptoApi)
: DownloadKeysForUsersTask {


View File

@ -26,7 +26,6 @@ import javax.inject.Inject

internal interface GetDevicesTask : Task<Unit, DevicesListResponse>

@SessionScope
internal class DefaultGetDevicesTask @Inject constructor(private val cryptoApi: CryptoApi)
: GetDevicesTask {


View File

@ -33,7 +33,6 @@ internal interface GetKeyChangesTask : Task<GetKeyChangesTask.Params, KeyChanges
)
}

@SessionScope
internal class DefaultGetKeyChangesTask @Inject constructor(private val cryptoApi: CryptoApi)
: GetKeyChangesTask {


View File

@ -37,7 +37,6 @@ internal interface SendToDeviceTask : Task<SendToDeviceTask.Params, Unit> {
)
}

@SessionScope
internal class DefaultSendToDeviceTask @Inject constructor(private val cryptoApi: CryptoApi)
: SendToDeviceTask {


View File

@ -34,7 +34,6 @@ internal interface SetDeviceNameTask : Task<SetDeviceNameTask.Params, Unit> {
)
}

@SessionScope
internal class DefaultSetDeviceNameTask @Inject constructor(private val cryptoApi: CryptoApi)
: SetDeviceNameTask {


View File

@ -38,7 +38,6 @@ internal interface UploadKeysTask : Task<UploadKeysTask.Params, KeysUploadRespon
val deviceId: String)
}

@SessionScope
internal class DefaultUploadKeysTask @Inject constructor(private val cryptoApi: CryptoApi)
: UploadKeysTask {


View File

@ -29,12 +29,12 @@ import im.vector.matrix.android.internal.network.NetworkConnectivityChecker
import im.vector.matrix.android.internal.task.TaskExecutor
import im.vector.matrix.android.internal.util.BackgroundDetectionObserver
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
import im.vector.matrix.android.internal.worker.WorkerBindingModule
import okhttp3.OkHttpClient
import org.matrix.olm.OlmManager
import retrofit2.Retrofit


@Component(modules = [MatrixModule::class, NetworkModule::class, AuthModule::class, WorkerBindingModule::class])
@Component(modules = [MatrixModule::class, NetworkModule::class, AuthModule::class])
@MatrixScope
internal interface MatrixComponent {

@ -44,6 +44,8 @@ internal interface MatrixComponent {

fun retrofitBuilder(): Retrofit.Builder

fun okHttpClient(): OkHttpClient

fun authenticator(): Authenticator

fun context(): Context

View File

@ -31,7 +31,6 @@ internal object MatrixModule {

@JvmStatic
@Provides
@MatrixScope
fun providesMatrixCoroutineDispatchers(): MatrixCoroutineDispatchers {
val cryptoHandler = CryptoAsyncHelper.getDecryptBackgroundHandler()
return MatrixCoroutineDispatchers(io = Dispatchers.IO,
@ -43,7 +42,6 @@ internal object MatrixModule {

@JvmStatic
@Provides
@MatrixScope
fun providesResources(context: Context): Resources {
return context.resources
}

View File

@ -36,7 +36,6 @@ import java.util.concurrent.TimeUnit
@Module
internal object NetworkModule {

@MatrixScope
@Provides
@JvmStatic
fun providesHttpLogingInterceptor(): HttpLoggingInterceptor {
@ -46,21 +45,18 @@ internal object NetworkModule {
return interceptor
}

@MatrixScope
@Provides
@JvmStatic
fun providesOkReplayInterceptor(): OkReplayInterceptor {
return OkReplayInterceptor()
}

@MatrixScope
@Provides
@JvmStatic
fun providesStethoInterceptor(): StethoInterceptor {
return StethoInterceptor()
}

@MatrixScope
@Provides
@JvmStatic
fun providesCurlLoggingInterceptor(): CurlLoggingInterceptor {
@ -93,14 +89,12 @@ internal object NetworkModule {
.build()
}

@MatrixScope
@Provides
@JvmStatic
fun providesMoshi(): Moshi {
return MoshiProvider.providesMoshi()
}

@MatrixScope
@Provides
@JvmStatic
fun providesRetrofitBuilder(okHttpClient: OkHttpClient,

View File

@ -22,7 +22,6 @@ import okhttp3.Interceptor
import okhttp3.Response
import javax.inject.Inject

@MatrixScope
internal class AccessTokenInterceptor @Inject constructor(private val sessionParamsStore: SessionParamsStore) : Interceptor {

override fun intercept(chain: Interceptor.Chain): Response {

View File

@ -21,7 +21,6 @@ import okhttp3.Interceptor
import okhttp3.Response
import javax.inject.Inject

@MatrixScope
internal class UserAgentInterceptor @Inject constructor(private val userAgentHolder: UserAgentHolder) : Interceptor {

override fun intercept(chain: Interceptor.Chain): Response {

View File

@ -143,13 +143,9 @@ internal class DefaultSession @Inject constructor(override val sessionParams: Se
})
}

override fun contentUrlResolver(): ContentUrlResolver {
return contentUrlResolver
}
override fun contentUrlResolver() = contentUrlResolver

override fun contentUploadProgressTracker(): ContentUploadStateTracker {
return contentUploadProgressTracker
}
override fun contentUploadProgressTracker() = contentUploadProgressTracker

override fun addListener(listener: Session.Listener) {
sessionListeners.addListener(listener)

View File

@ -21,13 +21,18 @@ import dagger.Component
import im.vector.matrix.android.api.auth.data.SessionParams
import im.vector.matrix.android.api.session.Session
import im.vector.matrix.android.internal.crypto.CryptoModule
import im.vector.matrix.android.internal.di.MatrixAssistedModule
import im.vector.matrix.android.internal.di.MatrixComponent
import im.vector.matrix.android.internal.session.cache.CacheModule
import im.vector.matrix.android.internal.session.content.ContentModule
import im.vector.matrix.android.internal.session.content.UploadContentWorker
import im.vector.matrix.android.internal.session.filter.FilterModule
import im.vector.matrix.android.internal.session.group.GetGroupDataWorker
import im.vector.matrix.android.internal.session.group.GroupModule
import im.vector.matrix.android.internal.session.room.RoomModule
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
import im.vector.matrix.android.internal.session.signout.SignOutModule
import im.vector.matrix.android.internal.session.sync.SyncModule
import im.vector.matrix.android.internal.session.user.UserModule
@ -44,8 +49,7 @@ import im.vector.matrix.android.internal.session.user.UserModule
GroupModule::class,
ContentModule::class,
CacheModule::class,
CryptoModule::class,
MatrixAssistedModule::class
CryptoModule::class
]
)
@SessionScope
@ -53,6 +57,19 @@ internal interface SessionComponent {

fun session(): Session

fun inject(sendEventWorker: SendEventWorker)

fun inject(sendEventWorker: SendRelationWorker)

fun inject(encryptEventWorker: EncryptEventWorker)

fun inject(redactEventWorker: RedactEventWorker)

fun inject(getGroupDataWorker: GetGroupDataWorker)

fun inject(uploadContentWorker: UploadContentWorker)


@Component.Factory
interface Factory {
fun create(

View File

@ -46,7 +46,6 @@ internal abstract class SessionModule {

@JvmStatic
@Provides
@SessionScope
fun providesHomeServerConnectionConfig(sessionParams: SessionParams): HomeServerConnectionConfig {
return sessionParams.homeServerConnectionConfig
}
@ -54,15 +53,14 @@ internal abstract class SessionModule {

@JvmStatic
@Provides
@SessionScope
fun providesCredentials(sessionParams: SessionParams): Credentials {
return sessionParams.credentials
}

@JvmStatic
@Provides
@SessionScope
@SessionDatabase
@SessionScope
fun providesRealmConfiguration(sessionParams: SessionParams, context: Context): RealmConfiguration {
val childPath = sessionParams.credentials.userId.md5()
val directory = File(context.filesDir, childPath)
@ -96,27 +94,22 @@ internal abstract class SessionModule {
}

@Binds
@SessionScope
abstract fun bindSession(session: DefaultSession): Session

@Binds
@IntoSet
@SessionScope
abstract fun bindGroupSummaryUpdater(groupSummaryUpdater: GroupSummaryUpdater): LiveEntityObserver

@Binds
@IntoSet
@SessionScope
abstract fun bindEventsPruner(eventsPruner: EventsPruner): LiveEntityObserver

@Binds
@IntoSet
@SessionScope
abstract fun bindEventRelationsAggregationUpdater(groupSummaryUpdater: EventRelationsAggregationUpdater): LiveEntityObserver

@Binds
@IntoSet
@SessionScope
abstract fun bindUserEntityUpdater(groupSummaryUpdater: UserEntityUpdater): LiveEntityObserver

}

View File

@ -33,7 +33,6 @@ internal abstract class CacheModule {
companion object {
@JvmStatic
@Provides
@SessionScope
@SessionDatabase
fun providesClearCacheTask(@SessionDatabase realmConfiguration: RealmConfiguration): ClearCacheTask {
return RealmClearCacheTask(realmConfiguration)
@ -41,7 +40,6 @@ internal abstract class CacheModule {
}

@Binds
@SessionScope
abstract fun bindCacheService(cacheService: DefaultCacheService): CacheService

}

View File

@ -26,7 +26,6 @@ import javax.inject.Named

internal interface ClearCacheTask : Task<Unit, Unit>

@SessionScope
internal class RealmClearCacheTask @Inject constructor(private val realmConfiguration: RealmConfiguration) : ClearCacheTask {

override suspend fun execute(params: Unit): Try<Unit> {

View File

@ -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 {


View File

@ -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
}

View File

@ -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


View File

@ -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 {

View File

@ -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) {

View File

@ -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<Params>(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

}


View File

@ -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 {

View File

@ -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 {

View File

@ -35,7 +35,6 @@ internal interface SaveFilterTask : Task<SaveFilterTask.Params, Unit> {

}

@SessionScope
internal class DefaultSaveFilterTask @Inject constructor(private val sessionParams: SessionParams,
private val filterAPI: FilterApi,
private val filterRepository: FilterRepository

View File

@ -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



View File

@ -39,7 +39,6 @@ internal interface GetGroupDataTask : Task<GetGroupDataTask.Params, Unit> {

}

@SessionScope
internal class DefaultGetGroupDataTask @Inject constructor(
private val groupAPI: GroupAPI,
private val monarchy: Monarchy

View File

@ -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? {

View File

@ -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<String>
)
): SessionWorkerParams

@Inject lateinit var getGroupDataTask: GetGroupDataTask

override suspend fun doWork(): Result {
val params = WorkerParamsFactory.fromData<Params>(inputData)
?: return Result.failure()

val sessionComponent = getSessionComponent(params.userId) ?: return Result.success()
sessionComponent.inject(this)

val results = params.groupIds.map { groupId ->
fetchGroupData(groupId)
}

View File

@ -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
}

View File

@ -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<GroupEntity>(monarchy) {
internal class GroupSummaryUpdater @Inject constructor(private val context: Context,
private val credentials: Credentials,
monarchy: Monarchy) : RealmLiveEntityObserver<GroupEntity>(monarchy) {

override val query = Monarchy.Query<GroupEntity> { GroupEntity.where(it) }

@ -42,7 +44,7 @@ internal class GroupSummaryUpdater @Inject constructor(monarchy: Monarchy) : Rea

override fun processChanges(inserted: List<GroupEntity>, updated: List<GroupEntity>, deleted: List<GroupEntity>) {
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<GetGroupDataWorker>()
@ -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()
}

View File

@ -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<RoomSummary> by lazy {
val liveRealmData = RealmLiveData<RoomSummaryEntity>(monarchy.realmConfiguration) { realm ->

View File

@ -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,

View File

@ -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? {

View File

@ -44,7 +44,6 @@ internal interface EventRelationsAggregationTask : Task<EventRelationsAggregatio
/**
* Called by EventRelationAggregationUpdater, when new events that can affect relations are inserted in base.
*/
@SessionScope
internal class DefaultEventRelationsAggregationTask @Inject constructor(private val monarchy: Monarchy) : EventRelationsAggregationTask {

//OPT OUT serer aggregation until API mature enough

View File

@ -33,7 +33,6 @@ import javax.inject.Inject
* The summaries can then be extracted and added (as a decoration) to a TimelineEvent for final display.
*/

@SessionScope
internal class EventRelationsAggregationUpdater @Inject constructor(monarchy: Monarchy,
private val credentials: Credentials,
private val task: EventRelationsAggregationTask,

View File

@ -31,7 +31,6 @@ import im.vector.matrix.android.internal.session.SessionScope
import im.vector.matrix.android.internal.session.room.membership.RoomMembers
import javax.inject.Inject

@SessionScope
internal class RoomAvatarResolver @Inject constructor(private val monarchy: Monarchy,
private val credentials: Credentials) {


View File

@ -16,10 +16,11 @@

package im.vector.matrix.android.internal.session.room

import android.content.Context
import com.zhuinden.monarchy.Monarchy
import im.vector.matrix.android.api.auth.data.Credentials
import im.vector.matrix.android.api.session.crypto.CryptoService
import im.vector.matrix.android.api.session.room.Room
import im.vector.matrix.android.internal.session.SessionScope
import im.vector.matrix.android.internal.session.room.membership.DefaultMembershipService
import im.vector.matrix.android.internal.session.room.membership.LoadRoomMembersTask
import im.vector.matrix.android.internal.session.room.membership.SenderRoomMemberExtractor
@ -42,8 +43,9 @@ import im.vector.matrix.android.internal.session.room.timeline.TimelineEventFact
import im.vector.matrix.android.internal.task.TaskExecutor
import javax.inject.Inject

@SessionScope
internal class RoomFactory @Inject constructor(private val monarchy: Monarchy,
internal class RoomFactory @Inject constructor(private val context: Context,
private val credentials: Credentials,
private val monarchy: Monarchy,
private val eventFactory: LocalEchoEventFactory,
private val taskExecutor: TaskExecutor,
private val loadRoomMembersTask: LoadRoomMembersTask,
@ -63,11 +65,11 @@ internal class RoomFactory @Inject constructor(private val monarchy: Monarchy,
val relationExtractor = EventRelationExtractor()
val timelineEventFactory = TimelineEventFactory(roomMemberExtractor, relationExtractor, cryptoService)
val timelineService = DefaultTimelineService(roomId, monarchy, taskExecutor, timelineEventFactory, contextOfEventTask, paginationTask)
val sendService = DefaultSendService(roomId, eventFactory, cryptoService, monarchy)
val sendService = DefaultSendService(context, credentials, roomId, eventFactory, cryptoService, monarchy)
val stateService = DefaultStateService(roomId, taskExecutor, sendStateTask)
val roomMembersService = DefaultMembershipService(roomId, monarchy, taskExecutor, loadRoomMembersTask, inviteTask, joinRoomTask, leaveRoomTask)
val readService = DefaultReadService(roomId, monarchy, taskExecutor, setReadMarkersTask)
val reactionService = DefaultRelationService(roomId, eventFactory, findReactionEventForUndoTask, updateQuickReactionTask, monarchy, taskExecutor)
val reactionService = DefaultRelationService(context, credentials, roomId, eventFactory, findReactionEventForUndoTask, updateQuickReactionTask, monarchy, taskExecutor)

return DefaultRoom(
roomId,

View File

@ -61,104 +61,81 @@ internal abstract class RoomModule {

@Module
companion object {
@SessionScope
@Provides
@JvmStatic
@SessionScope
fun providesRoomAPI(retrofit: Retrofit): RoomAPI {
return retrofit.create(RoomAPI::class.java)
}
}

@Binds
@SessionScope
abstract fun bindRoomService(roomService: DefaultRoomService): RoomService

@Binds
@SessionScope
abstract fun bindRoomDirectoryService(roomDirectoryService: DefaultRoomDirectoryService): RoomDirectoryService

@Binds
@SessionScope
abstract fun bindEventRelationsAggregationTask(eventRelationsAggregationTask: DefaultEventRelationsAggregationTask): EventRelationsAggregationTask

@Binds
@SessionScope
abstract fun bindCreateRoomTask(createRoomTask: DefaultCreateRoomTask): CreateRoomTask

@Binds
@SessionScope
abstract fun bindGetPublicRoomTask(getPublicRoomTask: DefaultGetPublicRoomTask): GetPublicRoomTask

@Binds
@SessionScope
abstract fun bindGetThirdPartyProtocolsTask(getThirdPartyProtocolsTask: DefaultGetThirdPartyProtocolsTask): GetThirdPartyProtocolsTask

@Binds
@SessionScope
abstract fun bindInviteTask(inviteTask: DefaultInviteTask): InviteTask

@Binds
@SessionScope
abstract fun bindJoinRoomTask(joinRoomTask: DefaultJoinRoomTask): JoinRoomTask

@Binds
@SessionScope
abstract fun bindLeaveRoomTask(leaveRoomTask: DefaultLeaveRoomTask): LeaveRoomTask

@Binds
@SessionScope
abstract fun bindMembershipService(membershipService: DefaultMembershipService): MembershipService

@Binds
@SessionScope
abstract fun bindLoadRoomMembersTask(loadRoomMembersTask: DefaultLoadRoomMembersTask): LoadRoomMembersTask

@Binds
@SessionScope
abstract fun bindPruneEventTask(pruneEventTask: DefaultPruneEventTask): PruneEventTask

@Binds
@SessionScope
abstract fun bindReadService(readService: DefaultReadService): ReadService

@Binds
@SessionScope
abstract fun bindSetReadMarkersTask(setReadMarkersTask: DefaultSetReadMarkersTask): SetReadMarkersTask

@Binds
@SessionScope
abstract fun bindRelationService(relationService: DefaultRelationService): RelationService

@Binds
@SessionScope
abstract fun bindFindReactionEventForUndoTask(findReactionEventForUndoTask: DefaultFindReactionEventForUndoTask): FindReactionEventForUndoTask

@Binds
@SessionScope
abstract fun bindUpdateQuickReactionTask(updateQuickReactionTask: DefaultUpdateQuickReactionTask): UpdateQuickReactionTask

@Binds
@SessionScope
abstract fun bindSendStateTask(sendStateTask: DefaultSendStateTask): SendStateTask

@Binds
@SessionScope
abstract fun bindSendService(sendService: DefaultSendService): SendService

@Binds
@SessionScope
abstract fun bindStateService(stateService: DefaultStateService): StateService

@Binds
@SessionScope
abstract fun bindGetContextOfEventTask(getContextOfEventTask: DefaultGetContextOfEventTask): GetContextOfEventTask

@Binds
@SessionScope
abstract fun bindPaginationTask(paginationTask: DefaultPaginationTask): PaginationTask

@Binds
@SessionScope
abstract fun bindTimelineService(timelineService: DefaultTimelineService): TimelineService



View File

@ -38,7 +38,6 @@ import io.realm.Realm
import io.realm.kotlin.createObject
import javax.inject.Inject

@SessionScope
internal class RoomSummaryUpdater @Inject constructor(private val credentials: Credentials,
private val roomDisplayNameResolver: RoomDisplayNameResolver,
private val roomAvatarResolver: RoomAvatarResolver) {

View File

@ -32,7 +32,6 @@ import javax.inject.Inject

internal interface CreateRoomTask : Task<CreateRoomParams, String>

@SessionScope
internal class DefaultCreateRoomTask @Inject constructor(private val roomAPI: RoomAPI,
@SessionDatabase private val realmConfiguration: RealmConfiguration) : CreateRoomTask {


View File

@ -32,7 +32,6 @@ internal interface GetPublicRoomTask : Task<GetPublicRoomTask.Params, PublicRoom
)
}

@SessionScope
internal class DefaultGetPublicRoomTask @Inject constructor(private val roomAPI: RoomAPI) : GetPublicRoomTask {

override suspend fun execute(params: GetPublicRoomTask.Params): Try<PublicRoomsResponse> {

View File

@ -26,7 +26,6 @@ import javax.inject.Inject

internal interface GetThirdPartyProtocolsTask : Task<Unit, Map<String, ThirdPartyProtocol>>

@SessionScope
internal class DefaultGetThirdPartyProtocolsTask @Inject constructor (private val roomAPI: RoomAPI) : GetThirdPartyProtocolsTask {

override suspend fun execute(params: Unit): Try<Map<String, ThirdPartyProtocol>> {

View File

@ -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,

View File

@ -40,7 +40,6 @@ internal interface LoadRoomMembersTask : Task<LoadRoomMembersTask.Params, Boolea
)
}

@SessionScope
internal class DefaultLoadRoomMembersTask @Inject constructor(private val roomAPI: RoomAPI,
private val monarchy: Monarchy,
private val syncTokenStore: SyncTokenStore,

View File

@ -31,8 +31,9 @@ import im.vector.matrix.android.internal.database.query.where
import io.realm.Realm
import io.realm.RealmList
import io.realm.RealmQuery
import javax.inject.Inject

internal class SenderRoomMemberExtractor(private val roomId: String) {
internal class SenderRoomMemberExtractor @Inject constructor(private val roomId: String) {

fun extractFrom(event: EventEntity, realm: Realm = event.realm): RoomMember? {
val sender = event.sender ?: return null

View File

@ -31,7 +31,6 @@ internal interface InviteTask : Task<InviteTask.Params, Unit> {
)
}

@SessionScope
internal class DefaultInviteTask @Inject constructor(private val roomAPI: RoomAPI) : InviteTask {

override suspend fun execute(params: InviteTask.Params): Try<Unit> {

View File

@ -29,7 +29,6 @@ internal interface JoinRoomTask : Task<JoinRoomTask.Params, Unit> {
)
}

@SessionScope
internal class DefaultJoinRoomTask @Inject constructor(private val roomAPI: RoomAPI) : JoinRoomTask {

override suspend fun execute(params: JoinRoomTask.Params): Try<Unit> {

View File

@ -29,7 +29,6 @@ internal interface LeaveRoomTask : Task<LeaveRoomTask.Params, Unit> {
)
}

@SessionScope
internal class DefaultLeaveRoomTask @Inject constructor(private val roomAPI: RoomAPI) : LeaveRoomTask {

override suspend fun execute(params: LeaveRoomTask.Params): Try<Unit> {

View File

@ -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,

View File

@ -43,7 +43,6 @@ internal interface PruneEventTask : Task<PruneEventTask.Params, Unit> {

}

@SessionScope
internal class DefaultPruneEventTask @Inject constructor(private val monarchy: Monarchy) : PruneEventTask {

override suspend fun execute(params: PruneEventTask.Params): Try<Unit> {

View File

@ -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,

View File

@ -47,7 +47,6 @@ internal interface SetReadMarkersTask : Task<SetReadMarkersTask.Params, Unit> {
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

View File

@ -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<SendEventWorker>(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<RedactEventWorker>(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<SendEventWorker>(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<SendEventWorker>(sendWorkData)
TimelineSendEventWorkCommon.postWork(roomId, workRequest)
return CancelableWork(workRequest.id)
TimelineSendEventWorkCommon.postWork(context, roomId, workRequest)
return CancelableWork(context, workRequest.id)
}



View File

@ -42,7 +42,6 @@ internal interface FindReactionEventForUndoTask : Task<FindReactionEventForUndoT

}

@SessionScope
internal class DefaultFindReactionEventForUndoTask @Inject constructor(private val monarchy: Monarchy) : FindReactionEventForUndoTask {

override suspend fun execute(params: FindReactionEventForUndoTask.Params): Try<FindReactionEventForUndoTask.Result> {

View File

@ -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<Params>(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
}

View File

@ -43,7 +43,6 @@ internal interface UpdateQuickReactionTask : Task<UpdateQuickReactionTask.Params
)
}

@SessionScope
internal class DefaultUpdateQuickReactionTask @Inject constructor(private val monarchy: Monarchy) : UpdateQuickReactionTask {
override suspend fun execute(params: UpdateQuickReactionTask.Params): Try<UpdateQuickReactionTask.Result> {
return Try {

View File

@ -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<ContentAttachmentData>): 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<EncryptEventWorker>()
@ -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<SendEventWorker>(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<RedactEventWorker>(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<UploadContentWorker>()

Some files were not shown because too many files have changed in this diff Show More