mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-25 02:45:53 +03:00
Start to introduce Dagger into SDK [WIP]
This commit is contained in:
parent
df4f0eac20
commit
3d465f6fdf
142 changed files with 1093 additions and 1384 deletions
|
@ -91,6 +91,7 @@ dependencies {
|
|||
def lifecycle_version = '2.0.0'
|
||||
def coroutines_version = "1.0.1"
|
||||
def markwon_version = '3.0.0'
|
||||
def daggerVersion = '2.23.1'
|
||||
|
||||
implementation fileTree(dir: 'libs', include: ['*.aar'])
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
|
@ -132,8 +133,10 @@ dependencies {
|
|||
implementation 'org.matrix.gitlab.matrix-org:olm:3.1.2'
|
||||
|
||||
// DI
|
||||
implementation "org.koin:koin-core:$koin_version"
|
||||
implementation "org.koin:koin-core-ext:$koin_version"
|
||||
implementation "com.google.dagger:dagger:$daggerVersion"
|
||||
kapt "com.google.dagger:dagger-compiler:$daggerVersion"
|
||||
compileOnly 'com.squareup.inject:assisted-inject-annotations-dagger2:0.4.0'
|
||||
kapt 'com.squareup.inject:assisted-inject-processor-dagger2:0.4.0'
|
||||
|
||||
// Logging
|
||||
implementation 'com.jakewharton.timber:timber:4.7.1'
|
||||
|
|
|
@ -23,7 +23,7 @@ import im.vector.matrix.android.internal.session.room.timeline.TokenChunkEvent
|
|||
import im.vector.matrix.android.internal.session.room.timeline.TokenChunkEventPersistor
|
||||
import kotlin.random.Random
|
||||
|
||||
internal class FakeGetContextOfEventTask(private val tokenChunkEventPersistor: TokenChunkEventPersistor) : GetContextOfEventTask {
|
||||
internal class FakeGetContextOfEventTask @Inject constructor(private val tokenChunkEventPersistor: TokenChunkEventPersistor) : GetContextOfEventTask {
|
||||
|
||||
override suspend fun execute(params: GetContextOfEventTask.Params): Try<TokenChunkEventPersistor.Result> {
|
||||
val fakeEvents = RoomDataHelper.createFakeListOfEvents(30)
|
||||
|
|
|
@ -21,7 +21,7 @@ import im.vector.matrix.android.internal.session.room.timeline.PaginationTask
|
|||
import im.vector.matrix.android.internal.session.room.timeline.TokenChunkEventPersistor
|
||||
import kotlin.random.Random
|
||||
|
||||
internal class FakePaginationTask(private val tokenChunkEventPersistor: TokenChunkEventPersistor) : PaginationTask {
|
||||
internal class FakePaginationTask @Inject constructor(private val tokenChunkEventPersistor: TokenChunkEventPersistor) : PaginationTask {
|
||||
|
||||
override suspend fun execute(params: PaginationTask.Params): Try<TokenChunkEventPersistor.Result> {
|
||||
val fakeEvents = RoomDataHelper.createFakeListOfEvents(30)
|
||||
|
|
|
@ -59,8 +59,8 @@ internal class TimelineTest : InstrumentedTest {
|
|||
private fun createTimeline(initialEventId: String? = null): Timeline {
|
||||
val taskExecutor = TaskExecutor(testCoroutineDispatchers)
|
||||
val tokenChunkEventPersistor = TokenChunkEventPersistor(monarchy)
|
||||
val paginationTask = FakePaginationTask(tokenChunkEventPersistor)
|
||||
val getContextOfEventTask = FakeGetContextOfEventTask(tokenChunkEventPersistor)
|
||||
val paginationTask = FakePaginationTask @Inject constructor(tokenChunkEventPersistor)
|
||||
val getContextOfEventTask = FakeGetContextOfEventTask @Inject constructor(tokenChunkEventPersistor)
|
||||
val roomMemberExtractor = SenderRoomMemberExtractor(ROOM_ID)
|
||||
val timelineEventFactory = TimelineEventFactory(roomMemberExtractor, EventRelationExtractor())
|
||||
return DefaultTimeline(
|
||||
|
|
|
@ -17,12 +17,14 @@
|
|||
|
||||
package im.vector.matrix.android.internal.network.interceptors
|
||||
|
||||
import im.vector.matrix.android.internal.di.MatrixScope
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import okio.Buffer
|
||||
import java.io.IOException
|
||||
import java.nio.charset.Charset
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* An OkHttp interceptor that logs requests as curl shell commands. They can then
|
||||
|
@ -33,7 +35,8 @@ import java.nio.charset.Charset
|
|||
* information. It should only be used in a controlled manner or in a
|
||||
* non-production environment.
|
||||
*/
|
||||
internal class CurlLoggingInterceptor(private val logger: HttpLoggingInterceptor.Logger = HttpLoggingInterceptor.Logger.DEFAULT)
|
||||
@MatrixScope
|
||||
internal class CurlLoggingInterceptor @Inject constructor(private val logger: HttpLoggingInterceptor.Logger = HttpLoggingInterceptor.Logger.DEFAULT)
|
||||
: Interceptor {
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,34 +22,25 @@ 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.auth.AuthModule
|
||||
import im.vector.matrix.android.internal.di.MatrixKoinComponent
|
||||
import im.vector.matrix.android.internal.di.MatrixKoinHolder
|
||||
import im.vector.matrix.android.internal.di.MatrixModule
|
||||
import im.vector.matrix.android.internal.di.NetworkModule
|
||||
import im.vector.matrix.android.internal.network.UserAgentHolder
|
||||
import im.vector.matrix.android.internal.util.BackgroundDetectionObserver
|
||||
import org.koin.standalone.inject
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* 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) : MatrixKoinComponent {
|
||||
class Matrix private constructor(context: Context) {
|
||||
|
||||
private val authenticator by inject<Authenticator>()
|
||||
private val userAgentHolder by inject<UserAgentHolder>()
|
||||
private val backgroundDetectionObserver by inject<BackgroundDetectionObserver>()
|
||||
@Inject internal lateinit var authenticator: Authenticator
|
||||
@Inject internal lateinit var userAgentHolder: UserAgentHolder
|
||||
@Inject internal lateinit var backgroundDetectionObserver: BackgroundDetectionObserver
|
||||
var currentSession: Session? = null
|
||||
|
||||
init {
|
||||
Monarchy.init(context)
|
||||
val matrixModule = MatrixModule(context).definition
|
||||
val networkModule = NetworkModule().definition
|
||||
val authModule = AuthModule().definition
|
||||
MatrixKoinHolder.instance.loadModules(listOf(matrixModule, networkModule, authModule))
|
||||
ProcessLifecycleOwner.get().lifecycle.addObserver(backgroundDetectionObserver)
|
||||
authenticator.getLastActiveSession()?.also {
|
||||
currentSession = it
|
||||
|
|
|
@ -17,38 +17,27 @@
|
|||
package im.vector.matrix.android.internal.auth
|
||||
|
||||
import android.content.Context
|
||||
import im.vector.matrix.android.api.auth.Authenticator
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import im.vector.matrix.android.internal.auth.db.AuthRealmModule
|
||||
import im.vector.matrix.android.internal.auth.db.RealmSessionParamsStore
|
||||
import im.vector.matrix.android.internal.auth.db.SessionParamsMapper
|
||||
import im.vector.matrix.android.internal.di.MatrixScope
|
||||
import io.realm.RealmConfiguration
|
||||
import org.koin.dsl.module.module
|
||||
import java.io.File
|
||||
|
||||
class AuthModule {
|
||||
@Module
|
||||
internal class AuthModule {
|
||||
|
||||
val definition = module {
|
||||
|
||||
single {
|
||||
DefaultAuthenticator(get(), get(), get()) as Authenticator
|
||||
@Provides
|
||||
@MatrixScope
|
||||
fun providesRealmConfiguration(context: Context): RealmConfiguration {
|
||||
val old = File(context.filesDir, "matrix-sdk-auth")
|
||||
if (old.exists()) {
|
||||
old.renameTo(File(context.filesDir, "matrix-sdk-auth.realm"))
|
||||
}
|
||||
|
||||
single {
|
||||
val context: Context = get()
|
||||
val old = File(context.filesDir, "matrix-sdk-auth")
|
||||
|
||||
if (old.exists()) {
|
||||
old.renameTo(File(context.filesDir, "matrix-sdk-auth.realm"))
|
||||
}
|
||||
|
||||
val mapper = SessionParamsMapper((get()))
|
||||
val realmConfiguration = RealmConfiguration.Builder()
|
||||
.name("matrix-sdk-auth.realm")
|
||||
.modules(AuthRealmModule())
|
||||
.deleteRealmIfMigrationNeeded()
|
||||
.build()
|
||||
RealmSessionParamsStore(mapper, realmConfiguration) as SessionParamsStore
|
||||
}
|
||||
|
||||
return RealmConfiguration.Builder()
|
||||
.name("matrix-sdk-auth.realm")
|
||||
.modules(AuthRealmModule())
|
||||
.deleteRealmIfMigrationNeeded()
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,25 +19,32 @@ package im.vector.matrix.android.internal.auth
|
|||
import android.util.Patterns
|
||||
import im.vector.matrix.android.api.MatrixCallback
|
||||
import im.vector.matrix.android.api.auth.Authenticator
|
||||
import im.vector.matrix.android.api.auth.data.Credentials
|
||||
import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig
|
||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.matrix.android.api.util.Cancelable
|
||||
import im.vector.matrix.android.api.auth.data.Credentials
|
||||
import im.vector.matrix.android.internal.auth.data.PasswordLoginParams
|
||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
||||
import im.vector.matrix.android.internal.auth.data.ThreePidMedium
|
||||
import im.vector.matrix.android.internal.di.MatrixScope
|
||||
import im.vector.matrix.android.internal.network.executeRequest
|
||||
import im.vector.matrix.android.internal.session.DefaultSession
|
||||
import im.vector.matrix.android.internal.session.SessionFactory
|
||||
import im.vector.matrix.android.internal.util.CancelableCoroutine
|
||||
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import retrofit2.Retrofit
|
||||
import javax.inject.Inject
|
||||
import kotlin.random.Random
|
||||
|
||||
internal class DefaultAuthenticator(private val retrofitBuilder: Retrofit.Builder,
|
||||
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
||||
private val sessionParamsStore: SessionParamsStore) : Authenticator {
|
||||
@MatrixScope
|
||||
internal class DefaultAuthenticator @Inject constructor(private val retrofitBuilder: Retrofit.Builder,
|
||||
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
||||
private val sessionParamsStore: SessionParamsStore,
|
||||
private val sessionFactory: DefaultSession.Factory
|
||||
) : Authenticator {
|
||||
|
||||
override fun hasActiveSessions(): Boolean {
|
||||
return sessionParamsStore.get() != null
|
||||
|
@ -46,7 +53,7 @@ internal class DefaultAuthenticator(private val retrofitBuilder: Retrofit.Builde
|
|||
override fun getLastActiveSession(): Session? {
|
||||
val sessionParams = sessionParamsStore.get()
|
||||
return sessionParams?.let {
|
||||
DefaultSession(it)
|
||||
sessionFactory.create(it)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +87,7 @@ internal class DefaultAuthenticator(private val retrofitBuilder: Retrofit.Builde
|
|||
sessionParamsStore.save(sessionParams)
|
||||
sessionParams
|
||||
}.map {
|
||||
DefaultSession(it)
|
||||
sessionFactory.create(it)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,11 +19,14 @@ package im.vector.matrix.android.internal.auth.db
|
|||
import arrow.core.Try
|
||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
||||
import im.vector.matrix.android.internal.auth.SessionParamsStore
|
||||
import im.vector.matrix.android.internal.di.MatrixScope
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmConfiguration
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class RealmSessionParamsStore(private val mapper: SessionParamsMapper,
|
||||
private val realmConfiguration: RealmConfiguration) : SessionParamsStore {
|
||||
@MatrixScope
|
||||
internal class RealmSessionParamsStore @Inject constructor(private val mapper: SessionParamsMapper,
|
||||
private val realmConfiguration: RealmConfiguration) : SessionParamsStore {
|
||||
|
||||
override fun save(sessionParams: SessionParams): Try<SessionParams> {
|
||||
return Try {
|
||||
|
|
|
@ -63,6 +63,7 @@ import im.vector.matrix.android.internal.crypto.verification.DefaultSasVerificat
|
|||
import im.vector.matrix.android.internal.database.model.EventEntity
|
||||
import im.vector.matrix.android.internal.database.query.where
|
||||
import im.vector.matrix.android.internal.di.MoshiProvider
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.session.cache.ClearCacheTask
|
||||
import im.vector.matrix.android.internal.session.room.membership.LoadRoomMembersTask
|
||||
import im.vector.matrix.android.internal.session.room.membership.RoomMembers
|
||||
|
@ -76,6 +77,7 @@ import org.matrix.olm.OlmManager
|
|||
import timber.log.Timber
|
||||
import java.util.*
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import javax.inject.Inject
|
||||
import kotlin.coroutines.EmptyCoroutineContext
|
||||
|
||||
/**
|
||||
|
@ -88,7 +90,8 @@ import kotlin.coroutines.EmptyCoroutineContext
|
|||
* CryptoService maintains all necessary keys and their sharing with other devices required for the crypto.
|
||||
* Specially, it tracks all room membership changes events in order to do keys updates.
|
||||
*/
|
||||
internal class CryptoManager(
|
||||
@SessionScope
|
||||
internal class CryptoManager @Inject constructor(
|
||||
// The credentials,
|
||||
private val credentials: Credentials,
|
||||
private val myDeviceInfoHolder: MyDeviceInfoHolder,
|
||||
|
|
|
@ -17,316 +17,62 @@
|
|||
package im.vector.matrix.android.internal.crypto
|
||||
|
||||
import android.content.Context
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import im.vector.matrix.android.api.auth.data.Credentials
|
||||
import im.vector.matrix.android.api.session.crypto.CryptoService
|
||||
import im.vector.matrix.android.internal.crypto.actions.*
|
||||
import im.vector.matrix.android.internal.crypto.algorithms.megolm.MXMegolmDecryptionFactory
|
||||
import im.vector.matrix.android.internal.crypto.algorithms.megolm.MXMegolmEncryptionFactory
|
||||
import im.vector.matrix.android.internal.crypto.algorithms.olm.MXOlmDecryptionFactory
|
||||
import im.vector.matrix.android.internal.crypto.algorithms.olm.MXOlmEncryptionFactory
|
||||
import im.vector.matrix.android.internal.crypto.api.CryptoApi
|
||||
import im.vector.matrix.android.internal.crypto.keysbackup.KeysBackup
|
||||
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
|
||||
import im.vector.matrix.android.internal.crypto.keysbackup.tasks.*
|
||||
import im.vector.matrix.android.internal.crypto.repository.WarnOnUnknownDeviceRepository
|
||||
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
||||
import im.vector.matrix.android.internal.crypto.store.db.RealmCryptoStore
|
||||
import im.vector.matrix.android.internal.crypto.store.db.RealmCryptoStoreMigration
|
||||
import im.vector.matrix.android.internal.crypto.store.db.RealmCryptoStoreModule
|
||||
import im.vector.matrix.android.internal.crypto.store.db.hash
|
||||
import im.vector.matrix.android.internal.crypto.tasks.*
|
||||
import im.vector.matrix.android.internal.crypto.verification.DefaultSasVerificationService
|
||||
import im.vector.matrix.android.internal.session.DefaultSession
|
||||
import im.vector.matrix.android.internal.session.cache.ClearCacheTask
|
||||
import im.vector.matrix.android.internal.session.cache.RealmClearCacheTask
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import io.realm.RealmConfiguration
|
||||
import org.koin.dsl.module.module
|
||||
import org.matrix.olm.OlmManager
|
||||
import retrofit2.Retrofit
|
||||
import java.io.File
|
||||
|
||||
@Module
|
||||
internal class CryptoModule {
|
||||
|
||||
val definition = module(override = true) {
|
||||
|
||||
/* ==========================================================================================
|
||||
* Crypto Main
|
||||
* ========================================================================================== */
|
||||
|
||||
// Realm configuration, named to avoid clash with main cache realm configuration
|
||||
scope(DefaultSession.SCOPE, name = "CryptoRealmConfiguration") {
|
||||
val context: Context = get()
|
||||
|
||||
val credentials: Credentials = get()
|
||||
|
||||
RealmConfiguration.Builder()
|
||||
.directory(File(context.filesDir, credentials.userId.hash()))
|
||||
.name("crypto_store.realm")
|
||||
.modules(RealmCryptoStoreModule())
|
||||
.schemaVersion(RealmCryptoStoreMigration.CRYPTO_STORE_SCHEMA_VERSION)
|
||||
.migration(RealmCryptoStoreMigration)
|
||||
.build()
|
||||
}
|
||||
|
||||
// CryptoStore
|
||||
scope(DefaultSession.SCOPE) {
|
||||
RealmCryptoStore(false /* TODO*/,
|
||||
get("CryptoRealmConfiguration"),
|
||||
get()) as IMXCryptoStore
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
val retrofit: Retrofit = get()
|
||||
retrofit.create(CryptoApi::class.java)
|
||||
}
|
||||
|
||||
// CryptoService
|
||||
scope(DefaultSession.SCOPE) {
|
||||
get<CryptoManager>() as CryptoService
|
||||
}
|
||||
|
||||
//
|
||||
scope(DefaultSession.SCOPE) {
|
||||
OutgoingRoomKeyRequestManager(get(), get(), get())
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
IncomingRoomKeyRequestManager(get(), get(), get())
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
RoomDecryptorProvider(get(), get())
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
// Ensure OlmManager is loaded first
|
||||
get<OlmManager>()
|
||||
MXOlmDevice(get())
|
||||
}
|
||||
|
||||
// ObjectSigner
|
||||
scope(DefaultSession.SCOPE) {
|
||||
ObjectSigner(get(), get())
|
||||
}
|
||||
|
||||
// OneTimeKeysUploader
|
||||
scope(DefaultSession.SCOPE) {
|
||||
OneTimeKeysUploader(get(), get(), get(), get())
|
||||
}
|
||||
|
||||
// Actions
|
||||
scope(DefaultSession.SCOPE) {
|
||||
SetDeviceVerificationAction(get(), get(), get())
|
||||
}
|
||||
|
||||
// Device info
|
||||
scope(DefaultSession.SCOPE) {
|
||||
MyDeviceInfoHolder(get(), get(), get())
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
EnsureOlmSessionsForDevicesAction(get(), get())
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
EnsureOlmSessionsForUsersAction(get(), get(), get())
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
MegolmSessionDataImporter(get(), get(), get(), get())
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
MessageEncrypter(get(), get())
|
||||
}
|
||||
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
WarnOnUnknownDeviceRepository()
|
||||
}
|
||||
|
||||
// Factories
|
||||
scope(DefaultSession.SCOPE) {
|
||||
MXMegolmDecryptionFactory(
|
||||
get(), get(), get(), get(), get(), get(), get(), get(), get()
|
||||
)
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
MXMegolmEncryptionFactory(
|
||||
get(), get(), get(), get(), get(), get(), get(), get(), get(), get()
|
||||
)
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
MXOlmDecryptionFactory(
|
||||
get(), get()
|
||||
)
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
MXOlmEncryptionFactory(
|
||||
get(), get(), get(), get(), get(), get()
|
||||
)
|
||||
}
|
||||
|
||||
// CryptoManager
|
||||
scope(DefaultSession.SCOPE) {
|
||||
CryptoManager(
|
||||
credentials = get(),
|
||||
myDeviceInfoHolder = get(),
|
||||
cryptoStore = get(),
|
||||
olmDevice = get(),
|
||||
cryptoConfig = get(),
|
||||
deviceListManager = get(),
|
||||
keysBackup = get(),
|
||||
objectSigner = get(),
|
||||
oneTimeKeysUploader = get(),
|
||||
roomDecryptorProvider = get(),
|
||||
sasVerificationService = get(),
|
||||
incomingRoomKeyRequestManager = get(),
|
||||
outgoingRoomKeyRequestManager = get(),
|
||||
olmManager = get(),
|
||||
setDeviceVerificationAction = get(),
|
||||
megolmSessionDataImporter = get(),
|
||||
warnOnUnknownDevicesRepository = get(),
|
||||
megolmEncryptionFactory = get(),
|
||||
olmEncryptionFactory = get(),
|
||||
deleteDeviceTask = get(),
|
||||
// Tasks
|
||||
getDevicesTask = get(),
|
||||
setDeviceNameTask = get(),
|
||||
uploadKeysTask = get(),
|
||||
loadRoomMembersTask = get(),
|
||||
clearCryptoDataTask = get("ClearTaskCryptoCache"),
|
||||
monarchy = get(),
|
||||
coroutineDispatchers = get(),
|
||||
taskExecutor = get()
|
||||
)
|
||||
}
|
||||
|
||||
// Olm manager
|
||||
single {
|
||||
// load the crypto libs.
|
||||
OlmManager()
|
||||
}
|
||||
|
||||
|
||||
// Crypto config
|
||||
scope(DefaultSession.SCOPE) {
|
||||
MXCryptoConfig()
|
||||
}
|
||||
|
||||
// Device list
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DeviceListManager(get(), get(), get(), get(), get())
|
||||
}
|
||||
|
||||
// Crypto tasks
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultClaimOneTimeKeysForUsersDevice(get()) as ClaimOneTimeKeysForUsersDeviceTask
|
||||
}
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultDeleteDeviceTask(get()) as DeleteDeviceTask
|
||||
}
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultDownloadKeysForUsers(get()) as DownloadKeysForUsersTask
|
||||
}
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultGetDevicesTask(get()) as GetDevicesTask
|
||||
}
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultGetKeyChangesTask(get()) as GetKeyChangesTask
|
||||
}
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultSendToDeviceTask(get()) as SendToDeviceTask
|
||||
}
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultSetDeviceNameTask(get()) as SetDeviceNameTask
|
||||
}
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultUploadKeysTask(get()) as UploadKeysTask
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE, name = "ClearTaskCryptoCache") {
|
||||
RealmClearCacheTask(get("CryptoRealmConfiguration")) as ClearCacheTask
|
||||
}
|
||||
|
||||
/* ==========================================================================================
|
||||
* Keys backup
|
||||
* ========================================================================================== */
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
val retrofit: Retrofit = get()
|
||||
retrofit.create(RoomKeysApi::class.java)
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
KeysBackup(
|
||||
// Credentials
|
||||
get(),
|
||||
// CryptoStore
|
||||
get(),
|
||||
get(),
|
||||
get(),
|
||||
get(),
|
||||
// Task
|
||||
get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(),
|
||||
// Task executor
|
||||
get())
|
||||
}
|
||||
|
||||
// Key backup tasks
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultCreateKeysBackupVersionTask(get()) as CreateKeysBackupVersionTask
|
||||
}
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultDeleteBackupTask(get()) as DeleteBackupTask
|
||||
}
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultDeleteRoomSessionDataTask(get()) as DeleteRoomSessionDataTask
|
||||
}
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultDeleteRoomSessionsDataTask(get()) as DeleteRoomSessionsDataTask
|
||||
}
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultDeleteSessionsDataTask(get()) as DeleteSessionsDataTask
|
||||
}
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultGetKeysBackupLastVersionTask(get()) as GetKeysBackupLastVersionTask
|
||||
}
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultGetKeysBackupVersionTask(get()) as GetKeysBackupVersionTask
|
||||
}
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultGetRoomSessionDataTask(get()) as GetRoomSessionDataTask
|
||||
}
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultGetRoomSessionsDataTask(get()) as GetRoomSessionsDataTask
|
||||
}
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultGetSessionsDataTask(get()) as GetSessionsDataTask
|
||||
}
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultStoreRoomSessionDataTask(get()) as StoreRoomSessionDataTask
|
||||
}
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultStoreRoomSessionsDataTask(get()) as StoreRoomSessionsDataTask
|
||||
}
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultStoreSessionsDataTask(get()) as StoreSessionsDataTask
|
||||
}
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultUpdateKeysBackupVersionTask(get()) as UpdateKeysBackupVersionTask
|
||||
}
|
||||
|
||||
/* ==========================================================================================
|
||||
* SAS Verification
|
||||
* ========================================================================================== */
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultSasVerificationService(get(), get(), get(), get(), get(), get(), get(), get())
|
||||
}
|
||||
|
||||
// Realm configuration, named to avoid clash with main cache realm configuration
|
||||
@Provides
|
||||
@SessionScope
|
||||
fun providesRealmConfiguration(context: Context, credentials: Credentials): RealmConfiguration {
|
||||
return RealmConfiguration.Builder()
|
||||
.directory(File(context.filesDir, credentials.userId.hash()))
|
||||
.name("crypto_store.realm")
|
||||
.modules(RealmCryptoStoreModule())
|
||||
.schemaVersion(RealmCryptoStoreMigration.CRYPTO_STORE_SCHEMA_VERSION)
|
||||
.migration(RealmCryptoStoreMigration)
|
||||
.build()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@SessionScope
|
||||
fun providesCryptoStore(realmConfiguration: RealmConfiguration, credentials: Credentials): IMXCryptoStore {
|
||||
return RealmCryptoStore(false /* TODO*/,
|
||||
realmConfiguration,
|
||||
credentials)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@SessionScope
|
||||
fun providesCryptoAPI(retrofit: Retrofit): CryptoApi {
|
||||
return retrofit.create(CryptoApi::class.java)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@SessionScope
|
||||
fun providesRoomKeysAPI(retrofit: Retrofit): RoomKeysApi {
|
||||
return retrofit.create(RoomKeysApi::class.java)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@SessionScope
|
||||
fun providesCryptoConfig(): MXCryptoConfig {
|
||||
return MXCryptoConfig()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -26,16 +26,20 @@ import im.vector.matrix.android.internal.crypto.model.MXDeviceInfo
|
|||
import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap
|
||||
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
||||
import im.vector.matrix.android.internal.crypto.tasks.DownloadKeysForUsersTask
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.session.sync.SyncTokenStore
|
||||
import timber.log.Timber
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
// Legacy name: MXDeviceList
|
||||
internal class DeviceListManager(private val cryptoStore: IMXCryptoStore,
|
||||
private val olmDevice: MXOlmDevice,
|
||||
private val syncTokenStore: SyncTokenStore,
|
||||
private val credentials: Credentials,
|
||||
private val downloadKeysForUsersTask: DownloadKeysForUsersTask) {
|
||||
|
||||
@SessionScope
|
||||
internal class DeviceListManager @Inject constructor(private val cryptoStore: IMXCryptoStore,
|
||||
private val olmDevice: MXOlmDevice,
|
||||
private val syncTokenStore: SyncTokenStore,
|
||||
private val credentials: Credentials,
|
||||
private val downloadKeysForUsersTask: DownloadKeysForUsersTask) {
|
||||
|
||||
// HS not ready for retry
|
||||
private val notReadyToRetryHS = HashSet<String>()
|
||||
|
@ -410,7 +414,7 @@ internal class DeviceListManager(private val cryptoStore: IMXCryptoStore,
|
|||
|
||||
if (!isVerified) {
|
||||
Timber.e("## validateDeviceKeys() : Unable to verify signature on device " + userId + ":"
|
||||
+ deviceKeys.deviceId + " with error " + errorMessage)
|
||||
+ deviceKeys.deviceId + " with error " + errorMessage)
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -421,8 +425,8 @@ internal class DeviceListManager(private val cryptoStore: IMXCryptoStore,
|
|||
//
|
||||
// Should we warn the user about it somehow?
|
||||
Timber.e("## validateDeviceKeys() : WARNING:Ed25519 key for device " + userId + ":"
|
||||
+ deviceKeys.deviceId + " has changed : "
|
||||
+ previouslyStoredDeviceKeys.fingerprint() + " -> " + signKey)
|
||||
+ deviceKeys.deviceId + " has changed : "
|
||||
+ previouslyStoredDeviceKeys.fingerprint() + " -> " + signKey)
|
||||
|
||||
Timber.e("## validateDeviceKeys() : $previouslyStoredDeviceKeys -> $deviceKeys")
|
||||
Timber.e("## validateDeviceKeys() : " + previouslyStoredDeviceKeys.keys + " -> " + deviceKeys.keys)
|
||||
|
|
|
@ -23,11 +23,14 @@ 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.internal.crypto.model.rest.RoomKeyShare
|
||||
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import timber.log.Timber
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
internal class IncomingRoomKeyRequestManager(
|
||||
@SessionScope
|
||||
internal class IncomingRoomKeyRequestManager @Inject constructor(
|
||||
private val credentials: Credentials,
|
||||
private val cryptoStore: IMXCryptoStore,
|
||||
private val roomDecryptorProvider: RoomDecryptorProvider) {
|
||||
|
|
|
@ -26,15 +26,23 @@ import im.vector.matrix.android.internal.crypto.model.OlmInboundGroupSessionWrap
|
|||
import im.vector.matrix.android.internal.crypto.model.OlmSessionWrapper
|
||||
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
||||
import im.vector.matrix.android.internal.di.MoshiProvider
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.util.convertFromUTF8
|
||||
import im.vector.matrix.android.internal.util.convertToUTF8
|
||||
import org.matrix.olm.*
|
||||
import org.matrix.olm.OlmAccount
|
||||
import org.matrix.olm.OlmInboundGroupSession
|
||||
import org.matrix.olm.OlmMessage
|
||||
import org.matrix.olm.OlmOutboundGroupSession
|
||||
import org.matrix.olm.OlmSession
|
||||
import org.matrix.olm.OlmUtility
|
||||
import timber.log.Timber
|
||||
import java.net.URLEncoder
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
// The libolm wrapper.
|
||||
internal class MXOlmDevice(
|
||||
@SessionScope
|
||||
internal class MXOlmDevice @Inject constructor(
|
||||
/**
|
||||
* The store where crypto data is saved.
|
||||
*/
|
||||
|
@ -670,7 +678,7 @@ internal class MXOlmDevice(
|
|||
val reason = String.format(MXCryptoError.DUPLICATE_MESSAGE_INDEX_REASON, decryptResult.mIndex)
|
||||
Timber.e("## decryptGroupMessage() : $reason")
|
||||
throw MXDecryptionException(MXCryptoError(MXCryptoError.DUPLICATED_MESSAGE_INDEX_ERROR_CODE,
|
||||
MXCryptoError.UNABLE_TO_DECRYPT, reason))
|
||||
MXCryptoError.UNABLE_TO_DECRYPT, reason))
|
||||
}
|
||||
|
||||
inboundGroupSessionMessageIndexes[timeline]!!.put(messageIndexKey, true)
|
||||
|
@ -703,7 +711,7 @@ internal class MXOlmDevice(
|
|||
val reason = String.format(MXCryptoError.INBOUND_SESSION_MISMATCH_ROOM_ID_REASON, roomId, session.roomId)
|
||||
Timber.e("## decryptGroupMessage() : $reason")
|
||||
throw MXDecryptionException(MXCryptoError(MXCryptoError.INBOUND_SESSION_MISMATCH_ROOM_ID_ERROR_CODE,
|
||||
MXCryptoError.UNABLE_TO_DECRYPT, reason))
|
||||
MXCryptoError.UNABLE_TO_DECRYPT, reason))
|
||||
}
|
||||
} else {
|
||||
Timber.e("## decryptGroupMessage() : Cannot retrieve inbound group session $sessionId")
|
||||
|
|
|
@ -20,9 +20,12 @@ import android.text.TextUtils
|
|||
import im.vector.matrix.android.api.auth.data.Credentials
|
||||
import im.vector.matrix.android.internal.crypto.model.MXDeviceInfo
|
||||
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class MyDeviceInfoHolder(
|
||||
@SessionScope
|
||||
internal class MyDeviceInfoHolder @Inject constructor(
|
||||
// The credentials,
|
||||
credentials: Credentials,
|
||||
// the crypto store
|
||||
|
|
|
@ -17,9 +17,12 @@
|
|||
package im.vector.matrix.android.internal.crypto
|
||||
|
||||
import im.vector.matrix.android.api.auth.data.Credentials
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class ObjectSigner(private val credentials: Credentials,
|
||||
@SessionScope
|
||||
internal class ObjectSigner @Inject constructor(private val credentials: Credentials,
|
||||
private val olmDevice: MXOlmDevice) {
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,11 +23,14 @@ import im.vector.matrix.android.internal.crypto.model.MXKey
|
|||
import im.vector.matrix.android.internal.crypto.model.rest.KeysUploadResponse
|
||||
import im.vector.matrix.android.internal.crypto.tasks.UploadKeysTask
|
||||
import im.vector.matrix.android.internal.di.MoshiProvider
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import org.matrix.olm.OlmAccount
|
||||
import timber.log.Timber
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class OneTimeKeysUploader(
|
||||
@SessionScope
|
||||
internal class OneTimeKeysUploader @Inject constructor(
|
||||
private val credentials: Credentials,
|
||||
private val olmDevice: MXOlmDevice,
|
||||
private val objectSigner: ObjectSigner,
|
||||
|
|
|
@ -26,12 +26,15 @@ import im.vector.matrix.android.internal.crypto.model.rest.RoomKeyShareCancellat
|
|||
import im.vector.matrix.android.internal.crypto.model.rest.RoomKeyShareRequest
|
||||
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
||||
import im.vector.matrix.android.internal.crypto.tasks.SendToDeviceTask
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||
import im.vector.matrix.android.internal.task.configureWith
|
||||
import timber.log.Timber
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class OutgoingRoomKeyRequestManager(
|
||||
@SessionScope
|
||||
internal class OutgoingRoomKeyRequestManager @Inject constructor(
|
||||
private val cryptoStore: IMXCryptoStore,
|
||||
private val sendToDeviceTask: SendToDeviceTask,
|
||||
private val taskExecutor: TaskExecutor) {
|
||||
|
|
|
@ -20,10 +20,13 @@ import android.text.TextUtils
|
|||
import im.vector.matrix.android.internal.crypto.algorithms.IMXDecrypting
|
||||
import im.vector.matrix.android.internal.crypto.algorithms.megolm.MXMegolmDecryptionFactory
|
||||
import im.vector.matrix.android.internal.crypto.algorithms.olm.MXOlmDecryptionFactory
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import timber.log.Timber
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class RoomDecryptorProvider(
|
||||
@SessionScope
|
||||
internal class RoomDecryptorProvider @Inject constructor(
|
||||
private val olmDecryptionFactory: MXOlmDecryptionFactory,
|
||||
private val megolmDecryptionFactory: MXMegolmDecryptionFactory
|
||||
) {
|
||||
|
|
|
@ -24,11 +24,14 @@ import im.vector.matrix.android.internal.crypto.model.MXKey
|
|||
import im.vector.matrix.android.internal.crypto.model.MXOlmSessionResult
|
||||
import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap
|
||||
import im.vector.matrix.android.internal.crypto.tasks.ClaimOneTimeKeysForUsersDeviceTask
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import timber.log.Timber
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class EnsureOlmSessionsForDevicesAction(private val olmDevice: MXOlmDevice,
|
||||
private val oneTimeKeysForUsersDeviceTask: ClaimOneTimeKeysForUsersDeviceTask) {
|
||||
@SessionScope
|
||||
internal class EnsureOlmSessionsForDevicesAction @Inject constructor(private val olmDevice: MXOlmDevice,
|
||||
private val oneTimeKeysForUsersDeviceTask: ClaimOneTimeKeysForUsersDeviceTask) {
|
||||
|
||||
|
||||
suspend fun handle(devicesByUser: Map<String, List<MXDeviceInfo>>): Try<MXUsersDevicesMap<MXOlmSessionResult>> {
|
||||
|
|
|
@ -24,10 +24,13 @@ import im.vector.matrix.android.internal.crypto.model.MXDeviceInfo
|
|||
import im.vector.matrix.android.internal.crypto.model.MXOlmSessionResult
|
||||
import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap
|
||||
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import timber.log.Timber
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class EnsureOlmSessionsForUsersAction(private val olmDevice: MXOlmDevice,
|
||||
@SessionScope
|
||||
internal class EnsureOlmSessionsForUsersAction @Inject constructor(private val olmDevice: MXOlmDevice,
|
||||
private val cryptoStore: IMXCryptoStore,
|
||||
private val ensureOlmSessionsForDevicesAction: EnsureOlmSessionsForDevicesAction) {
|
||||
|
||||
|
|
|
@ -26,12 +26,15 @@ import im.vector.matrix.android.internal.crypto.RoomDecryptorProvider
|
|||
import im.vector.matrix.android.internal.crypto.model.ImportRoomKeysResult
|
||||
import im.vector.matrix.android.internal.crypto.model.rest.RoomKeyRequestBody
|
||||
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class MegolmSessionDataImporter(private val olmDevice: MXOlmDevice,
|
||||
private val roomDecryptorProvider: RoomDecryptorProvider,
|
||||
private val outgoingRoomKeyRequestManager: OutgoingRoomKeyRequestManager,
|
||||
private val cryptoStore: IMXCryptoStore) {
|
||||
@SessionScope
|
||||
internal class MegolmSessionDataImporter @Inject constructor(private val olmDevice: MXOlmDevice,
|
||||
private val roomDecryptorProvider: RoomDecryptorProvider,
|
||||
private val outgoingRoomKeyRequestManager: OutgoingRoomKeyRequestManager,
|
||||
private val cryptoStore: IMXCryptoStore) {
|
||||
|
||||
/**
|
||||
* Import a list of megolm session keys.
|
||||
|
|
|
@ -23,12 +23,15 @@ import im.vector.matrix.android.internal.crypto.MXOlmDevice
|
|||
import im.vector.matrix.android.internal.crypto.model.MXDeviceInfo
|
||||
import im.vector.matrix.android.internal.crypto.model.rest.EncryptedMessage
|
||||
import im.vector.matrix.android.internal.di.MoshiProvider
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.util.convertToUTF8
|
||||
import timber.log.Timber
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class MessageEncrypter(private val credentials: Credentials,
|
||||
private val olmDevice: MXOlmDevice) {
|
||||
@SessionScope
|
||||
internal class MessageEncrypter @Inject constructor(private val credentials: Credentials,
|
||||
private val olmDevice: MXOlmDevice) {
|
||||
|
||||
/**
|
||||
* Encrypt an event payload for a list of devices.
|
||||
|
|
|
@ -19,9 +19,12 @@ package im.vector.matrix.android.internal.crypto.actions
|
|||
import im.vector.matrix.android.api.auth.data.Credentials
|
||||
import im.vector.matrix.android.internal.crypto.keysbackup.KeysBackup
|
||||
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class SetDeviceVerificationAction(private val cryptoStore: IMXCryptoStore,
|
||||
@SessionScope
|
||||
internal class SetDeviceVerificationAction @Inject constructor(private val cryptoStore: IMXCryptoStore,
|
||||
private val credentials: Credentials,
|
||||
private val keysBackup: KeysBackup) {
|
||||
|
||||
|
|
|
@ -24,9 +24,12 @@ import im.vector.matrix.android.internal.crypto.actions.EnsureOlmSessionsForDevi
|
|||
import im.vector.matrix.android.internal.crypto.actions.MessageEncrypter
|
||||
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
||||
import im.vector.matrix.android.internal.crypto.tasks.SendToDeviceTask
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class MXMegolmDecryptionFactory(private val credentials: Credentials,
|
||||
@SessionScope
|
||||
internal class MXMegolmDecryptionFactory @Inject constructor(private val credentials: Credentials,
|
||||
private val olmDevice: MXOlmDevice,
|
||||
private val deviceListManager: DeviceListManager,
|
||||
private val outgoingRoomKeyRequestManager: OutgoingRoomKeyRequestManager,
|
||||
|
|
|
@ -25,9 +25,12 @@ import im.vector.matrix.android.internal.crypto.keysbackup.KeysBackup
|
|||
import im.vector.matrix.android.internal.crypto.repository.WarnOnUnknownDeviceRepository
|
||||
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
||||
import im.vector.matrix.android.internal.crypto.tasks.SendToDeviceTask
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class MXMegolmEncryptionFactory(
|
||||
@SessionScope
|
||||
internal class MXMegolmEncryptionFactory @Inject constructor(
|
||||
private val olmDevice: MXOlmDevice,
|
||||
private val keysBackup: KeysBackup,
|
||||
private val cryptoStore: IMXCryptoStore,
|
||||
|
|
|
@ -18,9 +18,12 @@ package im.vector.matrix.android.internal.crypto.algorithms.olm
|
|||
|
||||
import im.vector.matrix.android.api.auth.data.Credentials
|
||||
import im.vector.matrix.android.internal.crypto.MXOlmDevice
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class MXOlmDecryptionFactory(private val olmDevice: MXOlmDevice,
|
||||
private val credentials: Credentials) {
|
||||
@SessionScope
|
||||
internal class MXOlmDecryptionFactory @Inject constructor(private val olmDevice: MXOlmDevice,
|
||||
private val credentials: Credentials) {
|
||||
|
||||
fun create(): MXOlmDecryption {
|
||||
return MXOlmDecryption(
|
||||
|
|
|
@ -21,14 +21,17 @@ import im.vector.matrix.android.internal.crypto.MXOlmDevice
|
|||
import im.vector.matrix.android.internal.crypto.actions.EnsureOlmSessionsForUsersAction
|
||||
import im.vector.matrix.android.internal.crypto.actions.MessageEncrypter
|
||||
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class MXOlmEncryptionFactory(private val olmDevice: MXOlmDevice,
|
||||
private val cryptoStore: IMXCryptoStore,
|
||||
private val messageEncrypter: MessageEncrypter,
|
||||
private val deviceListManager: DeviceListManager,
|
||||
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
||||
private val ensureOlmSessionsForUsersAction: EnsureOlmSessionsForUsersAction) {
|
||||
@SessionScope
|
||||
internal class MXOlmEncryptionFactory @Inject constructor(private val olmDevice: MXOlmDevice,
|
||||
private val cryptoStore: IMXCryptoStore,
|
||||
private val messageEncrypter: MessageEncrypter,
|
||||
private val deviceListManager: DeviceListManager,
|
||||
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
||||
private val ensureOlmSessionsForUsersAction: EnsureOlmSessionsForUsersAction) {
|
||||
|
||||
fun create(roomId: String): MXOlmEncryption {
|
||||
return MXOlmEncryption(
|
||||
|
|
|
@ -47,6 +47,7 @@ import im.vector.matrix.android.internal.crypto.model.OlmInboundGroupSessionWrap
|
|||
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
||||
import im.vector.matrix.android.internal.crypto.store.db.model.KeysBackupDataEntity
|
||||
import im.vector.matrix.android.internal.di.MoshiProvider
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.task.Task
|
||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||
import im.vector.matrix.android.internal.task.TaskThread
|
||||
|
@ -58,13 +59,16 @@ import org.matrix.olm.OlmPkMessage
|
|||
import timber.log.Timber
|
||||
import java.security.InvalidParameterException
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
import kotlin.collections.HashMap
|
||||
|
||||
/**
|
||||
* A KeysBackup class instance manage incremental backup of e2e keys (megolm keys)
|
||||
* to the user's homeserver.
|
||||
*/
|
||||
internal class KeysBackup(
|
||||
|
||||
@SessionScope
|
||||
internal class KeysBackup @Inject constructor(
|
||||
private val credentials: Credentials,
|
||||
private val cryptoStore: IMXCryptoStore,
|
||||
private val olmDevice: MXOlmDevice,
|
||||
|
|
|
@ -21,12 +21,14 @@ 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>
|
||||
|
||||
|
||||
internal class DefaultCreateKeysBackupVersionTask(private val roomKeysApi: RoomKeysApi)
|
||||
@SessionScope
|
||||
internal class DefaultCreateKeysBackupVersionTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
|
||||
: CreateKeysBackupVersionTask {
|
||||
|
||||
|
||||
|
|
|
@ -19,7 +19,9 @@ package im.vector.matrix.android.internal.crypto.keysbackup.tasks
|
|||
import arrow.core.Try
|
||||
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
|
||||
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 DeleteBackupTask : Task<DeleteBackupTask.Params, Unit> {
|
||||
|
@ -28,8 +30,8 @@ internal interface DeleteBackupTask : Task<DeleteBackupTask.Params, Unit> {
|
|||
)
|
||||
}
|
||||
|
||||
|
||||
internal class DefaultDeleteBackupTask(private val roomKeysApi: RoomKeysApi)
|
||||
@SessionScope
|
||||
internal class DefaultDeleteBackupTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
|
||||
: DeleteBackupTask {
|
||||
|
||||
override suspend fun execute(params: DeleteBackupTask.Params): Try<Unit> {
|
||||
|
|
|
@ -19,7 +19,9 @@ package im.vector.matrix.android.internal.crypto.keysbackup.tasks
|
|||
import arrow.core.Try
|
||||
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
|
||||
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 DeleteRoomSessionDataTask : Task<DeleteRoomSessionDataTask.Params, Unit> {
|
||||
data class Params(
|
||||
|
@ -29,8 +31,8 @@ internal interface DeleteRoomSessionDataTask : Task<DeleteRoomSessionDataTask.Pa
|
|||
)
|
||||
}
|
||||
|
||||
|
||||
internal class DefaultDeleteRoomSessionDataTask(private val roomKeysApi: RoomKeysApi)
|
||||
@SessionScope
|
||||
internal class DefaultDeleteRoomSessionDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
|
||||
: DeleteRoomSessionDataTask {
|
||||
|
||||
override suspend fun execute(params: DeleteRoomSessionDataTask.Params): Try<Unit> {
|
||||
|
|
|
@ -19,7 +19,9 @@ package im.vector.matrix.android.internal.crypto.keysbackup.tasks
|
|||
import arrow.core.Try
|
||||
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
|
||||
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 DeleteRoomSessionsDataTask : Task<DeleteRoomSessionsDataTask.Params, Unit> {
|
||||
data class Params(
|
||||
|
@ -28,8 +30,8 @@ internal interface DeleteRoomSessionsDataTask : Task<DeleteRoomSessionsDataTask.
|
|||
)
|
||||
}
|
||||
|
||||
|
||||
internal class DefaultDeleteRoomSessionsDataTask(private val roomKeysApi: RoomKeysApi)
|
||||
@SessionScope
|
||||
internal class DefaultDeleteRoomSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
|
||||
: DeleteRoomSessionsDataTask {
|
||||
|
||||
override suspend fun execute(params: DeleteRoomSessionsDataTask.Params): Try<Unit> {
|
||||
|
|
|
@ -19,7 +19,9 @@ package im.vector.matrix.android.internal.crypto.keysbackup.tasks
|
|||
import arrow.core.Try
|
||||
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
|
||||
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 DeleteSessionsDataTask : Task<DeleteSessionsDataTask.Params, Unit> {
|
||||
data class Params(
|
||||
|
@ -27,8 +29,8 @@ internal interface DeleteSessionsDataTask : Task<DeleteSessionsDataTask.Params,
|
|||
)
|
||||
}
|
||||
|
||||
|
||||
internal class DefaultDeleteSessionsDataTask(private val roomKeysApi: RoomKeysApi)
|
||||
@SessionScope
|
||||
internal class DefaultDeleteSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
|
||||
: DeleteSessionsDataTask {
|
||||
|
||||
override suspend fun execute(params: DeleteSessionsDataTask.Params): Try<Unit> {
|
||||
|
|
|
@ -20,12 +20,14 @@ 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>
|
||||
|
||||
|
||||
internal class DefaultGetKeysBackupLastVersionTask(private val roomKeysApi: RoomKeysApi)
|
||||
@SessionScope
|
||||
internal class DefaultGetKeysBackupLastVersionTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
|
||||
: GetKeysBackupLastVersionTask {
|
||||
|
||||
|
||||
|
|
|
@ -20,12 +20,14 @@ 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>
|
||||
|
||||
|
||||
internal class DefaultGetKeysBackupVersionTask(private val roomKeysApi: RoomKeysApi)
|
||||
@SessionScope
|
||||
internal class DefaultGetKeysBackupVersionTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
|
||||
: GetKeysBackupVersionTask {
|
||||
|
||||
|
||||
|
|
|
@ -20,7 +20,9 @@ import arrow.core.Try
|
|||
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
|
||||
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeyBackupData
|
||||
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 GetRoomSessionDataTask : Task<GetRoomSessionDataTask.Params, KeyBackupData> {
|
||||
data class Params(
|
||||
|
@ -30,8 +32,8 @@ internal interface GetRoomSessionDataTask : Task<GetRoomSessionDataTask.Params,
|
|||
)
|
||||
}
|
||||
|
||||
|
||||
internal class DefaultGetRoomSessionDataTask(private val roomKeysApi: RoomKeysApi)
|
||||
@SessionScope
|
||||
internal class DefaultGetRoomSessionDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
|
||||
: GetRoomSessionDataTask {
|
||||
|
||||
override suspend fun execute(params: GetRoomSessionDataTask.Params): Try<KeyBackupData> {
|
||||
|
|
|
@ -20,7 +20,9 @@ import arrow.core.Try
|
|||
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
|
||||
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.RoomKeysBackupData
|
||||
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 GetRoomSessionsDataTask : Task<GetRoomSessionsDataTask.Params, RoomKeysBackupData> {
|
||||
|
@ -30,8 +32,8 @@ internal interface GetRoomSessionsDataTask : Task<GetRoomSessionsDataTask.Params
|
|||
)
|
||||
}
|
||||
|
||||
|
||||
internal class DefaultGetRoomSessionsDataTask(private val roomKeysApi: RoomKeysApi)
|
||||
@SessionScope
|
||||
internal class DefaultGetRoomSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
|
||||
: GetRoomSessionsDataTask {
|
||||
|
||||
override suspend fun execute(params: GetRoomSessionsDataTask.Params): Try<RoomKeysBackupData> {
|
||||
|
|
|
@ -20,7 +20,9 @@ import arrow.core.Try
|
|||
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
|
||||
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeysBackupData
|
||||
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 GetSessionsDataTask : Task<GetSessionsDataTask.Params, KeysBackupData> {
|
||||
data class Params(
|
||||
|
@ -28,8 +30,8 @@ internal interface GetSessionsDataTask : Task<GetSessionsDataTask.Params, KeysBa
|
|||
)
|
||||
}
|
||||
|
||||
|
||||
internal class DefaultGetSessionsDataTask(private val roomKeysApi: RoomKeysApi)
|
||||
@SessionScope
|
||||
internal class DefaultGetSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
|
||||
: GetSessionsDataTask {
|
||||
|
||||
override suspend fun execute(params: GetSessionsDataTask.Params): Try<KeysBackupData> {
|
||||
|
|
|
@ -21,7 +21,9 @@ import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
|
|||
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeyBackupData
|
||||
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.BackupKeysResult
|
||||
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 StoreRoomSessionDataTask : Task<StoreRoomSessionDataTask.Params, BackupKeysResult> {
|
||||
data class Params(
|
||||
|
@ -32,8 +34,8 @@ internal interface StoreRoomSessionDataTask : Task<StoreRoomSessionDataTask.Para
|
|||
)
|
||||
}
|
||||
|
||||
|
||||
internal class DefaultStoreRoomSessionDataTask(private val roomKeysApi: RoomKeysApi)
|
||||
@SessionScope
|
||||
internal class DefaultStoreRoomSessionDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
|
||||
: StoreRoomSessionDataTask {
|
||||
|
||||
override suspend fun execute(params: StoreRoomSessionDataTask.Params): Try<BackupKeysResult> {
|
||||
|
|
|
@ -21,7 +21,9 @@ import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
|
|||
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.RoomKeysBackupData
|
||||
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.BackupKeysResult
|
||||
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 StoreRoomSessionsDataTask : Task<StoreRoomSessionsDataTask.Params, BackupKeysResult> {
|
||||
data class Params(
|
||||
|
@ -31,8 +33,8 @@ internal interface StoreRoomSessionsDataTask : Task<StoreRoomSessionsDataTask.Pa
|
|||
)
|
||||
}
|
||||
|
||||
|
||||
internal class DefaultStoreRoomSessionsDataTask(private val roomKeysApi: RoomKeysApi)
|
||||
@SessionScope
|
||||
internal class DefaultStoreRoomSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
|
||||
: StoreRoomSessionsDataTask {
|
||||
|
||||
override suspend fun execute(params: StoreRoomSessionsDataTask.Params): Try<BackupKeysResult> {
|
||||
|
|
|
@ -21,7 +21,9 @@ import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
|
|||
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeysBackupData
|
||||
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.BackupKeysResult
|
||||
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 StoreSessionsDataTask : Task<StoreSessionsDataTask.Params, BackupKeysResult> {
|
||||
data class Params(
|
||||
|
@ -30,8 +32,8 @@ internal interface StoreSessionsDataTask : Task<StoreSessionsDataTask.Params, Ba
|
|||
)
|
||||
}
|
||||
|
||||
|
||||
internal class DefaultStoreSessionsDataTask(private val roomKeysApi: RoomKeysApi)
|
||||
@SessionScope
|
||||
internal class DefaultStoreSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
|
||||
: StoreSessionsDataTask {
|
||||
|
||||
override suspend fun execute(params: StoreSessionsDataTask.Params): Try<BackupKeysResult> {
|
||||
|
|
|
@ -20,7 +20,9 @@ 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
|
||||
|
||||
internal interface UpdateKeysBackupVersionTask : Task<UpdateKeysBackupVersionTask.Params, Unit> {
|
||||
data class Params(
|
||||
|
@ -29,8 +31,8 @@ internal interface UpdateKeysBackupVersionTask : Task<UpdateKeysBackupVersionTas
|
|||
)
|
||||
}
|
||||
|
||||
|
||||
internal class DefaultUpdateKeysBackupVersionTask(private val roomKeysApi: RoomKeysApi)
|
||||
@SessionScope
|
||||
internal class DefaultUpdateKeysBackupVersionTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
|
||||
: UpdateKeysBackupVersionTask {
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,11 @@
|
|||
|
||||
package im.vector.matrix.android.internal.crypto.repository
|
||||
|
||||
internal class WarnOnUnknownDeviceRepository {
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import javax.inject.Inject
|
||||
|
||||
@SessionScope
|
||||
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.
|
||||
|
|
|
@ -23,9 +23,11 @@ import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap
|
|||
import im.vector.matrix.android.internal.crypto.model.rest.KeysClaimBody
|
||||
import im.vector.matrix.android.internal.crypto.model.rest.KeysClaimResponse
|
||||
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 timber.log.Timber
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
internal interface ClaimOneTimeKeysForUsersDeviceTask : Task<ClaimOneTimeKeysForUsersDeviceTask.Params, MXUsersDevicesMap<MXKey>> {
|
||||
data class Params(
|
||||
|
@ -34,7 +36,8 @@ internal interface ClaimOneTimeKeysForUsersDeviceTask : Task<ClaimOneTimeKeysFor
|
|||
)
|
||||
}
|
||||
|
||||
internal class DefaultClaimOneTimeKeysForUsersDevice(private val cryptoApi: CryptoApi)
|
||||
@SessionScope
|
||||
internal class DefaultClaimOneTimeKeysForUsersDevice @Inject constructor(private val cryptoApi: CryptoApi)
|
||||
: ClaimOneTimeKeysForUsersDeviceTask {
|
||||
|
||||
override suspend fun execute(params: ClaimOneTimeKeysForUsersDeviceTask.Params): Try<MXUsersDevicesMap<MXKey>> {
|
||||
|
|
|
@ -20,7 +20,9 @@ import arrow.core.Try
|
|||
import im.vector.matrix.android.internal.crypto.api.CryptoApi
|
||||
import im.vector.matrix.android.internal.crypto.model.rest.DeleteDeviceParams
|
||||
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 DeleteDeviceTask : Task<DeleteDeviceTask.Params, Unit> {
|
||||
data class Params(
|
||||
|
@ -29,7 +31,8 @@ internal interface DeleteDeviceTask : Task<DeleteDeviceTask.Params, Unit> {
|
|||
)
|
||||
}
|
||||
|
||||
internal class DefaultDeleteDeviceTask(private val cryptoApi: CryptoApi)
|
||||
@SessionScope
|
||||
internal class DefaultDeleteDeviceTask @Inject constructor(private val cryptoApi: CryptoApi)
|
||||
: DeleteDeviceTask {
|
||||
|
||||
override suspend fun execute(params: DeleteDeviceTask.Params): Try<Unit> {
|
||||
|
|
|
@ -22,8 +22,10 @@ import im.vector.matrix.android.internal.crypto.api.CryptoApi
|
|||
import im.vector.matrix.android.internal.crypto.model.rest.KeysQueryBody
|
||||
import im.vector.matrix.android.internal.crypto.model.rest.KeysQueryResponse
|
||||
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 java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
internal interface DownloadKeysForUsersTask : Task<DownloadKeysForUsersTask.Params, KeysQueryResponse> {
|
||||
data class Params(
|
||||
|
@ -33,7 +35,8 @@ internal interface DownloadKeysForUsersTask : Task<DownloadKeysForUsersTask.Para
|
|||
val token: String?)
|
||||
}
|
||||
|
||||
internal class DefaultDownloadKeysForUsers(private val cryptoApi: CryptoApi)
|
||||
@SessionScope
|
||||
internal class DefaultDownloadKeysForUsers @Inject constructor(private val cryptoApi: CryptoApi)
|
||||
: DownloadKeysForUsersTask {
|
||||
|
||||
override suspend fun execute(params: DownloadKeysForUsersTask.Params): Try<KeysQueryResponse> {
|
||||
|
|
|
@ -20,11 +20,14 @@ import arrow.core.Try
|
|||
import im.vector.matrix.android.internal.crypto.api.CryptoApi
|
||||
import im.vector.matrix.android.internal.crypto.model.rest.DevicesListResponse
|
||||
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 GetDevicesTask : Task<Unit, DevicesListResponse>
|
||||
|
||||
internal class DefaultGetDevicesTask(private val cryptoApi: CryptoApi)
|
||||
@SessionScope
|
||||
internal class DefaultGetDevicesTask @Inject constructor(private val cryptoApi: CryptoApi)
|
||||
: GetDevicesTask {
|
||||
|
||||
override suspend fun execute(params: Unit): Try<DevicesListResponse> {
|
||||
|
|
|
@ -20,7 +20,9 @@ import arrow.core.Try
|
|||
import im.vector.matrix.android.internal.crypto.api.CryptoApi
|
||||
import im.vector.matrix.android.internal.crypto.model.rest.KeyChangesResponse
|
||||
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 GetKeyChangesTask : Task<GetKeyChangesTask.Params, KeyChangesResponse> {
|
||||
data class Params(
|
||||
|
@ -31,7 +33,8 @@ internal interface GetKeyChangesTask : Task<GetKeyChangesTask.Params, KeyChanges
|
|||
)
|
||||
}
|
||||
|
||||
internal class DefaultGetKeyChangesTask(private val cryptoApi: CryptoApi)
|
||||
@SessionScope
|
||||
internal class DefaultGetKeyChangesTask @Inject constructor(private val cryptoApi: CryptoApi)
|
||||
: GetKeyChangesTask {
|
||||
|
||||
override suspend fun execute(params: GetKeyChangesTask.Params): Try<KeyChangesResponse> {
|
||||
|
|
|
@ -21,8 +21,10 @@ import im.vector.matrix.android.internal.crypto.api.CryptoApi
|
|||
import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap
|
||||
import im.vector.matrix.android.internal.crypto.model.rest.SendToDeviceBody
|
||||
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 java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
internal interface SendToDeviceTask : Task<SendToDeviceTask.Params, Unit> {
|
||||
data class Params(
|
||||
|
@ -35,7 +37,8 @@ internal interface SendToDeviceTask : Task<SendToDeviceTask.Params, Unit> {
|
|||
)
|
||||
}
|
||||
|
||||
internal class DefaultSendToDeviceTask(private val cryptoApi: CryptoApi)
|
||||
@SessionScope
|
||||
internal class DefaultSendToDeviceTask @Inject constructor(private val cryptoApi: CryptoApi)
|
||||
: SendToDeviceTask {
|
||||
|
||||
override suspend fun execute(params: SendToDeviceTask.Params): Try<Unit> {
|
||||
|
|
|
@ -21,7 +21,9 @@ import arrow.core.Try
|
|||
import im.vector.matrix.android.internal.crypto.api.CryptoApi
|
||||
import im.vector.matrix.android.internal.crypto.model.rest.UpdateDeviceInfoBody
|
||||
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 SetDeviceNameTask : Task<SetDeviceNameTask.Params, Unit> {
|
||||
data class Params(
|
||||
|
@ -32,7 +34,8 @@ internal interface SetDeviceNameTask : Task<SetDeviceNameTask.Params, Unit> {
|
|||
)
|
||||
}
|
||||
|
||||
internal class DefaultSetDeviceNameTask(private val cryptoApi: CryptoApi)
|
||||
@SessionScope
|
||||
internal class DefaultSetDeviceNameTask @Inject constructor(private val cryptoApi: CryptoApi)
|
||||
: SetDeviceNameTask {
|
||||
|
||||
override suspend fun execute(params: SetDeviceNameTask.Params): Try<Unit> {
|
||||
|
|
|
@ -23,8 +23,10 @@ import im.vector.matrix.android.internal.crypto.model.rest.KeysUploadResponse
|
|||
import im.vector.matrix.android.internal.crypto.model.rest.DeviceKeys
|
||||
import im.vector.matrix.android.internal.crypto.model.rest.KeysUploadBody
|
||||
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 im.vector.matrix.android.internal.util.convertToUTF8
|
||||
import javax.inject.Inject
|
||||
|
||||
internal interface UploadKeysTask : Task<UploadKeysTask.Params, KeysUploadResponse> {
|
||||
data class Params(
|
||||
|
@ -36,7 +38,8 @@ internal interface UploadKeysTask : Task<UploadKeysTask.Params, KeysUploadRespon
|
|||
val deviceId: String)
|
||||
}
|
||||
|
||||
internal class DefaultUploadKeysTask(private val cryptoApi: CryptoApi)
|
||||
@SessionScope
|
||||
internal class DefaultUploadKeysTask @Inject constructor(private val cryptoApi: CryptoApi)
|
||||
: UploadKeysTask {
|
||||
|
||||
override suspend fun execute(params: UploadKeysTask.Params): Try<KeysUploadResponse> {
|
||||
|
|
|
@ -40,6 +40,7 @@ import im.vector.matrix.android.internal.crypto.model.rest.KeyVerificationMac
|
|||
import im.vector.matrix.android.internal.crypto.model.rest.KeyVerificationStart
|
||||
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
||||
import im.vector.matrix.android.internal.crypto.tasks.SendToDeviceTask
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||
import im.vector.matrix.android.internal.task.configureWith
|
||||
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
|
||||
|
@ -47,6 +48,7 @@ import kotlinx.coroutines.CoroutineScope
|
|||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
import kotlin.collections.HashMap
|
||||
|
||||
/**
|
||||
|
@ -54,14 +56,16 @@ import kotlin.collections.HashMap
|
|||
* Short codes interactive verification is a more user friendly way of verifying devices
|
||||
* that is still maintaining a good level of security (alternative to the 43-character strings compare method).
|
||||
*/
|
||||
internal class DefaultSasVerificationService(private val credentials: Credentials,
|
||||
private val cryptoStore: IMXCryptoStore,
|
||||
private val myDeviceInfoHolder: MyDeviceInfoHolder,
|
||||
private val deviceListManager: DeviceListManager,
|
||||
private val setDeviceVerificationAction: SetDeviceVerificationAction,
|
||||
private val sendToDeviceTask: SendToDeviceTask,
|
||||
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
||||
private val taskExecutor: TaskExecutor)
|
||||
|
||||
@SessionScope
|
||||
internal class DefaultSasVerificationService @Inject constructor(private val credentials: Credentials,
|
||||
private val cryptoStore: IMXCryptoStore,
|
||||
private val myDeviceInfoHolder: MyDeviceInfoHolder,
|
||||
private val deviceListManager: DeviceListManager,
|
||||
private val setDeviceVerificationAction: SetDeviceVerificationAction,
|
||||
private val sendToDeviceTask: SendToDeviceTask,
|
||||
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
||||
private val taskExecutor: TaskExecutor)
|
||||
: VerificationTransaction.Listener, SasVerificationService {
|
||||
|
||||
private val uiHandler = Handler(Looper.getMainLooper())
|
||||
|
|
|
@ -16,22 +16,12 @@
|
|||
|
||||
package im.vector.matrix.android.internal.di
|
||||
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.KoinContext
|
||||
import org.koin.standalone.KoinComponent
|
||||
import android.content.Context
|
||||
import androidx.work.ListenableWorker
|
||||
import androidx.work.WorkerParameters
|
||||
|
||||
internal object MatrixKoinHolder {
|
||||
interface ChildWorkerFactory {
|
||||
|
||||
val instance: Koin by lazy {
|
||||
Koin.create()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal interface MatrixKoinComponent : KoinComponent {
|
||||
|
||||
override fun getKoin(): KoinContext {
|
||||
return MatrixKoinHolder.instance.koinContext
|
||||
}
|
||||
fun create(appContext: Context, params: WorkerParameters): ListenableWorker
|
||||
|
||||
}
|
|
@ -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.di
|
||||
|
||||
import dagger.Component
|
||||
|
||||
@Component
|
||||
@MatrixScope
|
||||
interface MatrixComponent {
|
||||
|
||||
}
|
|
@ -17,43 +17,31 @@
|
|||
package im.vector.matrix.android.internal.di
|
||||
|
||||
import android.content.Context
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import im.vector.matrix.android.internal.crypto.CryptoAsyncHelper
|
||||
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.util.StringProvider
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.android.asCoroutineDispatcher
|
||||
import org.koin.dsl.module.module
|
||||
|
||||
@Module
|
||||
internal class MatrixModule(private val context: Context) {
|
||||
|
||||
class MatrixModule(private val context: Context) {
|
||||
|
||||
val definition = module {
|
||||
|
||||
single {
|
||||
context
|
||||
@Provides
|
||||
@MatrixScope
|
||||
fun providesContext(): Context {
|
||||
return context
|
||||
}
|
||||
|
||||
single {
|
||||
@Provides
|
||||
@MatrixScope
|
||||
fun providesMatrixCoroutineDispatchers(): MatrixCoroutineDispatchers {
|
||||
val cryptoHandler = CryptoAsyncHelper.getDecryptBackgroundHandler()
|
||||
MatrixCoroutineDispatchers(io = Dispatchers.IO,
|
||||
return MatrixCoroutineDispatchers(io = Dispatchers.IO,
|
||||
computation = Dispatchers.IO,
|
||||
main = Dispatchers.Main,
|
||||
crypto = cryptoHandler.asCoroutineDispatcher("crypto")
|
||||
)
|
||||
}
|
||||
|
||||
single {
|
||||
TaskExecutor(get())
|
||||
}
|
||||
single {
|
||||
StringProvider(context.resources)
|
||||
}
|
||||
|
||||
single {
|
||||
BackgroundDetectionObserver()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -14,18 +14,16 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.matrix.android.internal.session.user
|
||||
package im.vector.matrix.android.internal.di;
|
||||
|
||||
import im.vector.matrix.android.internal.session.DefaultSession
|
||||
import org.koin.dsl.module.module
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
|
||||
internal class UserModule {
|
||||
import javax.inject.Scope;
|
||||
|
||||
val definition = module(override = true) {
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultUpdateUserTask(get()) as UpdateUserTask
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@Scope
|
||||
@Documented
|
||||
@Retention(RUNTIME)
|
||||
public @interface MatrixScope {}
|
|
@ -17,85 +17,84 @@
|
|||
package im.vector.matrix.android.internal.di
|
||||
|
||||
import com.facebook.stetho.okhttp3.StethoInterceptor
|
||||
import com.squareup.moshi.Moshi
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import im.vector.matrix.android.BuildConfig
|
||||
import im.vector.matrix.android.internal.network.*
|
||||
import im.vector.matrix.android.internal.network.AccessTokenInterceptor
|
||||
import im.vector.matrix.android.internal.network.UnitConverterFactory
|
||||
import im.vector.matrix.android.internal.network.UserAgentInterceptor
|
||||
import im.vector.matrix.android.internal.network.interceptors.CurlLoggingInterceptor
|
||||
import im.vector.matrix.android.internal.network.interceptors.FormattedJsonHttpLogger
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import okreplay.OkReplayInterceptor
|
||||
import org.koin.dsl.module.module
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.moshi.MoshiConverterFactory
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class NetworkModule {
|
||||
|
||||
val definition = module {
|
||||
|
||||
single {
|
||||
UserAgentHolder(get())
|
||||
}
|
||||
|
||||
single {
|
||||
UserAgentInterceptor(get())
|
||||
}
|
||||
|
||||
single {
|
||||
AccessTokenInterceptor(get())
|
||||
}
|
||||
|
||||
single {
|
||||
val logger = FormattedJsonHttpLogger()
|
||||
val interceptor = HttpLoggingInterceptor(logger)
|
||||
interceptor.level = BuildConfig.OKHTTP_LOGGING_LEVEL
|
||||
interceptor
|
||||
}
|
||||
|
||||
single {
|
||||
CurlLoggingInterceptor()
|
||||
}
|
||||
|
||||
single {
|
||||
OkReplayInterceptor()
|
||||
}
|
||||
|
||||
single {
|
||||
StethoInterceptor()
|
||||
}
|
||||
|
||||
single {
|
||||
OkHttpClient.Builder()
|
||||
.connectTimeout(1, TimeUnit.MINUTES)
|
||||
.readTimeout(30, TimeUnit.SECONDS)
|
||||
.writeTimeout(30, TimeUnit.SECONDS)
|
||||
.addNetworkInterceptor(get<StethoInterceptor>())
|
||||
.addInterceptor(get<UserAgentInterceptor>())
|
||||
.addInterceptor(get<AccessTokenInterceptor>())
|
||||
.addInterceptor(get<HttpLoggingInterceptor>())
|
||||
.apply {
|
||||
if (BuildConfig.LOG_PRIVATE_DATA) {
|
||||
addInterceptor(get<CurlLoggingInterceptor>())
|
||||
}
|
||||
}
|
||||
.addInterceptor(get<OkReplayInterceptor>())
|
||||
.build()
|
||||
}
|
||||
|
||||
single {
|
||||
MoshiProvider.providesMoshi()
|
||||
}
|
||||
|
||||
single {
|
||||
NetworkConnectivityChecker(get())
|
||||
}
|
||||
|
||||
factory {
|
||||
Retrofit.Builder()
|
||||
.client(get())
|
||||
.addConverterFactory(UnitConverterFactory)
|
||||
.addConverterFactory(MoshiConverterFactory.create(get()))
|
||||
}
|
||||
@Module
|
||||
internal class NetworkModule {
|
||||
|
||||
@MatrixScope
|
||||
@Provides
|
||||
fun providesHttpLogingInterceptor(): HttpLoggingInterceptor {
|
||||
val logger = FormattedJsonHttpLogger()
|
||||
val interceptor = HttpLoggingInterceptor(logger)
|
||||
interceptor.level = BuildConfig.OKHTTP_LOGGING_LEVEL
|
||||
return interceptor
|
||||
}
|
||||
|
||||
@MatrixScope
|
||||
@Provides
|
||||
fun providesOkReplayInterceptor(): OkReplayInterceptor {
|
||||
return OkReplayInterceptor()
|
||||
}
|
||||
|
||||
@MatrixScope
|
||||
@Provides
|
||||
fun providesStethoInterceptor(): StethoInterceptor {
|
||||
return StethoInterceptor()
|
||||
}
|
||||
|
||||
@MatrixScope
|
||||
@Provides
|
||||
fun providesOkHttpClient(stethoInterceptor: StethoInterceptor,
|
||||
userAgentInterceptor: UserAgentInterceptor,
|
||||
accessTokenInterceptor: AccessTokenInterceptor,
|
||||
httpLoggingInterceptor: HttpLoggingInterceptor,
|
||||
curlLoggingInterceptor: CurlLoggingInterceptor,
|
||||
okReplayInterceptor: OkReplayInterceptor): OkHttpClient {
|
||||
return OkHttpClient.Builder()
|
||||
.connectTimeout(1, TimeUnit.MINUTES)
|
||||
.readTimeout(30, TimeUnit.SECONDS)
|
||||
.writeTimeout(30, TimeUnit.SECONDS)
|
||||
.addNetworkInterceptor(stethoInterceptor)
|
||||
.addInterceptor(userAgentInterceptor)
|
||||
.addInterceptor(accessTokenInterceptor)
|
||||
.addInterceptor(httpLoggingInterceptor)
|
||||
.apply {
|
||||
if (BuildConfig.LOG_PRIVATE_DATA) {
|
||||
addInterceptor(curlLoggingInterceptor)
|
||||
}
|
||||
}
|
||||
.addInterceptor(okReplayInterceptor)
|
||||
.build()
|
||||
}
|
||||
|
||||
@MatrixScope
|
||||
@Provides
|
||||
fun providesMoshi(): Moshi {
|
||||
return MoshiProvider.providesMoshi()
|
||||
}
|
||||
|
||||
@Provides
|
||||
fun providesRetrofitBuilder(okHttpClient: OkHttpClient,
|
||||
moshi: Moshi): Retrofit.Builder {
|
||||
return Retrofit.Builder()
|
||||
.client(okHttpClient)
|
||||
.addConverterFactory(UnitConverterFactory)
|
||||
.addConverterFactory(MoshiConverterFactory.create(moshi))
|
||||
}
|
||||
|
||||
}
|
|
@ -17,10 +17,13 @@
|
|||
package im.vector.matrix.android.internal.network
|
||||
|
||||
import im.vector.matrix.android.internal.auth.SessionParamsStore
|
||||
import im.vector.matrix.android.internal.di.MatrixScope
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class AccessTokenInterceptor(private val sessionParamsStore: SessionParamsStore) : Interceptor {
|
||||
@MatrixScope
|
||||
internal class AccessTokenInterceptor @Inject constructor(private val sessionParamsStore: SessionParamsStore) : Interceptor {
|
||||
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
var request = chain.request()
|
||||
|
|
|
@ -20,8 +20,11 @@ import android.content.Context
|
|||
import com.novoda.merlin.Merlin
|
||||
import com.novoda.merlin.MerlinsBeard
|
||||
import com.novoda.merlin.registerable.connection.Connectable
|
||||
import im.vector.matrix.android.internal.di.MatrixScope
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class NetworkConnectivityChecker(context: Context) {
|
||||
@MatrixScope
|
||||
internal class NetworkConnectivityChecker @Inject constructor(context: Context) {
|
||||
|
||||
private val merlin = Merlin.Builder().withConnectableCallbacks().build(context)
|
||||
private val merlinsBeard = MerlinsBeard.from(context)
|
||||
|
|
|
@ -19,9 +19,12 @@ package im.vector.matrix.android.internal.network
|
|||
import android.content.Context
|
||||
import android.text.TextUtils
|
||||
import im.vector.matrix.android.BuildConfig
|
||||
import im.vector.matrix.android.internal.di.MatrixScope
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class UserAgentHolder(val context: Context) {
|
||||
@MatrixScope
|
||||
internal class UserAgentHolder @Inject constructor(val context: Context) {
|
||||
|
||||
var userAgent: String = ""
|
||||
private set
|
||||
|
|
|
@ -16,10 +16,13 @@
|
|||
|
||||
package im.vector.matrix.android.internal.network
|
||||
|
||||
import im.vector.matrix.android.internal.di.MatrixScope
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class UserAgentInterceptor(private val userAgentHolder: UserAgentHolder) : Interceptor {
|
||||
@MatrixScope
|
||||
internal class UserAgentInterceptor @Inject constructor(private val userAgentHolder: UserAgentHolder) : Interceptor {
|
||||
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
var request = chain.request()
|
||||
|
|
|
@ -16,86 +16,63 @@
|
|||
|
||||
package im.vector.matrix.android.internal.session
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Looper
|
||||
import androidx.annotation.MainThread
|
||||
import androidx.lifecycle.LiveData
|
||||
import com.squareup.inject.assisted.Assisted
|
||||
import com.squareup.inject.assisted.AssistedInject
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import im.vector.matrix.android.api.MatrixCallback
|
||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
||||
import im.vector.matrix.android.api.listeners.ProgressListener
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.matrix.android.api.session.cache.CacheService
|
||||
import im.vector.matrix.android.api.session.content.ContentUploadStateTracker
|
||||
import im.vector.matrix.android.api.session.content.ContentUrlResolver
|
||||
import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupService
|
||||
import im.vector.matrix.android.api.session.crypto.keyshare.RoomKeysRequestListener
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationService
|
||||
import im.vector.matrix.android.api.session.events.model.Content
|
||||
import im.vector.matrix.android.api.session.events.model.Event
|
||||
import im.vector.matrix.android.api.session.group.Group
|
||||
import im.vector.matrix.android.api.session.crypto.CryptoService
|
||||
import im.vector.matrix.android.api.session.group.GroupService
|
||||
import im.vector.matrix.android.api.session.group.model.GroupSummary
|
||||
import im.vector.matrix.android.api.session.room.Room
|
||||
import im.vector.matrix.android.api.session.room.RoomDirectoryService
|
||||
import im.vector.matrix.android.api.session.room.RoomService
|
||||
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
||||
import im.vector.matrix.android.api.session.room.model.create.CreateRoomParams
|
||||
import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoomsParams
|
||||
import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoomsResponse
|
||||
import im.vector.matrix.android.api.session.room.model.thirdparty.ThirdPartyProtocol
|
||||
import im.vector.matrix.android.api.session.signout.SignOutService
|
||||
import im.vector.matrix.android.api.session.sync.FilterService
|
||||
import im.vector.matrix.android.api.session.sync.SyncState
|
||||
import im.vector.matrix.android.api.session.user.UserService
|
||||
import im.vector.matrix.android.api.session.user.model.User
|
||||
import im.vector.matrix.android.api.util.Cancelable
|
||||
import im.vector.matrix.android.api.util.MatrixCallbackDelegate
|
||||
import im.vector.matrix.android.internal.crypto.CryptoManager
|
||||
import im.vector.matrix.android.internal.crypto.CryptoModule
|
||||
import im.vector.matrix.android.internal.crypto.MXEventDecryptionResult
|
||||
import im.vector.matrix.android.internal.crypto.model.ImportRoomKeysResult
|
||||
import im.vector.matrix.android.internal.crypto.model.MXDeviceInfo
|
||||
import im.vector.matrix.android.internal.crypto.model.MXEncryptEventContentResult
|
||||
import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap
|
||||
import im.vector.matrix.android.internal.crypto.model.rest.DevicesListResponse
|
||||
import im.vector.matrix.android.internal.crypto.model.rest.RoomKeyRequestBody
|
||||
import im.vector.matrix.android.internal.database.LiveEntityObserver
|
||||
import im.vector.matrix.android.internal.di.MatrixKoinComponent
|
||||
import im.vector.matrix.android.internal.di.MatrixKoinHolder
|
||||
import im.vector.matrix.android.internal.session.content.ContentModule
|
||||
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.signout.SignOutModule
|
||||
import im.vector.matrix.android.internal.session.sync.SyncModule
|
||||
import im.vector.matrix.android.internal.session.sync.job.SyncThread
|
||||
import im.vector.matrix.android.internal.session.user.UserModule
|
||||
import org.koin.core.scope.Scope
|
||||
import org.koin.standalone.inject
|
||||
import timber.log.Timber
|
||||
|
||||
|
||||
internal class DefaultSession(override val sessionParams: SessionParams) : Session, MatrixKoinComponent {
|
||||
companion object {
|
||||
const val SCOPE: String = "session"
|
||||
internal class DefaultSession @AssistedInject constructor(@Assisted override val sessionParams: SessionParams,
|
||||
private val monarchy: Monarchy,
|
||||
private val liveEntityUpdaters: List<LiveEntityObserver>,
|
||||
private val sessionListeners: SessionListeners,
|
||||
private val roomService: RoomService,
|
||||
private val roomDirectoryService: RoomDirectoryService,
|
||||
private val groupService: GroupService,
|
||||
private val userService: UserService,
|
||||
private val filterService: FilterService,
|
||||
private val cacheService: CacheService,
|
||||
private val signOutService: SignOutService,
|
||||
private val cryptoService: CryptoManager,
|
||||
private val syncThread: SyncThread,
|
||||
private val contentUrlResolver: ContentUrlResolver,
|
||||
private val contentUploadProgressTracker: ContentUploadStateTracker)
|
||||
: Session,
|
||||
RoomService by roomService,
|
||||
RoomDirectoryService by roomDirectoryService,
|
||||
GroupService by groupService,
|
||||
UserService by userService,
|
||||
CryptoService by cryptoService,
|
||||
CacheService by cacheService,
|
||||
SignOutService by signOutService,
|
||||
FilterService by filterService {
|
||||
|
||||
@AssistedInject.Factory
|
||||
interface Factory {
|
||||
fun create(sessionParams: SessionParams): DefaultSession
|
||||
}
|
||||
|
||||
private lateinit var scope: Scope
|
||||
|
||||
private val monarchy by inject<Monarchy>()
|
||||
private val liveEntityUpdaters by inject<List<LiveEntityObserver>>()
|
||||
private val sessionListeners by inject<SessionListeners>()
|
||||
private val roomService by inject<RoomService>()
|
||||
private val roomDirectoryService by inject<RoomDirectoryService>()
|
||||
private val groupService by inject<GroupService>()
|
||||
private val userService by inject<UserService>()
|
||||
private val filterService by inject<FilterService>()
|
||||
private val cacheService by inject<CacheService>()
|
||||
private val signOutService by inject<SignOutService>()
|
||||
private val cryptoService by inject<CryptoManager>()
|
||||
private val syncThread by inject<SyncThread>()
|
||||
private val contentUrlResolver by inject<ContentUrlResolver>()
|
||||
private val contentUploadProgressTracker by inject<ContentUploadStateTracker>()
|
||||
private var isOpen = false
|
||||
|
||||
@MainThread
|
||||
|
@ -103,23 +80,6 @@ internal class DefaultSession(override val sessionParams: SessionParams) : Sessi
|
|||
assertMainThread()
|
||||
assert(!isOpen)
|
||||
isOpen = true
|
||||
val sessionModule = SessionModule(sessionParams).definition
|
||||
val syncModule = SyncModule().definition
|
||||
val roomModule = RoomModule().definition
|
||||
val groupModule = GroupModule().definition
|
||||
val signOutModule = SignOutModule().definition
|
||||
val userModule = UserModule().definition
|
||||
val contentModule = ContentModule().definition
|
||||
val cryptoModule = CryptoModule().definition
|
||||
MatrixKoinHolder.instance.loadModules(listOf(sessionModule,
|
||||
syncModule,
|
||||
roomModule,
|
||||
groupModule,
|
||||
userModule,
|
||||
signOutModule,
|
||||
contentModule,
|
||||
cryptoModule))
|
||||
scope = getKoin().getOrCreateScope(SCOPE)
|
||||
if (!monarchy.isMonarchyThreadOpen) {
|
||||
monarchy.openManually()
|
||||
}
|
||||
|
@ -147,7 +107,6 @@ internal class DefaultSession(override val sessionParams: SessionParams) : Sessi
|
|||
if (monarchy.isMonarchyThreadOpen) {
|
||||
monarchy.closeManually()
|
||||
}
|
||||
scope.close()
|
||||
isOpen = false
|
||||
}
|
||||
|
||||
|
@ -207,221 +166,6 @@ internal class DefaultSession(override val sessionParams: SessionParams) : Sessi
|
|||
sessionListeners.removeListener(listener)
|
||||
}
|
||||
|
||||
// ROOM SERVICE
|
||||
|
||||
override fun createRoom(createRoomParams: CreateRoomParams, callback: MatrixCallback<String>) {
|
||||
assert(isOpen)
|
||||
return roomService.createRoom(createRoomParams, callback)
|
||||
}
|
||||
|
||||
override fun getRoom(roomId: String): Room? {
|
||||
assert(isOpen)
|
||||
return roomService.getRoom(roomId)
|
||||
}
|
||||
|
||||
|
||||
override fun liveRoomSummaries(): LiveData<List<RoomSummary>> {
|
||||
assert(isOpen)
|
||||
return roomService.liveRoomSummaries()
|
||||
}
|
||||
|
||||
// ROOM DIRECTORY SERVICE
|
||||
|
||||
override fun getPublicRooms(server: String?, publicRoomsParams: PublicRoomsParams, callback: MatrixCallback<PublicRoomsResponse>): Cancelable {
|
||||
assert(isOpen)
|
||||
return roomDirectoryService.getPublicRooms(server, publicRoomsParams, callback)
|
||||
}
|
||||
|
||||
override fun joinRoom(roomId: String, callback: MatrixCallback<Unit>) {
|
||||
assert(isOpen)
|
||||
return roomDirectoryService.joinRoom(roomId, callback)
|
||||
}
|
||||
|
||||
override fun getThirdPartyProtocol(callback: MatrixCallback<Map<String, ThirdPartyProtocol>>) {
|
||||
assert(isOpen)
|
||||
return roomDirectoryService.getThirdPartyProtocol(callback)
|
||||
}
|
||||
|
||||
// GROUP SERVICE
|
||||
|
||||
override fun getGroup(groupId: String): Group? {
|
||||
assert(isOpen)
|
||||
return groupService.getGroup(groupId)
|
||||
}
|
||||
|
||||
override fun liveGroupSummaries(): LiveData<List<GroupSummary>> {
|
||||
assert(isOpen)
|
||||
return groupService.liveGroupSummaries()
|
||||
}
|
||||
|
||||
override fun setFilter(filterPreset: FilterService.FilterPreset) {
|
||||
assert(isOpen)
|
||||
return filterService.setFilter(filterPreset)
|
||||
}
|
||||
|
||||
override fun clearCache(callback: MatrixCallback<Unit>) {
|
||||
assert(isOpen)
|
||||
syncThread.pause()
|
||||
cacheService.clearCache(object : MatrixCallbackDelegate<Unit>(callback) {
|
||||
override fun onSuccess(data: Unit) {
|
||||
// Restart the sync
|
||||
syncThread.restart()
|
||||
|
||||
super.onSuccess(data)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// USER SERVICE
|
||||
|
||||
override fun getUser(userId: String): User? {
|
||||
assert(isOpen)
|
||||
return userService.getUser(userId)
|
||||
}
|
||||
|
||||
override fun observeUser(userId: String): LiveData<User?> {
|
||||
assert(isOpen)
|
||||
return userService.observeUser(userId)
|
||||
}
|
||||
|
||||
// CRYPTO SERVICE
|
||||
|
||||
override fun setDeviceName(deviceId: String, deviceName: String, callback: MatrixCallback<Unit>) {
|
||||
cryptoService.setDeviceName(deviceId, deviceName, callback)
|
||||
}
|
||||
|
||||
override fun deleteDevice(deviceId: String, accountPassword: String, callback: MatrixCallback<Unit>) {
|
||||
cryptoService.deleteDevice(deviceId, accountPassword, callback)
|
||||
}
|
||||
|
||||
override fun getCryptoVersion(context: Context, longFormat: Boolean): String {
|
||||
return cryptoService.getCryptoVersion(context, longFormat)
|
||||
}
|
||||
|
||||
override fun isCryptoEnabled(): Boolean {
|
||||
return cryptoService.isCryptoEnabled()
|
||||
}
|
||||
|
||||
override fun getSasVerificationService(): SasVerificationService {
|
||||
return cryptoService.getSasVerificationService()
|
||||
}
|
||||
|
||||
override fun getKeysBackupService(): KeysBackupService {
|
||||
return cryptoService.getKeysBackupService()
|
||||
}
|
||||
|
||||
override fun isRoomBlacklistUnverifiedDevices(roomId: String?): Boolean {
|
||||
return cryptoService.isRoomBlacklistUnverifiedDevices(roomId)
|
||||
}
|
||||
|
||||
override fun setWarnOnUnknownDevices(warn: Boolean) {
|
||||
cryptoService.setWarnOnUnknownDevices(warn)
|
||||
}
|
||||
|
||||
override fun setDeviceVerification(verificationStatus: Int, deviceId: String, userId: String) {
|
||||
cryptoService.setDeviceVerification(verificationStatus, deviceId, userId)
|
||||
}
|
||||
|
||||
override fun getUserDevices(userId: String): MutableList<MXDeviceInfo> {
|
||||
return cryptoService.getUserDevices(userId)
|
||||
}
|
||||
|
||||
override fun setDevicesKnown(devices: List<MXDeviceInfo>, callback: MatrixCallback<Unit>?) {
|
||||
cryptoService.setDevicesKnown(devices, callback)
|
||||
}
|
||||
|
||||
override fun deviceWithIdentityKey(senderKey: String, algorithm: String): MXDeviceInfo? {
|
||||
return cryptoService.deviceWithIdentityKey(senderKey, algorithm)
|
||||
}
|
||||
|
||||
override fun getMyDevice(): MXDeviceInfo {
|
||||
return cryptoService.getMyDevice()
|
||||
}
|
||||
|
||||
override fun getDevicesList(callback: MatrixCallback<DevicesListResponse>) {
|
||||
cryptoService.getDevicesList(callback)
|
||||
}
|
||||
|
||||
override fun inboundGroupSessionsCount(onlyBackedUp: Boolean): Int {
|
||||
return cryptoService.inboundGroupSessionsCount(onlyBackedUp)
|
||||
}
|
||||
|
||||
override fun getGlobalBlacklistUnverifiedDevices(): Boolean {
|
||||
return cryptoService.getGlobalBlacklistUnverifiedDevices()
|
||||
}
|
||||
|
||||
override fun setGlobalBlacklistUnverifiedDevices(block: Boolean) {
|
||||
cryptoService.setGlobalBlacklistUnverifiedDevices(block)
|
||||
}
|
||||
|
||||
override fun setRoomUnBlacklistUnverifiedDevices(roomId: String) {
|
||||
cryptoService.setRoomUnBlacklistUnverifiedDevices(roomId)
|
||||
}
|
||||
|
||||
override fun getDeviceTrackingStatus(userId: String): Int {
|
||||
return cryptoService.getDeviceTrackingStatus(userId)
|
||||
}
|
||||
|
||||
override fun importRoomKeys(roomKeysAsArray: ByteArray, password: String, progressListener: ProgressListener?, callback: MatrixCallback<ImportRoomKeysResult>) {
|
||||
cryptoService.importRoomKeys(roomKeysAsArray, password, progressListener, callback)
|
||||
}
|
||||
|
||||
override fun exportRoomKeys(password: String, callback: MatrixCallback<ByteArray>) {
|
||||
cryptoService.exportRoomKeys(password, callback)
|
||||
}
|
||||
|
||||
override fun setRoomBlacklistUnverifiedDevices(roomId: String) {
|
||||
cryptoService.setRoomBlacklistUnverifiedDevices(roomId)
|
||||
}
|
||||
|
||||
override fun isRoomEncrypted(roomId: String): Boolean {
|
||||
return cryptoService.isRoomEncrypted(roomId)
|
||||
}
|
||||
|
||||
override fun encryptEventContent(eventContent: Content, eventType: String, roomId: String, callback: MatrixCallback<MXEncryptEventContentResult>) {
|
||||
cryptoService.encryptEventContent(eventContent, eventType, roomId, callback)
|
||||
}
|
||||
|
||||
override fun getDeviceInfo(userId: String, deviceId: String?): MXDeviceInfo? {
|
||||
return cryptoService.getDeviceInfo(userId, deviceId)
|
||||
}
|
||||
|
||||
override fun reRequestRoomKeyForEvent(event: Event) {
|
||||
cryptoService.reRequestRoomKeyForEvent(event)
|
||||
}
|
||||
|
||||
override fun cancelRoomKeyRequest(requestBody: RoomKeyRequestBody) {
|
||||
cryptoService.cancelRoomKeyRequest(requestBody)
|
||||
}
|
||||
|
||||
override fun addRoomKeysRequestListener(listener: RoomKeysRequestListener) {
|
||||
cryptoService.addRoomKeysRequestListener(listener)
|
||||
}
|
||||
|
||||
override fun decryptEvent(event: Event, timeline: String): MXEventDecryptionResult? {
|
||||
return cryptoService.decryptEvent(event, timeline)
|
||||
}
|
||||
|
||||
override fun decryptEventAsync(event: Event, timeline: String, callback: MatrixCallback<MXEventDecryptionResult?>) {
|
||||
return cryptoService.decryptEventAsync(event, timeline, callback)
|
||||
}
|
||||
|
||||
override fun getEncryptionAlgorithm(roomId: String): String? {
|
||||
return cryptoService.getEncryptionAlgorithm(roomId)
|
||||
}
|
||||
|
||||
override fun shouldEncryptForInvitedMembers(roomId: String): Boolean {
|
||||
return cryptoService.shouldEncryptForInvitedMembers(roomId)
|
||||
}
|
||||
|
||||
override fun downloadKeys(userIds: List<String>, forceDownload: Boolean, callback: MatrixCallback<MXUsersDevicesMap<MXDeviceInfo>>) {
|
||||
cryptoService.downloadKeys(userIds, forceDownload, callback)
|
||||
}
|
||||
|
||||
override fun clearCryptoCache(callback: MatrixCallback<Unit>) {
|
||||
cryptoService.clearCryptoCache(callback)
|
||||
}
|
||||
|
||||
// Private methods *****************************************************************************
|
||||
|
||||
private fun assertMainThread() {
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* 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.session
|
||||
|
||||
import dagger.Component
|
||||
import im.vector.matrix.android.internal.di.MatrixComponent
|
||||
|
||||
@Component(dependencies = [MatrixComponent::class])
|
||||
@SessionScope
|
||||
interface SessionComponent {
|
||||
|
||||
@Component.Builder
|
||||
interface Builder {
|
||||
fun matrixComponent(matrixComponent: MatrixComponent): Builder
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* 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.session
|
||||
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.matrix.android.api.session.cache.CacheService
|
||||
import im.vector.matrix.android.api.session.content.ContentUploadStateTracker
|
||||
import im.vector.matrix.android.api.session.content.ContentUrlResolver
|
||||
import im.vector.matrix.android.api.session.group.GroupService
|
||||
import im.vector.matrix.android.api.session.room.RoomDirectoryService
|
||||
import im.vector.matrix.android.api.session.room.RoomService
|
||||
import im.vector.matrix.android.api.session.signout.SignOutService
|
||||
import im.vector.matrix.android.api.session.sync.FilterService
|
||||
import im.vector.matrix.android.api.session.user.UserService
|
||||
import im.vector.matrix.android.internal.crypto.CryptoManager
|
||||
import im.vector.matrix.android.internal.database.LiveEntityObserver
|
||||
import im.vector.matrix.android.internal.di.MatrixScope
|
||||
import im.vector.matrix.android.internal.session.sync.job.SyncThread
|
||||
import javax.inject.Inject
|
||||
|
||||
@MatrixScope
|
||||
internal class SessionFactory @Inject constructor(
|
||||
private val monarchy: Monarchy,
|
||||
private val liveEntityUpdaters: List<LiveEntityObserver>,
|
||||
private val sessionListeners: SessionListeners,
|
||||
private val roomService: RoomService,
|
||||
private val roomDirectoryService: RoomDirectoryService,
|
||||
private val groupService: GroupService,
|
||||
private val userService: UserService,
|
||||
private val filterService: FilterService,
|
||||
private val cacheService: CacheService,
|
||||
private val signOutService: SignOutService,
|
||||
private val cryptoService: CryptoManager,
|
||||
private val syncThread: SyncThread,
|
||||
private val contentUrlResolver: ContentUrlResolver,
|
||||
private val contentUploadProgressTracker: ContentUploadStateTracker) {
|
||||
|
||||
|
||||
fun create(sessionParams: SessionParams): Session {
|
||||
return DefaultSession(
|
||||
sessionParams,
|
||||
monarchy,
|
||||
liveEntityUpdaters,
|
||||
sessionListeners,
|
||||
roomService,
|
||||
roomDirectoryService,
|
||||
groupService,
|
||||
userService,
|
||||
filterService,
|
||||
cacheService,
|
||||
signOutService,
|
||||
cryptoService,
|
||||
syncThread,
|
||||
contentUrlResolver,
|
||||
contentUploadProgressTracker
|
||||
)
|
||||
}
|
||||
|
||||
}
|
|
@ -17,8 +17,9 @@
|
|||
package im.vector.matrix.android.internal.session
|
||||
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class SessionListeners {
|
||||
internal class SessionListeners @Inject constructor(){
|
||||
|
||||
private val listeners = ArrayList<Session.Listener>()
|
||||
|
||||
|
|
|
@ -18,161 +18,68 @@ package im.vector.matrix.android.internal.session
|
|||
|
||||
import android.content.Context
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import im.vector.matrix.android.api.auth.data.Credentials
|
||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
||||
import im.vector.matrix.android.api.session.cache.CacheService
|
||||
import im.vector.matrix.android.api.session.group.GroupService
|
||||
import im.vector.matrix.android.api.session.room.RoomDirectoryService
|
||||
import im.vector.matrix.android.api.session.room.RoomService
|
||||
import im.vector.matrix.android.api.session.signout.SignOutService
|
||||
import im.vector.matrix.android.api.session.sync.FilterService
|
||||
import im.vector.matrix.android.api.session.user.UserService
|
||||
import im.vector.matrix.android.internal.database.LiveEntityObserver
|
||||
import im.vector.matrix.android.internal.database.model.SessionRealmModule
|
||||
import im.vector.matrix.android.internal.session.cache.ClearCacheTask
|
||||
import im.vector.matrix.android.internal.session.cache.RealmCacheService
|
||||
import im.vector.matrix.android.internal.session.cache.RealmClearCacheTask
|
||||
import im.vector.matrix.android.internal.session.filter.*
|
||||
import im.vector.matrix.android.internal.session.group.DefaultGroupService
|
||||
import im.vector.matrix.android.internal.session.filter.FilterApi
|
||||
import im.vector.matrix.android.internal.session.group.GroupSummaryUpdater
|
||||
import im.vector.matrix.android.internal.session.room.*
|
||||
import im.vector.matrix.android.internal.session.room.directory.DefaultGetPublicRoomTask
|
||||
import im.vector.matrix.android.internal.session.room.directory.DefaultGetThirdPartyProtocolsTask
|
||||
import im.vector.matrix.android.internal.session.room.directory.GetPublicRoomTask
|
||||
import im.vector.matrix.android.internal.session.room.directory.GetThirdPartyProtocolsTask
|
||||
import im.vector.matrix.android.internal.session.room.membership.RoomDisplayNameResolver
|
||||
import im.vector.matrix.android.internal.session.room.membership.RoomMemberDisplayNameResolver
|
||||
import im.vector.matrix.android.internal.session.room.EventRelationsAggregationUpdater
|
||||
import im.vector.matrix.android.internal.session.room.prune.EventsPruner
|
||||
import im.vector.matrix.android.internal.session.signout.DefaultSignOutService
|
||||
import im.vector.matrix.android.internal.session.user.DefaultUserService
|
||||
import im.vector.matrix.android.internal.session.user.UserEntityUpdater
|
||||
import im.vector.matrix.android.internal.util.md5
|
||||
import io.realm.RealmConfiguration
|
||||
import org.koin.dsl.module.module
|
||||
import retrofit2.Retrofit
|
||||
import java.io.File
|
||||
|
||||
@Module
|
||||
internal class SessionModule(private val sessionParams: SessionParams) {
|
||||
|
||||
val definition = module(override = true) {
|
||||
@Provides
|
||||
fun providesCredentials(): Credentials {
|
||||
return sessionParams.credentials
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
sessionParams
|
||||
}
|
||||
@Provides
|
||||
fun providesRealmConfiguration(context: Context): RealmConfiguration {
|
||||
val childPath = sessionParams.credentials.userId.md5()
|
||||
val directory = File(context.filesDir, childPath)
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
sessionParams.credentials
|
||||
}
|
||||
return RealmConfiguration.Builder()
|
||||
.directory(directory)
|
||||
.name("disk_store.realm")
|
||||
.modules(SessionRealmModule())
|
||||
.deleteRealmIfMigrationNeeded()
|
||||
.build()
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE, name = "SessionRealmConfiguration") {
|
||||
val context = get<Context>()
|
||||
val childPath = sessionParams.credentials.userId.md5()
|
||||
val directory = File(context.filesDir, childPath)
|
||||
@Provides
|
||||
fun providesMonarchy(realmConfiguration: RealmConfiguration): Monarchy {
|
||||
return Monarchy.Builder()
|
||||
.setRealmConfiguration(realmConfiguration)
|
||||
.build()
|
||||
}
|
||||
|
||||
RealmConfiguration.Builder()
|
||||
.directory(directory)
|
||||
.name("disk_store.realm")
|
||||
.modules(SessionRealmModule())
|
||||
.deleteRealmIfMigrationNeeded()
|
||||
.build()
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
Monarchy.Builder()
|
||||
.setRealmConfiguration(get("SessionRealmConfiguration"))
|
||||
.build()
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
val retrofitBuilder = get<Retrofit.Builder>()
|
||||
retrofitBuilder
|
||||
.baseUrl(sessionParams.homeServerConnectionConfig.homeServerUri.toString())
|
||||
.build()
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
RoomMemberDisplayNameResolver()
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
RoomDisplayNameResolver(get(), get(), get(), sessionParams.credentials)
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
RoomAvatarResolver(get(), get())
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
RoomSummaryUpdater(get(), get(), get())
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultRoomService(get(), get(), get(), get()) as RoomService
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultGetPublicRoomTask(get()) as GetPublicRoomTask
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultGetThirdPartyProtocolsTask(get()) as GetThirdPartyProtocolsTask
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultRoomDirectoryService(get(), get(), get(), get()) as RoomDirectoryService
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultGroupService(get()) as GroupService
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultSignOutService(get(), get()) as SignOutService
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
RealmCacheService(get("ClearTaskMainCache"), get()) as CacheService
|
||||
}
|
||||
|
||||
// Give a name, because we have a clear task for crypto store as well
|
||||
scope(DefaultSession.SCOPE, name = "ClearTaskMainCache") {
|
||||
RealmClearCacheTask(get("SessionRealmConfiguration")) as ClearCacheTask
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultUserService(get()) as UserService
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
SessionListeners()
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultFilterRepository(get("SessionRealmConfiguration")) as FilterRepository
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultSaveFilterTask(get(), get(), get()) as SaveFilterTask
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultFilterService(get(), get(), get()) as FilterService
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
val retrofit: Retrofit = get()
|
||||
retrofit.create(FilterApi::class.java)
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
val groupSummaryUpdater = GroupSummaryUpdater(get())
|
||||
val userEntityUpdater = UserEntityUpdater(get(), get(), get())
|
||||
val aggregationUpdater = EventRelationsAggregationUpdater(get(), get(), get(), get())
|
||||
//Event pruner must be the last one, because it will clear contents
|
||||
val eventsPruner = EventsPruner(get(), get(), get(), get())
|
||||
listOf<LiveEntityObserver>(groupSummaryUpdater, userEntityUpdater, aggregationUpdater, eventsPruner)
|
||||
}
|
||||
@Provides
|
||||
fun providesRetrofit(retrofitBuilder: Retrofit.Builder): Retrofit {
|
||||
return retrofitBuilder
|
||||
.baseUrl(sessionParams.homeServerConnectionConfig.homeServerUri.toString())
|
||||
.build()
|
||||
}
|
||||
|
||||
@Provides
|
||||
fun providesFilterAPI(retrofit: Retrofit): FilterApi {
|
||||
return retrofit.create(FilterApi::class.java)
|
||||
}
|
||||
|
||||
@Provides
|
||||
fun providesLiveEntityObservers(groupSummaryUpdater: GroupSummaryUpdater,
|
||||
userEntityUpdater: UserEntityUpdater,
|
||||
aggregationUpdater: EventRelationsAggregationUpdater,
|
||||
eventsPruner: EventsPruner): List<LiveEntityObserver> {
|
||||
return listOf<LiveEntityObserver>(groupSummaryUpdater, userEntityUpdater, aggregationUpdater, eventsPruner)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* 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.session;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
|
||||
import javax.inject.Scope;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
@Scope
|
||||
@Documented
|
||||
@Retention(RUNTIME)
|
||||
public @interface SessionScope {}
|
|
@ -18,11 +18,14 @@ package im.vector.matrix.android.internal.session.cache
|
|||
|
||||
import im.vector.matrix.android.api.MatrixCallback
|
||||
import im.vector.matrix.android.api.session.cache.CacheService
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||
import im.vector.matrix.android.internal.task.configureWith
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class RealmCacheService(private val clearCacheTask: ClearCacheTask,
|
||||
private val taskExecutor: TaskExecutor) : CacheService {
|
||||
@SessionScope
|
||||
internal class RealmCacheService @Inject constructor(private val clearCacheTask: ClearCacheTask,
|
||||
private val taskExecutor: TaskExecutor) : CacheService {
|
||||
|
||||
override fun clearCache(callback: MatrixCallback<Unit>) {
|
||||
clearCacheTask
|
||||
|
|
|
@ -17,13 +17,16 @@
|
|||
package im.vector.matrix.android.internal.session.cache
|
||||
|
||||
import arrow.core.Try
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.task.Task
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmConfiguration
|
||||
import javax.inject.Inject
|
||||
|
||||
internal interface ClearCacheTask : Task<Unit, Unit>
|
||||
|
||||
internal class RealmClearCacheTask(val realmConfiguration: RealmConfiguration) : ClearCacheTask {
|
||||
@SessionScope
|
||||
internal class RealmClearCacheTask @Inject constructor(val realmConfiguration: RealmConfiguration) : ClearCacheTask {
|
||||
|
||||
override suspend fun execute(params: Unit): Try<Unit> {
|
||||
return Try {
|
||||
|
|
|
@ -16,34 +16,10 @@
|
|||
|
||||
package im.vector.matrix.android.internal.session.content
|
||||
|
||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
||||
import im.vector.matrix.android.api.session.content.ContentUploadStateTracker
|
||||
import im.vector.matrix.android.api.session.content.ContentUrlResolver
|
||||
import im.vector.matrix.android.internal.session.DefaultSession
|
||||
import org.koin.dsl.module.module
|
||||
import dagger.Module
|
||||
|
||||
@Module
|
||||
internal class ContentModule {
|
||||
|
||||
val definition = module(override = true) {
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultContentUploadStateTracker()
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
get<DefaultContentUploadStateTracker>() as ContentUploadStateTracker
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
FileUploader(get(), get())
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
val sessionParams = get<SessionParams>()
|
||||
DefaultContentUrlResolver(sessionParams.homeServerConnectionConfig) as ContentUrlResolver
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -19,8 +19,11 @@ 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.session.SessionScope
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class DefaultContentUploadStateTracker : ContentUploadStateTracker {
|
||||
@SessionScope
|
||||
internal class DefaultContentUploadStateTracker @Inject constructor() : ContentUploadStateTracker {
|
||||
|
||||
private val mainHandler = Handler(Looper.getMainLooper())
|
||||
private val states = mutableMapOf<String, ContentUploadStateTracker.State>()
|
||||
|
|
|
@ -18,12 +18,15 @@ package im.vector.matrix.android.internal.session.content
|
|||
|
||||
import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig
|
||||
import im.vector.matrix.android.api.session.content.ContentUrlResolver
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
private const val MATRIX_CONTENT_URI_SCHEME = "mxc://"
|
||||
private const val URI_PREFIX_CONTENT_API = "_matrix/media/v1/"
|
||||
|
||||
internal class DefaultContentUrlResolver(private val homeServerConnectionConfig: HomeServerConnectionConfig) : ContentUrlResolver {
|
||||
@SessionScope
|
||||
internal class DefaultContentUrlResolver @Inject constructor(private val homeServerConnectionConfig: HomeServerConnectionConfig) : ContentUrlResolver {
|
||||
|
||||
companion object {
|
||||
fun getUploadUrl(homeServerConnectionConfig: HomeServerConnectionConfig): String {
|
||||
|
|
|
@ -21,12 +21,15 @@ import arrow.core.Try.Companion.raise
|
|||
import im.vector.matrix.android.api.auth.data.SessionParams
|
||||
import im.vector.matrix.android.internal.di.MoshiProvider
|
||||
import im.vector.matrix.android.internal.network.ProgressRequestBody
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import okhttp3.*
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
internal class FileUploader(private val okHttpClient: OkHttpClient,
|
||||
@SessionScope
|
||||
internal class FileUploader @Inject constructor(private val okHttpClient: OkHttpClient,
|
||||
sessionParams: SessionParams) {
|
||||
|
||||
private val uploadUrl = DefaultContentUrlResolver.getUploadUrl(sessionParams.homeServerConnectionConfig)
|
||||
|
|
|
@ -19,26 +19,32 @@ 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
|
||||
import im.vector.matrix.android.api.session.events.model.Event
|
||||
import im.vector.matrix.android.api.session.events.model.toContent
|
||||
import im.vector.matrix.android.api.session.events.model.toModel
|
||||
import im.vector.matrix.android.api.session.room.model.message.*
|
||||
import im.vector.matrix.android.internal.di.MatrixKoinComponent
|
||||
import im.vector.matrix.android.api.session.room.model.message.MessageAudioContent
|
||||
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.di.ChildWorkerFactory
|
||||
import im.vector.matrix.android.internal.network.ProgressRequestBody
|
||||
import im.vector.matrix.android.internal.session.room.send.SendEventWorker
|
||||
import im.vector.matrix.android.internal.util.WorkerParamsFactory
|
||||
import org.koin.standalone.inject
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
|
||||
|
||||
internal class UploadContentWorker(context: Context, params: WorkerParameters)
|
||||
: CoroutineWorker(context, params), MatrixKoinComponent {
|
||||
|
||||
private val fileUploader by inject<FileUploader>()
|
||||
private val contentUploadProgressTracker by inject<DefaultContentUploadStateTracker>()
|
||||
internal class UploadContentWorker @AssistedInject constructor(
|
||||
@Assisted context: Context,
|
||||
@Assisted params: WorkerParameters,
|
||||
private val fileUploader: FileUploader,
|
||||
private val contentUploadStateTracker: DefaultContentUploadStateTracker)
|
||||
: CoroutineWorker(context, params) {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
internal data class Params(
|
||||
|
@ -69,7 +75,7 @@ internal class UploadContentWorker(context: Context, params: WorkerParameters)
|
|||
|
||||
val progressListener = object : ProgressRequestBody.Listener {
|
||||
override fun onProgress(current: Long, total: Long) {
|
||||
contentUploadProgressTracker.setProgress(eventId, current, total)
|
||||
contentUploadStateTracker.setProgress(eventId, current, total)
|
||||
}
|
||||
}
|
||||
return fileUploader
|
||||
|
@ -90,14 +96,14 @@ internal class UploadContentWorker(context: Context, params: WorkerParameters)
|
|||
}
|
||||
|
||||
private fun handleFailure(params: Params): Result {
|
||||
contentUploadProgressTracker.setFailure(params.event.eventId!!)
|
||||
contentUploadStateTracker.setFailure(params.event.eventId!!)
|
||||
return Result.success()
|
||||
}
|
||||
|
||||
private fun handleSuccess(params: Params,
|
||||
attachmentUrl: String,
|
||||
thumbnailUrl: String?): Result {
|
||||
contentUploadProgressTracker.setFailure(params.event.eventId!!)
|
||||
contentUploadStateTracker.setSuccess(params.event.eventId!!)
|
||||
val event = updateEvent(params.event, attachmentUrl, thumbnailUrl)
|
||||
val sendParams = SendEventWorker.Params(params.roomId, event)
|
||||
return Result.success(WorkerParamsFactory.toData(sendParams))
|
||||
|
@ -131,6 +137,8 @@ internal class UploadContentWorker(context: Context, params: WorkerParameters)
|
|||
return copy(url = url)
|
||||
}
|
||||
|
||||
@AssistedInject.Factory
|
||||
interface Factory : ChildWorkerFactory
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -19,11 +19,14 @@ package im.vector.matrix.android.internal.session.filter
|
|||
import im.vector.matrix.android.internal.database.model.FilterEntity
|
||||
import im.vector.matrix.android.internal.database.model.FilterEntityFields
|
||||
import im.vector.matrix.android.internal.database.query.getFilter
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmConfiguration
|
||||
import io.realm.kotlin.where
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class DefaultFilterRepository(val realmConfiguration: RealmConfiguration) : FilterRepository {
|
||||
@SessionScope
|
||||
internal class DefaultFilterRepository @Inject constructor(val realmConfiguration: RealmConfiguration) : FilterRepository {
|
||||
|
||||
override fun storeFilter(filterBody: FilterBody, roomEventFilter: RoomEventFilter): Boolean {
|
||||
val result: Boolean
|
||||
|
|
|
@ -17,12 +17,15 @@
|
|||
package im.vector.matrix.android.internal.session.filter
|
||||
|
||||
import im.vector.matrix.android.api.session.sync.FilterService
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||
import im.vector.matrix.android.internal.task.configureWith
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class DefaultFilterService(private val filterRepository: FilterRepository,
|
||||
private val saveFilterTask: SaveFilterTask,
|
||||
private val taskExecutor: TaskExecutor) : FilterService {
|
||||
@SessionScope
|
||||
internal class DefaultFilterService @Inject constructor(private val filterRepository: FilterRepository,
|
||||
private val saveFilterTask: SaveFilterTask,
|
||||
private val taskExecutor: TaskExecutor) : FilterService {
|
||||
|
||||
// TODO Pass a list of support events instead
|
||||
override fun setFilter(filterPreset: FilterService.FilterPreset) {
|
||||
|
@ -30,7 +33,7 @@ internal class DefaultFilterService(private val filterRepository: FilterReposito
|
|||
FilterService.FilterPreset.RiotFilter -> {
|
||||
FilterFactory.createRiotFilterBody()
|
||||
}
|
||||
FilterService.FilterPreset.NoFilter -> {
|
||||
FilterService.FilterPreset.NoFilter -> {
|
||||
FilterFactory.createDefaultFilterBody()
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +42,7 @@ internal class DefaultFilterService(private val filterRepository: FilterReposito
|
|||
FilterService.FilterPreset.RiotFilter -> {
|
||||
FilterFactory.createRiotRoomFilter()
|
||||
}
|
||||
FilterService.FilterPreset.NoFilter -> {
|
||||
FilterService.FilterPreset.NoFilter -> {
|
||||
FilterFactory.createDefaultRoomFilter()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,9 @@ package im.vector.matrix.android.internal.session.filter
|
|||
import arrow.core.Try
|
||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
||||
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
|
||||
|
||||
|
||||
/**
|
||||
|
@ -33,9 +35,10 @@ internal interface SaveFilterTask : Task<SaveFilterTask.Params, Unit> {
|
|||
|
||||
}
|
||||
|
||||
internal class DefaultSaveFilterTask(private val sessionParams: SessionParams,
|
||||
private val filterAPI: FilterApi,
|
||||
private val filterRepository: FilterRepository
|
||||
@SessionScope
|
||||
internal class DefaultSaveFilterTask @Inject constructor(private val sessionParams: SessionParams,
|
||||
private val filterAPI: FilterApi,
|
||||
private val filterRepository: FilterRepository
|
||||
) : SaveFilterTask {
|
||||
|
||||
override suspend fun execute(params: SaveFilterTask.Params): Try<Unit> {
|
||||
|
|
|
@ -25,11 +25,13 @@ import im.vector.matrix.android.internal.task.Task
|
|||
import im.vector.matrix.android.internal.database.model.GroupSummaryEntity
|
||||
import im.vector.matrix.android.internal.database.query.where
|
||||
import im.vector.matrix.android.internal.network.executeRequest
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.session.group.model.GroupRooms
|
||||
import im.vector.matrix.android.internal.session.group.model.GroupSummaryResponse
|
||||
import im.vector.matrix.android.internal.session.group.model.GroupUsers
|
||||
import im.vector.matrix.android.internal.util.tryTransactionSync
|
||||
import io.realm.kotlin.createObject
|
||||
import javax.inject.Inject
|
||||
|
||||
internal interface GetGroupDataTask : Task<GetGroupDataTask.Params, Unit> {
|
||||
|
||||
|
@ -37,8 +39,8 @@ internal interface GetGroupDataTask : Task<GetGroupDataTask.Params, Unit> {
|
|||
|
||||
}
|
||||
|
||||
|
||||
internal class DefaultGetGroupDataTask(
|
||||
@SessionScope
|
||||
internal class DefaultGetGroupDataTask @Inject constructor(
|
||||
private val groupAPI: GroupAPI,
|
||||
private val monarchy: Monarchy
|
||||
) : GetGroupDataTask {
|
||||
|
|
|
@ -25,8 +25,9 @@ import im.vector.matrix.android.internal.database.mapper.asDomain
|
|||
import im.vector.matrix.android.internal.database.model.GroupSummaryEntity
|
||||
import im.vector.matrix.android.internal.database.model.GroupSummaryEntityFields
|
||||
import im.vector.matrix.android.internal.database.query.where
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class DefaultGroupService(private val monarchy: Monarchy) : GroupService {
|
||||
internal class DefaultGroupService @Inject constructor(private val monarchy: Monarchy) : GroupService {
|
||||
|
||||
override fun getGroup(groupId: String): Group? {
|
||||
return null
|
||||
|
|
|
@ -18,25 +18,25 @@ package im.vector.matrix.android.internal.session.group
|
|||
|
||||
import android.content.Context
|
||||
import androidx.work.CoroutineWorker
|
||||
import androidx.work.Worker
|
||||
import androidx.work.WorkerParameters
|
||||
import arrow.core.Try
|
||||
import com.squareup.inject.assisted.Assisted
|
||||
import com.squareup.inject.assisted.AssistedInject
|
||||
import com.squareup.moshi.JsonClass
|
||||
import im.vector.matrix.android.internal.di.MatrixKoinComponent
|
||||
import im.vector.matrix.android.internal.di.ChildWorkerFactory
|
||||
import im.vector.matrix.android.internal.util.WorkerParamsFactory
|
||||
import org.koin.standalone.inject
|
||||
|
||||
internal class GetGroupDataWorker(context: Context,
|
||||
workerParameters: WorkerParameters
|
||||
) : CoroutineWorker(context, workerParameters), MatrixKoinComponent {
|
||||
internal class GetGroupDataWorker @AssistedInject constructor(
|
||||
@Assisted context: Context,
|
||||
@Assisted workerParameters: WorkerParameters,
|
||||
private val getGroupDataTask: GetGroupDataTask
|
||||
) : CoroutineWorker(context, workerParameters) {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
internal data class Params(
|
||||
val groupIds: List<String>
|
||||
)
|
||||
|
||||
private val getGroupDataTask by inject<GetGroupDataTask>()
|
||||
|
||||
override suspend fun doWork(): Result {
|
||||
val params = WorkerParamsFactory.fromData<Params>(inputData)
|
||||
?: return Result.failure()
|
||||
|
@ -52,4 +52,7 @@ internal class GetGroupDataWorker(context: Context,
|
|||
return getGroupDataTask.execute(GetGroupDataTask.Params(groupId))
|
||||
}
|
||||
|
||||
@AssistedInject.Factory
|
||||
interface Factory : ChildWorkerFactory
|
||||
|
||||
}
|
|
@ -16,22 +16,15 @@
|
|||
|
||||
package im.vector.matrix.android.internal.session.group
|
||||
|
||||
import im.vector.matrix.android.internal.session.DefaultSession
|
||||
import org.koin.dsl.module.module
|
||||
import dagger.Module
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import retrofit2.Retrofit
|
||||
|
||||
class GroupModule {
|
||||
|
||||
val definition = module(override = true) {
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
val retrofit: Retrofit = get()
|
||||
retrofit.create(GroupAPI::class.java)
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultGetGroupDataTask(get(), get()) as GetGroupDataTask
|
||||
}
|
||||
@Module
|
||||
internal class GroupModule {
|
||||
|
||||
@SessionScope
|
||||
fun providesGroupAPI(retrofit: Retrofit): GroupAPI {
|
||||
return retrofit.create(GroupAPI::class.java)
|
||||
}
|
||||
}
|
|
@ -25,12 +25,14 @@ import com.zhuinden.monarchy.Monarchy
|
|||
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.util.WorkerParamsFactory
|
||||
import javax.inject.Inject
|
||||
|
||||
private const val GET_GROUP_DATA_WORKER = "GET_GROUP_DATA_WORKER"
|
||||
|
||||
internal class GroupSummaryUpdater(monarchy: Monarchy
|
||||
) : RealmLiveEntityObserver<GroupEntity>(monarchy) {
|
||||
@SessionScope
|
||||
internal class GroupSummaryUpdater @Inject constructor(monarchy: Monarchy) : RealmLiveEntityObserver<GroupEntity>(monarchy) {
|
||||
|
||||
override val query = Monarchy.Query<GroupEntity> { GroupEntity.where(it) }
|
||||
|
||||
|
|
|
@ -27,11 +27,12 @@ import im.vector.matrix.android.internal.session.room.directory.GetThirdPartyPro
|
|||
import im.vector.matrix.android.internal.session.room.membership.joining.JoinRoomTask
|
||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||
import im.vector.matrix.android.internal.task.configureWith
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class DefaultRoomDirectoryService(private val getPublicRoomTask: GetPublicRoomTask,
|
||||
private val joinRoomTask: JoinRoomTask,
|
||||
private val getThirdPartyProtocolsTask: GetThirdPartyProtocolsTask,
|
||||
private val taskExecutor: TaskExecutor) : RoomDirectoryService {
|
||||
internal class DefaultRoomDirectoryService @Inject constructor(private val getPublicRoomTask: GetPublicRoomTask,
|
||||
private val joinRoomTask: JoinRoomTask,
|
||||
private val getThirdPartyProtocolsTask: GetThirdPartyProtocolsTask,
|
||||
private val taskExecutor: TaskExecutor) : RoomDirectoryService {
|
||||
|
||||
override fun getPublicRooms(server: String?,
|
||||
publicRoomsParams: PublicRoomsParams,
|
||||
|
|
|
@ -28,15 +28,18 @@ import im.vector.matrix.android.internal.database.model.RoomEntity
|
|||
import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
|
||||
import im.vector.matrix.android.internal.database.model.RoomSummaryEntityFields
|
||||
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.create.CreateRoomTask
|
||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||
import im.vector.matrix.android.internal.task.configureWith
|
||||
import im.vector.matrix.android.internal.util.fetchManaged
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class DefaultRoomService(private val monarchy: Monarchy,
|
||||
private val createRoomTask: CreateRoomTask,
|
||||
private val roomFactory: RoomFactory,
|
||||
private val taskExecutor: TaskExecutor) : RoomService {
|
||||
@SessionScope
|
||||
internal class DefaultRoomService @Inject constructor(private val monarchy: Monarchy,
|
||||
private val createRoomTask: CreateRoomTask,
|
||||
private val roomFactory: RoomFactory,
|
||||
private val taskExecutor: TaskExecutor) : RoomService {
|
||||
|
||||
override fun createRoom(createRoomParams: CreateRoomParams, callback: MatrixCallback<String>) {
|
||||
createRoomTask
|
||||
|
|
|
@ -20,12 +20,16 @@ import im.vector.matrix.android.internal.database.mapper.asDomain
|
|||
import im.vector.matrix.android.internal.database.model.EventAnnotationsSummaryEntity
|
||||
import im.vector.matrix.android.internal.database.model.EventEntity
|
||||
import im.vector.matrix.android.internal.database.query.where
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import io.realm.Realm
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Fetches annotations (reactions, edits...) associated to a given eventEntity from the data layer.
|
||||
*/
|
||||
internal class EventRelationExtractor {
|
||||
|
||||
@SessionScope
|
||||
internal class EventRelationExtractor @Inject constructor() {
|
||||
|
||||
fun extractFrom(event: EventEntity, realm: Realm = event.realm): EventAnnotationsSummary? {
|
||||
return EventAnnotationsSummaryEntity.where(realm, event.eventId).findFirst()?.asDomain()
|
||||
|
|
|
@ -26,10 +26,12 @@ import im.vector.matrix.android.internal.database.mapper.EventMapper
|
|||
import im.vector.matrix.android.internal.database.model.*
|
||||
import im.vector.matrix.android.internal.database.query.create
|
||||
import im.vector.matrix.android.internal.database.query.where
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.task.Task
|
||||
import im.vector.matrix.android.internal.util.tryTransactionSync
|
||||
import io.realm.Realm
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
internal interface EventRelationsAggregationTask : Task<EventRelationsAggregationTask.Params, Unit> {
|
||||
|
||||
|
@ -42,7 +44,8 @@ internal interface EventRelationsAggregationTask : Task<EventRelationsAggregatio
|
|||
/**
|
||||
* Called by EventRelationAggregationUpdater, when new events that can affect relations are inserted in base.
|
||||
*/
|
||||
internal class DefaultEventRelationsAggregationTask(private val monarchy: Monarchy) : EventRelationsAggregationTask {
|
||||
@SessionScope
|
||||
internal class DefaultEventRelationsAggregationTask @Inject constructor(private val monarchy: Monarchy) : EventRelationsAggregationTask {
|
||||
|
||||
//OPT OUT serer aggregation until API mature enough
|
||||
private val SHOULD_HANDLE_SERVER_AGREGGATION = false
|
||||
|
|
|
@ -21,19 +21,23 @@ import im.vector.matrix.android.internal.database.RealmLiveEntityObserver
|
|||
import im.vector.matrix.android.internal.database.mapper.asDomain
|
||||
import im.vector.matrix.android.internal.database.model.EventEntity
|
||||
import im.vector.matrix.android.internal.database.query.where
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||
import im.vector.matrix.android.internal.task.configureWith
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Acts as a listener of incoming messages in order to incrementally computes a summary of annotations.
|
||||
* For reactions will build a EventAnnotationsSummaryEntity, ans for edits a EditAggregatedSummaryEntity.
|
||||
* The summaries can then be extracted and added (as a decoration) to a TimelineEvent for final display.
|
||||
*/
|
||||
internal class EventRelationsAggregationUpdater(monarchy: Monarchy,
|
||||
private val credentials: Credentials,
|
||||
private val task: EventRelationsAggregationTask,
|
||||
private val taskExecutor: TaskExecutor) :
|
||||
|
||||
@SessionScope
|
||||
internal class EventRelationsAggregationUpdater @Inject constructor(monarchy: Monarchy,
|
||||
private val credentials: Credentials,
|
||||
private val task: EventRelationsAggregationTask,
|
||||
private val taskExecutor: TaskExecutor) :
|
||||
RealmLiveEntityObserver<EventEntity>(monarchy) {
|
||||
|
||||
override val query = Monarchy.Query<EventEntity> {
|
||||
|
|
|
@ -27,10 +27,13 @@ import im.vector.matrix.android.internal.database.model.EventEntity
|
|||
import im.vector.matrix.android.internal.database.model.RoomEntity
|
||||
import im.vector.matrix.android.internal.database.query.prev
|
||||
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.membership.RoomMembers
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class RoomAvatarResolver(private val monarchy: Monarchy,
|
||||
private val credentials: Credentials) {
|
||||
@SessionScope
|
||||
internal class RoomAvatarResolver @Inject constructor(private val monarchy: Monarchy,
|
||||
private val credentials: Credentials) {
|
||||
|
||||
/**
|
||||
* Compute the room avatar url
|
||||
|
|
|
@ -19,6 +19,7 @@ package im.vector.matrix.android.internal.session.room
|
|||
import com.zhuinden.monarchy.Monarchy
|
||||
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
|
||||
|
@ -39,21 +40,23 @@ import im.vector.matrix.android.internal.session.room.timeline.GetContextOfEvent
|
|||
import im.vector.matrix.android.internal.session.room.timeline.PaginationTask
|
||||
import im.vector.matrix.android.internal.session.room.timeline.TimelineEventFactory
|
||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class RoomFactory(private val monarchy: Monarchy,
|
||||
private val eventFactory: LocalEchoEventFactory,
|
||||
private val taskExecutor: TaskExecutor,
|
||||
private val loadRoomMembersTask: LoadRoomMembersTask,
|
||||
private val inviteTask: InviteTask,
|
||||
private val sendStateTask: SendStateTask,
|
||||
private val paginationTask: PaginationTask,
|
||||
private val contextOfEventTask: GetContextOfEventTask,
|
||||
private val setReadMarkersTask: SetReadMarkersTask,
|
||||
private val cryptoService: CryptoService,
|
||||
private val findReactionEventForUndoTask: FindReactionEventForUndoTask,
|
||||
private val updateQuickReactionTask: UpdateQuickReactionTask,
|
||||
private val joinRoomTask: JoinRoomTask,
|
||||
private val leaveRoomTask: LeaveRoomTask) {
|
||||
@SessionScope
|
||||
internal class RoomFactory @Inject constructor(private val monarchy: Monarchy,
|
||||
private val eventFactory: LocalEchoEventFactory,
|
||||
private val taskExecutor: TaskExecutor,
|
||||
private val loadRoomMembersTask: LoadRoomMembersTask,
|
||||
private val inviteTask: InviteTask,
|
||||
private val sendStateTask: SendStateTask,
|
||||
private val paginationTask: PaginationTask,
|
||||
private val contextOfEventTask: GetContextOfEventTask,
|
||||
private val setReadMarkersTask: SetReadMarkersTask,
|
||||
private val cryptoService: CryptoService,
|
||||
private val findReactionEventForUndoTask: FindReactionEventForUndoTask,
|
||||
private val updateQuickReactionTask: UpdateQuickReactionTask,
|
||||
private val joinRoomTask: JoinRoomTask,
|
||||
private val leaveRoomTask: LeaveRoomTask) {
|
||||
|
||||
fun instantiate(roomId: String): Room {
|
||||
val roomMemberExtractor = SenderRoomMemberExtractor(roomId)
|
||||
|
|
|
@ -16,7 +16,9 @@
|
|||
|
||||
package im.vector.matrix.android.internal.session.room
|
||||
|
||||
import im.vector.matrix.android.internal.session.DefaultSession
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.session.room.create.CreateRoomTask
|
||||
import im.vector.matrix.android.internal.session.room.create.DefaultCreateRoomTask
|
||||
import im.vector.matrix.android.internal.session.room.membership.DefaultLoadRoomMembersTask
|
||||
|
@ -39,87 +41,20 @@ import im.vector.matrix.android.internal.session.room.send.LocalEchoEventFactory
|
|||
import im.vector.matrix.android.internal.session.room.send.LocalEchoUpdater
|
||||
import im.vector.matrix.android.internal.session.room.state.DefaultSendStateTask
|
||||
import im.vector.matrix.android.internal.session.room.state.SendStateTask
|
||||
import im.vector.matrix.android.internal.session.room.timeline.*
|
||||
import org.koin.dsl.module.module
|
||||
import im.vector.matrix.android.internal.session.room.timeline.DefaultGetContextOfEventTask
|
||||
import im.vector.matrix.android.internal.session.room.timeline.DefaultPaginationTask
|
||||
import im.vector.matrix.android.internal.session.room.timeline.GetContextOfEventTask
|
||||
import im.vector.matrix.android.internal.session.room.timeline.PaginationTask
|
||||
import im.vector.matrix.android.internal.session.room.timeline.TokenChunkEventPersistor
|
||||
import retrofit2.Retrofit
|
||||
|
||||
@Module
|
||||
internal class RoomModule {
|
||||
|
||||
class RoomModule {
|
||||
|
||||
val definition = module(override = true) {
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
val retrofit: Retrofit = get()
|
||||
retrofit.create(RoomAPI::class.java)
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultLoadRoomMembersTask(get(), get(), get(), get()) as LoadRoomMembersTask
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
TokenChunkEventPersistor(get())
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultPaginationTask(get(), get(), get()) as PaginationTask
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultGetContextOfEventTask(get(), get(), get()) as GetContextOfEventTask
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultSetReadMarkersTask(get(), get(), get()) as SetReadMarkersTask
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
LocalEchoEventFactory(get(), get())
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
LocalEchoUpdater(get())
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
RoomFactory(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get())
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultCreateRoomTask(get(), get("SessionRealmConfiguration")) as CreateRoomTask
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultInviteTask(get()) as InviteTask
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultJoinRoomTask(get()) as JoinRoomTask
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultLeaveRoomTask(get()) as LeaveRoomTask
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultSendStateTask(get()) as SendStateTask
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultFindReactionEventForUndoTask(get()) as FindReactionEventForUndoTask
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultUpdateQuickReactionTask(get()) as UpdateQuickReactionTask
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultPruneEventTask(get()) as PruneEventTask
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultEventRelationsAggregationTask(get()) as EventRelationsAggregationTask
|
||||
}
|
||||
|
||||
@SessionScope
|
||||
@Provides
|
||||
fun providesRoomAPI(retrofit: Retrofit): RoomAPI {
|
||||
return retrofit.create(RoomAPI::class.java)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,16 +29,19 @@ import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
|
|||
import im.vector.matrix.android.internal.database.query.latestEvent
|
||||
import im.vector.matrix.android.internal.database.query.prev
|
||||
import im.vector.matrix.android.internal.database.query.where
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.session.room.membership.RoomDisplayNameResolver
|
||||
import im.vector.matrix.android.internal.session.room.membership.RoomMembers
|
||||
import im.vector.matrix.android.internal.session.sync.model.RoomSyncSummary
|
||||
import im.vector.matrix.android.internal.session.sync.model.RoomSyncUnreadNotifications
|
||||
import io.realm.Realm
|
||||
import io.realm.kotlin.createObject
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class RoomSummaryUpdater(private val credentials: Credentials,
|
||||
private val roomDisplayNameResolver: RoomDisplayNameResolver,
|
||||
private val roomAvatarResolver: RoomAvatarResolver) {
|
||||
@SessionScope
|
||||
internal class RoomSummaryUpdater @Inject constructor(private val credentials: Credentials,
|
||||
private val roomDisplayNameResolver: RoomDisplayNameResolver,
|
||||
private val roomAvatarResolver: RoomAvatarResolver) {
|
||||
|
||||
fun update(realm: Realm,
|
||||
roomId: String,
|
||||
|
|
|
@ -23,14 +23,16 @@ import im.vector.matrix.android.internal.database.RealmQueryLatch
|
|||
import im.vector.matrix.android.internal.database.model.RoomEntity
|
||||
import im.vector.matrix.android.internal.database.model.RoomEntityFields
|
||||
import im.vector.matrix.android.internal.network.executeRequest
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.session.room.RoomAPI
|
||||
import im.vector.matrix.android.internal.task.Task
|
||||
import io.realm.RealmConfiguration
|
||||
import javax.inject.Inject
|
||||
|
||||
internal interface CreateRoomTask : Task<CreateRoomParams, String>
|
||||
|
||||
|
||||
internal class DefaultCreateRoomTask(private val roomAPI: RoomAPI,
|
||||
@SessionScope
|
||||
internal class DefaultCreateRoomTask @Inject constructor(private val roomAPI: RoomAPI,
|
||||
private val realmConfiguration: RealmConfiguration) : CreateRoomTask {
|
||||
|
||||
|
||||
|
|
|
@ -20,8 +20,10 @@ import arrow.core.Try
|
|||
import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoomsParams
|
||||
import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoomsResponse
|
||||
import im.vector.matrix.android.internal.network.executeRequest
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.session.room.RoomAPI
|
||||
import im.vector.matrix.android.internal.task.Task
|
||||
import javax.inject.Inject
|
||||
|
||||
internal interface GetPublicRoomTask : Task<GetPublicRoomTask.Params, PublicRoomsResponse> {
|
||||
data class Params(
|
||||
|
@ -30,7 +32,8 @@ internal interface GetPublicRoomTask : Task<GetPublicRoomTask.Params, PublicRoom
|
|||
)
|
||||
}
|
||||
|
||||
internal class DefaultGetPublicRoomTask(private val roomAPI: RoomAPI) : GetPublicRoomTask {
|
||||
@SessionScope
|
||||
internal class DefaultGetPublicRoomTask @Inject constructor(private val roomAPI: RoomAPI) : GetPublicRoomTask {
|
||||
|
||||
override suspend fun execute(params: GetPublicRoomTask.Params): Try<PublicRoomsResponse> {
|
||||
return executeRequest {
|
||||
|
|
|
@ -19,12 +19,15 @@ package im.vector.matrix.android.internal.session.room.directory
|
|||
import arrow.core.Try
|
||||
import im.vector.matrix.android.api.session.room.model.thirdparty.ThirdPartyProtocol
|
||||
import im.vector.matrix.android.internal.network.executeRequest
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.session.room.RoomAPI
|
||||
import im.vector.matrix.android.internal.task.Task
|
||||
import javax.inject.Inject
|
||||
|
||||
internal interface GetThirdPartyProtocolsTask : Task<Unit, Map<String, ThirdPartyProtocol>>
|
||||
|
||||
internal class DefaultGetThirdPartyProtocolsTask(private val roomAPI: RoomAPI) : GetThirdPartyProtocolsTask {
|
||||
@SessionScope
|
||||
internal class DefaultGetThirdPartyProtocolsTask @Inject constructor (private val roomAPI: RoomAPI) : GetThirdPartyProtocolsTask {
|
||||
|
||||
override suspend fun execute(params: Unit): Try<Map<String, ThirdPartyProtocol>> {
|
||||
return executeRequest {
|
||||
|
|
|
@ -27,20 +27,23 @@ import im.vector.matrix.android.api.session.room.model.Membership
|
|||
import im.vector.matrix.android.api.session.room.model.RoomMember
|
||||
import im.vector.matrix.android.api.util.Cancelable
|
||||
import im.vector.matrix.android.internal.database.mapper.asDomain
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.session.room.membership.joining.InviteTask
|
||||
import im.vector.matrix.android.internal.session.room.membership.joining.JoinRoomTask
|
||||
import im.vector.matrix.android.internal.session.room.membership.leaving.LeaveRoomTask
|
||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||
import im.vector.matrix.android.internal.task.configureWith
|
||||
import im.vector.matrix.android.internal.util.fetchCopied
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class DefaultMembershipService(private val roomId: String,
|
||||
private val monarchy: Monarchy,
|
||||
private val taskExecutor: TaskExecutor,
|
||||
private val loadRoomMembersTask: LoadRoomMembersTask,
|
||||
private val inviteTask: InviteTask,
|
||||
private val joinTask: JoinRoomTask,
|
||||
private val leaveRoomTask: LeaveRoomTask
|
||||
@SessionScope
|
||||
internal class DefaultMembershipService @Inject constructor(private val roomId: String,
|
||||
private val monarchy: Monarchy,
|
||||
private val taskExecutor: TaskExecutor,
|
||||
private val loadRoomMembersTask: LoadRoomMembersTask,
|
||||
private val inviteTask: InviteTask,
|
||||
private val joinTask: JoinRoomTask,
|
||||
private val leaveRoomTask: LeaveRoomTask
|
||||
) : MembershipService {
|
||||
|
||||
override fun loadRoomMembersIfNeeded(): Cancelable {
|
||||
|
|
|
@ -23,12 +23,14 @@ import im.vector.matrix.android.internal.database.helper.addStateEvents
|
|||
import im.vector.matrix.android.internal.database.model.RoomEntity
|
||||
import im.vector.matrix.android.internal.database.query.where
|
||||
import im.vector.matrix.android.internal.network.executeRequest
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.session.room.RoomAPI
|
||||
import im.vector.matrix.android.internal.session.room.RoomSummaryUpdater
|
||||
import im.vector.matrix.android.internal.session.sync.SyncTokenStore
|
||||
import im.vector.matrix.android.internal.task.Task
|
||||
import im.vector.matrix.android.internal.util.tryTransactionSync
|
||||
import io.realm.kotlin.createObject
|
||||
import javax.inject.Inject
|
||||
|
||||
internal interface LoadRoomMembersTask : Task<LoadRoomMembersTask.Params, Boolean> {
|
||||
|
||||
|
@ -38,7 +40,8 @@ internal interface LoadRoomMembersTask : Task<LoadRoomMembersTask.Params, Boolea
|
|||
)
|
||||
}
|
||||
|
||||
internal class DefaultLoadRoomMembersTask(private val roomAPI: RoomAPI,
|
||||
@SessionScope
|
||||
internal class DefaultLoadRoomMembersTask @Inject constructor(private val roomAPI: RoomAPI,
|
||||
private val monarchy: Monarchy,
|
||||
private val syncTokenStore: SyncTokenStore,
|
||||
private val roomSummaryUpdater: RoomSummaryUpdater
|
||||
|
|
|
@ -32,14 +32,15 @@ import im.vector.matrix.android.internal.database.model.RoomEntity
|
|||
import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
|
||||
import im.vector.matrix.android.internal.database.query.prev
|
||||
import im.vector.matrix.android.internal.database.query.where
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* This class computes room display name
|
||||
*/
|
||||
internal class RoomDisplayNameResolver(private val context: Context,
|
||||
private val monarchy: Monarchy,
|
||||
private val roomMemberDisplayNameResolver: RoomMemberDisplayNameResolver,
|
||||
private val credentials: Credentials
|
||||
internal class RoomDisplayNameResolver @Inject constructor(private val context: Context,
|
||||
private val monarchy: Monarchy,
|
||||
private val roomMemberDisplayNameResolver: RoomMemberDisplayNameResolver,
|
||||
private val credentials: Credentials
|
||||
) {
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,8 +17,9 @@
|
|||
package im.vector.matrix.android.internal.session.room.membership
|
||||
|
||||
import im.vector.matrix.android.api.session.room.model.RoomMember
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class RoomMemberDisplayNameResolver {
|
||||
internal class RoomMemberDisplayNameResolver @Inject constructor() {
|
||||
|
||||
fun resolve(userId: String, members: Map<String, RoomMember>): String? {
|
||||
val currentMember = members[userId]
|
||||
|
|
|
@ -18,8 +18,10 @@ package im.vector.matrix.android.internal.session.room.membership.joining
|
|||
|
||||
import arrow.core.Try
|
||||
import im.vector.matrix.android.internal.network.executeRequest
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.session.room.RoomAPI
|
||||
import im.vector.matrix.android.internal.task.Task
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
internal interface InviteTask : Task<InviteTask.Params, Unit> {
|
||||
|
@ -29,7 +31,8 @@ internal interface InviteTask : Task<InviteTask.Params, Unit> {
|
|||
)
|
||||
}
|
||||
|
||||
internal class DefaultInviteTask(private val roomAPI: RoomAPI) : InviteTask {
|
||||
@SessionScope
|
||||
internal class DefaultInviteTask @Inject constructor(private val roomAPI: RoomAPI) : InviteTask {
|
||||
|
||||
override suspend fun execute(params: InviteTask.Params): Try<Unit> {
|
||||
return executeRequest {
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue