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() session.close()
} }
// FIXME This test does not past yet, due to usage of the EventBus.
@Test @Test
fun createAccountAndLoginAgainTest() { fun createAccountAndLoginAgainTest() {
val session = commonTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(withInitialSync = true)) 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 onlySuccessful true to fail if an error occurs. This is the default behavior
* @param <T> * @param <T>
*/ */
open class TestMatrixCallback<T> @JvmOverloads constructor(private val countDownLatch: CountDownLatch, open class TestMatrixCallback<T>(private val countDownLatch: CountDownLatch,
private val onlySuccessful: Boolean = true) : MatrixCallback<T> { private val onlySuccessful: Boolean = true) : MatrixCallback<T> {
@CallSuper @CallSuper
override fun onSuccess(data: T) { override fun onSuccess(data: T) {

View File

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

View File

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

View File

@ -29,11 +29,12 @@ internal interface RegisterAddThreePidTask : Task<RegisterAddThreePidTask.Params
) )
} }
internal class DefaultRegisterAddThreePidTask(private val authAPI: AuthAPI) internal class DefaultRegisterAddThreePidTask(
: RegisterAddThreePidTask { private val authAPI: AuthAPI
) : RegisterAddThreePidTask {
override suspend fun execute(params: RegisterAddThreePidTask.Params): AddThreePidRegistrationResponse { override suspend fun execute(params: RegisterAddThreePidTask.Params): AddThreePidRegistrationResponse {
return executeRequest { return executeRequest(null) {
apiCall = authAPI.add3Pid(params.threePid.toPath(), AddThreePidRegistrationParams.from(params)) 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) internal class DefaultRegisterTask(
: RegisterTask { private val authAPI: AuthAPI
) : RegisterTask {
override suspend fun execute(params: RegisterTask.Params): Credentials { override suspend fun execute(params: RegisterTask.Params): Credentials {
try { try {
return executeRequest { return executeRequest(null) {
apiCall = authAPI.register(params.registrationParams) apiCall = authAPI.register(params.registrationParams)
} }
} catch (throwable: Throwable) { } catch (throwable: Throwable) {

View File

@ -27,11 +27,12 @@ internal interface ValidateCodeTask : Task<ValidateCodeTask.Params, SuccessResul
) )
} }
internal class DefaultValidateCodeTask(private val authAPI: AuthAPI) internal class DefaultValidateCodeTask(
: ValidateCodeTask { private val authAPI: AuthAPI
) : ValidateCodeTask {
override suspend fun execute(params: ValidateCodeTask.Params): SuccessResult { override suspend fun execute(params: ValidateCodeTask.Params): SuccessResult {
return executeRequest { return executeRequest(null) {
apiCall = authAPI.validate3Pid(params.url, params.body) 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.crypto.keysbackup.model.rest.KeysVersion
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface CreateKeysBackupVersionTask : Task<CreateKeysBackupVersionBody, KeysVersion> internal interface CreateKeysBackupVersionTask : Task<CreateKeysBackupVersionBody, KeysVersion>
internal class DefaultCreateKeysBackupVersionTask @Inject constructor(private val roomKeysApi: RoomKeysApi) internal class DefaultCreateKeysBackupVersionTask @Inject constructor(
: CreateKeysBackupVersionTask { private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : CreateKeysBackupVersionTask {
override suspend fun execute(params: CreateKeysBackupVersionBody): KeysVersion { override suspend fun execute(params: CreateKeysBackupVersionBody): KeysVersion {
return executeRequest { return executeRequest(eventBus) {
apiCall = roomKeysApi.createKeysBackupVersion(params) 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.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface DeleteBackupTask : Task<DeleteBackupTask.Params, Unit> { 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) internal class DefaultDeleteBackupTask @Inject constructor(
: DeleteBackupTask { private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : DeleteBackupTask {
override suspend fun execute(params: DeleteBackupTask.Params) { override suspend fun execute(params: DeleteBackupTask.Params) {
return executeRequest { return executeRequest(eventBus) {
apiCall = roomKeysApi.deleteBackup(params.version) 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.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface DeleteRoomSessionDataTask : Task<DeleteRoomSessionDataTask.Params, Unit> { 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) internal class DefaultDeleteRoomSessionDataTask @Inject constructor(
: DeleteRoomSessionDataTask { private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : DeleteRoomSessionDataTask {
override suspend fun execute(params: DeleteRoomSessionDataTask.Params) { override suspend fun execute(params: DeleteRoomSessionDataTask.Params) {
return executeRequest { return executeRequest(eventBus) {
apiCall = roomKeysApi.deleteRoomSessionData( apiCall = roomKeysApi.deleteRoomSessionData(
params.roomId, params.roomId,
params.sessionId, 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.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface DeleteRoomSessionsDataTask : Task<DeleteRoomSessionsDataTask.Params, Unit> { 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) internal class DefaultDeleteRoomSessionsDataTask @Inject constructor(
: DeleteRoomSessionsDataTask { private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : DeleteRoomSessionsDataTask {
override suspend fun execute(params: DeleteRoomSessionsDataTask.Params) { override suspend fun execute(params: DeleteRoomSessionsDataTask.Params) {
return executeRequest { return executeRequest(eventBus) {
apiCall = roomKeysApi.deleteRoomSessionsData( apiCall = roomKeysApi.deleteRoomSessionsData(
params.roomId, params.roomId,
params.version) 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.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface DeleteSessionsDataTask : Task<DeleteSessionsDataTask.Params, Unit> { 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) internal class DefaultDeleteSessionsDataTask @Inject constructor(
: DeleteSessionsDataTask { private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : DeleteSessionsDataTask {
override suspend fun execute(params: DeleteSessionsDataTask.Params) { override suspend fun execute(params: DeleteSessionsDataTask.Params) {
return executeRequest { return executeRequest(eventBus) {
apiCall = roomKeysApi.deleteSessionsData(params.version) 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.crypto.keysbackup.model.rest.KeysVersionResult
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetKeysBackupLastVersionTask : Task<Unit, KeysVersionResult> internal interface GetKeysBackupLastVersionTask : Task<Unit, KeysVersionResult>
internal class DefaultGetKeysBackupLastVersionTask @Inject constructor(private val roomKeysApi: RoomKeysApi) internal class DefaultGetKeysBackupLastVersionTask @Inject constructor(
: GetKeysBackupLastVersionTask { private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : GetKeysBackupLastVersionTask {
override suspend fun execute(params: Unit): KeysVersionResult { override suspend fun execute(params: Unit): KeysVersionResult {
return executeRequest { return executeRequest(eventBus) {
apiCall = roomKeysApi.getKeysBackupLastVersion() 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.crypto.keysbackup.model.rest.KeysVersionResult
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetKeysBackupVersionTask : Task<String, KeysVersionResult> internal interface GetKeysBackupVersionTask : Task<String, KeysVersionResult>
internal class DefaultGetKeysBackupVersionTask @Inject constructor(private val roomKeysApi: RoomKeysApi) internal class DefaultGetKeysBackupVersionTask @Inject constructor(
: GetKeysBackupVersionTask { private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : GetKeysBackupVersionTask {
override suspend fun execute(params: String): KeysVersionResult { override suspend fun execute(params: String): KeysVersionResult {
return executeRequest { return executeRequest(eventBus) {
apiCall = roomKeysApi.getKeysBackupVersion(params) 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.crypto.keysbackup.model.rest.KeyBackupData
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetRoomSessionDataTask : Task<GetRoomSessionDataTask.Params, KeyBackupData> { 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) internal class DefaultGetRoomSessionDataTask @Inject constructor(
: GetRoomSessionDataTask { private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : GetRoomSessionDataTask {
override suspend fun execute(params: GetRoomSessionDataTask.Params): KeyBackupData { override suspend fun execute(params: GetRoomSessionDataTask.Params): KeyBackupData {
return executeRequest { return executeRequest(eventBus) {
apiCall = roomKeysApi.getRoomSessionData( apiCall = roomKeysApi.getRoomSessionData(
params.roomId, params.roomId,
params.sessionId, 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.crypto.keysbackup.model.rest.RoomKeysBackupData
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetRoomSessionsDataTask : Task<GetRoomSessionsDataTask.Params, RoomKeysBackupData> { 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) internal class DefaultGetRoomSessionsDataTask @Inject constructor(
: GetRoomSessionsDataTask { private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : GetRoomSessionsDataTask {
override suspend fun execute(params: GetRoomSessionsDataTask.Params): RoomKeysBackupData { override suspend fun execute(params: GetRoomSessionsDataTask.Params): RoomKeysBackupData {
return executeRequest { return executeRequest(eventBus) {
apiCall = roomKeysApi.getRoomSessionsData( apiCall = roomKeysApi.getRoomSessionsData(
params.roomId, params.roomId,
params.version) 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.crypto.keysbackup.model.rest.KeysBackupData
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetSessionsDataTask : Task<GetSessionsDataTask.Params, KeysBackupData> { 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) internal class DefaultGetSessionsDataTask @Inject constructor(
: GetSessionsDataTask { private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : GetSessionsDataTask {
override suspend fun execute(params: GetSessionsDataTask.Params): KeysBackupData { override suspend fun execute(params: GetSessionsDataTask.Params): KeysBackupData {
return executeRequest { return executeRequest(eventBus) {
apiCall = roomKeysApi.getSessionsData(params.version) 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.crypto.keysbackup.model.rest.KeyBackupData
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface StoreRoomSessionDataTask : Task<StoreRoomSessionDataTask.Params, BackupKeysResult> { 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) internal class DefaultStoreRoomSessionDataTask @Inject constructor(
: StoreRoomSessionDataTask { private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : StoreRoomSessionDataTask {
override suspend fun execute(params: StoreRoomSessionDataTask.Params): BackupKeysResult { override suspend fun execute(params: StoreRoomSessionDataTask.Params): BackupKeysResult {
return executeRequest { return executeRequest(eventBus) {
apiCall = roomKeysApi.storeRoomSessionData( apiCall = roomKeysApi.storeRoomSessionData(
params.roomId, params.roomId,
params.sessionId, 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.crypto.keysbackup.model.rest.RoomKeysBackupData
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface StoreRoomSessionsDataTask : Task<StoreRoomSessionsDataTask.Params, BackupKeysResult> { 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) internal class DefaultStoreRoomSessionsDataTask @Inject constructor(
: StoreRoomSessionsDataTask { private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : StoreRoomSessionsDataTask {
override suspend fun execute(params: StoreRoomSessionsDataTask.Params): BackupKeysResult { override suspend fun execute(params: StoreRoomSessionsDataTask.Params): BackupKeysResult {
return executeRequest { return executeRequest(eventBus) {
apiCall = roomKeysApi.storeRoomSessionsData( apiCall = roomKeysApi.storeRoomSessionsData(
params.roomId, params.roomId,
params.version, 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.crypto.keysbackup.model.rest.KeysBackupData
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface StoreSessionsDataTask : Task<StoreSessionsDataTask.Params, BackupKeysResult> { 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) internal class DefaultStoreSessionsDataTask @Inject constructor(
: StoreSessionsDataTask { private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : StoreSessionsDataTask {
override suspend fun execute(params: StoreSessionsDataTask.Params): BackupKeysResult { override suspend fun execute(params: StoreSessionsDataTask.Params): BackupKeysResult {
return executeRequest { return executeRequest(eventBus) {
apiCall = roomKeysApi.storeSessionsData( apiCall = roomKeysApi.storeSessionsData(
params.version, params.version,
params.keysBackupData) 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.crypto.keysbackup.model.rest.UpdateKeysBackupVersionBody
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface UpdateKeysBackupVersionTask : Task<UpdateKeysBackupVersionTask.Params, Unit> { 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) internal class DefaultUpdateKeysBackupVersionTask @Inject constructor(
: UpdateKeysBackupVersionTask { private val roomKeysApi: RoomKeysApi,
private val eventBus: EventBus
) : UpdateKeysBackupVersionTask {
override suspend fun execute(params: UpdateKeysBackupVersionTask.Params) { override suspend fun execute(params: UpdateKeysBackupVersionTask.Params) {
return executeRequest { return executeRequest(eventBus) {
apiCall = roomKeysApi.updateKeysBackupVersion(params.version, params.keysBackupVersionBody) 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.crypto.model.rest.KeysClaimResponse
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@ -33,13 +34,15 @@ internal interface ClaimOneTimeKeysForUsersDeviceTask : Task<ClaimOneTimeKeysFor
) )
} }
internal class DefaultClaimOneTimeKeysForUsersDevice @Inject constructor(private val cryptoApi: CryptoApi) internal class DefaultClaimOneTimeKeysForUsersDevice @Inject constructor(
: ClaimOneTimeKeysForUsersDeviceTask { private val cryptoApi: CryptoApi,
private val eventBus: EventBus
) : ClaimOneTimeKeysForUsersDeviceTask {
override suspend fun execute(params: ClaimOneTimeKeysForUsersDeviceTask.Params): MXUsersDevicesMap<MXKey> { override suspend fun execute(params: ClaimOneTimeKeysForUsersDeviceTask.Params): MXUsersDevicesMap<MXKey> {
val body = KeysClaimBody(oneTimeKeys = params.usersDevicesKeyTypesMap.map) val body = KeysClaimBody(oneTimeKeys = params.usersDevicesKeyTypesMap.map)
val keysClaimResponse = executeRequest<KeysClaimResponse> { val keysClaimResponse = executeRequest<KeysClaimResponse>(eventBus) {
apiCall = cryptoApi.claimOneTimeKeysForUsersDevices(body) apiCall = cryptoApi.claimOneTimeKeysForUsersDevices(body)
} }
val map = MXUsersDevicesMap<MXKey>() 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.di.MoshiProvider
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface DeleteDeviceTask : Task<DeleteDeviceTask.Params, Unit> { 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) internal class DefaultDeleteDeviceTask @Inject constructor(
: DeleteDeviceTask { private val cryptoApi: CryptoApi,
private val eventBus: EventBus
) : DeleteDeviceTask {
override suspend fun execute(params: DeleteDeviceTask.Params) { override suspend fun execute(params: DeleteDeviceTask.Params) {
try { try {
executeRequest<Unit> { executeRequest<Unit>(eventBus) {
apiCall = cryptoApi.deleteDevice(params.deviceId, DeleteDeviceParams()) apiCall = cryptoApi.deleteDevice(params.deviceId, DeleteDeviceParams())
} }
} catch (throwable: Throwable) { } 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.di.UserId
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface DeleteDeviceWithUserPasswordTask : Task<DeleteDeviceWithUserPasswordTask.Params, Unit> { 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, internal class DefaultDeleteDeviceWithUserPasswordTask @Inject constructor(
@UserId private val userId: String) private val cryptoApi: CryptoApi,
: DeleteDeviceWithUserPasswordTask { @UserId private val userId: String,
private val eventBus: EventBus
) : DeleteDeviceWithUserPasswordTask {
override suspend fun execute(params: DeleteDeviceWithUserPasswordTask.Params) { override suspend fun execute(params: DeleteDeviceWithUserPasswordTask.Params) {
return executeRequest { return executeRequest(eventBus) {
apiCall = cryptoApi.deleteDevice(params.deviceId, DeleteDeviceParams() apiCall = cryptoApi.deleteDevice(params.deviceId, DeleteDeviceParams()
.apply { .apply {
deleteDeviceAuth = DeleteDeviceAuth() 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.crypto.model.rest.KeysQueryResponse
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface DownloadKeysForUsersTask : Task<DownloadKeysForUsersTask.Params, KeysQueryResponse> { internal interface DownloadKeysForUsersTask : Task<DownloadKeysForUsersTask.Params, KeysQueryResponse> {
@ -31,8 +32,10 @@ internal interface DownloadKeysForUsersTask : Task<DownloadKeysForUsersTask.Para
val token: String?) val token: String?)
} }
internal class DefaultDownloadKeysForUsers @Inject constructor(private val cryptoApi: CryptoApi) internal class DefaultDownloadKeysForUsers @Inject constructor(
: DownloadKeysForUsersTask { private val cryptoApi: CryptoApi,
private val eventBus: EventBus
) : DownloadKeysForUsersTask {
override suspend fun execute(params: DownloadKeysForUsersTask.Params): KeysQueryResponse { override suspend fun execute(params: DownloadKeysForUsersTask.Params): KeysQueryResponse {
val downloadQuery = params.userIds?.associateWith { emptyMap<String, Any>() }.orEmpty() 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 body.token = params.token
} }
return executeRequest { return executeRequest(eventBus) {
apiCall = cryptoApi.downloadKeysForUsers(body) 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.crypto.model.rest.DeviceInfo
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetDeviceInfoTask : Task<GetDeviceInfoTask.Params, DeviceInfo> { internal interface GetDeviceInfoTask : Task<GetDeviceInfoTask.Params, DeviceInfo> {
data class Params(val deviceId: String) data class Params(val deviceId: String)
} }
internal class DefaultGetDeviceInfoTask @Inject constructor(private val cryptoApi: CryptoApi) internal class DefaultGetDeviceInfoTask @Inject constructor(
: GetDeviceInfoTask { private val cryptoApi: CryptoApi,
private val eventBus: EventBus
) : GetDeviceInfoTask {
override suspend fun execute(params: GetDeviceInfoTask.Params): DeviceInfo { override suspend fun execute(params: GetDeviceInfoTask.Params): DeviceInfo {
return executeRequest { return executeRequest(eventBus) {
apiCall = cryptoApi.getDeviceInfo(params.deviceId) 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.crypto.model.rest.DevicesListResponse
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetDevicesTask : Task<Unit, DevicesListResponse> internal interface GetDevicesTask : Task<Unit, DevicesListResponse>
internal class DefaultGetDevicesTask @Inject constructor(private val cryptoApi: CryptoApi) internal class DefaultGetDevicesTask @Inject constructor(
: GetDevicesTask { private val cryptoApi: CryptoApi,
private val eventBus: EventBus
) : GetDevicesTask {
override suspend fun execute(params: Unit): DevicesListResponse { override suspend fun execute(params: Unit): DevicesListResponse {
return executeRequest { return executeRequest(eventBus) {
apiCall = cryptoApi.getDevices() 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.crypto.model.rest.KeyChangesResponse
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetKeyChangesTask : Task<GetKeyChangesTask.Params, KeyChangesResponse> { 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) internal class DefaultGetKeyChangesTask @Inject constructor(
: GetKeyChangesTask { private val cryptoApi: CryptoApi,
private val eventBus: EventBus
) : GetKeyChangesTask {
override suspend fun execute(params: GetKeyChangesTask.Params): KeyChangesResponse { override suspend fun execute(params: GetKeyChangesTask.Params): KeyChangesResponse {
return executeRequest { return executeRequest(eventBus) {
apiCall = cryptoApi.getKeyChanges(params.from, params.to) 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.crypto.model.rest.SendToDeviceBody
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
import kotlin.random.Random import kotlin.random.Random
@ -35,14 +36,16 @@ internal interface SendToDeviceTask : Task<SendToDeviceTask.Params, Unit> {
) )
} }
internal class DefaultSendToDeviceTask @Inject constructor(private val cryptoApi: CryptoApi) internal class DefaultSendToDeviceTask @Inject constructor(
: SendToDeviceTask { private val cryptoApi: CryptoApi,
private val eventBus: EventBus
) : SendToDeviceTask {
override suspend fun execute(params: SendToDeviceTask.Params) { override suspend fun execute(params: SendToDeviceTask.Params) {
val sendToDeviceBody = SendToDeviceBody() val sendToDeviceBody = SendToDeviceBody()
sendToDeviceBody.messages = params.contentMap.map sendToDeviceBody.messages = params.contentMap.map
return executeRequest { return executeRequest(eventBus) {
apiCall = cryptoApi.sendToDevice( apiCall = cryptoApi.sendToDevice(
params.eventType, params.eventType,
params.transactionId ?: Random.nextInt(Integer.MAX_VALUE).toString(), 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.crypto.model.rest.UpdateDeviceInfoBody
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface SetDeviceNameTask : Task<SetDeviceNameTask.Params, Unit> { 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) internal class DefaultSetDeviceNameTask @Inject constructor(
: SetDeviceNameTask { private val cryptoApi: CryptoApi,
private val eventBus: EventBus
) : SetDeviceNameTask {
override suspend fun execute(params: SetDeviceNameTask.Params) { override suspend fun execute(params: SetDeviceNameTask.Params) {
val body = UpdateDeviceInfoBody( val body = UpdateDeviceInfoBody(
displayName = params.deviceName displayName = params.deviceName
) )
return executeRequest { return executeRequest(eventBus) {
apiCall = cryptoApi.updateDeviceInfo(params.deviceId, body) 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.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import im.vector.matrix.android.internal.util.convertToUTF8 import im.vector.matrix.android.internal.util.convertToUTF8
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface UploadKeysTask : Task<UploadKeysTask.Params, KeysUploadResponse> { internal interface UploadKeysTask : Task<UploadKeysTask.Params, KeysUploadResponse> {
@ -36,8 +37,10 @@ internal interface UploadKeysTask : Task<UploadKeysTask.Params, KeysUploadRespon
val deviceId: String) val deviceId: String)
} }
internal class DefaultUploadKeysTask @Inject constructor(private val cryptoApi: CryptoApi) internal class DefaultUploadKeysTask @Inject constructor(
: UploadKeysTask { private val cryptoApi: CryptoApi,
private val eventBus: EventBus
) : UploadKeysTask {
override suspend fun execute(params: UploadKeysTask.Params): KeysUploadResponse { override suspend fun execute(params: UploadKeysTask.Params): KeysUploadResponse {
val encodedDeviceId = convertToUTF8(params.deviceId) val encodedDeviceId = convertToUTF8(params.deviceId)
@ -52,7 +55,7 @@ internal class DefaultUploadKeysTask @Inject constructor(private val cryptoApi:
body.oneTimeKeys = params.oneTimeKeys body.oneTimeKeys = params.oneTimeKeys
} }
return executeRequest { return executeRequest(eventBus) {
apiCall = if (encodedDeviceId.isBlank()) { apiCall = if (encodedDeviceId.isBlank()) {
cryptoApi.uploadKeys(body) cryptoApi.uploadKeys(body)
} else { } else {

View File

@ -18,12 +18,14 @@ package im.vector.matrix.android.internal.network
import im.vector.matrix.android.api.failure.Failure import im.vector.matrix.android.api.failure.Failure
import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CancellationException
import org.greenrobot.eventbus.EventBus
import retrofit2.Call import retrofit2.Call
import java.io.IOException 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> lateinit var apiCall: Call<DATA>
@ -34,7 +36,7 @@ internal class Request<DATA> {
response.body() response.body()
?: throw IllegalStateException("The request returned a null body") ?: throw IllegalStateException("The request returned a null body")
} else { } else {
throw response.toFailure() throw response.toFailure(eventBus)
} }
} catch (exception: Throwable) { } catch (exception: Throwable) {
throw when (exception) { 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 * Convert a retrofit Response to a Failure, and eventually parse errorBody to convert it to a MatrixError
*/ */
internal fun <T> Response<T>.toFailure(): Failure { internal fun <T> Response<T>.toFailure(eventBus: EventBus?): Failure {
return toFailure(errorBody(), code()) return toFailure(errorBody(), code(), eventBus)
} }
/** /**
* Convert a okhttp3 Response to a Failure, and eventually parse errorBody to convert it to a MatrixError * Convert a okhttp3 Response to a Failure, and eventually parse errorBody to convert it to a MatrixError
*/ */
internal fun okhttp3.Response.toFailure(): Failure { internal fun okhttp3.Response.toFailure(eventBus: EventBus?): Failure {
return toFailure(body, code) 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) { if (errorBody == null) {
return Failure.Unknown(RuntimeException("errorBody should not be 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 != null) {
if (matrixError.code == MatrixError.M_CONSENT_NOT_GIVEN && !matrixError.consentUri.isNullOrBlank()) { if (matrixError.code == MatrixError.M_CONSENT_NOT_GIVEN && !matrixError.consentUri.isNullOrBlank()) {
// Also send this error to the bus, for a global management // 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 */ } else if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED /* 401 */
&& matrixError.code == MatrixError.M_UNKNOWN_TOKEN) { && matrixError.code == MatrixError.M_UNKNOWN_TOKEN) {
// Also send this error to the bus, for a global management // 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) return Failure.ServerError(matrixError, httpCode)

View File

@ -17,7 +17,6 @@
package im.vector.matrix.android.internal.session package im.vector.matrix.android.internal.session
import android.content.Context import android.content.Context
import android.os.Looper
import androidx.annotation.MainThread import androidx.annotation.MainThread
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import dagger.Lazy import dagger.Lazy
@ -62,6 +61,7 @@ import javax.inject.Provider
@SessionScope @SessionScope
internal class DefaultSession @Inject constructor(override val sessionParams: SessionParams, internal class DefaultSession @Inject constructor(override val sessionParams: SessionParams,
private val context: Context, private val context: Context,
private val eventBus: EventBus,
private val liveEntityObservers: Set<@JvmSuppressWildcards LiveEntityObserver>, private val liveEntityObservers: Set<@JvmSuppressWildcards LiveEntityObserver>,
private val sessionListeners: SessionListeners, private val sessionListeners: SessionListeners,
private val roomService: Lazy<RoomService>, 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 initialSyncProgressService: Lazy<InitialSyncProgressService>,
private val homeServerCapabilitiesService: Lazy<HomeServerCapabilitiesService>) private val homeServerCapabilitiesService: Lazy<HomeServerCapabilitiesService>)
: Session, : Session,
RoomService by roomService.get(), RoomService by roomService.get(),
RoomDirectoryService by roomDirectoryService.get(), RoomDirectoryService by roomDirectoryService.get(),
GroupService by groupService.get(), GroupService by groupService.get(),
UserService by userService.get(), UserService by userService.get(),
CryptoService by cryptoService.get(), CryptoService by cryptoService.get(),
SignOutService by signOutService.get(), SignOutService by signOutService.get(),
FilterService by filterService.get(), FilterService by filterService.get(),
PushRuleService by pushRuleService.get(), PushRuleService by pushRuleService.get(),
PushersService by pushersService.get(), PushersService by pushersService.get(),
FileService by fileService.get(), FileService by fileService.get(),
InitialSyncProgressService by initialSyncProgressService.get(), InitialSyncProgressService by initialSyncProgressService.get(),
SecureStorageService by secureStorageService.get(), SecureStorageService by secureStorageService.get(),
HomeServerCapabilitiesService by homeServerCapabilitiesService.get() { HomeServerCapabilitiesService by homeServerCapabilitiesService.get() {
private var isOpen = false private var isOpen = false
@ -111,7 +111,7 @@ internal class DefaultSession @Inject constructor(override val sessionParams: Se
assert(!isOpen) assert(!isOpen)
isOpen = true isOpen = true
liveEntityObservers.forEach { it.start() } liveEntityObservers.forEach { it.start() }
EventBus.getDefault().register(this) eventBus.register(this)
} }
override fun requireBackgroundSync() { override fun requireBackgroundSync() {
@ -151,7 +151,7 @@ internal class DefaultSession @Inject constructor(override val sessionParams: Se
liveEntityObservers.forEach { it.dispose() } liveEntityObservers.forEach { it.dispose() }
cryptoService.get().close() cryptoService.get().close()
isOpen = false isOpen = false
EventBus.getDefault().unregister(this) eventBus.unregister(this)
syncTaskSequencer.close() syncTaskSequencer.close()
} }
@ -179,7 +179,7 @@ internal class DefaultSession @Inject constructor(override val sessionParams: Se
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
fun onGlobalError(globalError: GlobalError) { fun onGlobalError(globalError: GlobalError) {
if (globalError is GlobalError.InvalidToken if (globalError is GlobalError.InvalidToken
&& globalError.softLogout) { && globalError.softLogout) {
// Mark the token has invalid // Mark the token has invalid
GlobalScope.launch(Dispatchers.IO) { GlobalScope.launch(Dispatchers.IO) {
sessionParamsStore.setTokenInvalid(myUserId) 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 im.vector.matrix.android.internal.util.md5
import io.realm.RealmConfiguration import io.realm.RealmConfiguration
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import org.greenrobot.eventbus.EventBus
import retrofit2.Retrofit import retrofit2.Retrofit
import java.io.File import java.io.File
@ -154,6 +155,13 @@ internal abstract class SessionModule {
return retrofitFactory return retrofitFactory
.create(okHttpClient, sessionParams.homeServerConnectionConfig.homeServerUri.toString()) .create(okHttpClient, sessionParams.homeServerConnectionConfig.homeServerUri.toString())
} }
@JvmStatic
@Provides
@SessionScope
fun providesEventBus(): EventBus {
return EventBus.builder().build()
}
} }
@Binds @Binds

View File

@ -29,12 +29,14 @@ import okhttp3.Request
import okhttp3.RequestBody import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.asRequestBody import okhttp3.RequestBody.Companion.asRequestBody
import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.RequestBody.Companion.toRequestBody
import org.greenrobot.eventbus.EventBus
import java.io.File import java.io.File
import java.io.IOException import java.io.IOException
import javax.inject.Inject import javax.inject.Inject
internal class FileUploader @Inject constructor(@Authenticated internal class FileUploader @Inject constructor(@Authenticated
private val okHttpClient: OkHttpClient, private val okHttpClient: OkHttpClient,
private val eventBus: EventBus,
sessionParams: SessionParams, sessionParams: SessionParams,
moshi: Moshi) { moshi: Moshi) {
@ -73,7 +75,7 @@ internal class FileUploader @Inject constructor(@Authenticated
return okHttpClient.newCall(request).awaitResponse().use { response -> return okHttpClient.newCall(request).awaitResponse().use { response ->
if (!response.isSuccessful) { if (!response.isSuccessful) {
throw response.toFailure() throw response.toFailure(eventBus)
} else { } else {
response.body?.source()?.let { response.body?.source()?.let {
responseAdapter.fromJson(it) 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.di.UserId
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject 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, internal class DefaultSaveFilterTask @Inject constructor(
private val filterAPI: FilterApi, @UserId private val userId: String,
private val filterRepository: FilterRepository private val filterAPI: FilterApi,
private val filterRepository: FilterRepository,
private val eventBus: EventBus
) : SaveFilterTask { ) : SaveFilterTask {
override suspend fun execute(params: SaveFilterTask.Params) { 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) val updated = filterRepository.storeFilter(filterBody, roomFilter)
if (updated) { if (updated) {
val filterResponse = executeRequest<FilterResponse> { val filterResponse = executeRequest<FilterResponse>(eventBus) {
// TODO auto retry // TODO auto retry
apiCall = filterAPI.uploadFilter(userId, filterBody) 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.GroupSummaryResponse
import im.vector.matrix.android.internal.session.group.model.GroupUsers import im.vector.matrix.android.internal.session.group.model.GroupUsers
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetGroupDataTask : Task<GetGroupDataTask.Params, Unit> { internal interface GetGroupDataTask : Task<GetGroupDataTask.Params, Unit> {
@ -34,18 +35,19 @@ internal interface GetGroupDataTask : Task<GetGroupDataTask.Params, Unit> {
internal class DefaultGetGroupDataTask @Inject constructor( internal class DefaultGetGroupDataTask @Inject constructor(
private val groupAPI: GroupAPI, private val groupAPI: GroupAPI,
private val monarchy: Monarchy private val monarchy: Monarchy,
private val eventBus: EventBus
) : GetGroupDataTask { ) : GetGroupDataTask {
override suspend fun execute(params: GetGroupDataTask.Params) { override suspend fun execute(params: GetGroupDataTask.Params) {
val groupId = params.groupId val groupId = params.groupId
val groupSummary = executeRequest<GroupSummaryResponse> { val groupSummary = executeRequest<GroupSummaryResponse>(eventBus) {
apiCall = groupAPI.getSummary(groupId) apiCall = groupAPI.getSummary(groupId)
} }
val groupRooms = executeRequest<GroupRooms> { val groupRooms = executeRequest<GroupRooms>(eventBus) {
apiCall = groupAPI.getRooms(groupId) apiCall = groupAPI.getRooms(groupId)
} }
val groupUsers = executeRequest<GroupUsers> { val groupUsers = executeRequest<GroupUsers>(eventBus) {
apiCall = groupAPI.getUsers(groupId) apiCall = groupAPI.getUsers(groupId)
} }
insertInDb(groupSummary, groupRooms, groupUsers, 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.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import im.vector.matrix.android.internal.util.awaitTransaction import im.vector.matrix.android.internal.util.awaitTransaction
import java.util.Date import org.greenrobot.eventbus.EventBus
import java.util.*
import javax.inject.Inject import javax.inject.Inject
internal interface GetHomeServerCapabilitiesTask : Task<Unit, Unit> internal interface GetHomeServerCapabilitiesTask : Task<Unit, Unit>
internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor( internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
private val capabilitiesAPI: CapabilitiesAPI, private val capabilitiesAPI: CapabilitiesAPI,
private val monarchy: Monarchy private val monarchy: Monarchy,
private val eventBus: EventBus
) : GetHomeServerCapabilitiesTask { ) : GetHomeServerCapabilitiesTask {
override suspend fun execute(params: Unit) { override suspend fun execute(params: Unit) {
@ -45,7 +47,7 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
return return
} }
val uploadCapabilities = executeRequest<GetUploadCapabilitiesResult> { val uploadCapabilities = executeRequest<GetUploadCapabilitiesResult>(eventBus) {
apiCall = capabilitiesAPI.getUploadCapabilities() 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.util.awaitTransaction
import im.vector.matrix.android.internal.worker.WorkerParamsFactory import im.vector.matrix.android.internal.worker.WorkerParamsFactory
import im.vector.matrix.android.internal.worker.getSessionComponent import im.vector.matrix.android.internal.worker.getSessionComponent
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal class AddHttpPusherWorker(context: Context, params: WorkerParameters) 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 pushersAPI: PushersAPI
@Inject lateinit var monarchy: Monarchy @Inject lateinit var monarchy: Monarchy
@Inject lateinit var eventBus: EventBus
override suspend fun doWork(): Result { override suspend fun doWork(): Result {
val params = WorkerParamsFactory.fromData<Params>(inputData) val params = WorkerParamsFactory.fromData<Params>(inputData)
@ -76,7 +78,7 @@ internal class AddHttpPusherWorker(context: Context, params: WorkerParameters)
} }
private suspend fun setPusher(pusher: JsonPusher) { private suspend fun setPusher(pusher: JsonPusher) {
executeRequest<Unit> { executeRequest<Unit>(eventBus) {
apiCall = pushersAPI.setPusher(pusher) apiCall = pushersAPI.setPusher(pusher)
} }
monarchy.awaitTransaction { realm -> 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.api.pushrules.rest.PushRule
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface AddPushRuleTask : Task<AddPushRuleTask.Params, Unit> { 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) internal class DefaultAddPushRuleTask @Inject constructor(
: AddPushRuleTask { private val pushRulesApi: PushRulesApi,
private val eventBus: EventBus
) : AddPushRuleTask {
override suspend fun execute(params: AddPushRuleTask.Params) { override suspend fun execute(params: AddPushRuleTask.Params) {
return executeRequest { return executeRequest(eventBus) {
apiCall = pushRulesApi.addRule(params.kind.value, params.pushRule.ruleId, params.pushRule) 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.api.pushrules.rest.GetPushRulesResponse
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetPushRulesTask : Task<GetPushRulesTask.Params, Unit> { 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 * 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, internal class DefaultGetPushRulesTask @Inject constructor(
private val savePushRulesTask: SavePushRulesTask) : GetPushRulesTask { private val pushRulesApi: PushRulesApi,
private val savePushRulesTask: SavePushRulesTask,
private val eventBus: EventBus
) : GetPushRulesTask {
override suspend fun execute(params: GetPushRulesTask.Params) { override suspend fun execute(params: GetPushRulesTask.Params) {
val response = executeRequest<GetPushRulesResponse> { val response = executeRequest<GetPushRulesResponse>(eventBus) {
apiCall = pushRulesApi.getAllRules() 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.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import im.vector.matrix.android.internal.util.awaitTransaction import im.vector.matrix.android.internal.util.awaitTransaction
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetPushersTask : Task<Unit, Unit> internal interface GetPushersTask : Task<Unit, Unit>
internal class DefaultGetPushersTask @Inject constructor(private val pushersAPI: PushersAPI, internal class DefaultGetPushersTask @Inject constructor(
private val monarchy: Monarchy) : GetPushersTask { private val pushersAPI: PushersAPI,
private val monarchy: Monarchy,
private val eventBus: EventBus
) : GetPushersTask {
override suspend fun execute(params: Unit) { override suspend fun execute(params: Unit) {
val response = executeRequest<GetPushersResponse> { val response = executeRequest<GetPushersResponse>(eventBus) {
apiCall = pushersAPI.getPushers() apiCall = pushersAPI.getPushers()
} }
monarchy.awaitTransaction { realm -> 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.api.pushrules.rest.PushRule
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface RemovePushRuleTask : Task<RemovePushRuleTask.Params, Unit> { 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) internal class DefaultRemovePushRuleTask @Inject constructor(
: RemovePushRuleTask { private val pushRulesApi: PushRulesApi,
private val eventBus: EventBus
) : RemovePushRuleTask {
override suspend fun execute(params: RemovePushRuleTask.Params) { override suspend fun execute(params: RemovePushRuleTask.Params) {
return executeRequest { return executeRequest(eventBus) {
apiCall = pushRulesApi.deleteRule(params.kind.value, params.pushRule.ruleId) 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.task.Task
import im.vector.matrix.android.internal.util.awaitTransaction import im.vector.matrix.android.internal.util.awaitTransaction
import io.realm.Realm import io.realm.Realm
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface RemovePusherTask : Task<RemovePusherTask.Params, Unit> { internal interface RemovePusherTask : Task<RemovePusherTask.Params, Unit> {
@ -34,7 +35,8 @@ internal interface RemovePusherTask : Task<RemovePusherTask.Params, Unit> {
internal class DefaultRemovePusherTask @Inject constructor( internal class DefaultRemovePusherTask @Inject constructor(
private val pushersAPI: PushersAPI, private val pushersAPI: PushersAPI,
private val monarchy: Monarchy private val monarchy: Monarchy,
private val eventBus: EventBus
) : RemovePusherTask { ) : RemovePusherTask {
override suspend fun execute(params: RemovePusherTask.Params) { override suspend fun execute(params: RemovePusherTask.Params) {
@ -59,7 +61,7 @@ internal class DefaultRemovePusherTask @Inject constructor(
data = JsonPusherData(existing.data.url, existing.data.format), data = JsonPusherData(existing.data.url, existing.data.format),
append = false append = false
) )
executeRequest<Unit> { executeRequest<Unit>(eventBus) {
apiCall = pushersAPI.setPusher(deleteBody) apiCall = pushersAPI.setPusher(deleteBody)
} }
monarchy.awaitTransaction { 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.api.pushrules.rest.PushRule
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface UpdatePushRuleEnableStatusTask : Task<UpdatePushRuleEnableStatusTask.Params, Unit> { internal interface UpdatePushRuleEnableStatusTask : Task<UpdatePushRuleEnableStatusTask.Params, Unit> {
@ -27,11 +28,13 @@ internal interface UpdatePushRuleEnableStatusTask : Task<UpdatePushRuleEnableSta
val enabled: Boolean) val enabled: Boolean)
} }
internal class DefaultUpdatePushRuleEnableStatusTask @Inject constructor(private val pushRulesApi: PushRulesApi) internal class DefaultUpdatePushRuleEnableStatusTask @Inject constructor(
: UpdatePushRuleEnableStatusTask { private val pushRulesApi: PushRulesApi,
private val eventBus: EventBus
) : UpdatePushRuleEnableStatusTask {
override suspend fun execute(params: UpdatePushRuleEnableStatusTask.Params) { override suspend fun execute(params: UpdatePushRuleEnableStatusTask.Params) {
return executeRequest { return executeRequest(eventBus) {
apiCall = pushRulesApi.updateEnableRuleStatus(params.kind.value, params.pushRule.ruleId, params.enabled) 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.session.room.RoomAPI
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import io.realm.Realm import io.realm.Realm
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetRoomIdByAliasTask : Task<GetRoomIdByAliasTask.Params, Optional<String>> { 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, internal class DefaultGetRoomIdByAliasTask @Inject constructor(
private val roomAPI: RoomAPI) : GetRoomIdByAliasTask { private val monarchy: Monarchy,
private val roomAPI: RoomAPI,
private val eventBus: EventBus
) : GetRoomIdByAliasTask {
override suspend fun execute(params: GetRoomIdByAliasTask.Params): Optional<String> { override suspend fun execute(params: GetRoomIdByAliasTask.Params): Optional<String> {
var roomId = Realm.getInstance(monarchy.realmConfiguration).use { var roomId = Realm.getInstance(monarchy.realmConfiguration).use {
@ -45,7 +49,7 @@ internal class DefaultGetRoomIdByAliasTask @Inject constructor(private val monar
} else if (!params.searchOnServer) { } else if (!params.searchOnServer) {
Optional.from<String>(null) Optional.from<String>(null)
} else { } else {
roomId = executeRequest<RoomAliasDescription> { roomId = executeRequest<RoomAliasDescription>(eventBus) {
apiCall = roomAPI.getRoomIdByAlias(params.roomAlias) apiCall = roomAPI.getRoomIdByAlias(params.roomAlias)
}.roomId }.roomId
Optional.from(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 im.vector.matrix.android.internal.util.awaitTransaction
import io.realm.RealmConfiguration import io.realm.RealmConfiguration
import kotlinx.coroutines.TimeoutCancellationException import kotlinx.coroutines.TimeoutCancellationException
import org.greenrobot.eventbus.EventBus
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
internal interface CreateRoomTask : Task<CreateRoomParams, String> internal interface CreateRoomTask : Task<CreateRoomParams, String>
internal class DefaultCreateRoomTask @Inject constructor(private val roomAPI: RoomAPI, internal class DefaultCreateRoomTask @Inject constructor(
private val monarchy: Monarchy, private val roomAPI: RoomAPI,
private val directChatsHelper: DirectChatsHelper, private val monarchy: Monarchy,
private val updateUserAccountDataTask: UpdateUserAccountDataTask, private val directChatsHelper: DirectChatsHelper,
private val readMarkersTask: SetReadMarkersTask, private val updateUserAccountDataTask: UpdateUserAccountDataTask,
@SessionDatabase private val readMarkersTask: SetReadMarkersTask,
private val realmConfiguration: RealmConfiguration) : CreateRoomTask { @SessionDatabase
private val realmConfiguration: RealmConfiguration,
private val eventBus: EventBus
) : CreateRoomTask {
override suspend fun execute(params: CreateRoomParams): String { override suspend fun execute(params: CreateRoomParams): String {
val createRoomResponse = executeRequest<CreateRoomResponse> { val createRoomResponse = executeRequest<CreateRoomResponse>(eventBus) {
apiCall = roomAPI.createRoom(params) apiCall = roomAPI.createRoom(params)
} }
val roomId = createRoomResponse.roomId!! 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.network.executeRequest
import im.vector.matrix.android.internal.session.room.RoomAPI import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetPublicRoomTask : Task<GetPublicRoomTask.Params, PublicRoomsResponse> { 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 { override suspend fun execute(params: GetPublicRoomTask.Params): PublicRoomsResponse {
return executeRequest { return executeRequest(eventBus) {
apiCall = roomAPI.publicRooms(params.server, params.publicRoomsParams) 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.network.executeRequest
import im.vector.matrix.android.internal.session.room.RoomAPI import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetThirdPartyProtocolsTask : Task<Unit, Map<String, ThirdPartyProtocol>> 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> { override suspend fun execute(params: Unit): Map<String, ThirdPartyProtocol> {
return executeRequest { return executeRequest(eventBus) {
apiCall = roomAPI.thirdPartyProtocols() 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 im.vector.matrix.android.internal.util.awaitTransaction
import io.realm.Realm import io.realm.Realm
import io.realm.kotlin.createObject import io.realm.kotlin.createObject
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface LoadRoomMembersTask : Task<LoadRoomMembersTask.Params, Unit> { 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, internal class DefaultLoadRoomMembersTask @Inject constructor(
private val monarchy: Monarchy, private val roomAPI: RoomAPI,
private val syncTokenStore: SyncTokenStore, private val monarchy: Monarchy,
private val roomSummaryUpdater: RoomSummaryUpdater, private val syncTokenStore: SyncTokenStore,
private val roomMemberEventHandler: RoomMemberEventHandler, private val roomSummaryUpdater: RoomSummaryUpdater,
private val timelineEventSenderVisitor: TimelineEventSenderVisitor private val roomMemberEventHandler: RoomMemberEventHandler,
private val timelineEventSenderVisitor: TimelineEventSenderVisitor,
private val eventBus: EventBus
) : LoadRoomMembersTask { ) : LoadRoomMembersTask {
override suspend fun execute(params: LoadRoomMembersTask.Params) { override suspend fun execute(params: LoadRoomMembersTask.Params) {
@ -53,7 +56,7 @@ internal class DefaultLoadRoomMembersTask @Inject constructor(private val roomAP
return return
} }
val lastToken = syncTokenStore.getLastToken() val lastToken = syncTokenStore.getLastToken()
val response = executeRequest<RoomMembersResponse> { val response = executeRequest<RoomMembersResponse>(eventBus) {
apiCall = roomAPI.getMembers(params.roomId, lastToken, null, params.excludeMembership?.value) apiCall = roomAPI.getMembers(params.roomId, lastToken, null, params.excludeMembership?.value)
} }
insertInDb(response, params.roomId) 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.network.executeRequest
import im.vector.matrix.android.internal.session.room.RoomAPI import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface InviteTask : Task<InviteTask.Params, Unit> { 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) { override suspend fun execute(params: InviteTask.Params) {
return executeRequest { return executeRequest(eventBus) {
val body = InviteBody(params.userId, params.reason) val body = InviteBody(params.userId, params.reason)
apiCall = roomAPI.invite(params.roomId, body) 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 im.vector.matrix.android.internal.task.Task
import io.realm.RealmConfiguration import io.realm.RealmConfiguration
import kotlinx.coroutines.TimeoutCancellationException import kotlinx.coroutines.TimeoutCancellationException
import org.greenrobot.eventbus.EventBus
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
@ -38,13 +39,16 @@ internal interface JoinRoomTask : Task<JoinRoomTask.Params, Unit> {
) )
} }
internal class DefaultJoinRoomTask @Inject constructor(private val roomAPI: RoomAPI, internal class DefaultJoinRoomTask @Inject constructor(
private val readMarkersTask: SetReadMarkersTask, private val roomAPI: RoomAPI,
@SessionDatabase private val readMarkersTask: SetReadMarkersTask,
private val realmConfiguration: RealmConfiguration) : JoinRoomTask { @SessionDatabase
private val realmConfiguration: RealmConfiguration,
private val eventBus: EventBus
) : JoinRoomTask {
override suspend fun execute(params: JoinRoomTask.Params) { override suspend fun execute(params: JoinRoomTask.Params) {
executeRequest<Unit> { executeRequest<Unit>(eventBus) {
apiCall = roomAPI.join(params.roomId, params.viaServers, mapOf("reason" to params.reason)) 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) // 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.network.executeRequest
import im.vector.matrix.android.internal.session.room.RoomAPI import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface LeaveRoomTask : Task<LeaveRoomTask.Params, Unit> { 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) { override suspend fun execute(params: LeaveRoomTask.Params) {
return executeRequest { return executeRequest(eventBus) {
apiCall = roomAPI.leave(params.roomId, mapOf("reason" to params.reason)) 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.api.session.events.model.LocalEcho
import im.vector.matrix.android.internal.database.model.RoomSummaryEntity 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.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.latestEvent
import im.vector.matrix.android.internal.database.query.where import im.vector.matrix.android.internal.database.query.where
import im.vector.matrix.android.internal.di.UserId 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.task.Task
import im.vector.matrix.android.internal.util.awaitTransaction import im.vector.matrix.android.internal.util.awaitTransaction
import io.realm.Realm import io.realm.Realm
import org.greenrobot.eventbus.EventBus
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
import kotlin.collections.HashMap
import kotlin.collections.set
internal interface SetReadMarkersTask : Task<SetReadMarkersTask.Params, Unit> { 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_MARKER = "m.fully_read"
private const val READ_RECEIPT = "m.read" private const val READ_RECEIPT = "m.read"
internal class DefaultSetReadMarkersTask @Inject constructor(private val roomAPI: RoomAPI, internal class DefaultSetReadMarkersTask @Inject constructor(
private val monarchy: Monarchy, private val roomAPI: RoomAPI,
private val roomFullyReadHandler: RoomFullyReadHandler, private val monarchy: Monarchy,
private val readReceiptHandler: ReadReceiptHandler, private val roomFullyReadHandler: RoomFullyReadHandler,
@UserId private val userId: String) private val readReceiptHandler: ReadReceiptHandler,
: SetReadMarkersTask { @UserId private val userId: String,
private val eventBus: EventBus
) : SetReadMarkersTask {
override suspend fun execute(params: SetReadMarkersTask.Params) { override suspend fun execute(params: SetReadMarkersTask.Params) {
val markers = HashMap<String, String>() val markers = HashMap<String, String>()
@ -76,7 +82,7 @@ internal class DefaultSetReadMarkersTask @Inject constructor(private val roomAPI
} }
if (readReceiptEventId != null if (readReceiptEventId != null
&& !isEventRead(monarchy, userId, params.roomId, readReceiptEventId)) { && !isEventRead(monarchy, userId, params.roomId, readReceiptEventId)) {
if (LocalEcho.isLocalEchoId(readReceiptEventId)) { if (LocalEcho.isLocalEchoId(readReceiptEventId)) {
Timber.w("Can't set read receipt for local event $readReceiptEventId") Timber.w("Can't set read receipt for local event $readReceiptEventId")
} else { } else {
@ -87,7 +93,7 @@ internal class DefaultSetReadMarkersTask @Inject constructor(private val roomAPI
return return
} }
updateDatabase(params.roomId, markers) updateDatabase(params.roomId, markers)
executeRequest<Unit> { executeRequest<Unit>(eventBus) {
apiCall = roomAPI.sendReadMarker(params.roomId, markers) 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 val isLatestReceived = TimelineEventEntity.latestEvent(realm, roomId = roomId, includesSending = false)?.eventId == readReceiptId
if (isLatestReceived) { if (isLatestReceived) {
val roomSummary = RoomSummaryEntity.where(realm, roomId).findFirst() val roomSummary = RoomSummaryEntity.where(realm, roomId).findFirst()
?: return@awaitTransaction ?: return@awaitTransaction
roomSummary.notificationCount = 0 roomSummary.notificationCount = 0
roomSummary.highlightCount = 0 roomSummary.highlightCount = 0
roomSummary.hasUnreadMessages = false 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.network.executeRequest
import im.vector.matrix.android.internal.session.room.RoomAPI import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface FetchEditHistoryTask : Task<FetchEditHistoryTask.Params, List<Event>> { internal interface FetchEditHistoryTask : Task<FetchEditHistoryTask.Params, List<Event>> {
@ -33,11 +34,12 @@ internal interface FetchEditHistoryTask : Task<FetchEditHistoryTask.Params, List
} }
internal class DefaultFetchEditHistoryTask @Inject constructor( internal class DefaultFetchEditHistoryTask @Inject constructor(
private val roomAPI: RoomAPI private val roomAPI: RoomAPI,
private val eventBus: EventBus
) : FetchEditHistoryTask { ) : FetchEditHistoryTask {
override suspend fun execute(params: FetchEditHistoryTask.Params): List<Event> { override suspend fun execute(params: FetchEditHistoryTask.Params): List<Event> {
val response = executeRequest<RelationsResponse> { val response = executeRequest<RelationsResponse>(eventBus) {
apiCall = roomAPI.getRelations(params.roomId, apiCall = roomAPI.getRelations(params.roomId,
params.eventId, params.eventId,
RelationType.REPLACE, 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.SessionWorkerParams
import im.vector.matrix.android.internal.worker.WorkerParamsFactory import im.vector.matrix.android.internal.worker.WorkerParamsFactory
import im.vector.matrix.android.internal.worker.getSessionComponent import im.vector.matrix.android.internal.worker.getSessionComponent
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal class SendRelationWorker(context: Context, params: WorkerParameters) : CoroutineWorker(context, params) { internal class SendRelationWorker(context: Context, params: WorkerParameters) : CoroutineWorker(context, params) {
@ -44,6 +45,7 @@ internal class SendRelationWorker(context: Context, params: WorkerParameters) :
) : SessionWorkerParams ) : SessionWorkerParams
@Inject lateinit var roomAPI: RoomAPI @Inject lateinit var roomAPI: RoomAPI
@Inject lateinit var eventBus: EventBus
override suspend fun doWork(): Result { override suspend fun doWork(): Result {
val params = WorkerParamsFactory.fromData<Params>(inputData) 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) { private suspend fun sendRelation(roomId: String, relationType: String, relatedEventId: String, localEvent: Event) {
executeRequest<SendResponse> { executeRequest<SendResponse>(eventBus) {
apiCall = roomAPI.sendRelation( apiCall = roomAPI.sendRelation(
roomId = roomId, roomId = roomId,
parent_id = relatedEventId, 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.network.executeRequest
import im.vector.matrix.android.internal.session.room.RoomAPI import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface ReportContentTask : Task<ReportContentTask.Params, Unit> { 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) { override suspend fun execute(params: ReportContentTask.Params) {
return executeRequest { return executeRequest(eventBus) {
apiCall = roomAPI.reportContent(params.roomId, params.eventId, ReportContentBody(params.score, params.reason)) 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.SessionWorkerParams
import im.vector.matrix.android.internal.worker.WorkerParamsFactory import im.vector.matrix.android.internal.worker.WorkerParamsFactory
import im.vector.matrix.android.internal.worker.getSessionComponent import im.vector.matrix.android.internal.worker.getSessionComponent
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal class RedactEventWorker(context: Context, params: WorkerParameters) : CoroutineWorker(context, params) { internal class RedactEventWorker(context: Context, params: WorkerParameters) : CoroutineWorker(context, params) {
@ -40,6 +41,7 @@ internal class RedactEventWorker(context: Context, params: WorkerParameters) : C
) : SessionWorkerParams ) : SessionWorkerParams
@Inject lateinit var roomAPI: RoomAPI @Inject lateinit var roomAPI: RoomAPI
@Inject lateinit var eventBus: EventBus
override suspend fun doWork(): Result { override suspend fun doWork(): Result {
val params = WorkerParamsFactory.fromData<Params>(inputData) val params = WorkerParamsFactory.fromData<Params>(inputData)
@ -55,7 +57,7 @@ internal class RedactEventWorker(context: Context, params: WorkerParameters) : C
val eventId = params.eventId val eventId = params.eventId
return runCatching { return runCatching {
executeRequest<SendResponse> { executeRequest<SendResponse>(eventBus) {
apiCall = roomAPI.redactEvent( apiCall = roomAPI.redactEvent(
params.txID, params.txID,
params.roomId, 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.SessionWorkerParams
import im.vector.matrix.android.internal.worker.WorkerParamsFactory import im.vector.matrix.android.internal.worker.WorkerParamsFactory
import im.vector.matrix.android.internal.worker.getSessionComponent import im.vector.matrix.android.internal.worker.getSessionComponent
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal class SendEventWorker constructor(context: Context, params: WorkerParameters) 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 localEchoUpdater: LocalEchoUpdater
@Inject lateinit var roomAPI: RoomAPI @Inject lateinit var roomAPI: RoomAPI
@Inject lateinit var eventBus: EventBus
override suspend fun doWork(): Result { override suspend fun doWork(): Result {
val params = WorkerParamsFactory.fromData<Params>(inputData) 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) { private suspend fun sendEvent(eventId: String, eventType: String, content: Content?, roomId: String) {
localEchoUpdater.updateSendState(eventId, SendState.SENDING) localEchoUpdater.updateSendState(eventId, SendState.SENDING)
executeRequest<SendResponse> { executeRequest<SendResponse>(eventBus) {
apiCall = roomAPI.send( apiCall = roomAPI.send(
eventId, eventId,
roomId, 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.network.executeRequest
import im.vector.matrix.android.internal.session.room.RoomAPI import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface SendStateTask : Task<SendStateTask.Params, Unit> { 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) { override suspend fun execute(params: SendStateTask.Params) {
return executeRequest { return executeRequest(eventBus) {
apiCall = roomAPI.sendStateEvent(params.roomId, params.eventType, params.body) 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.filter.FilterRepository
import im.vector.matrix.android.internal.session.room.RoomAPI import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface GetContextOfEventTask : Task<GetContextOfEventTask.Params, TokenChunkEventPersistor.Result> { 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, internal class DefaultGetContextOfEventTask @Inject constructor(
private val filterRepository: FilterRepository, private val roomAPI: RoomAPI,
private val tokenChunkEventPersistor: TokenChunkEventPersistor private val filterRepository: FilterRepository,
private val tokenChunkEventPersistor: TokenChunkEventPersistor,
private val eventBus: EventBus
) : GetContextOfEventTask { ) : GetContextOfEventTask {
override suspend fun execute(params: GetContextOfEventTask.Params): TokenChunkEventPersistor.Result { override suspend fun execute(params: GetContextOfEventTask.Params): TokenChunkEventPersistor.Result {
val filter = filterRepository.getRoomFilter() val filter = filterRepository.getRoomFilter()
val response = executeRequest<EventContextResponse> { val response = executeRequest<EventContextResponse>(eventBus) {
apiCall = roomAPI.getContextOfEvent(params.roomId, params.eventId, params.limit, filter) apiCall = roomAPI.getContextOfEvent(params.roomId, params.eventId, params.limit, filter)
} }
return tokenChunkEventPersistor.insertInDb(response, params.roomId, PaginationDirection.BACKWARDS) 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.filter.FilterRepository
import im.vector.matrix.android.internal.session.room.RoomAPI import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface PaginationTask : Task<PaginationTask.Params, TokenChunkEventPersistor.Result> { 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, internal class DefaultPaginationTask @Inject constructor(
private val filterRepository: FilterRepository, private val roomAPI: RoomAPI,
private val tokenChunkEventPersistor: TokenChunkEventPersistor private val filterRepository: FilterRepository,
private val tokenChunkEventPersistor: TokenChunkEventPersistor,
private val eventBus: EventBus
) : PaginationTask { ) : PaginationTask {
override suspend fun execute(params: PaginationTask.Params): TokenChunkEventPersistor.Result { override suspend fun execute(params: PaginationTask.Params): TokenChunkEventPersistor.Result {
val filter = filterRepository.getRoomFilter() 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) apiCall = roomAPI.getRoomMessagesFrom(params.roomId, params.from, params.direction.value, params.limit, filter)
} }
return tokenChunkEventPersistor.insertInDb(chunk, params.roomId, params.direction) 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.network.executeRequest
import im.vector.matrix.android.internal.session.room.RoomAPI import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject 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> { ) : Task<GetEventTask.Params, Event> {
internal data class Params( internal data class Params(
@ -31,7 +34,7 @@ internal class GetEventTask @Inject constructor(private val roomAPI: RoomAPI
) )
override suspend fun execute(params: Params): Event { override suspend fun execute(params: Params): Event {
return executeRequest { return executeRequest(eventBus) {
apiCall = roomAPI.getEvent(params.roomId, params.eventId) 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.auth.data.PasswordLoginParams
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface SignInAgainTask : Task<SignInAgainTask.Params, Unit> { internal interface SignInAgainTask : Task<SignInAgainTask.Params, Unit> {
@ -33,10 +34,12 @@ internal interface SignInAgainTask : Task<SignInAgainTask.Params, Unit> {
internal class DefaultSignInAgainTask @Inject constructor( internal class DefaultSignInAgainTask @Inject constructor(
private val signOutAPI: SignOutAPI, private val signOutAPI: SignOutAPI,
private val sessionParams: SessionParams, 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) { override suspend fun execute(params: SignInAgainTask.Params) {
val newCredentials = executeRequest<Credentials> { val newCredentials = executeRequest<Credentials>(eventBus) {
apiCall = signOutAPI.loginAgain( apiCall = signOutAPI.loginAgain(
PasswordLoginParams.userIdentifier( PasswordLoginParams.userIdentifier(
// Reuse the same userId // 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 im.vector.matrix.android.internal.worker.WorkManagerUtil
import io.realm.Realm import io.realm.Realm
import io.realm.RealmConfiguration import io.realm.RealmConfiguration
import org.greenrobot.eventbus.EventBus
import timber.log.Timber import timber.log.Timber
import java.io.File import java.io.File
import java.net.HttpURLConnection import java.net.HttpURLConnection
@ -43,25 +44,28 @@ internal interface SignOutTask : Task<SignOutTask.Params, Unit> {
) )
} }
internal class DefaultSignOutTask @Inject constructor(private val context: Context, internal class DefaultSignOutTask @Inject constructor(
@UserId private val userId: String, private val context: Context,
private val signOutAPI: SignOutAPI, @UserId private val userId: String,
private val sessionManager: SessionManager, private val signOutAPI: SignOutAPI,
private val sessionParamsStore: SessionParamsStore, private val sessionManager: SessionManager,
@SessionDatabase private val clearSessionDataTask: ClearCacheTask, private val sessionParamsStore: SessionParamsStore,
@CryptoDatabase private val clearCryptoDataTask: ClearCacheTask, @SessionDatabase private val clearSessionDataTask: ClearCacheTask,
@UserCacheDirectory private val userFile: File, @CryptoDatabase private val clearCryptoDataTask: ClearCacheTask,
private val realmKeysUtils: RealmKeysUtils, @UserCacheDirectory private val userFile: File,
@SessionDatabase private val realmSessionConfiguration: RealmConfiguration, private val realmKeysUtils: RealmKeysUtils,
@CryptoDatabase private val realmCryptoConfiguration: RealmConfiguration, @SessionDatabase private val realmSessionConfiguration: RealmConfiguration,
@UserMd5 private val userMd5: String) : SignOutTask { @CryptoDatabase private val realmCryptoConfiguration: RealmConfiguration,
@UserMd5 private val userMd5: String,
private val eventBus: EventBus
) : SignOutTask {
override suspend fun execute(params: SignOutTask.Params) { 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 // It should be done even after a soft logout, to be sure the deviceId is deleted on the
if (params.sigOutFromHomeserver) { if (params.sigOutFromHomeserver) {
Timber.d("SignOut: send request...") Timber.d("SignOut: send request...")
try { try {
executeRequest<Unit> { executeRequest<Unit>(eventBus) {
apiCall = signOutAPI.signOut() apiCall = signOutAPI.signOut()
} }
} catch (throwable: Throwable) { } 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.sync.model.SyncResponse
import im.vector.matrix.android.internal.session.user.UserStore import im.vector.matrix.android.internal.session.user.UserStore
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@ -33,15 +34,17 @@ internal interface SyncTask : Task<SyncTask.Params, Unit> {
data class Params(var timeout: Long = 30_000L) data class Params(var timeout: Long = 30_000L)
} }
internal class DefaultSyncTask @Inject constructor(private val syncAPI: SyncAPI, internal class DefaultSyncTask @Inject constructor(
@UserId private val userId: String, private val syncAPI: SyncAPI,
private val filterRepository: FilterRepository, @UserId private val userId: String,
private val syncResponseHandler: SyncResponseHandler, private val filterRepository: FilterRepository,
private val initialSyncProgressService: DefaultInitialSyncProgressService, private val syncResponseHandler: SyncResponseHandler,
private val syncTokenStore: SyncTokenStore, private val initialSyncProgressService: DefaultInitialSyncProgressService,
private val getHomeServerCapabilitiesTask: GetHomeServerCapabilitiesTask, private val syncTokenStore: SyncTokenStore,
private val userStore: UserStore, private val getHomeServerCapabilitiesTask: GetHomeServerCapabilitiesTask,
private val syncTaskSequencer: SyncTaskSequencer private val userStore: UserStore,
private val syncTaskSequencer: SyncTaskSequencer,
private val eventBus: EventBus
) : SyncTask { ) : SyncTask {
override suspend fun execute(params: SyncTask.Params) = syncTaskSequencer.post { 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.endAll()
initialSyncProgressService.startTask(R.string.initial_sync_start_importing_account, 100) initialSyncProgressService.startTask(R.string.initial_sync_start_importing_account, 100)
} }
val syncResponse = executeRequest<SyncResponse> { val syncResponse = executeRequest<SyncResponse>(eventBus) {
apiCall = syncAPI.sync(requestParams) apiCall = syncAPI.sync(requestParams)
} }
syncResponseHandler.handleResponse(syncResponse, token) 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.IgnoredUsersContent
import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountData import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountData
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface UpdateIgnoredUserIdsTask : Task<UpdateIgnoredUserIdsTask.Params, Unit> { 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, internal class DefaultUpdateIgnoredUserIdsTask @Inject constructor(
private val monarchy: Monarchy, private val accountDataApi: AccountDataAPI,
private val saveIgnoredUsersTask: SaveIgnoredUsersTask, private val monarchy: Monarchy,
@UserId private val userId: String) : UpdateIgnoredUserIdsTask { private val saveIgnoredUsersTask: SaveIgnoredUsersTask,
@UserId private val userId: String,
private val eventBus: EventBus
) : UpdateIgnoredUserIdsTask {
override suspend fun execute(params: UpdateIgnoredUserIdsTask.Params) { override suspend fun execute(params: UpdateIgnoredUserIdsTask.Params) {
// Get current list // Get current list
@ -58,7 +62,7 @@ internal class DefaultUpdateIgnoredUserIdsTask @Inject constructor(private val a
val list = ignoredUserIds.toList() val list = ignoredUserIds.toList()
val body = IgnoredUsersContent.createWithUserIds(list) val body = IgnoredUsersContent.createWithUserIds(list)
executeRequest<Unit> { executeRequest<Unit>(eventBus) {
apiCall = accountDataApi.setAccountData(userId, UserAccountData.TYPE_IGNORED_USER_LIST, body) 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.BreadcrumbsContent
import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountData import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountData
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface UpdateUserAccountDataTask : Task<UpdateUserAccountDataTask.Params, Unit> { 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, internal class DefaultUpdateUserAccountDataTask @Inject constructor(
@UserId private val userId: String) : UpdateUserAccountDataTask { private val accountDataApi: AccountDataAPI,
@UserId private val userId: String,
private val eventBus: EventBus
) : UpdateUserAccountDataTask {
override suspend fun execute(params: UpdateUserAccountDataTask.Params) { override suspend fun execute(params: UpdateUserAccountDataTask.Params) {
return executeRequest { return executeRequest(eventBus) {
apiCall = accountDataApi.setAccountData(userId, params.type, params.getData()) 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.network.executeRequest
import im.vector.matrix.android.internal.session.user.SearchUserAPI import im.vector.matrix.android.internal.session.user.SearchUserAPI
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject import javax.inject.Inject
internal interface SearchUserTask : Task<SearchUserTask.Params, List<User>> { 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> { 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)) apiCall = searchUserAPI.searchUsers(SearchUsersParams(params.search, params.limit))
} }
return response.users.map { return response.users.map {