TI: inject EventBus to allow multiple sessions - WIP

This commit is contained in:
Benoit Marty 2020-01-07 16:45:06 +01:00
parent 6746f68411
commit e177251ec0
70 changed files with 453 additions and 252 deletions

View File

@ -41,7 +41,6 @@ class AccountCreationTest : InstrumentedTest {
session.close()
}
// FIXME This test does not past yet, due to usage of the EventBus.
@Test
fun createAccountAndLoginAgainTest() {
val session = commonTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(withInitialSync = true))

View File

@ -27,8 +27,8 @@ import java.util.concurrent.CountDownLatch
* @param onlySuccessful true to fail if an error occurs. This is the default behavior
* @param <T>
*/
open class TestMatrixCallback<T> @JvmOverloads constructor(private val countDownLatch: CountDownLatch,
private val onlySuccessful: Boolean = true) : MatrixCallback<T> {
open class TestMatrixCallback<T>(private val countDownLatch: CountDownLatch,
private val onlySuccessful: Boolean = true) : MatrixCallback<T> {
@CallSuper
override fun onSuccess(data: T) {

View File

@ -45,14 +45,15 @@ import okhttp3.OkHttpClient
import javax.inject.Inject
import javax.net.ssl.HttpsURLConnection
internal class DefaultAuthenticationService @Inject constructor(@Unauthenticated
private val okHttpClient: Lazy<OkHttpClient>,
private val retrofitFactory: RetrofitFactory,
private val coroutineDispatchers: MatrixCoroutineDispatchers,
private val sessionParamsStore: SessionParamsStore,
private val sessionManager: SessionManager,
private val sessionCreator: SessionCreator,
private val pendingSessionStore: PendingSessionStore
internal class DefaultAuthenticationService @Inject constructor(
@Unauthenticated
private val okHttpClient: Lazy<OkHttpClient>,
private val retrofitFactory: RetrofitFactory,
private val coroutineDispatchers: MatrixCoroutineDispatchers,
private val sessionParamsStore: SessionParamsStore,
private val sessionManager: SessionManager,
private val sessionCreator: SessionCreator,
private val pendingSessionStore: PendingSessionStore
) : AuthenticationService {
private var pendingSessionData: PendingSessionData? = pendingSessionStore.getPendingSessionData()
@ -112,7 +113,7 @@ internal class DefaultAuthenticationService @Inject constructor(@Unauthenticated
// First check the homeserver version
runCatching {
executeRequest<Versions> {
executeRequest<Versions>(null) {
apiCall = authAPI.versions()
}
}
@ -141,7 +142,7 @@ internal class DefaultAuthenticationService @Inject constructor(@Unauthenticated
val authAPI = buildAuthAPI(homeServerConnectionConfig)
// Ok, try to get the config.json file of a RiotWeb client
val riotConfig = executeRequest<RiotConfig> {
val riotConfig = executeRequest<RiotConfig>(null) {
apiCall = authAPI.getRiotConfig()
}
@ -153,7 +154,7 @@ internal class DefaultAuthenticationService @Inject constructor(@Unauthenticated
val newAuthAPI = buildAuthAPI(newHomeServerConnectionConfig)
val versions = executeRequest<Versions> {
val versions = executeRequest<Versions>(null) {
apiCall = newAuthAPI.versions()
}
@ -167,7 +168,7 @@ internal class DefaultAuthenticationService @Inject constructor(@Unauthenticated
private suspend fun getLoginFlowResult(authAPI: AuthAPI, versions: Versions, homeServerUrl: String): LoginFlowResult {
return if (versions.isSupportedBySdk()) {
// Get the login flow
val loginFlowResponse = executeRequest<LoginFlowResponse> {
val loginFlowResponse = executeRequest<LoginFlowResponse>(null) {
apiCall = authAPI.getLoginFlows()
}
LoginFlowResult.Success(loginFlowResponse, versions.isLoginAndRegistrationSupportedBySdk(), homeServerUrl)

View File

@ -72,7 +72,7 @@ internal class DefaultLoginWizard(
} else {
PasswordLoginParams.userIdentifier(login, password, deviceName)
}
val credentials = executeRequest<Credentials> {
val credentials = executeRequest<Credentials>(null) {
apiCall = authAPI.login(loginParams)
}
@ -95,7 +95,7 @@ internal class DefaultLoginWizard(
pendingSessionData = pendingSessionData.copy(sendAttempt = pendingSessionData.sendAttempt + 1)
.also { pendingSessionStore.savePendingSessionData(it) }
val result = executeRequest<AddThreePidRegistrationResponse> {
val result = executeRequest<AddThreePidRegistrationResponse>(null) {
apiCall = authAPI.resetPassword(AddThreePidRegistrationParams.from(param))
}
@ -120,7 +120,7 @@ internal class DefaultLoginWizard(
resetPasswordData.newPassword
)
executeRequest<Unit> {
executeRequest<Unit>(null) {
apiCall = authAPI.resetPasswordMailConfirmed(param)
}

View File

@ -29,11 +29,12 @@ internal interface RegisterAddThreePidTask : Task<RegisterAddThreePidTask.Params
)
}
internal class DefaultRegisterAddThreePidTask(private val authAPI: AuthAPI)
: RegisterAddThreePidTask {
internal class DefaultRegisterAddThreePidTask(
private val authAPI: AuthAPI
) : RegisterAddThreePidTask {
override suspend fun execute(params: RegisterAddThreePidTask.Params): AddThreePidRegistrationResponse {
return executeRequest {
return executeRequest(null) {
apiCall = authAPI.add3Pid(params.threePid.toPath(), AddThreePidRegistrationParams.from(params))
}
}

View File

@ -29,12 +29,13 @@ internal interface RegisterTask : Task<RegisterTask.Params, Credentials> {
)
}
internal class DefaultRegisterTask(private val authAPI: AuthAPI)
: RegisterTask {
internal class DefaultRegisterTask(
private val authAPI: AuthAPI
) : RegisterTask {
override suspend fun execute(params: RegisterTask.Params): Credentials {
try {
return executeRequest {
return executeRequest(null) {
apiCall = authAPI.register(params.registrationParams)
}
} catch (throwable: Throwable) {

View File

@ -27,11 +27,12 @@ internal interface ValidateCodeTask : Task<ValidateCodeTask.Params, SuccessResul
)
}
internal class DefaultValidateCodeTask(private val authAPI: AuthAPI)
: ValidateCodeTask {
internal class DefaultValidateCodeTask(
private val authAPI: AuthAPI
) : ValidateCodeTask {
override suspend fun execute(params: ValidateCodeTask.Params): SuccessResult {
return executeRequest {
return executeRequest(null) {
apiCall = authAPI.validate3Pid(params.url, params.body)
}
}

View File

@ -21,15 +21,18 @@ import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.CreateKeys
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.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface CreateKeysBackupVersionTask : Task<CreateKeysBackupVersionBody, KeysVersion>
internal class DefaultCreateKeysBackupVersionTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: CreateKeysBackupVersionTask {
internal class DefaultCreateKeysBackupVersionTask @Inject constructor(
private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : CreateKeysBackupVersionTask {
override suspend fun execute(params: CreateKeysBackupVersionBody): KeysVersion {
return executeRequest {
return executeRequest(eventBus) {
apiCall = roomKeysApi.createKeysBackupVersion(params)
}
}

View File

@ -19,6 +19,7 @@ package im.vector.matrix.android.internal.crypto.keysbackup.tasks
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface DeleteBackupTask : Task<DeleteBackupTask.Params, Unit> {
@ -27,11 +28,13 @@ internal interface DeleteBackupTask : Task<DeleteBackupTask.Params, Unit> {
)
}
internal class DefaultDeleteBackupTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: DeleteBackupTask {
internal class DefaultDeleteBackupTask @Inject constructor(
private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : DeleteBackupTask {
override suspend fun execute(params: DeleteBackupTask.Params) {
return executeRequest {
return executeRequest(eventBus) {
apiCall = roomKeysApi.deleteBackup(params.version)
}
}

View File

@ -19,6 +19,7 @@ package im.vector.matrix.android.internal.crypto.keysbackup.tasks
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface DeleteRoomSessionDataTask : Task<DeleteRoomSessionDataTask.Params, Unit> {
@ -29,11 +30,13 @@ internal interface DeleteRoomSessionDataTask : Task<DeleteRoomSessionDataTask.Pa
)
}
internal class DefaultDeleteRoomSessionDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: DeleteRoomSessionDataTask {
internal class DefaultDeleteRoomSessionDataTask @Inject constructor(
private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : DeleteRoomSessionDataTask {
override suspend fun execute(params: DeleteRoomSessionDataTask.Params) {
return executeRequest {
return executeRequest(eventBus) {
apiCall = roomKeysApi.deleteRoomSessionData(
params.roomId,
params.sessionId,

View File

@ -19,6 +19,7 @@ package im.vector.matrix.android.internal.crypto.keysbackup.tasks
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface DeleteRoomSessionsDataTask : Task<DeleteRoomSessionsDataTask.Params, Unit> {
@ -28,11 +29,13 @@ internal interface DeleteRoomSessionsDataTask : Task<DeleteRoomSessionsDataTask.
)
}
internal class DefaultDeleteRoomSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: DeleteRoomSessionsDataTask {
internal class DefaultDeleteRoomSessionsDataTask @Inject constructor(
private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : DeleteRoomSessionsDataTask {
override suspend fun execute(params: DeleteRoomSessionsDataTask.Params) {
return executeRequest {
return executeRequest(eventBus) {
apiCall = roomKeysApi.deleteRoomSessionsData(
params.roomId,
params.version)

View File

@ -19,6 +19,7 @@ package im.vector.matrix.android.internal.crypto.keysbackup.tasks
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface DeleteSessionsDataTask : Task<DeleteSessionsDataTask.Params, Unit> {
@ -27,11 +28,13 @@ internal interface DeleteSessionsDataTask : Task<DeleteSessionsDataTask.Params,
)
}
internal class DefaultDeleteSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: DeleteSessionsDataTask {
internal class DefaultDeleteSessionsDataTask @Inject constructor(
private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : DeleteSessionsDataTask {
override suspend fun execute(params: DeleteSessionsDataTask.Params) {
return executeRequest {
return executeRequest(eventBus) {
apiCall = roomKeysApi.deleteSessionsData(params.version)
}
}

View File

@ -20,15 +20,18 @@ 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.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetKeysBackupLastVersionTask : Task<Unit, KeysVersionResult>
internal class DefaultGetKeysBackupLastVersionTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: GetKeysBackupLastVersionTask {
internal class DefaultGetKeysBackupLastVersionTask @Inject constructor(
private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : GetKeysBackupLastVersionTask {
override suspend fun execute(params: Unit): KeysVersionResult {
return executeRequest {
return executeRequest(eventBus) {
apiCall = roomKeysApi.getKeysBackupLastVersion()
}
}

View File

@ -20,15 +20,18 @@ 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.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetKeysBackupVersionTask : Task<String, KeysVersionResult>
internal class DefaultGetKeysBackupVersionTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: GetKeysBackupVersionTask {
internal class DefaultGetKeysBackupVersionTask @Inject constructor(
private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : GetKeysBackupVersionTask {
override suspend fun execute(params: String): KeysVersionResult {
return executeRequest {
return executeRequest(eventBus) {
apiCall = roomKeysApi.getKeysBackupVersion(params)
}
}

View File

@ -20,6 +20,7 @@ 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.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetRoomSessionDataTask : Task<GetRoomSessionDataTask.Params, KeyBackupData> {
@ -30,11 +31,13 @@ internal interface GetRoomSessionDataTask : Task<GetRoomSessionDataTask.Params,
)
}
internal class DefaultGetRoomSessionDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: GetRoomSessionDataTask {
internal class DefaultGetRoomSessionDataTask @Inject constructor(
private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : GetRoomSessionDataTask {
override suspend fun execute(params: GetRoomSessionDataTask.Params): KeyBackupData {
return executeRequest {
return executeRequest(eventBus) {
apiCall = roomKeysApi.getRoomSessionData(
params.roomId,
params.sessionId,

View File

@ -20,6 +20,7 @@ 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.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetRoomSessionsDataTask : Task<GetRoomSessionsDataTask.Params, RoomKeysBackupData> {
@ -29,11 +30,13 @@ internal interface GetRoomSessionsDataTask : Task<GetRoomSessionsDataTask.Params
)
}
internal class DefaultGetRoomSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: GetRoomSessionsDataTask {
internal class DefaultGetRoomSessionsDataTask @Inject constructor(
private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : GetRoomSessionsDataTask {
override suspend fun execute(params: GetRoomSessionsDataTask.Params): RoomKeysBackupData {
return executeRequest {
return executeRequest(eventBus) {
apiCall = roomKeysApi.getRoomSessionsData(
params.roomId,
params.version)

View File

@ -20,6 +20,7 @@ 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.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetSessionsDataTask : Task<GetSessionsDataTask.Params, KeysBackupData> {
@ -28,11 +29,13 @@ internal interface GetSessionsDataTask : Task<GetSessionsDataTask.Params, KeysBa
)
}
internal class DefaultGetSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: GetSessionsDataTask {
internal class DefaultGetSessionsDataTask @Inject constructor(
private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : GetSessionsDataTask {
override suspend fun execute(params: GetSessionsDataTask.Params): KeysBackupData {
return executeRequest {
return executeRequest(eventBus) {
apiCall = roomKeysApi.getSessionsData(params.version)
}
}

View File

@ -21,6 +21,7 @@ import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.BackupKeys
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.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface StoreRoomSessionDataTask : Task<StoreRoomSessionDataTask.Params, BackupKeysResult> {
@ -32,11 +33,13 @@ internal interface StoreRoomSessionDataTask : Task<StoreRoomSessionDataTask.Para
)
}
internal class DefaultStoreRoomSessionDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: StoreRoomSessionDataTask {
internal class DefaultStoreRoomSessionDataTask @Inject constructor(
private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : StoreRoomSessionDataTask {
override suspend fun execute(params: StoreRoomSessionDataTask.Params): BackupKeysResult {
return executeRequest {
return executeRequest(eventBus) {
apiCall = roomKeysApi.storeRoomSessionData(
params.roomId,
params.sessionId,

View File

@ -21,6 +21,7 @@ import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.BackupKeys
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.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface StoreRoomSessionsDataTask : Task<StoreRoomSessionsDataTask.Params, BackupKeysResult> {
@ -31,11 +32,13 @@ internal interface StoreRoomSessionsDataTask : Task<StoreRoomSessionsDataTask.Pa
)
}
internal class DefaultStoreRoomSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: StoreRoomSessionsDataTask {
internal class DefaultStoreRoomSessionsDataTask @Inject constructor(
private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : StoreRoomSessionsDataTask {
override suspend fun execute(params: StoreRoomSessionsDataTask.Params): BackupKeysResult {
return executeRequest {
return executeRequest(eventBus) {
apiCall = roomKeysApi.storeRoomSessionsData(
params.roomId,
params.version,

View File

@ -21,6 +21,7 @@ import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.BackupKeys
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.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface StoreSessionsDataTask : Task<StoreSessionsDataTask.Params, BackupKeysResult> {
@ -30,11 +31,13 @@ internal interface StoreSessionsDataTask : Task<StoreSessionsDataTask.Params, Ba
)
}
internal class DefaultStoreSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: StoreSessionsDataTask {
internal class DefaultStoreSessionsDataTask @Inject constructor(
private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : StoreSessionsDataTask {
override suspend fun execute(params: StoreSessionsDataTask.Params): BackupKeysResult {
return executeRequest {
return executeRequest(eventBus) {
apiCall = roomKeysApi.storeSessionsData(
params.version,
params.keysBackupData)

View File

@ -20,6 +20,7 @@ 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.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface UpdateKeysBackupVersionTask : Task<UpdateKeysBackupVersionTask.Params, Unit> {
@ -29,11 +30,13 @@ internal interface UpdateKeysBackupVersionTask : Task<UpdateKeysBackupVersionTas
)
}
internal class DefaultUpdateKeysBackupVersionTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: UpdateKeysBackupVersionTask {
internal class DefaultUpdateKeysBackupVersionTask @Inject constructor(
private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : UpdateKeysBackupVersionTask {
override suspend fun execute(params: UpdateKeysBackupVersionTask.Params) {
return executeRequest {
return executeRequest(eventBus) {
apiCall = roomKeysApi.updateKeysBackupVersion(params.version, params.keysBackupVersionBody)
}
}

View File

@ -23,6 +23,7 @@ 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.task.Task
import org.greenrobot.eventbus.EventBus
import timber.log.Timber
import javax.inject.Inject
@ -33,13 +34,15 @@ internal interface ClaimOneTimeKeysForUsersDeviceTask : Task<ClaimOneTimeKeysFor
)
}
internal class DefaultClaimOneTimeKeysForUsersDevice @Inject constructor(private val cryptoApi: CryptoApi)
: ClaimOneTimeKeysForUsersDeviceTask {
internal class DefaultClaimOneTimeKeysForUsersDevice @Inject constructor(
private val cryptoApi: CryptoApi,
private val eventBus: EventBus
) : ClaimOneTimeKeysForUsersDeviceTask {
override suspend fun execute(params: ClaimOneTimeKeysForUsersDeviceTask.Params): MXUsersDevicesMap<MXKey> {
val body = KeysClaimBody(oneTimeKeys = params.usersDevicesKeyTypesMap.map)
val keysClaimResponse = executeRequest<KeysClaimResponse> {
val keysClaimResponse = executeRequest<KeysClaimResponse>(eventBus) {
apiCall = cryptoApi.claimOneTimeKeysForUsersDevices(body)
}
val map = MXUsersDevicesMap<MXKey>()

View File

@ -23,6 +23,7 @@ import im.vector.matrix.android.internal.crypto.model.rest.DeleteDeviceParams
import im.vector.matrix.android.internal.di.MoshiProvider
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface DeleteDeviceTask : Task<DeleteDeviceTask.Params, Unit> {
@ -31,12 +32,14 @@ internal interface DeleteDeviceTask : Task<DeleteDeviceTask.Params, Unit> {
)
}
internal class DefaultDeleteDeviceTask @Inject constructor(private val cryptoApi: CryptoApi)
: DeleteDeviceTask {
internal class DefaultDeleteDeviceTask @Inject constructor(
private val cryptoApi: CryptoApi,
private val eventBus: EventBus
) : DeleteDeviceTask {
override suspend fun execute(params: DeleteDeviceTask.Params) {
try {
executeRequest<Unit> {
executeRequest<Unit>(eventBus) {
apiCall = cryptoApi.deleteDevice(params.deviceId, DeleteDeviceParams())
}
} catch (throwable: Throwable) {

View File

@ -23,6 +23,7 @@ import im.vector.matrix.android.internal.crypto.model.rest.DeleteDeviceParams
import im.vector.matrix.android.internal.di.UserId
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface DeleteDeviceWithUserPasswordTask : Task<DeleteDeviceWithUserPasswordTask.Params, Unit> {
@ -33,12 +34,14 @@ internal interface DeleteDeviceWithUserPasswordTask : Task<DeleteDeviceWithUserP
)
}
internal class DefaultDeleteDeviceWithUserPasswordTask @Inject constructor(private val cryptoApi: CryptoApi,
@UserId private val userId: String)
: DeleteDeviceWithUserPasswordTask {
internal class DefaultDeleteDeviceWithUserPasswordTask @Inject constructor(
private val cryptoApi: CryptoApi,
@UserId private val userId: String,
private val eventBus: EventBus
) : DeleteDeviceWithUserPasswordTask {
override suspend fun execute(params: DeleteDeviceWithUserPasswordTask.Params) {
return executeRequest {
return executeRequest(eventBus) {
apiCall = cryptoApi.deleteDevice(params.deviceId, DeleteDeviceParams()
.apply {
deleteDeviceAuth = DeleteDeviceAuth()

View File

@ -21,6 +21,7 @@ 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.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface DownloadKeysForUsersTask : Task<DownloadKeysForUsersTask.Params, KeysQueryResponse> {
@ -31,8 +32,10 @@ internal interface DownloadKeysForUsersTask : Task<DownloadKeysForUsersTask.Para
val token: String?)
}
internal class DefaultDownloadKeysForUsers @Inject constructor(private val cryptoApi: CryptoApi)
: DownloadKeysForUsersTask {
internal class DefaultDownloadKeysForUsers @Inject constructor(
private val cryptoApi: CryptoApi,
private val eventBus: EventBus
) : DownloadKeysForUsersTask {
override suspend fun execute(params: DownloadKeysForUsersTask.Params): KeysQueryResponse {
val downloadQuery = params.userIds?.associateWith { emptyMap<String, Any>() }.orEmpty()
@ -45,7 +48,7 @@ internal class DefaultDownloadKeysForUsers @Inject constructor(private val crypt
body.token = params.token
}
return executeRequest {
return executeRequest(eventBus) {
apiCall = cryptoApi.downloadKeysForUsers(body)
}
}

View File

@ -20,17 +20,20 @@ import im.vector.matrix.android.internal.crypto.api.CryptoApi
import im.vector.matrix.android.internal.crypto.model.rest.DeviceInfo
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetDeviceInfoTask : Task<GetDeviceInfoTask.Params, DeviceInfo> {
data class Params(val deviceId: String)
}
internal class DefaultGetDeviceInfoTask @Inject constructor(private val cryptoApi: CryptoApi)
: GetDeviceInfoTask {
internal class DefaultGetDeviceInfoTask @Inject constructor(
private val cryptoApi: CryptoApi,
private val eventBus: EventBus
) : GetDeviceInfoTask {
override suspend fun execute(params: GetDeviceInfoTask.Params): DeviceInfo {
return executeRequest {
return executeRequest(eventBus) {
apiCall = cryptoApi.getDeviceInfo(params.deviceId)
}
}

View File

@ -20,15 +20,18 @@ 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.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetDevicesTask : Task<Unit, DevicesListResponse>
internal class DefaultGetDevicesTask @Inject constructor(private val cryptoApi: CryptoApi)
: GetDevicesTask {
internal class DefaultGetDevicesTask @Inject constructor(
private val cryptoApi: CryptoApi,
private val eventBus: EventBus
) : GetDevicesTask {
override suspend fun execute(params: Unit): DevicesListResponse {
return executeRequest {
return executeRequest(eventBus) {
apiCall = cryptoApi.getDevices()
}
}

View File

@ -20,6 +20,7 @@ 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.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetKeyChangesTask : Task<GetKeyChangesTask.Params, KeyChangesResponse> {
@ -31,11 +32,13 @@ internal interface GetKeyChangesTask : Task<GetKeyChangesTask.Params, KeyChanges
)
}
internal class DefaultGetKeyChangesTask @Inject constructor(private val cryptoApi: CryptoApi)
: GetKeyChangesTask {
internal class DefaultGetKeyChangesTask @Inject constructor(
private val cryptoApi: CryptoApi,
private val eventBus: EventBus
) : GetKeyChangesTask {
override suspend fun execute(params: GetKeyChangesTask.Params): KeyChangesResponse {
return executeRequest {
return executeRequest(eventBus) {
apiCall = cryptoApi.getKeyChanges(params.from, params.to)
}
}

View File

@ -21,6 +21,7 @@ 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.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
import kotlin.random.Random
@ -35,14 +36,16 @@ internal interface SendToDeviceTask : Task<SendToDeviceTask.Params, Unit> {
)
}
internal class DefaultSendToDeviceTask @Inject constructor(private val cryptoApi: CryptoApi)
: SendToDeviceTask {
internal class DefaultSendToDeviceTask @Inject constructor(
private val cryptoApi: CryptoApi,
private val eventBus: EventBus
) : SendToDeviceTask {
override suspend fun execute(params: SendToDeviceTask.Params) {
val sendToDeviceBody = SendToDeviceBody()
sendToDeviceBody.messages = params.contentMap.map
return executeRequest {
return executeRequest(eventBus) {
apiCall = cryptoApi.sendToDevice(
params.eventType,
params.transactionId ?: Random.nextInt(Integer.MAX_VALUE).toString(),

View File

@ -20,6 +20,7 @@ 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.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface SetDeviceNameTask : Task<SetDeviceNameTask.Params, Unit> {
@ -31,14 +32,16 @@ internal interface SetDeviceNameTask : Task<SetDeviceNameTask.Params, Unit> {
)
}
internal class DefaultSetDeviceNameTask @Inject constructor(private val cryptoApi: CryptoApi)
: SetDeviceNameTask {
internal class DefaultSetDeviceNameTask @Inject constructor(
private val cryptoApi: CryptoApi,
private val eventBus: EventBus
) : SetDeviceNameTask {
override suspend fun execute(params: SetDeviceNameTask.Params) {
val body = UpdateDeviceInfoBody(
displayName = params.deviceName
)
return executeRequest {
return executeRequest(eventBus) {
apiCall = cryptoApi.updateDeviceInfo(params.deviceId, body)
}
}

View File

@ -24,6 +24,7 @@ import im.vector.matrix.android.internal.crypto.model.rest.KeysUploadResponse
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task
import im.vector.matrix.android.internal.util.convertToUTF8
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface UploadKeysTask : Task<UploadKeysTask.Params, KeysUploadResponse> {
@ -36,8 +37,10 @@ internal interface UploadKeysTask : Task<UploadKeysTask.Params, KeysUploadRespon
val deviceId: String)
}
internal class DefaultUploadKeysTask @Inject constructor(private val cryptoApi: CryptoApi)
: UploadKeysTask {
internal class DefaultUploadKeysTask @Inject constructor(
private val cryptoApi: CryptoApi,
private val eventBus: EventBus
) : UploadKeysTask {
override suspend fun execute(params: UploadKeysTask.Params): KeysUploadResponse {
val encodedDeviceId = convertToUTF8(params.deviceId)
@ -52,7 +55,7 @@ internal class DefaultUploadKeysTask @Inject constructor(private val cryptoApi:
body.oneTimeKeys = params.oneTimeKeys
}
return executeRequest {
return executeRequest(eventBus) {
apiCall = if (encodedDeviceId.isBlank()) {
cryptoApi.uploadKeys(body)
} else {

View File

@ -18,12 +18,14 @@ package im.vector.matrix.android.internal.network
import im.vector.matrix.android.api.failure.Failure
import kotlinx.coroutines.CancellationException
import org.greenrobot.eventbus.EventBus
import retrofit2.Call
import java.io.IOException
internal suspend inline fun <DATA> executeRequest(block: Request<DATA>.() -> Unit) = Request<DATA>().apply(block).execute()
internal suspend inline fun <DATA> executeRequest(eventBus: EventBus?,
block: Request<DATA>.() -> Unit) = Request<DATA>(eventBus).apply(block).execute()
internal class Request<DATA> {
internal class Request<DATA>(private val eventBus: EventBus?) {
lateinit var apiCall: Call<DATA>
@ -34,7 +36,7 @@ internal class Request<DATA> {
response.body()
?: throw IllegalStateException("The request returned a null body")
} else {
throw response.toFailure()
throw response.toFailure(eventBus)
}
} catch (exception: Throwable) {
throw when (exception) {

View File

@ -74,18 +74,18 @@ internal suspend fun okhttp3.Call.awaitResponse(): okhttp3.Response {
/**
* Convert a retrofit Response to a Failure, and eventually parse errorBody to convert it to a MatrixError
*/
internal fun <T> Response<T>.toFailure(): Failure {
return toFailure(errorBody(), code())
internal fun <T> Response<T>.toFailure(eventBus: EventBus?): Failure {
return toFailure(errorBody(), code(), eventBus)
}
/**
* Convert a okhttp3 Response to a Failure, and eventually parse errorBody to convert it to a MatrixError
*/
internal fun okhttp3.Response.toFailure(): Failure {
return toFailure(body, code)
internal fun okhttp3.Response.toFailure(eventBus: EventBus?): Failure {
return toFailure(body, code, eventBus)
}
private fun toFailure(errorBody: ResponseBody?, httpCode: Int): Failure {
private fun toFailure(errorBody: ResponseBody?, httpCode: Int, eventBus: EventBus?): Failure {
if (errorBody == null) {
return Failure.Unknown(RuntimeException("errorBody should not be null"))
}
@ -100,11 +100,11 @@ private fun toFailure(errorBody: ResponseBody?, httpCode: Int): Failure {
if (matrixError != null) {
if (matrixError.code == MatrixError.M_CONSENT_NOT_GIVEN && !matrixError.consentUri.isNullOrBlank()) {
// Also send this error to the bus, for a global management
EventBus.getDefault().post(GlobalError.ConsentNotGivenError(matrixError.consentUri))
eventBus?.post(GlobalError.ConsentNotGivenError(matrixError.consentUri))
} else if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED /* 401 */
&& matrixError.code == MatrixError.M_UNKNOWN_TOKEN) {
// Also send this error to the bus, for a global management
EventBus.getDefault().post(GlobalError.InvalidToken(matrixError.isSoftLogout))
eventBus?.post(GlobalError.InvalidToken(matrixError.isSoftLogout))
}
return Failure.ServerError(matrixError, httpCode)

View File

@ -17,7 +17,6 @@
package im.vector.matrix.android.internal.session
import android.content.Context
import android.os.Looper
import androidx.annotation.MainThread
import androidx.lifecycle.LiveData
import dagger.Lazy
@ -62,6 +61,7 @@ import javax.inject.Provider
@SessionScope
internal class DefaultSession @Inject constructor(override val sessionParams: SessionParams,
private val context: Context,
private val eventBus: EventBus,
private val liveEntityObservers: Set<@JvmSuppressWildcards LiveEntityObserver>,
private val sessionListeners: SessionListeners,
private val roomService: Lazy<RoomService>,
@ -85,19 +85,19 @@ internal class DefaultSession @Inject constructor(override val sessionParams: Se
private val initialSyncProgressService: Lazy<InitialSyncProgressService>,
private val homeServerCapabilitiesService: Lazy<HomeServerCapabilitiesService>)
: Session,
RoomService by roomService.get(),
RoomDirectoryService by roomDirectoryService.get(),
GroupService by groupService.get(),
UserService by userService.get(),
CryptoService by cryptoService.get(),
SignOutService by signOutService.get(),
FilterService by filterService.get(),
PushRuleService by pushRuleService.get(),
PushersService by pushersService.get(),
FileService by fileService.get(),
InitialSyncProgressService by initialSyncProgressService.get(),
SecureStorageService by secureStorageService.get(),
HomeServerCapabilitiesService by homeServerCapabilitiesService.get() {
RoomService by roomService.get(),
RoomDirectoryService by roomDirectoryService.get(),
GroupService by groupService.get(),
UserService by userService.get(),
CryptoService by cryptoService.get(),
SignOutService by signOutService.get(),
FilterService by filterService.get(),
PushRuleService by pushRuleService.get(),
PushersService by pushersService.get(),
FileService by fileService.get(),
InitialSyncProgressService by initialSyncProgressService.get(),
SecureStorageService by secureStorageService.get(),
HomeServerCapabilitiesService by homeServerCapabilitiesService.get() {
private var isOpen = false
@ -111,7 +111,7 @@ internal class DefaultSession @Inject constructor(override val sessionParams: Se
assert(!isOpen)
isOpen = true
liveEntityObservers.forEach { it.start() }
EventBus.getDefault().register(this)
eventBus.register(this)
}
override fun requireBackgroundSync() {
@ -151,7 +151,7 @@ internal class DefaultSession @Inject constructor(override val sessionParams: Se
liveEntityObservers.forEach { it.dispose() }
cryptoService.get().close()
isOpen = false
EventBus.getDefault().unregister(this)
eventBus.unregister(this)
syncTaskSequencer.close()
}
@ -179,7 +179,7 @@ internal class DefaultSession @Inject constructor(override val sessionParams: Se
@Subscribe(threadMode = ThreadMode.MAIN)
fun onGlobalError(globalError: GlobalError) {
if (globalError is GlobalError.InvalidToken
&& globalError.softLogout) {
&& globalError.softLogout) {
// Mark the token has invalid
GlobalScope.launch(Dispatchers.IO) {
sessionParamsStore.setTokenInvalid(myUserId)

View File

@ -47,6 +47,7 @@ import im.vector.matrix.android.internal.session.securestorage.DefaultSecureStor
import im.vector.matrix.android.internal.util.md5
import io.realm.RealmConfiguration
import okhttp3.OkHttpClient
import org.greenrobot.eventbus.EventBus
import retrofit2.Retrofit
import java.io.File
@ -154,6 +155,13 @@ internal abstract class SessionModule {
return retrofitFactory
.create(okHttpClient, sessionParams.homeServerConnectionConfig.homeServerUri.toString())
}
@JvmStatic
@Provides
@SessionScope
fun providesEventBus(): EventBus {
return EventBus.builder().build()
}
}
@Binds

View File

@ -29,12 +29,14 @@ import okhttp3.Request
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.asRequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import org.greenrobot.eventbus.EventBus
import java.io.File
import java.io.IOException
import javax.inject.Inject
internal class FileUploader @Inject constructor(@Authenticated
private val okHttpClient: OkHttpClient,
private val eventBus: EventBus,
sessionParams: SessionParams,
moshi: Moshi) {
@ -73,7 +75,7 @@ internal class FileUploader @Inject constructor(@Authenticated
return okHttpClient.newCall(request).awaitResponse().use { response ->
if (!response.isSuccessful) {
throw response.toFailure()
throw response.toFailure(eventBus)
} else {
response.body?.source()?.let {
responseAdapter.fromJson(it)

View File

@ -20,6 +20,7 @@ import im.vector.matrix.android.api.session.sync.FilterService
import im.vector.matrix.android.internal.di.UserId
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
/**
@ -32,9 +33,11 @@ internal interface SaveFilterTask : Task<SaveFilterTask.Params, Unit> {
)
}
internal class DefaultSaveFilterTask @Inject constructor(@UserId private val userId: String,
private val filterAPI: FilterApi,
private val filterRepository: FilterRepository
internal class DefaultSaveFilterTask @Inject constructor(
@UserId private val userId: String,
private val filterAPI: FilterApi,
private val filterRepository: FilterRepository,
private val eventBus: EventBus
) : SaveFilterTask {
override suspend fun execute(params: SaveFilterTask.Params) {
@ -56,7 +59,7 @@ internal class DefaultSaveFilterTask @Inject constructor(@UserId private val use
}
val updated = filterRepository.storeFilter(filterBody, roomFilter)
if (updated) {
val filterResponse = executeRequest<FilterResponse> {
val filterResponse = executeRequest<FilterResponse>(eventBus) {
// TODO auto retry
apiCall = filterAPI.uploadFilter(userId, filterBody)
}

View File

@ -25,6 +25,7 @@ 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.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetGroupDataTask : Task<GetGroupDataTask.Params, Unit> {
@ -34,18 +35,19 @@ internal interface GetGroupDataTask : Task<GetGroupDataTask.Params, Unit> {
internal class DefaultGetGroupDataTask @Inject constructor(
private val groupAPI: GroupAPI,
private val monarchy: Monarchy
private val monarchy: Monarchy,
private val eventBus: EventBus
) : GetGroupDataTask {
override suspend fun execute(params: GetGroupDataTask.Params) {
val groupId = params.groupId
val groupSummary = executeRequest<GroupSummaryResponse> {
val groupSummary = executeRequest<GroupSummaryResponse>(eventBus) {
apiCall = groupAPI.getSummary(groupId)
}
val groupRooms = executeRequest<GroupRooms> {
val groupRooms = executeRequest<GroupRooms>(eventBus) {
apiCall = groupAPI.getRooms(groupId)
}
val groupUsers = executeRequest<GroupUsers> {
val groupUsers = executeRequest<GroupUsers>(eventBus) {
apiCall = groupAPI.getUsers(groupId)
}
insertInDb(groupSummary, groupRooms, groupUsers, groupId)

View File

@ -23,14 +23,16 @@ import im.vector.matrix.android.internal.database.query.getOrCreate
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task
import im.vector.matrix.android.internal.util.awaitTransaction
import java.util.Date
import org.greenrobot.eventbus.EventBus
import java.util.*
import javax.inject.Inject
internal interface GetHomeServerCapabilitiesTask : Task<Unit, Unit>
internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
private val capabilitiesAPI: CapabilitiesAPI,
private val monarchy: Monarchy
private val monarchy: Monarchy,
private val eventBus: EventBus
) : GetHomeServerCapabilitiesTask {
override suspend fun execute(params: Unit) {
@ -45,7 +47,7 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
return
}
val uploadCapabilities = executeRequest<GetUploadCapabilitiesResult> {
val uploadCapabilities = executeRequest<GetUploadCapabilitiesResult>(eventBus) {
apiCall = capabilitiesAPI.getUploadCapabilities()
}

View File

@ -29,6 +29,7 @@ import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.util.awaitTransaction
import im.vector.matrix.android.internal.worker.WorkerParamsFactory
import im.vector.matrix.android.internal.worker.getSessionComponent
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal class AddHttpPusherWorker(context: Context, params: WorkerParameters)
@ -42,6 +43,7 @@ internal class AddHttpPusherWorker(context: Context, params: WorkerParameters)
@Inject lateinit var pushersAPI: PushersAPI
@Inject lateinit var monarchy: Monarchy
@Inject lateinit var eventBus: EventBus
override suspend fun doWork(): Result {
val params = WorkerParamsFactory.fromData<Params>(inputData)
@ -76,7 +78,7 @@ internal class AddHttpPusherWorker(context: Context, params: WorkerParameters)
}
private suspend fun setPusher(pusher: JsonPusher) {
executeRequest<Unit> {
executeRequest<Unit>(eventBus) {
apiCall = pushersAPI.setPusher(pusher)
}
monarchy.awaitTransaction { realm ->

View File

@ -19,6 +19,7 @@ import im.vector.matrix.android.api.pushrules.RuleKind
import im.vector.matrix.android.api.pushrules.rest.PushRule
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface AddPushRuleTask : Task<AddPushRuleTask.Params, Unit> {
@ -28,11 +29,13 @@ internal interface AddPushRuleTask : Task<AddPushRuleTask.Params, Unit> {
)
}
internal class DefaultAddPushRuleTask @Inject constructor(private val pushRulesApi: PushRulesApi)
: AddPushRuleTask {
internal class DefaultAddPushRuleTask @Inject constructor(
private val pushRulesApi: PushRulesApi,
private val eventBus: EventBus
) : AddPushRuleTask {
override suspend fun execute(params: AddPushRuleTask.Params) {
return executeRequest {
return executeRequest(eventBus) {
apiCall = pushRulesApi.addRule(params.kind.value, params.pushRule.ruleId, params.pushRule)
}
}

View File

@ -18,6 +18,7 @@ package im.vector.matrix.android.internal.session.pushers
import im.vector.matrix.android.api.pushrules.rest.GetPushRulesResponse
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetPushRulesTask : Task<GetPushRulesTask.Params, Unit> {
@ -27,11 +28,14 @@ internal interface GetPushRulesTask : Task<GetPushRulesTask.Params, Unit> {
/**
* We keep this task, but it should not be used anymore, the push rules comes from the sync response
*/
internal class DefaultGetPushRulesTask @Inject constructor(private val pushRulesApi: PushRulesApi,
private val savePushRulesTask: SavePushRulesTask) : GetPushRulesTask {
internal class DefaultGetPushRulesTask @Inject constructor(
private val pushRulesApi: PushRulesApi,
private val savePushRulesTask: SavePushRulesTask,
private val eventBus: EventBus
) : GetPushRulesTask {
override suspend fun execute(params: GetPushRulesTask.Params) {
val response = executeRequest<GetPushRulesResponse> {
val response = executeRequest<GetPushRulesResponse>(eventBus) {
apiCall = pushRulesApi.getAllRules()
}

View File

@ -22,15 +22,19 @@ import im.vector.matrix.android.internal.database.model.PusherEntity
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task
import im.vector.matrix.android.internal.util.awaitTransaction
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetPushersTask : Task<Unit, Unit>
internal class DefaultGetPushersTask @Inject constructor(private val pushersAPI: PushersAPI,
private val monarchy: Monarchy) : GetPushersTask {
internal class DefaultGetPushersTask @Inject constructor(
private val pushersAPI: PushersAPI,
private val monarchy: Monarchy,
private val eventBus: EventBus
) : GetPushersTask {
override suspend fun execute(params: Unit) {
val response = executeRequest<GetPushersResponse> {
val response = executeRequest<GetPushersResponse>(eventBus) {
apiCall = pushersAPI.getPushers()
}
monarchy.awaitTransaction { realm ->

View File

@ -19,6 +19,7 @@ import im.vector.matrix.android.api.pushrules.RuleKind
import im.vector.matrix.android.api.pushrules.rest.PushRule
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface RemovePushRuleTask : Task<RemovePushRuleTask.Params, Unit> {
@ -28,11 +29,13 @@ internal interface RemovePushRuleTask : Task<RemovePushRuleTask.Params, Unit> {
)
}
internal class DefaultRemovePushRuleTask @Inject constructor(private val pushRulesApi: PushRulesApi)
: RemovePushRuleTask {
internal class DefaultRemovePushRuleTask @Inject constructor(
private val pushRulesApi: PushRulesApi,
private val eventBus: EventBus
) : RemovePushRuleTask {
override suspend fun execute(params: RemovePushRuleTask.Params) {
return executeRequest {
return executeRequest(eventBus) {
apiCall = pushRulesApi.deleteRule(params.kind.value, params.pushRule.ruleId)
}
}

View File

@ -25,6 +25,7 @@ import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task
import im.vector.matrix.android.internal.util.awaitTransaction
import io.realm.Realm
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface RemovePusherTask : Task<RemovePusherTask.Params, Unit> {
@ -34,7 +35,8 @@ internal interface RemovePusherTask : Task<RemovePusherTask.Params, Unit> {
internal class DefaultRemovePusherTask @Inject constructor(
private val pushersAPI: PushersAPI,
private val monarchy: Monarchy
private val monarchy: Monarchy,
private val eventBus: EventBus
) : RemovePusherTask {
override suspend fun execute(params: RemovePusherTask.Params) {
@ -59,7 +61,7 @@ internal class DefaultRemovePusherTask @Inject constructor(
data = JsonPusherData(existing.data.url, existing.data.format),
append = false
)
executeRequest<Unit> {
executeRequest<Unit>(eventBus) {
apiCall = pushersAPI.setPusher(deleteBody)
}
monarchy.awaitTransaction {

View File

@ -19,6 +19,7 @@ import im.vector.matrix.android.api.pushrules.RuleKind
import im.vector.matrix.android.api.pushrules.rest.PushRule
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface UpdatePushRuleEnableStatusTask : Task<UpdatePushRuleEnableStatusTask.Params, Unit> {
@ -27,11 +28,13 @@ internal interface UpdatePushRuleEnableStatusTask : Task<UpdatePushRuleEnableSta
val enabled: Boolean)
}
internal class DefaultUpdatePushRuleEnableStatusTask @Inject constructor(private val pushRulesApi: PushRulesApi)
: UpdatePushRuleEnableStatusTask {
internal class DefaultUpdatePushRuleEnableStatusTask @Inject constructor(
private val pushRulesApi: PushRulesApi,
private val eventBus: EventBus
) : UpdatePushRuleEnableStatusTask {
override suspend fun execute(params: UpdatePushRuleEnableStatusTask.Params) {
return executeRequest {
return executeRequest(eventBus) {
apiCall = pushRulesApi.updateEnableRuleStatus(params.kind.value, params.pushRule.ruleId, params.enabled)
}
}

View File

@ -24,6 +24,7 @@ import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.task.Task
import io.realm.Realm
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetRoomIdByAliasTask : Task<GetRoomIdByAliasTask.Params, Optional<String>> {
@ -33,8 +34,11 @@ internal interface GetRoomIdByAliasTask : Task<GetRoomIdByAliasTask.Params, Opti
)
}
internal class DefaultGetRoomIdByAliasTask @Inject constructor(private val monarchy: Monarchy,
private val roomAPI: RoomAPI) : GetRoomIdByAliasTask {
internal class DefaultGetRoomIdByAliasTask @Inject constructor(
private val monarchy: Monarchy,
private val roomAPI: RoomAPI,
private val eventBus: EventBus
) : GetRoomIdByAliasTask {
override suspend fun execute(params: GetRoomIdByAliasTask.Params): Optional<String> {
var roomId = Realm.getInstance(monarchy.realmConfiguration).use {
@ -45,7 +49,7 @@ internal class DefaultGetRoomIdByAliasTask @Inject constructor(private val monar
} else if (!params.searchOnServer) {
Optional.from<String>(null)
} else {
roomId = executeRequest<RoomAliasDescription> {
roomId = executeRequest<RoomAliasDescription>(eventBus) {
apiCall = roomAPI.getRoomIdByAlias(params.roomAlias)
}.roomId
Optional.from(roomId)

View File

@ -35,21 +35,25 @@ import im.vector.matrix.android.internal.task.Task
import im.vector.matrix.android.internal.util.awaitTransaction
import io.realm.RealmConfiguration
import kotlinx.coroutines.TimeoutCancellationException
import org.greenrobot.eventbus.EventBus
import java.util.concurrent.TimeUnit
import javax.inject.Inject
internal interface CreateRoomTask : Task<CreateRoomParams, String>
internal class DefaultCreateRoomTask @Inject constructor(private val roomAPI: RoomAPI,
private val monarchy: Monarchy,
private val directChatsHelper: DirectChatsHelper,
private val updateUserAccountDataTask: UpdateUserAccountDataTask,
private val readMarkersTask: SetReadMarkersTask,
@SessionDatabase
private val realmConfiguration: RealmConfiguration) : CreateRoomTask {
internal class DefaultCreateRoomTask @Inject constructor(
private val roomAPI: RoomAPI,
private val monarchy: Monarchy,
private val directChatsHelper: DirectChatsHelper,
private val updateUserAccountDataTask: UpdateUserAccountDataTask,
private val readMarkersTask: SetReadMarkersTask,
@SessionDatabase
private val realmConfiguration: RealmConfiguration,
private val eventBus: EventBus
) : CreateRoomTask {
override suspend fun execute(params: CreateRoomParams): String {
val createRoomResponse = executeRequest<CreateRoomResponse> {
val createRoomResponse = executeRequest<CreateRoomResponse>(eventBus) {
apiCall = roomAPI.createRoom(params)
}
val roomId = createRoomResponse.roomId!!

View File

@ -21,6 +21,7 @@ import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRooms
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetPublicRoomTask : Task<GetPublicRoomTask.Params, PublicRoomsResponse> {
@ -30,10 +31,13 @@ internal interface GetPublicRoomTask : Task<GetPublicRoomTask.Params, PublicRoom
)
}
internal class DefaultGetPublicRoomTask @Inject constructor(private val roomAPI: RoomAPI) : GetPublicRoomTask {
internal class DefaultGetPublicRoomTask @Inject constructor(
private val roomAPI: RoomAPI,
private val eventBus: EventBus
) : GetPublicRoomTask {
override suspend fun execute(params: GetPublicRoomTask.Params): PublicRoomsResponse {
return executeRequest {
return executeRequest(eventBus) {
apiCall = roomAPI.publicRooms(params.server, params.publicRoomsParams)
}
}

View File

@ -20,14 +20,18 @@ import im.vector.matrix.android.api.session.room.model.thirdparty.ThirdPartyProt
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetThirdPartyProtocolsTask : Task<Unit, Map<String, ThirdPartyProtocol>>
internal class DefaultGetThirdPartyProtocolsTask @Inject constructor(private val roomAPI: RoomAPI) : GetThirdPartyProtocolsTask {
internal class DefaultGetThirdPartyProtocolsTask @Inject constructor(
private val roomAPI: RoomAPI,
private val eventBus: EventBus
) : GetThirdPartyProtocolsTask {
override suspend fun execute(params: Unit): Map<String, ThirdPartyProtocol> {
return executeRequest {
return executeRequest(eventBus) {
apiCall = roomAPI.thirdPartyProtocols()
}
}

View File

@ -30,6 +30,7 @@ import im.vector.matrix.android.internal.task.Task
import im.vector.matrix.android.internal.util.awaitTransaction
import io.realm.Realm
import io.realm.kotlin.createObject
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface LoadRoomMembersTask : Task<LoadRoomMembersTask.Params, Unit> {
@ -40,12 +41,14 @@ internal interface LoadRoomMembersTask : Task<LoadRoomMembersTask.Params, Unit>
)
}
internal class DefaultLoadRoomMembersTask @Inject constructor(private val roomAPI: RoomAPI,
private val monarchy: Monarchy,
private val syncTokenStore: SyncTokenStore,
private val roomSummaryUpdater: RoomSummaryUpdater,
private val roomMemberEventHandler: RoomMemberEventHandler,
private val timelineEventSenderVisitor: TimelineEventSenderVisitor
internal class DefaultLoadRoomMembersTask @Inject constructor(
private val roomAPI: RoomAPI,
private val monarchy: Monarchy,
private val syncTokenStore: SyncTokenStore,
private val roomSummaryUpdater: RoomSummaryUpdater,
private val roomMemberEventHandler: RoomMemberEventHandler,
private val timelineEventSenderVisitor: TimelineEventSenderVisitor,
private val eventBus: EventBus
) : LoadRoomMembersTask {
override suspend fun execute(params: LoadRoomMembersTask.Params) {
@ -53,7 +56,7 @@ internal class DefaultLoadRoomMembersTask @Inject constructor(private val roomAP
return
}
val lastToken = syncTokenStore.getLastToken()
val response = executeRequest<RoomMembersResponse> {
val response = executeRequest<RoomMembersResponse>(eventBus) {
apiCall = roomAPI.getMembers(params.roomId, lastToken, null, params.excludeMembership?.value)
}
insertInDb(response, params.roomId)

View File

@ -19,6 +19,7 @@ package im.vector.matrix.android.internal.session.room.membership.joining
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface InviteTask : Task<InviteTask.Params, Unit> {
@ -29,10 +30,13 @@ internal interface InviteTask : Task<InviteTask.Params, Unit> {
)
}
internal class DefaultInviteTask @Inject constructor(private val roomAPI: RoomAPI) : InviteTask {
internal class DefaultInviteTask @Inject constructor(
private val roomAPI: RoomAPI,
private val eventBus: EventBus
) : InviteTask {
override suspend fun execute(params: InviteTask.Params) {
return executeRequest {
return executeRequest(eventBus) {
val body = InviteBody(params.userId, params.reason)
apiCall = roomAPI.invite(params.roomId, body)
}

View File

@ -27,6 +27,7 @@ import im.vector.matrix.android.internal.session.room.read.SetReadMarkersTask
import im.vector.matrix.android.internal.task.Task
import io.realm.RealmConfiguration
import kotlinx.coroutines.TimeoutCancellationException
import org.greenrobot.eventbus.EventBus
import java.util.concurrent.TimeUnit
import javax.inject.Inject
@ -38,13 +39,16 @@ internal interface JoinRoomTask : Task<JoinRoomTask.Params, Unit> {
)
}
internal class DefaultJoinRoomTask @Inject constructor(private val roomAPI: RoomAPI,
private val readMarkersTask: SetReadMarkersTask,
@SessionDatabase
private val realmConfiguration: RealmConfiguration) : JoinRoomTask {
internal class DefaultJoinRoomTask @Inject constructor(
private val roomAPI: RoomAPI,
private val readMarkersTask: SetReadMarkersTask,
@SessionDatabase
private val realmConfiguration: RealmConfiguration,
private val eventBus: EventBus
) : JoinRoomTask {
override suspend fun execute(params: JoinRoomTask.Params) {
executeRequest<Unit> {
executeRequest<Unit>(eventBus) {
apiCall = roomAPI.join(params.roomId, params.viaServers, mapOf("reason" to params.reason))
}
// Wait for room to come back from the sync (but it can maybe be in the DB is the sync response is received before)

View File

@ -19,6 +19,7 @@ package im.vector.matrix.android.internal.session.room.membership.leaving
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface LeaveRoomTask : Task<LeaveRoomTask.Params, Unit> {
@ -28,10 +29,13 @@ internal interface LeaveRoomTask : Task<LeaveRoomTask.Params, Unit> {
)
}
internal class DefaultLeaveRoomTask @Inject constructor(private val roomAPI: RoomAPI) : LeaveRoomTask {
internal class DefaultLeaveRoomTask @Inject constructor(
private val roomAPI: RoomAPI,
private val eventBus: EventBus
) : LeaveRoomTask {
override suspend fun execute(params: LeaveRoomTask.Params) {
return executeRequest {
return executeRequest(eventBus) {
apiCall = roomAPI.leave(params.roomId, mapOf("reason" to params.reason))
}
}

View File

@ -20,7 +20,8 @@ import com.zhuinden.monarchy.Monarchy
import im.vector.matrix.android.api.session.events.model.LocalEcho
import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
import im.vector.matrix.android.internal.database.model.TimelineEventEntity
import im.vector.matrix.android.internal.database.query.*
import im.vector.matrix.android.internal.database.query.isEventRead
import im.vector.matrix.android.internal.database.query.isReadMarkerMoreRecent
import im.vector.matrix.android.internal.database.query.latestEvent
import im.vector.matrix.android.internal.database.query.where
import im.vector.matrix.android.internal.di.UserId
@ -31,8 +32,11 @@ import im.vector.matrix.android.internal.session.sync.RoomFullyReadHandler
import im.vector.matrix.android.internal.task.Task
import im.vector.matrix.android.internal.util.awaitTransaction
import io.realm.Realm
import org.greenrobot.eventbus.EventBus
import timber.log.Timber
import javax.inject.Inject
import kotlin.collections.HashMap
import kotlin.collections.set
internal interface SetReadMarkersTask : Task<SetReadMarkersTask.Params, Unit> {
@ -47,12 +51,14 @@ internal interface SetReadMarkersTask : Task<SetReadMarkersTask.Params, Unit> {
private const val READ_MARKER = "m.fully_read"
private const val READ_RECEIPT = "m.read"
internal class DefaultSetReadMarkersTask @Inject constructor(private val roomAPI: RoomAPI,
private val monarchy: Monarchy,
private val roomFullyReadHandler: RoomFullyReadHandler,
private val readReceiptHandler: ReadReceiptHandler,
@UserId private val userId: String)
: SetReadMarkersTask {
internal class DefaultSetReadMarkersTask @Inject constructor(
private val roomAPI: RoomAPI,
private val monarchy: Monarchy,
private val roomFullyReadHandler: RoomFullyReadHandler,
private val readReceiptHandler: ReadReceiptHandler,
@UserId private val userId: String,
private val eventBus: EventBus
) : SetReadMarkersTask {
override suspend fun execute(params: SetReadMarkersTask.Params) {
val markers = HashMap<String, String>()
@ -76,7 +82,7 @@ internal class DefaultSetReadMarkersTask @Inject constructor(private val roomAPI
}
if (readReceiptEventId != null
&& !isEventRead(monarchy, userId, params.roomId, readReceiptEventId)) {
&& !isEventRead(monarchy, userId, params.roomId, readReceiptEventId)) {
if (LocalEcho.isLocalEchoId(readReceiptEventId)) {
Timber.w("Can't set read receipt for local event $readReceiptEventId")
} else {
@ -87,7 +93,7 @@ internal class DefaultSetReadMarkersTask @Inject constructor(private val roomAPI
return
}
updateDatabase(params.roomId, markers)
executeRequest<Unit> {
executeRequest<Unit>(eventBus) {
apiCall = roomAPI.sendReadMarker(params.roomId, markers)
}
}
@ -105,7 +111,7 @@ internal class DefaultSetReadMarkersTask @Inject constructor(private val roomAPI
val isLatestReceived = TimelineEventEntity.latestEvent(realm, roomId = roomId, includesSending = false)?.eventId == readReceiptId
if (isLatestReceived) {
val roomSummary = RoomSummaryEntity.where(realm, roomId).findFirst()
?: return@awaitTransaction
?: return@awaitTransaction
roomSummary.notificationCount = 0
roomSummary.highlightCount = 0
roomSummary.hasUnreadMessages = false

View File

@ -21,6 +21,7 @@ import im.vector.matrix.android.api.session.events.model.RelationType
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface FetchEditHistoryTask : Task<FetchEditHistoryTask.Params, List<Event>> {
@ -33,11 +34,12 @@ internal interface FetchEditHistoryTask : Task<FetchEditHistoryTask.Params, List
}
internal class DefaultFetchEditHistoryTask @Inject constructor(
private val roomAPI: RoomAPI
private val roomAPI: RoomAPI,
private val eventBus: EventBus
) : FetchEditHistoryTask {
override suspend fun execute(params: FetchEditHistoryTask.Params): List<Event> {
val response = executeRequest<RelationsResponse> {
val response = executeRequest<RelationsResponse>(eventBus) {
apiCall = roomAPI.getRelations(params.roomId,
params.eventId,
RelationType.REPLACE,

View File

@ -30,6 +30,7 @@ import im.vector.matrix.android.internal.session.room.send.SendResponse
import im.vector.matrix.android.internal.worker.SessionWorkerParams
import im.vector.matrix.android.internal.worker.WorkerParamsFactory
import im.vector.matrix.android.internal.worker.getSessionComponent
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal class SendRelationWorker(context: Context, params: WorkerParameters) : CoroutineWorker(context, params) {
@ -44,6 +45,7 @@ internal class SendRelationWorker(context: Context, params: WorkerParameters) :
) : SessionWorkerParams
@Inject lateinit var roomAPI: RoomAPI
@Inject lateinit var eventBus: EventBus
override suspend fun doWork(): Result {
val params = WorkerParamsFactory.fromData<Params>(inputData)
@ -82,7 +84,7 @@ internal class SendRelationWorker(context: Context, params: WorkerParameters) :
}
private suspend fun sendRelation(roomId: String, relationType: String, relatedEventId: String, localEvent: Event) {
executeRequest<SendResponse> {
executeRequest<SendResponse>(eventBus) {
apiCall = roomAPI.sendRelation(
roomId = roomId,
parent_id = relatedEventId,

View File

@ -19,6 +19,7 @@ package im.vector.matrix.android.internal.session.room.reporting
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface ReportContentTask : Task<ReportContentTask.Params, Unit> {
@ -30,9 +31,13 @@ internal interface ReportContentTask : Task<ReportContentTask.Params, Unit> {
)
}
internal class DefaultReportContentTask @Inject constructor(private val roomAPI: RoomAPI) : ReportContentTask {
internal class DefaultReportContentTask @Inject constructor(
private val roomAPI: RoomAPI,
private val eventBus: EventBus
) : ReportContentTask {
override suspend fun execute(params: ReportContentTask.Params) {
return executeRequest {
return executeRequest(eventBus) {
apiCall = roomAPI.reportContent(params.roomId, params.eventId, ReportContentBody(params.score, params.reason))
}
}

View File

@ -25,6 +25,7 @@ import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.worker.SessionWorkerParams
import im.vector.matrix.android.internal.worker.WorkerParamsFactory
import im.vector.matrix.android.internal.worker.getSessionComponent
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal class RedactEventWorker(context: Context, params: WorkerParameters) : CoroutineWorker(context, params) {
@ -40,6 +41,7 @@ internal class RedactEventWorker(context: Context, params: WorkerParameters) : C
) : SessionWorkerParams
@Inject lateinit var roomAPI: RoomAPI
@Inject lateinit var eventBus: EventBus
override suspend fun doWork(): Result {
val params = WorkerParamsFactory.fromData<Params>(inputData)
@ -55,7 +57,7 @@ internal class RedactEventWorker(context: Context, params: WorkerParameters) : C
val eventId = params.eventId
return runCatching {
executeRequest<SendResponse> {
executeRequest<SendResponse>(eventBus) {
apiCall = roomAPI.redactEvent(
params.txID,
params.roomId,

View File

@ -30,6 +30,7 @@ import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.worker.SessionWorkerParams
import im.vector.matrix.android.internal.worker.WorkerParamsFactory
import im.vector.matrix.android.internal.worker.getSessionComponent
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal class SendEventWorker constructor(context: Context, params: WorkerParameters)
@ -45,6 +46,7 @@ internal class SendEventWorker constructor(context: Context, params: WorkerParam
@Inject lateinit var localEchoUpdater: LocalEchoUpdater
@Inject lateinit var roomAPI: RoomAPI
@Inject lateinit var eventBus: EventBus
override suspend fun doWork(): Result {
val params = WorkerParamsFactory.fromData<Params>(inputData)
@ -84,7 +86,7 @@ internal class SendEventWorker constructor(context: Context, params: WorkerParam
private suspend fun sendEvent(eventId: String, eventType: String, content: Content?, roomId: String) {
localEchoUpdater.updateSendState(eventId, SendState.SENDING)
executeRequest<SendResponse> {
executeRequest<SendResponse>(eventBus) {
apiCall = roomAPI.send(
eventId,
roomId,

View File

@ -19,6 +19,7 @@ package im.vector.matrix.android.internal.session.room.state
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface SendStateTask : Task<SendStateTask.Params, Unit> {
@ -29,9 +30,13 @@ internal interface SendStateTask : Task<SendStateTask.Params, Unit> {
)
}
internal class DefaultSendStateTask @Inject constructor(private val roomAPI: RoomAPI) : SendStateTask {
internal class DefaultSendStateTask @Inject constructor(
private val roomAPI: RoomAPI,
private val eventBus: EventBus
) : SendStateTask {
override suspend fun execute(params: SendStateTask.Params) {
return executeRequest {
return executeRequest(eventBus) {
apiCall = roomAPI.sendStateEvent(params.roomId, params.eventType, params.body)
}
}

View File

@ -20,6 +20,7 @@ import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.filter.FilterRepository
import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetContextOfEventTask : Task<GetContextOfEventTask.Params, TokenChunkEventPersistor.Result> {
@ -31,14 +32,16 @@ internal interface GetContextOfEventTask : Task<GetContextOfEventTask.Params, To
)
}
internal class DefaultGetContextOfEventTask @Inject constructor(private val roomAPI: RoomAPI,
private val filterRepository: FilterRepository,
private val tokenChunkEventPersistor: TokenChunkEventPersistor
internal class DefaultGetContextOfEventTask @Inject constructor(
private val roomAPI: RoomAPI,
private val filterRepository: FilterRepository,
private val tokenChunkEventPersistor: TokenChunkEventPersistor,
private val eventBus: EventBus
) : GetContextOfEventTask {
override suspend fun execute(params: GetContextOfEventTask.Params): TokenChunkEventPersistor.Result {
val filter = filterRepository.getRoomFilter()
val response = executeRequest<EventContextResponse> {
val response = executeRequest<EventContextResponse>(eventBus) {
apiCall = roomAPI.getContextOfEvent(params.roomId, params.eventId, params.limit, filter)
}
return tokenChunkEventPersistor.insertInDb(response, params.roomId, PaginationDirection.BACKWARDS)

View File

@ -20,6 +20,7 @@ import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.filter.FilterRepository
import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface PaginationTask : Task<PaginationTask.Params, TokenChunkEventPersistor.Result> {
@ -32,14 +33,16 @@ internal interface PaginationTask : Task<PaginationTask.Params, TokenChunkEventP
)
}
internal class DefaultPaginationTask @Inject constructor(private val roomAPI: RoomAPI,
private val filterRepository: FilterRepository,
private val tokenChunkEventPersistor: TokenChunkEventPersistor
internal class DefaultPaginationTask @Inject constructor(
private val roomAPI: RoomAPI,
private val filterRepository: FilterRepository,
private val tokenChunkEventPersistor: TokenChunkEventPersistor,
private val eventBus: EventBus
) : PaginationTask {
override suspend fun execute(params: PaginationTask.Params): TokenChunkEventPersistor.Result {
val filter = filterRepository.getRoomFilter()
val chunk = executeRequest<PaginationResponse> {
val chunk = executeRequest<PaginationResponse>(eventBus) {
apiCall = roomAPI.getRoomMessagesFrom(params.roomId, params.from, params.direction.value, params.limit, filter)
}
return tokenChunkEventPersistor.insertInDb(chunk, params.roomId, params.direction)

View File

@ -20,9 +20,12 @@ import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal class GetEventTask @Inject constructor(private val roomAPI: RoomAPI
internal class GetEventTask @Inject constructor(
private val roomAPI: RoomAPI,
private val eventBus: EventBus
) : Task<GetEventTask.Params, Event> {
internal data class Params(
@ -31,7 +34,7 @@ internal class GetEventTask @Inject constructor(private val roomAPI: RoomAPI
)
override suspend fun execute(params: Params): Event {
return executeRequest {
return executeRequest(eventBus) {
apiCall = roomAPI.getEvent(params.roomId, params.eventId)
}
}

View File

@ -22,6 +22,7 @@ import im.vector.matrix.android.internal.auth.SessionParamsStore
import im.vector.matrix.android.internal.auth.data.PasswordLoginParams
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface SignInAgainTask : Task<SignInAgainTask.Params, Unit> {
@ -33,10 +34,12 @@ internal interface SignInAgainTask : Task<SignInAgainTask.Params, Unit> {
internal class DefaultSignInAgainTask @Inject constructor(
private val signOutAPI: SignOutAPI,
private val sessionParams: SessionParams,
private val sessionParamsStore: SessionParamsStore) : SignInAgainTask {
private val sessionParamsStore: SessionParamsStore,
private val eventBus: EventBus
) : SignInAgainTask {
override suspend fun execute(params: SignInAgainTask.Params) {
val newCredentials = executeRequest<Credentials> {
val newCredentials = executeRequest<Credentials>(eventBus) {
apiCall = signOutAPI.loginAgain(
PasswordLoginParams.userIdentifier(
// Reuse the same userId

View File

@ -32,6 +32,7 @@ import im.vector.matrix.android.internal.task.Task
import im.vector.matrix.android.internal.worker.WorkManagerUtil
import io.realm.Realm
import io.realm.RealmConfiguration
import org.greenrobot.eventbus.EventBus
import timber.log.Timber
import java.io.File
import java.net.HttpURLConnection
@ -43,25 +44,28 @@ internal interface SignOutTask : Task<SignOutTask.Params, Unit> {
)
}
internal class DefaultSignOutTask @Inject constructor(private val context: Context,
@UserId private val userId: String,
private val signOutAPI: SignOutAPI,
private val sessionManager: SessionManager,
private val sessionParamsStore: SessionParamsStore,
@SessionDatabase private val clearSessionDataTask: ClearCacheTask,
@CryptoDatabase private val clearCryptoDataTask: ClearCacheTask,
@UserCacheDirectory private val userFile: File,
private val realmKeysUtils: RealmKeysUtils,
@SessionDatabase private val realmSessionConfiguration: RealmConfiguration,
@CryptoDatabase private val realmCryptoConfiguration: RealmConfiguration,
@UserMd5 private val userMd5: String) : SignOutTask {
internal class DefaultSignOutTask @Inject constructor(
private val context: Context,
@UserId private val userId: String,
private val signOutAPI: SignOutAPI,
private val sessionManager: SessionManager,
private val sessionParamsStore: SessionParamsStore,
@SessionDatabase private val clearSessionDataTask: ClearCacheTask,
@CryptoDatabase private val clearCryptoDataTask: ClearCacheTask,
@UserCacheDirectory private val userFile: File,
private val realmKeysUtils: RealmKeysUtils,
@SessionDatabase private val realmSessionConfiguration: RealmConfiguration,
@CryptoDatabase private val realmCryptoConfiguration: RealmConfiguration,
@UserMd5 private val userMd5: String,
private val eventBus: EventBus
) : SignOutTask {
override suspend fun execute(params: SignOutTask.Params) {
// It should be done even after a soft logout, to be sure the deviceId is deleted on the
if (params.sigOutFromHomeserver) {
Timber.d("SignOut: send request...")
try {
executeRequest<Unit> {
executeRequest<Unit>(eventBus) {
apiCall = signOutAPI.signOut()
}
} catch (throwable: Throwable) {

View File

@ -25,6 +25,7 @@ import im.vector.matrix.android.internal.session.homeserver.GetHomeServerCapabil
import im.vector.matrix.android.internal.session.sync.model.SyncResponse
import im.vector.matrix.android.internal.session.user.UserStore
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import timber.log.Timber
import javax.inject.Inject
@ -33,15 +34,17 @@ internal interface SyncTask : Task<SyncTask.Params, Unit> {
data class Params(var timeout: Long = 30_000L)
}
internal class DefaultSyncTask @Inject constructor(private val syncAPI: SyncAPI,
@UserId private val userId: String,
private val filterRepository: FilterRepository,
private val syncResponseHandler: SyncResponseHandler,
private val initialSyncProgressService: DefaultInitialSyncProgressService,
private val syncTokenStore: SyncTokenStore,
private val getHomeServerCapabilitiesTask: GetHomeServerCapabilitiesTask,
private val userStore: UserStore,
private val syncTaskSequencer: SyncTaskSequencer
internal class DefaultSyncTask @Inject constructor(
private val syncAPI: SyncAPI,
@UserId private val userId: String,
private val filterRepository: FilterRepository,
private val syncResponseHandler: SyncResponseHandler,
private val initialSyncProgressService: DefaultInitialSyncProgressService,
private val syncTokenStore: SyncTokenStore,
private val getHomeServerCapabilitiesTask: GetHomeServerCapabilitiesTask,
private val userStore: UserStore,
private val syncTaskSequencer: SyncTaskSequencer,
private val eventBus: EventBus
) : SyncTask {
override suspend fun execute(params: SyncTask.Params) = syncTaskSequencer.post {
@ -70,7 +73,7 @@ internal class DefaultSyncTask @Inject constructor(private val syncAPI: SyncAPI,
initialSyncProgressService.endAll()
initialSyncProgressService.startTask(R.string.initial_sync_start_importing_account, 100)
}
val syncResponse = executeRequest<SyncResponse> {
val syncResponse = executeRequest<SyncResponse>(eventBus) {
apiCall = syncAPI.sync(requestParams)
}
syncResponseHandler.handleResponse(syncResponse, token)

View File

@ -23,6 +23,7 @@ import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.sync.model.accountdata.IgnoredUsersContent
import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountData
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface UpdateIgnoredUserIdsTask : Task<UpdateIgnoredUserIdsTask.Params, Unit> {
@ -33,10 +34,13 @@ internal interface UpdateIgnoredUserIdsTask : Task<UpdateIgnoredUserIdsTask.Para
)
}
internal class DefaultUpdateIgnoredUserIdsTask @Inject constructor(private val accountDataApi: AccountDataAPI,
private val monarchy: Monarchy,
private val saveIgnoredUsersTask: SaveIgnoredUsersTask,
@UserId private val userId: String) : UpdateIgnoredUserIdsTask {
internal class DefaultUpdateIgnoredUserIdsTask @Inject constructor(
private val accountDataApi: AccountDataAPI,
private val monarchy: Monarchy,
private val saveIgnoredUsersTask: SaveIgnoredUsersTask,
@UserId private val userId: String,
private val eventBus: EventBus
) : UpdateIgnoredUserIdsTask {
override suspend fun execute(params: UpdateIgnoredUserIdsTask.Params) {
// Get current list
@ -58,7 +62,7 @@ internal class DefaultUpdateIgnoredUserIdsTask @Inject constructor(private val a
val list = ignoredUserIds.toList()
val body = IgnoredUsersContent.createWithUserIds(list)
executeRequest<Unit> {
executeRequest<Unit>(eventBus) {
apiCall = accountDataApi.setAccountData(userId, UserAccountData.TYPE_IGNORED_USER_LIST, body)
}

View File

@ -21,6 +21,7 @@ import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.sync.model.accountdata.BreadcrumbsContent
import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountData
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface UpdateUserAccountDataTask : Task<UpdateUserAccountDataTask.Params, Unit> {
@ -50,11 +51,14 @@ internal interface UpdateUserAccountDataTask : Task<UpdateUserAccountDataTask.Pa
}
}
internal class DefaultUpdateUserAccountDataTask @Inject constructor(private val accountDataApi: AccountDataAPI,
@UserId private val userId: String) : UpdateUserAccountDataTask {
internal class DefaultUpdateUserAccountDataTask @Inject constructor(
private val accountDataApi: AccountDataAPI,
@UserId private val userId: String,
private val eventBus: EventBus
) : UpdateUserAccountDataTask {
override suspend fun execute(params: UpdateUserAccountDataTask.Params) {
return executeRequest {
return executeRequest(eventBus) {
apiCall = accountDataApi.setAccountData(userId, params.type, params.getData())
}
}

View File

@ -20,6 +20,7 @@ import im.vector.matrix.android.api.session.user.model.User
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.user.SearchUserAPI
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface SearchUserTask : Task<SearchUserTask.Params, List<User>> {
@ -31,10 +32,13 @@ internal interface SearchUserTask : Task<SearchUserTask.Params, List<User>> {
)
}
internal class DefaultSearchUserTask @Inject constructor(private val searchUserAPI: SearchUserAPI) : SearchUserTask {
internal class DefaultSearchUserTask @Inject constructor(
private val searchUserAPI: SearchUserAPI,
private val eventBus: EventBus
) : SearchUserTask {
override suspend fun execute(params: SearchUserTask.Params): List<User> {
val response = executeRequest<SearchUsersResponse> {
val response = executeRequest<SearchUsersResponse>(eventBus) {
apiCall = searchUserAPI.searchUsers(SearchUsersParams(params.search, params.limit))
}
return response.users.map {