From 6a91c2b355a6e621e91c8831ae204c27360811aa Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 31 Mar 2021 14:21:47 +0200 Subject: [PATCH] Migrate Retrofit interface to coroutine calls --- CHANGES.md | 1 + .../android/sdk/internal/auth/AuthAPI.kt | 27 ++- .../auth/DefaultAuthenticationService.kt | 25 ++- .../auth/IsValidClientServerApiTask.kt | 5 +- .../internal/auth/login/DefaultLoginWizard.kt | 18 +- .../internal/auth/login/DirectLoginTask.kt | 20 +-- .../registration/RegisterAddThreePidTask.kt | 2 +- .../auth/registration/RegisterTask.kt | 2 +- .../auth/registration/ValidateCodeTask.kt | 2 +- .../sdk/internal/crypto/api/CryptoApi.kt | 33 ++-- .../crypto/keysbackup/api/RoomKeysApi.kt | 55 +++--- .../tasks/CreateKeysBackupVersionTask.kt | 2 +- .../keysbackup/tasks/DeleteBackupTask.kt | 2 +- .../tasks/DeleteRoomSessionDataTask.kt | 2 +- .../tasks/DeleteRoomSessionsDataTask.kt | 2 +- .../tasks/DeleteSessionsDataTask.kt | 2 +- .../tasks/GetKeysBackupLastVersionTask.kt | 2 +- .../tasks/GetKeysBackupVersionTask.kt | 2 +- .../tasks/GetRoomSessionDataTask.kt | 2 +- .../tasks/GetRoomSessionsDataTask.kt | 2 +- .../keysbackup/tasks/GetSessionsDataTask.kt | 2 +- .../tasks/StoreRoomSessionDataTask.kt | 2 +- .../tasks/StoreRoomSessionsDataTask.kt | 2 +- .../keysbackup/tasks/StoreSessionsDataTask.kt | 2 +- .../tasks/UpdateKeysBackupVersionTask.kt | 2 +- .../ClaimOneTimeKeysForUsersDeviceTask.kt | 5 +- .../internal/crypto/tasks/DeleteDeviceTask.kt | 4 +- .../crypto/tasks/DownloadKeysForUsersTask.kt | 6 +- .../crypto/tasks/GetDeviceInfoTask.kt | 2 +- .../internal/crypto/tasks/GetDevicesTask.kt | 2 +- .../crypto/tasks/GetKeyChangesTask.kt | 2 +- .../internal/crypto/tasks/RedactEventTask.kt | 7 +- .../internal/crypto/tasks/SendEventTask.kt | 7 +- .../internal/crypto/tasks/SendToDeviceTask.kt | 23 ++- .../tasks/SendVerificationMessageTask.kt | 7 +- .../crypto/tasks/SetDeviceNameTask.kt | 2 +- .../internal/crypto/tasks/UploadKeysTask.kt | 2 +- .../crypto/tasks/UploadSignaturesTask.kt | 14 +- .../crypto/tasks/UploadSigningKeysTask.kt | 5 +- .../sdk/internal/federation/FederationAPI.kt | 3 +- .../federation/GetFederationVersionTask.kt | 4 +- .../android/sdk/internal/network/Request.kt | 41 +++-- .../internal/network/RetrofitExtensions.kt | 8 + .../android/sdk/internal/raw/GetUrlTask.kt | 5 +- .../matrix/android/sdk/internal/raw/RawAPI.kt | 3 +- .../internal/session/account/AccountAPI.kt | 5 +- .../session/account/ChangePasswordTask.kt | 8 +- .../session/account/DeactivateAccountTask.kt | 4 +- .../session/call/GetTurnServerTask.kt | 2 +- .../sdk/internal/session/call/VoipApi.kt | 3 +- .../session/directory/DirectoryAPI.kt | 15 +- .../sdk/internal/session/filter/FilterApi.kt | 9 +- .../internal/session/filter/SaveFilterTask.kt | 4 +- .../session/group/GetGroupDataTask.kt | 12 +- .../sdk/internal/session/group/GroupAPI.kt | 7 +- .../session/homeserver/CapabilitiesAPI.kt | 7 +- .../GetHomeServerCapabilitiesTask.kt | 12 +- .../session/homeserver/HomeServerPinger.kt | 4 +- .../internal/session/identity/IdentityAPI.kt | 17 +- .../session/identity/IdentityAuthAPI.kt | 7 +- .../identity/IdentityBulkLookupTask.kt | 4 +- .../identity/IdentityDisconnectTask.kt | 4 +- .../session/identity/IdentityPingTask.kt | 8 +- .../session/identity/IdentityRegisterTask.kt | 2 +- .../IdentityRequestTokenForBindingTask.kt | 5 +- .../IdentitySubmitTokenForBindingTask.kt | 5 +- .../session/identity/IdentityTaskHelper.kt | 5 +- .../session/media/GetPreviewUrlTask.kt | 4 +- .../session/media/GetRawPreviewUrlTask.kt | 2 +- .../sdk/internal/session/media/MediaAPI.kt | 5 +- .../session/openid/GetOpenIdTokenTask.kt | 2 +- .../sdk/internal/session/openid/OpenIdAPI.kt | 5 +- .../session/profile/AddThreePidTask.kt | 32 ++-- .../session/profile/BindThreePidsTask.kt | 4 +- .../session/profile/DeleteThreePidTask.kt | 12 +- .../profile/FinalizeAddingThreePidTask.kt | 4 +- .../session/profile/GetProfileInfoTask.kt | 2 +- .../internal/session/profile/ProfileAPI.kt | 29 ++-- .../profile/RefreshUserThreePidsTask.kt | 4 +- .../session/profile/SetAvatarUrlTask.kt | 8 +- .../session/profile/SetDisplayNameTask.kt | 8 +- .../session/profile/UnbindThreePidsTask.kt | 4 +- .../session/profile/ValidateSmsCodeTask.kt | 5 +- .../session/pushers/AddHttpPusherWorker.kt | 4 +- .../session/pushers/AddPushRuleTask.kt | 2 +- .../session/pushers/GetPushRulesTask.kt | 5 +- .../session/pushers/GetPushersTask.kt | 4 +- .../internal/session/pushers/PushRulesApi.kt | 29 ++-- .../internal/session/pushers/PushersAPI.kt | 5 +- .../session/pushers/RemovePushRuleTask.kt | 2 +- .../session/pushers/RemovePusherTask.kt | 4 +- .../pushers/UpdatePushRuleActionsTask.kt | 8 +- .../pushers/UpdatePushRuleEnableStatusTask.kt | 2 +- .../session/pushers/gateway/PushGatewayAPI.kt | 3 +- .../pushers/gateway/PushGatewayNotifyTask.kt | 4 +- .../sdk/internal/session/room/RoomAPI.kt | 157 +++++++++--------- .../session/room/alias/AddRoomAliasTask.kt | 4 +- .../session/room/alias/DeleteRoomAliasTask.kt | 4 +- .../room/alias/GetRoomIdByAliasTask.kt | 4 +- .../room/alias/GetRoomLocalAliasesTask.kt | 4 +- .../alias/RoomAliasAvailabilityChecker.kt | 4 +- .../session/room/create/CreateRoomTask.kt | 4 +- .../room/directory/GetPublicRoomTask.kt | 2 +- .../GetRoomDirectoryVisibilityTask.kt | 5 +- .../SetRoomDirectoryVisibilityTask.kt | 4 +- .../room/membership/LoadRoomMembersTask.kt | 4 +- .../membership/admin/MembershipAdminTask.kt | 4 +- .../room/membership/joining/InviteTask.kt | 14 +- .../room/membership/joining/JoinRoomTask.kt | 5 +- .../room/membership/leaving/LeaveRoomTask.kt | 4 +- .../membership/threepid/InviteThreePidTask.kt | 2 +- .../room/peeking/ResolveRoomStateTask.kt | 2 +- .../session/room/read/SetReadMarkersTask.kt | 8 +- .../room/relation/FetchEditHistoryTask.kt | 4 +- .../room/relation/SendRelationWorker.kt | 5 +- .../room/reporting/ReportContentTask.kt | 2 +- .../session/room/send/RedactEventWorker.kt | 4 +- .../session/room/state/SendStateTask.kt | 2 +- .../session/room/tags/AddTagToRoomTask.kt | 4 +- .../room/tags/DeleteTagFromRoomTask.kt | 4 +- .../timeline/FetchTokenAndPaginateTask.kt | 4 +- .../room/timeline/GetContextOfEventTask.kt | 4 +- .../session/room/timeline/GetEventTask.kt | 2 +- .../session/room/timeline/PaginationTask.kt | 8 +- .../session/room/typing/SendTypingTask.kt | 4 +- .../session/room/uploads/GetUploadsTask.kt | 5 +- .../sdk/internal/session/search/SearchAPI.kt | 5 +- .../sdk/internal/session/search/SearchTask.kt | 38 ++--- .../session/signout/SignInAgainTask.kt | 5 +- .../internal/session/signout/SignOutAPI.kt | 5 +- .../internal/session/signout/SignOutTask.kt | 4 +- .../sdk/internal/session/sync/SyncAPI.kt | 10 +- .../sdk/internal/session/sync/SyncTask.kt | 9 +- .../session/terms/DefaultTermsService.kt | 14 +- .../sdk/internal/session/terms/TermsAPI.kt | 9 +- .../thirdparty/GetThirdPartyProtocolsTask.kt | 2 +- .../thirdparty/GetThirdPartyUserTask.kt | 2 +- .../session/thirdparty/ThirdPartyAPI.kt | 6 +- .../internal/session/user/SearchUserAPI.kt | 3 +- .../user/accountdata/AccountDataAPI.kt | 7 +- .../accountdata/UpdateIgnoredUserIdsTask.kt | 4 +- .../accountdata/UpdateUserAccountDataTask.kt | 2 +- .../session/user/model/SearchUserTask.kt | 4 +- .../session/widgets/CreateWidgetTask.kt | 4 +- .../internal/session/widgets/WidgetsAPI.kt | 9 +- .../widgets/token/GetScalarTokenTask.kt | 9 +- .../internal/wellknown/GetWellknownTask.kt | 12 +- .../sdk/internal/wellknown/WellKnownAPI.kt | 3 +- 148 files changed, 576 insertions(+), 598 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index ed549c918f..a97430eff9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -35,6 +35,7 @@ Test: Other changes: - Add version details on the login screen, in debug or developer mode + - Migrate Retrofit interface to coroutine calls Changes in Element 1.1.3 (2021-03-18) =================================================== diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/AuthAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/AuthAPI.kt index f92ae7e0ee..2ce5c67a94 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/AuthAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/AuthAPI.kt @@ -29,7 +29,6 @@ import org.matrix.android.sdk.internal.auth.registration.SuccessResult import org.matrix.android.sdk.internal.auth.registration.ValidationCodeBody import org.matrix.android.sdk.internal.auth.version.Versions import org.matrix.android.sdk.internal.network.NetworkConstants -import retrofit2.Call import retrofit2.http.Body import retrofit2.http.GET import retrofit2.http.Headers @@ -45,26 +44,26 @@ internal interface AuthAPI { * Get a Riot config file, using the name including the domain */ @GET("config.{domain}.json") - fun getRiotConfigDomain(@Path("domain") domain: String): Call + suspend fun getRiotConfigDomain(@Path("domain") domain: String): RiotConfig /** * Get a Riot config file */ @GET("config.json") - fun getRiotConfig(): Call + suspend fun getRiotConfig(): RiotConfig /** * Get the version information of the homeserver */ @GET(NetworkConstants.URI_API_PREFIX_PATH_ + "versions") - fun versions(): Call + suspend fun versions(): Versions /** * Register to the homeserver, or get error 401 with a RegistrationFlowResponse object if registration is incomplete * Ref: https://matrix.org/docs/spec/client_server/latest#account-registration-and-management */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "register") - fun register(@Body registrationParams: RegistrationParams): Call + suspend fun register(@Body registrationParams: RegistrationParams): Credentials /** * Add 3Pid during registration @@ -72,22 +71,22 @@ internal interface AuthAPI { * https://github.com/matrix-org/matrix-doc/pull/2290 */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "register/{threePid}/requestToken") - fun add3Pid(@Path("threePid") threePid: String, - @Body params: AddThreePidRegistrationParams): Call + suspend fun add3Pid(@Path("threePid") threePid: String, + @Body params: AddThreePidRegistrationParams): AddThreePidRegistrationResponse /** * Validate 3pid */ @POST - fun validate3Pid(@Url url: String, - @Body params: ValidationCodeBody): Call + suspend fun validate3Pid(@Url url: String, + @Body params: ValidationCodeBody): SuccessResult /** * Get the supported login flow * Ref: https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-login */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "login") - fun getLoginFlows(): Call + suspend fun getLoginFlows(): LoginFlowResponse /** * Pass params to the server for the current login phase. @@ -97,22 +96,22 @@ internal interface AuthAPI { */ @Headers("CONNECT_TIMEOUT:60000", "READ_TIMEOUT:60000", "WRITE_TIMEOUT:60000") @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "login") - fun login(@Body loginParams: PasswordLoginParams): Call + suspend fun login(@Body loginParams: PasswordLoginParams): Credentials // Unfortunately we cannot use interface for @Body parameter, so I duplicate the method for the type TokenLoginParams @Headers("CONNECT_TIMEOUT:60000", "READ_TIMEOUT:60000", "WRITE_TIMEOUT:60000") @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "login") - fun login(@Body loginParams: TokenLoginParams): Call + suspend fun login(@Body loginParams: TokenLoginParams): Credentials /** * Ask the homeserver to reset the password associated with the provided email. */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/password/email/requestToken") - fun resetPassword(@Body params: AddThreePidRegistrationParams): Call + suspend fun resetPassword(@Body params: AddThreePidRegistrationParams): AddThreePidRegistrationResponse /** * Ask the homeserver to reset the password with the provided new password once the email is validated. */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/password") - fun resetPasswordMailConfirmed(@Body params: ResetPasswordMailConfirmed): Call + suspend fun resetPasswordMailConfirmed(@Body params: ResetPasswordMailConfirmed) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/DefaultAuthenticationService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/DefaultAuthenticationService.kt index 4f3451cf30..e26286ad2f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/DefaultAuthenticationService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/DefaultAuthenticationService.kt @@ -31,7 +31,6 @@ import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.util.appendParamToUrl import org.matrix.android.sdk.internal.SessionManager -import org.matrix.android.sdk.internal.auth.data.LoginFlowResponse import org.matrix.android.sdk.internal.auth.data.RiotConfig import org.matrix.android.sdk.internal.auth.db.PendingSessionData import org.matrix.android.sdk.internal.auth.login.DefaultLoginWizard @@ -172,8 +171,8 @@ internal class DefaultAuthenticationService @Inject constructor( // First check the homeserver version return runCatching { - executeRequest(null) { - apiCall = authAPI.versions() + executeRequest(null) { + authAPI.versions() } } .map { versions -> @@ -204,8 +203,8 @@ internal class DefaultAuthenticationService @Inject constructor( // Ok, try to get the config.domain.json file of a RiotWeb client return runCatching { - executeRequest(null) { - apiCall = authAPI.getRiotConfigDomain(domain) + executeRequest(null) { + authAPI.getRiotConfigDomain(domain) } } .map { riotConfig -> @@ -232,8 +231,8 @@ internal class DefaultAuthenticationService @Inject constructor( // Ok, try to get the config.json file of a RiotWeb client return runCatching { - executeRequest(null) { - apiCall = authAPI.getRiotConfig() + executeRequest(null) { + authAPI.getRiotConfig() } } .map { riotConfig -> @@ -265,8 +264,8 @@ internal class DefaultAuthenticationService @Inject constructor( val newAuthAPI = buildAuthAPI(newHomeServerConnectionConfig) - val versions = executeRequest(null) { - apiCall = newAuthAPI.versions() + val versions = executeRequest(null) { + newAuthAPI.versions() } return getLoginFlowResult(newAuthAPI, versions, defaultHomeServerUrl) @@ -293,8 +292,8 @@ internal class DefaultAuthenticationService @Inject constructor( val newAuthAPI = buildAuthAPI(newHomeServerConnectionConfig) - val versions = executeRequest(null) { - apiCall = newAuthAPI.versions() + val versions = executeRequest(null) { + newAuthAPI.versions() } getLoginFlowResult(newAuthAPI, versions, wellknownResult.homeServerUrl) @@ -305,8 +304,8 @@ internal class DefaultAuthenticationService @Inject constructor( private suspend fun getLoginFlowResult(authAPI: AuthAPI, versions: Versions, homeServerUrl: String): LoginFlowResult { // Get the login flow - val loginFlowResponse = executeRequest(null) { - apiCall = authAPI.getLoginFlows() + val loginFlowResponse = executeRequest(null) { + authAPI.getLoginFlows() } return LoginFlowResult.Success( loginFlowResponse.flows.orEmpty().mapNotNull { it.type }, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/IsValidClientServerApiTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/IsValidClientServerApiTask.kt index b8416d69bf..867cf46b8d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/IsValidClientServerApiTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/IsValidClientServerApiTask.kt @@ -20,7 +20,6 @@ import dagger.Lazy import okhttp3.OkHttpClient import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig import org.matrix.android.sdk.api.failure.Failure -import org.matrix.android.sdk.internal.auth.data.LoginFlowResponse import org.matrix.android.sdk.internal.di.Unauthenticated import org.matrix.android.sdk.internal.network.RetrofitFactory import org.matrix.android.sdk.internal.network.executeRequest @@ -49,8 +48,8 @@ internal class DefaultIsValidClientServerApiTask @Inject constructor( .create(AuthAPI::class.java) return try { - executeRequest(null) { - apiCall = authAPI.getLoginFlows() + executeRequest(null) { + authAPI.getLoginFlows() } // We get a response, so the API is valid true diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/login/DefaultLoginWizard.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/login/DefaultLoginWizard.kt index 4167875849..8b81f42e03 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/login/DefaultLoginWizard.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/login/DefaultLoginWizard.kt @@ -17,7 +17,6 @@ package org.matrix.android.sdk.internal.auth.login import android.util.Patterns -import org.matrix.android.sdk.api.auth.data.Credentials import org.matrix.android.sdk.api.auth.login.LoginWizard import org.matrix.android.sdk.api.auth.registration.RegisterThreePid import org.matrix.android.sdk.api.session.Session @@ -29,7 +28,6 @@ import org.matrix.android.sdk.internal.auth.data.ThreePidMedium import org.matrix.android.sdk.internal.auth.data.TokenLoginParams import org.matrix.android.sdk.internal.auth.db.PendingSessionData import org.matrix.android.sdk.internal.auth.registration.AddThreePidRegistrationParams -import org.matrix.android.sdk.internal.auth.registration.AddThreePidRegistrationResponse import org.matrix.android.sdk.internal.auth.registration.RegisterAddThreePidTask import org.matrix.android.sdk.internal.network.executeRequest @@ -49,8 +47,8 @@ internal class DefaultLoginWizard( } else { PasswordLoginParams.userIdentifier(login, password, deviceName) } - val credentials = executeRequest(null) { - apiCall = authAPI.login(loginParams) + val credentials = executeRequest(null) { + authAPI.login(loginParams) } return sessionCreator.createSession(credentials, pendingSessionData.homeServerConnectionConfig) @@ -63,8 +61,8 @@ internal class DefaultLoginWizard( val loginParams = TokenLoginParams( token = loginToken ) - val credentials = executeRequest(null) { - apiCall = authAPI.login(loginParams) + val credentials = executeRequest(null) { + authAPI.login(loginParams) } return sessionCreator.createSession(credentials, pendingSessionData.homeServerConnectionConfig) @@ -80,8 +78,8 @@ internal class DefaultLoginWizard( pendingSessionData = pendingSessionData.copy(sendAttempt = pendingSessionData.sendAttempt + 1) .also { pendingSessionStore.savePendingSessionData(it) } - val result = executeRequest(null) { - apiCall = authAPI.resetPassword(AddThreePidRegistrationParams.from(param)) + val result = executeRequest(null) { + authAPI.resetPassword(AddThreePidRegistrationParams.from(param)) } pendingSessionData = pendingSessionData.copy(resetPasswordData = ResetPasswordData(newPassword, result)) @@ -98,8 +96,8 @@ internal class DefaultLoginWizard( safeResetPasswordData.newPassword ) - executeRequest(null) { - apiCall = authAPI.resetPasswordMailConfirmed(param) + executeRequest(null) { + authAPI.resetPasswordMailConfirmed(param) } // Set to null? diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/login/DirectLoginTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/login/DirectLoginTask.kt index be6ff38931..77bbb8096f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/login/DirectLoginTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/login/DirectLoginTask.kt @@ -17,7 +17,6 @@ package org.matrix.android.sdk.internal.auth.login import dagger.Lazy -import org.matrix.android.sdk.api.auth.data.Credentials import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.session.Session @@ -59,19 +58,16 @@ internal class DefaultDirectLoginTask @Inject constructor( val loginParams = PasswordLoginParams.userIdentifier(params.userId, params.password, params.deviceName) val credentials = try { - executeRequest(null) { - apiCall = authAPI.login(loginParams) + executeRequest(null) { + authAPI.login(loginParams) } } catch (throwable: Throwable) { - when (throwable) { - is UnrecognizedCertificateException -> { - throw Failure.UnrecognizedCertificateFailure( - homeServerUrl, - throwable.fingerprint - ) - } - else -> - throw throwable + throw when (throwable) { + is UnrecognizedCertificateException -> Failure.UnrecognizedCertificateFailure( + homeServerUrl, + throwable.fingerprint + ) + else -> throwable } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/registration/RegisterAddThreePidTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/registration/RegisterAddThreePidTask.kt index 57c4b72b8a..54a8ba0e6c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/registration/RegisterAddThreePidTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/registration/RegisterAddThreePidTask.kt @@ -35,7 +35,7 @@ internal class DefaultRegisterAddThreePidTask( override suspend fun execute(params: RegisterAddThreePidTask.Params): AddThreePidRegistrationResponse { return executeRequest(null) { - apiCall = authAPI.add3Pid(params.threePid.toPath(), AddThreePidRegistrationParams.from(params)) + authAPI.add3Pid(params.threePid.toPath(), AddThreePidRegistrationParams.from(params)) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/registration/RegisterTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/registration/RegisterTask.kt index bf5d899276..45668cb8ad 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/registration/RegisterTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/registration/RegisterTask.kt @@ -36,7 +36,7 @@ internal class DefaultRegisterTask( override suspend fun execute(params: RegisterTask.Params): Credentials { try { return executeRequest(null) { - apiCall = authAPI.register(params.registrationParams) + authAPI.register(params.registrationParams) } } catch (throwable: Throwable) { throw throwable.toRegistrationFlowResponse() diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/registration/ValidateCodeTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/registration/ValidateCodeTask.kt index b297c9849d..d68b7cd9eb 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/registration/ValidateCodeTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/registration/ValidateCodeTask.kt @@ -33,7 +33,7 @@ internal class DefaultValidateCodeTask( override suspend fun execute(params: ValidateCodeTask.Params): SuccessResult { return executeRequest(null) { - apiCall = authAPI.validate3Pid(params.url, params.body) + authAPI.validate3Pid(params.url, params.body) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/api/CryptoApi.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/api/CryptoApi.kt index 5604e97152..cef86e8b5e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/api/CryptoApi.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/api/CryptoApi.kt @@ -30,7 +30,6 @@ import org.matrix.android.sdk.internal.crypto.model.rest.SignatureUploadResponse import org.matrix.android.sdk.internal.crypto.model.rest.UpdateDeviceInfoBody import org.matrix.android.sdk.internal.crypto.model.rest.UploadSigningKeysBody import org.matrix.android.sdk.internal.network.NetworkConstants -import retrofit2.Call import retrofit2.http.Body import retrofit2.http.GET import retrofit2.http.HTTP @@ -46,14 +45,14 @@ internal interface CryptoApi { * Doc: https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-devices */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "devices") - fun getDevices(): Call + suspend fun getDevices(): DevicesListResponse /** * Get the device info by id * Doc: https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-devices-deviceid */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "devices/{deviceId}") - fun getDeviceInfo(@Path("deviceId") deviceId: String): Call + suspend fun getDeviceInfo(@Path("deviceId") deviceId: String): DeviceInfo /** * Upload device and/or one-time keys. @@ -62,7 +61,7 @@ internal interface CryptoApi { * @param body the keys to be sent. */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "keys/upload") - fun uploadKeys(@Body body: KeysUploadBody): Call + suspend fun uploadKeys(@Body body: KeysUploadBody): KeysUploadResponse /** * Download device keys. @@ -71,7 +70,7 @@ internal interface CryptoApi { * @param params the params. */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "keys/query") - fun downloadKeysForUsers(@Body params: KeysQueryBody): Call + suspend fun downloadKeysForUsers(@Body params: KeysQueryBody): KeysQueryResponse /** * CrossSigning - Uploading signing keys @@ -79,7 +78,7 @@ internal interface CryptoApi { * This endpoint requires UI Auth. */ @POST(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "keys/device_signing/upload") - fun uploadSigningKeys(@Body params: UploadSigningKeysBody): Call + suspend fun uploadSigningKeys(@Body params: UploadSigningKeysBody): KeysQueryResponse /** * CrossSigning - Uploading signatures @@ -98,7 +97,7 @@ internal interface CryptoApi { * However, signatures made for other users' keys, made by her user-signing key, will not be included. */ @POST(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "keys/signatures/upload") - fun uploadSignatures(@Body params: Map?): Call + suspend fun uploadSignatures(@Body params: Map?): SignatureUploadResponse /** * Claim one-time keys. @@ -107,7 +106,7 @@ internal interface CryptoApi { * @param params the params. */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "keys/claim") - fun claimOneTimeKeysForUsersDevices(@Body body: KeysClaimBody): Call + suspend fun claimOneTimeKeysForUsersDevices(@Body body: KeysClaimBody): KeysClaimResponse /** * Send an event to a specific list of devices @@ -118,9 +117,9 @@ internal interface CryptoApi { * @param body the body */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "sendToDevice/{eventType}/{txnId}") - fun sendToDevice(@Path("eventType") eventType: String, - @Path("txnId") transactionId: String, - @Body body: SendToDeviceBody): Call + suspend fun sendToDevice(@Path("eventType") eventType: String, + @Path("txnId") transactionId: String, + @Body body: SendToDeviceBody) /** * Delete a device. @@ -130,8 +129,8 @@ internal interface CryptoApi { * @param params the deletion parameters */ @HTTP(path = NetworkConstants.URI_API_PREFIX_PATH_R0 + "devices/{device_id}", method = "DELETE", hasBody = true) - fun deleteDevice(@Path("device_id") deviceId: String, - @Body params: DeleteDeviceParams): Call + suspend fun deleteDevice(@Path("device_id") deviceId: String, + @Body params: DeleteDeviceParams) /** * Update the device information. @@ -141,8 +140,8 @@ internal interface CryptoApi { * @param params the params */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "devices/{device_id}") - fun updateDeviceInfo(@Path("device_id") deviceId: String, - @Body params: UpdateDeviceInfoBody): Call + suspend fun updateDeviceInfo(@Path("device_id") deviceId: String, + @Body params: UpdateDeviceInfoBody) /** * Get the update devices list from two sync token. @@ -152,6 +151,6 @@ internal interface CryptoApi { * @param newToken the up-to token. */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "keys/changes") - fun getKeyChanges(@Query("from") oldToken: String, - @Query("to") newToken: String): Call + suspend fun getKeyChanges(@Query("from") oldToken: String, + @Query("to") newToken: String): KeyChangesResponse } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/api/RoomKeysApi.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/api/RoomKeysApi.kt index 3f8333528f..eb4c55a3e7 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/api/RoomKeysApi.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/api/RoomKeysApi.kt @@ -25,7 +25,6 @@ import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysVersionR import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.RoomKeysBackupData import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.UpdateKeysBackupVersionBody import org.matrix.android.sdk.internal.network.NetworkConstants -import retrofit2.Call import retrofit2.http.Body import retrofit2.http.DELETE import retrofit2.http.GET @@ -48,14 +47,14 @@ internal interface RoomKeysApi { * @param createKeysBackupVersionBody the body */ @POST(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version") - fun createKeysBackupVersion(@Body createKeysBackupVersionBody: CreateKeysBackupVersionBody): Call + suspend fun createKeysBackupVersion(@Body createKeysBackupVersionBody: CreateKeysBackupVersionBody): KeysVersion /** * Get the key backup last version * If not supported by the server, an error is returned: {"errcode":"M_NOT_FOUND","error":"No backup found"} */ @GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version") - fun getKeysBackupLastVersion(): Call + suspend fun getKeysBackupLastVersion(): KeysVersionResult /** * Get information about the given version. @@ -64,7 +63,7 @@ internal interface RoomKeysApi { * @param version version */ @GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version/{version}") - fun getKeysBackupVersion(@Path("version") version: String): Call + suspend fun getKeysBackupVersion(@Path("version") version: String): KeysVersionResult /** * Update information about the given version. @@ -72,8 +71,8 @@ internal interface RoomKeysApi { * @param updateKeysBackupVersionBody the body */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version/{version}") - fun updateKeysBackupVersion(@Path("version") version: String, - @Body keysBackupVersionBody: UpdateKeysBackupVersionBody): Call + suspend fun updateKeysBackupVersion(@Path("version") version: String, + @Body keysBackupVersionBody: UpdateKeysBackupVersionBody) /* ========================================================================================== * Storing keys @@ -94,10 +93,10 @@ internal interface RoomKeysApi { * @param keyBackupData the data to send */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}/{sessionId}") - fun storeRoomSessionData(@Path("roomId") roomId: String, - @Path("sessionId") sessionId: String, - @Query("version") version: String, - @Body keyBackupData: KeyBackupData): Call + suspend fun storeRoomSessionData(@Path("roomId") roomId: String, + @Path("sessionId") sessionId: String, + @Query("version") version: String, + @Body keyBackupData: KeyBackupData): BackupKeysResult /** * Store several keys for the given room, using the given backup version. @@ -107,9 +106,9 @@ internal interface RoomKeysApi { * @param roomKeysBackupData the data to send */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}") - fun storeRoomSessionsData(@Path("roomId") roomId: String, - @Query("version") version: String, - @Body roomKeysBackupData: RoomKeysBackupData): Call + suspend fun storeRoomSessionsData(@Path("roomId") roomId: String, + @Query("version") version: String, + @Body roomKeysBackupData: RoomKeysBackupData): BackupKeysResult /** * Store several keys, using the given backup version. @@ -118,8 +117,8 @@ internal interface RoomKeysApi { * @param keysBackupData the data to send */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys") - fun storeSessionsData(@Query("version") version: String, - @Body keysBackupData: KeysBackupData): Call + suspend fun storeSessionsData(@Query("version") version: String, + @Body keysBackupData: KeysBackupData): BackupKeysResult /* ========================================================================================== * Retrieving keys @@ -133,9 +132,9 @@ internal interface RoomKeysApi { * @param version the version of the backup, or empty String to retrieve the last version */ @GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}/{sessionId}") - fun getRoomSessionData(@Path("roomId") roomId: String, - @Path("sessionId") sessionId: String, - @Query("version") version: String): Call + suspend fun getRoomSessionData(@Path("roomId") roomId: String, + @Path("sessionId") sessionId: String, + @Query("version") version: String): KeyBackupData /** * Retrieve all the keys for the given room from the backup. @@ -144,8 +143,8 @@ internal interface RoomKeysApi { * @param version the version of the backup, or empty String to retrieve the last version */ @GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}") - fun getRoomSessionsData(@Path("roomId") roomId: String, - @Query("version") version: String): Call + suspend fun getRoomSessionsData(@Path("roomId") roomId: String, + @Query("version") version: String): RoomKeysBackupData /** * Retrieve all the keys from the backup. @@ -153,7 +152,7 @@ internal interface RoomKeysApi { * @param version the version of the backup, or empty String to retrieve the last version */ @GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys") - fun getSessionsData(@Query("version") version: String): Call + suspend fun getSessionsData(@Query("version") version: String): KeysBackupData /* ========================================================================================== * Deleting keys @@ -163,22 +162,22 @@ internal interface RoomKeysApi { * Deletes keys from the backup. */ @DELETE(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}/{sessionId}") - fun deleteRoomSessionData(@Path("roomId") roomId: String, - @Path("sessionId") sessionId: String, - @Query("version") version: String): Call + suspend fun deleteRoomSessionData(@Path("roomId") roomId: String, + @Path("sessionId") sessionId: String, + @Query("version") version: String) /** * Deletes keys from the backup. */ @DELETE(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}") - fun deleteRoomSessionsData(@Path("roomId") roomId: String, - @Query("version") version: String): Call + suspend fun deleteRoomSessionsData(@Path("roomId") roomId: String, + @Query("version") version: String) /** * Deletes keys from the backup. */ @DELETE(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys") - fun deleteSessionsData(@Query("version") version: String): Call + suspend fun deleteSessionsData(@Query("version") version: String) /* ========================================================================================== * Deleting backup @@ -188,5 +187,5 @@ internal interface RoomKeysApi { * Deletes a backup. */ @DELETE(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version/{version}") - fun deleteBackup(@Path("version") version: String): Call + suspend fun deleteBackup(@Path("version") version: String) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/CreateKeysBackupVersionTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/CreateKeysBackupVersionTask.kt index 5c59cfd80e..62610a0b7b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/CreateKeysBackupVersionTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/CreateKeysBackupVersionTask.kt @@ -33,7 +33,7 @@ internal class DefaultCreateKeysBackupVersionTask @Inject constructor( override suspend fun execute(params: CreateKeysBackupVersionBody): KeysVersion { return executeRequest(globalErrorReceiver) { - apiCall = roomKeysApi.createKeysBackupVersion(params) + roomKeysApi.createKeysBackupVersion(params) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteBackupTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteBackupTask.kt index ec09da7240..7ee6f2358d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteBackupTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteBackupTask.kt @@ -35,7 +35,7 @@ internal class DefaultDeleteBackupTask @Inject constructor( override suspend fun execute(params: DeleteBackupTask.Params) { return executeRequest(globalErrorReceiver) { - apiCall = roomKeysApi.deleteBackup(params.version) + roomKeysApi.deleteBackup(params.version) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteRoomSessionDataTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteRoomSessionDataTask.kt index 9c477efb78..7f1b03b932 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteRoomSessionDataTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteRoomSessionDataTask.kt @@ -37,7 +37,7 @@ internal class DefaultDeleteRoomSessionDataTask @Inject constructor( override suspend fun execute(params: DeleteRoomSessionDataTask.Params) { return executeRequest(globalErrorReceiver) { - apiCall = roomKeysApi.deleteRoomSessionData( + roomKeysApi.deleteRoomSessionData( params.roomId, params.sessionId, params.version) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteRoomSessionsDataTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteRoomSessionsDataTask.kt index 82d022f3ab..394cc861d6 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteRoomSessionsDataTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteRoomSessionsDataTask.kt @@ -36,7 +36,7 @@ internal class DefaultDeleteRoomSessionsDataTask @Inject constructor( override suspend fun execute(params: DeleteRoomSessionsDataTask.Params) { return executeRequest(globalErrorReceiver) { - apiCall = roomKeysApi.deleteRoomSessionsData( + roomKeysApi.deleteRoomSessionsData( params.roomId, params.version) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteSessionsDataTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteSessionsDataTask.kt index e4df379963..808c6c9956 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteSessionsDataTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteSessionsDataTask.kt @@ -35,7 +35,7 @@ internal class DefaultDeleteSessionsDataTask @Inject constructor( override suspend fun execute(params: DeleteSessionsDataTask.Params) { return executeRequest(globalErrorReceiver) { - apiCall = roomKeysApi.deleteSessionsData(params.version) + roomKeysApi.deleteSessionsData(params.version) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetKeysBackupLastVersionTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetKeysBackupLastVersionTask.kt index 3566ff0e68..54dbf85e30 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetKeysBackupLastVersionTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetKeysBackupLastVersionTask.kt @@ -32,7 +32,7 @@ internal class DefaultGetKeysBackupLastVersionTask @Inject constructor( override suspend fun execute(params: Unit): KeysVersionResult { return executeRequest(globalErrorReceiver) { - apiCall = roomKeysApi.getKeysBackupLastVersion() + roomKeysApi.getKeysBackupLastVersion() } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetKeysBackupVersionTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetKeysBackupVersionTask.kt index 13c99fb0f4..390873eb68 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetKeysBackupVersionTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetKeysBackupVersionTask.kt @@ -32,7 +32,7 @@ internal class DefaultGetKeysBackupVersionTask @Inject constructor( override suspend fun execute(params: String): KeysVersionResult { return executeRequest(globalErrorReceiver) { - apiCall = roomKeysApi.getKeysBackupVersion(params) + roomKeysApi.getKeysBackupVersion(params) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetRoomSessionDataTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetRoomSessionDataTask.kt index 168020d9cd..ff515ed80f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetRoomSessionDataTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetRoomSessionDataTask.kt @@ -38,7 +38,7 @@ internal class DefaultGetRoomSessionDataTask @Inject constructor( override suspend fun execute(params: GetRoomSessionDataTask.Params): KeyBackupData { return executeRequest(globalErrorReceiver) { - apiCall = roomKeysApi.getRoomSessionData( + roomKeysApi.getRoomSessionData( params.roomId, params.sessionId, params.version) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetRoomSessionsDataTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetRoomSessionsDataTask.kt index 95d5ef2e53..1b4fe2d966 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetRoomSessionsDataTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetRoomSessionsDataTask.kt @@ -37,7 +37,7 @@ internal class DefaultGetRoomSessionsDataTask @Inject constructor( override suspend fun execute(params: GetRoomSessionsDataTask.Params): RoomKeysBackupData { return executeRequest(globalErrorReceiver) { - apiCall = roomKeysApi.getRoomSessionsData( + roomKeysApi.getRoomSessionsData( params.roomId, params.version) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetSessionsDataTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetSessionsDataTask.kt index e41a13e3eb..707125f4cd 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetSessionsDataTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetSessionsDataTask.kt @@ -36,7 +36,7 @@ internal class DefaultGetSessionsDataTask @Inject constructor( override suspend fun execute(params: GetSessionsDataTask.Params): KeysBackupData { return executeRequest(globalErrorReceiver) { - apiCall = roomKeysApi.getSessionsData(params.version) + roomKeysApi.getSessionsData(params.version) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/StoreRoomSessionDataTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/StoreRoomSessionDataTask.kt index 3954277e39..180aaecf82 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/StoreRoomSessionDataTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/StoreRoomSessionDataTask.kt @@ -40,7 +40,7 @@ internal class DefaultStoreRoomSessionDataTask @Inject constructor( override suspend fun execute(params: StoreRoomSessionDataTask.Params): BackupKeysResult { return executeRequest(globalErrorReceiver) { - apiCall = roomKeysApi.storeRoomSessionData( + roomKeysApi.storeRoomSessionData( params.roomId, params.sessionId, params.version, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/StoreRoomSessionsDataTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/StoreRoomSessionsDataTask.kt index 4e209b4abc..d1aa9d2eb0 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/StoreRoomSessionsDataTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/StoreRoomSessionsDataTask.kt @@ -39,7 +39,7 @@ internal class DefaultStoreRoomSessionsDataTask @Inject constructor( override suspend fun execute(params: StoreRoomSessionsDataTask.Params): BackupKeysResult { return executeRequest(globalErrorReceiver) { - apiCall = roomKeysApi.storeRoomSessionsData( + roomKeysApi.storeRoomSessionsData( params.roomId, params.version, params.roomKeysBackupData) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/StoreSessionsDataTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/StoreSessionsDataTask.kt index a607477d21..3dbeafe9de 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/StoreSessionsDataTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/StoreSessionsDataTask.kt @@ -38,7 +38,7 @@ internal class DefaultStoreSessionsDataTask @Inject constructor( override suspend fun execute(params: StoreSessionsDataTask.Params): BackupKeysResult { return executeRequest(globalErrorReceiver) { - apiCall = roomKeysApi.storeSessionsData( + roomKeysApi.storeSessionsData( params.version, params.keysBackupData) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/UpdateKeysBackupVersionTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/UpdateKeysBackupVersionTask.kt index f012cd13eb..2b3d044ab7 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/UpdateKeysBackupVersionTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/UpdateKeysBackupVersionTask.kt @@ -37,7 +37,7 @@ internal class DefaultUpdateKeysBackupVersionTask @Inject constructor( override suspend fun execute(params: UpdateKeysBackupVersionTask.Params) { return executeRequest(globalErrorReceiver) { - apiCall = roomKeysApi.updateKeysBackupVersion(params.version, params.keysBackupVersionBody) + roomKeysApi.updateKeysBackupVersion(params.version, params.keysBackupVersionBody) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/ClaimOneTimeKeysForUsersDeviceTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/ClaimOneTimeKeysForUsersDeviceTask.kt index 3df6312adb..d5cf749db7 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/ClaimOneTimeKeysForUsersDeviceTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/ClaimOneTimeKeysForUsersDeviceTask.kt @@ -20,7 +20,6 @@ import org.matrix.android.sdk.internal.crypto.api.CryptoApi import org.matrix.android.sdk.internal.crypto.model.MXKey import org.matrix.android.sdk.internal.crypto.model.MXUsersDevicesMap import org.matrix.android.sdk.internal.crypto.model.rest.KeysClaimBody -import org.matrix.android.sdk.internal.crypto.model.rest.KeysClaimResponse import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task @@ -42,8 +41,8 @@ internal class DefaultClaimOneTimeKeysForUsersDevice @Inject constructor( override suspend fun execute(params: ClaimOneTimeKeysForUsersDeviceTask.Params): MXUsersDevicesMap { val body = KeysClaimBody(oneTimeKeys = params.usersDevicesKeyTypesMap.map) - val keysClaimResponse = executeRequest(globalErrorReceiver) { - apiCall = cryptoApi.claimOneTimeKeysForUsersDevices(body) + val keysClaimResponse = executeRequest(globalErrorReceiver) { + cryptoApi.claimOneTimeKeysForUsersDevices(body) } val map = MXUsersDevicesMap() keysClaimResponse.oneTimeKeys?.let { oneTimeKeys -> diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DeleteDeviceTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DeleteDeviceTask.kt index 61596bb5b6..bdb8e8d137 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DeleteDeviceTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DeleteDeviceTask.kt @@ -42,8 +42,8 @@ internal class DefaultDeleteDeviceTask @Inject constructor( override suspend fun execute(params: DeleteDeviceTask.Params) { try { - executeRequest(globalErrorReceiver) { - apiCall = cryptoApi.deleteDevice(params.deviceId, DeleteDeviceParams(params.userAuthParam?.asMap())) + executeRequest(globalErrorReceiver) { + cryptoApi.deleteDevice(params.deviceId, DeleteDeviceParams(params.userAuthParam?.asMap())) } } catch (throwable: Throwable) { if (params.userInteractiveAuthInterceptor == null diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DownloadKeysForUsersTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DownloadKeysForUsersTask.kt index 0c17cbb43a..86f02866ae 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DownloadKeysForUsersTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DownloadKeysForUsersTask.kt @@ -72,8 +72,8 @@ internal class DefaultDownloadKeysForUsers @Inject constructor( } .map { body -> async { - val result = executeRequest(globalErrorReceiver) { - apiCall = cryptoApi.downloadKeysForUsers(body) + val result = executeRequest(globalErrorReceiver) { + cryptoApi.downloadKeysForUsers(body) } mutex.withLock { @@ -98,7 +98,7 @@ internal class DefaultDownloadKeysForUsers @Inject constructor( } else { // No need to chunk, direct request executeRequest(globalErrorReceiver) { - apiCall = cryptoApi.downloadKeysForUsers( + cryptoApi.downloadKeysForUsers( KeysQueryBody( deviceKeys = params.userIds.associateWith { emptyList() }, token = token diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/GetDeviceInfoTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/GetDeviceInfoTask.kt index 5f6d2e344f..9f20ea598d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/GetDeviceInfoTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/GetDeviceInfoTask.kt @@ -34,7 +34,7 @@ internal class DefaultGetDeviceInfoTask @Inject constructor( override suspend fun execute(params: GetDeviceInfoTask.Params): DeviceInfo { return executeRequest(globalErrorReceiver) { - apiCall = cryptoApi.getDeviceInfo(params.deviceId) + cryptoApi.getDeviceInfo(params.deviceId) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/GetDevicesTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/GetDevicesTask.kt index ea33a918bc..52f9f73299 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/GetDevicesTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/GetDevicesTask.kt @@ -32,7 +32,7 @@ internal class DefaultGetDevicesTask @Inject constructor( override suspend fun execute(params: Unit): DevicesListResponse { return executeRequest(globalErrorReceiver) { - apiCall = cryptoApi.getDevices() + cryptoApi.getDevices() } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/GetKeyChangesTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/GetKeyChangesTask.kt index 4cc9ab2fcb..6e524c7fbe 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/GetKeyChangesTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/GetKeyChangesTask.kt @@ -39,7 +39,7 @@ internal class DefaultGetKeyChangesTask @Inject constructor( override suspend fun execute(params: GetKeyChangesTask.Params): KeyChangesResponse { return executeRequest(globalErrorReceiver) { - apiCall = cryptoApi.getKeyChanges(params.from, params.to) + cryptoApi.getKeyChanges(params.from, params.to) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/RedactEventTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/RedactEventTask.kt index 5226e52b33..d6a7f3c6a0 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/RedactEventTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/RedactEventTask.kt @@ -18,7 +18,6 @@ package org.matrix.android.sdk.internal.crypto.tasks import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.room.RoomAPI -import org.matrix.android.sdk.internal.session.room.send.SendResponse import org.matrix.android.sdk.internal.task.Task import javax.inject.Inject @@ -36,14 +35,14 @@ internal class DefaultRedactEventTask @Inject constructor( private val globalErrorReceiver: GlobalErrorReceiver) : RedactEventTask { override suspend fun execute(params: RedactEventTask.Params): String { - val executeRequest = executeRequest(globalErrorReceiver) { - apiCall = roomAPI.redactEvent( + val response = executeRequest(globalErrorReceiver) { + roomAPI.redactEvent( txId = params.txID, roomId = params.roomId, eventId = params.eventId, reason = if (params.reason == null) emptyMap() else mapOf("reason" to params.reason) ) } - return executeRequest.eventId + return response.eventId } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendEventTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendEventTask.kt index 573f2c3a54..e1e297767b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendEventTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendEventTask.kt @@ -22,7 +22,6 @@ import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.session.room.membership.LoadRoomMembersTask import org.matrix.android.sdk.internal.session.room.send.LocalEchoRepository -import org.matrix.android.sdk.internal.session.room.send.SendResponse import org.matrix.android.sdk.internal.task.Task import javax.inject.Inject @@ -52,8 +51,8 @@ internal class DefaultSendEventTask @Inject constructor( val event = handleEncryption(params) val localId = event.eventId!! localEchoRepository.updateSendState(localId, params.event.roomId, SendState.SENDING) - val executeRequest = executeRequest(globalErrorReceiver) { - apiCall = roomAPI.send( + val response = executeRequest(globalErrorReceiver) { + roomAPI.send( localId, roomId = event.roomId ?: "", content = event.content, @@ -61,7 +60,7 @@ internal class DefaultSendEventTask @Inject constructor( ) } localEchoRepository.updateSendState(localId, params.event.roomId, SendState.SENT) - return executeRequest.eventId + return response.eventId } catch (e: Throwable) { // localEchoRepository.updateSendState(params.event.eventId!!, SendState.UNDELIVERED) throw e diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendToDeviceTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendToDeviceTask.kt index d2af91601b..fe6868968b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendToDeviceTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendToDeviceTask.kt @@ -46,14 +46,19 @@ internal class DefaultSendToDeviceTask @Inject constructor( messages = params.contentMap.map ) - return executeRequest(globalErrorReceiver) { - apiCall = cryptoApi.sendToDevice( - params.eventType, - params.transactionId ?: Random.nextInt(Integer.MAX_VALUE).toString(), - sendToDeviceBody - ) - isRetryable = true - maxRetryCount = 3 - } + return executeRequest( + globalErrorReceiver, + { + cryptoApi.sendToDevice( + params.eventType, + params.transactionId ?: Random.nextInt(Integer.MAX_VALUE).toString(), + sendToDeviceBody + ) + }, + { + isRetryable = true + maxRetryCount = 3 + } + ) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendVerificationMessageTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendVerificationMessageTask.kt index ab125135bb..d8b9d3cd86 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendVerificationMessageTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendVerificationMessageTask.kt @@ -22,7 +22,6 @@ import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.session.room.send.LocalEchoRepository -import org.matrix.android.sdk.internal.session.room.send.SendResponse import org.matrix.android.sdk.internal.task.Task import javax.inject.Inject @@ -45,8 +44,8 @@ internal class DefaultSendVerificationMessageTask @Inject constructor( try { localEchoRepository.updateSendState(localId, event.roomId, SendState.SENDING) - val executeRequest = executeRequest(globalErrorReceiver) { - apiCall = roomAPI.send( + val response = executeRequest(globalErrorReceiver) { + roomAPI.send( localId, roomId = event.roomId ?: "", content = event.content, @@ -54,7 +53,7 @@ internal class DefaultSendVerificationMessageTask @Inject constructor( ) } localEchoRepository.updateSendState(localId, event.roomId, SendState.SENT) - return executeRequest.eventId + return response.eventId } catch (e: Throwable) { localEchoRepository.updateSendState(localId, event.roomId, SendState.UNDELIVERED) throw e diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SetDeviceNameTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SetDeviceNameTask.kt index b835d46236..4bedb1f393 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SetDeviceNameTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SetDeviceNameTask.kt @@ -42,7 +42,7 @@ internal class DefaultSetDeviceNameTask @Inject constructor( displayName = params.deviceName ) return executeRequest(globalErrorReceiver) { - apiCall = cryptoApi.updateDeviceInfo(params.deviceId, body) + cryptoApi.updateDeviceInfo(params.deviceId, body) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadKeysTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadKeysTask.kt index eb53bbbf8d..cac4dadd93 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadKeysTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadKeysTask.kt @@ -50,7 +50,7 @@ internal class DefaultUploadKeysTask @Inject constructor( Timber.i("## Uploading device keys -> $body") return executeRequest(globalErrorReceiver) { - apiCall = cryptoApi.uploadKeys(body) + cryptoApi.uploadKeys(body) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSignaturesTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSignaturesTask.kt index c50faf37b1..bac886cafc 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSignaturesTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSignaturesTask.kt @@ -17,7 +17,6 @@ package org.matrix.android.sdk.internal.crypto.tasks import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.internal.crypto.api.CryptoApi -import org.matrix.android.sdk.internal.crypto.model.rest.SignatureUploadResponse import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task @@ -36,11 +35,14 @@ internal class DefaultUploadSignaturesTask @Inject constructor( override suspend fun execute(params: UploadSignaturesTask.Params) { try { - val response = executeRequest(globalErrorReceiver) { - this.isRetryable = true - this.maxRetryCount = 10 - this.apiCall = cryptoApi.uploadSignatures(params.signatures) - } + val response = executeRequest( + globalErrorReceiver, + { cryptoApi.uploadSignatures(params.signatures) }, + { + isRetryable = true + maxRetryCount = 10 + } + ) if (response.failures?.isNotEmpty() == true) { throw Throwable(response.failures.toString()) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSigningKeysTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSigningKeysTask.kt index 14fad2ea38..08c767ba34 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSigningKeysTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSigningKeysTask.kt @@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.crypto.tasks import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.internal.crypto.api.CryptoApi import org.matrix.android.sdk.internal.crypto.model.CryptoCrossSigningKey -import org.matrix.android.sdk.internal.crypto.model.rest.KeysQueryResponse import org.matrix.android.sdk.api.auth.UIABaseAuth import org.matrix.android.sdk.internal.crypto.model.rest.UploadSigningKeysBody import org.matrix.android.sdk.internal.crypto.model.toRest @@ -61,8 +60,8 @@ internal class DefaultUploadSigningKeysTask @Inject constructor( } private suspend fun doRequest(uploadQuery: UploadSigningKeysBody) { - val keysQueryResponse = executeRequest(globalErrorReceiver) { - apiCall = cryptoApi.uploadSigningKeys(uploadQuery) + val keysQueryResponse = executeRequest(globalErrorReceiver) { + cryptoApi.uploadSigningKeys(uploadQuery) } if (keysQueryResponse.failures?.isNotEmpty() == true) { throw UploadSigningKeys(keysQueryResponse.failures) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/federation/FederationAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/federation/FederationAPI.kt index 1816616336..c37392494f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/federation/FederationAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/federation/FederationAPI.kt @@ -18,10 +18,9 @@ package org.matrix.android.sdk.internal.federation import org.matrix.android.sdk.internal.network.NetworkConstants -import retrofit2.Call import retrofit2.http.GET internal interface FederationAPI { @GET(NetworkConstants.URI_FEDERATION_PATH + "version") - fun getVersion(): Call + suspend fun getVersion(): FederationGetVersionResult } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/federation/GetFederationVersionTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/federation/GetFederationVersionTask.kt index ce35e48f6b..b7f73a606c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/federation/GetFederationVersionTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/federation/GetFederationVersionTask.kt @@ -28,8 +28,8 @@ internal class DefaultGetFederationVersionTask @Inject constructor( ) : GetFederationVersionTask { override suspend fun execute(params: Unit): FederationVersion { - val result = executeRequest(null) { - apiCall = federationAPI.getVersion() + val result = executeRequest(null) { + federationAPI.getVersion() } return FederationVersion( diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/Request.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/Request.kt index 442029127d..9f3000ce18 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/Request.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/Request.kt @@ -21,15 +21,28 @@ import kotlinx.coroutines.delay import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.failure.shouldBeRetried import org.matrix.android.sdk.internal.network.ssl.CertUtil -import retrofit2.Call -import retrofit2.awaitResponse +import retrofit2.HttpException import timber.log.Timber import java.io.IOException +// To use when there is no init block to provide internal suspend inline fun executeRequest(globalErrorReceiver: GlobalErrorReceiver?, - block: Request.() -> Unit) = Request(globalErrorReceiver).apply(block).execute() + noinline requestBlock: suspend () -> DATA): DATA { + return executeRequest(globalErrorReceiver, requestBlock, {}) +} -internal class Request(private val globalErrorReceiver: GlobalErrorReceiver?) { +internal suspend inline fun executeRequest(globalErrorReceiver: GlobalErrorReceiver?, + noinline requestBlock: suspend () -> DATA, + initBlock: Request.() -> Unit): DATA { + return Request(globalErrorReceiver, requestBlock) + .apply(initBlock) + .execute() +} + +internal class Request( + private val globalErrorReceiver: GlobalErrorReceiver?, + private val requestBlock: suspend () -> DATA +) { var isRetryable = false var initialDelay: Long = 100L @@ -37,20 +50,22 @@ internal class Request(private val globalErrorReceiver: GlobalErrorR var maxRetryCount = Int.MAX_VALUE private var currentRetryCount = 0 private var currentDelay = initialDelay - lateinit var apiCall: Call suspend fun execute(): DATA { return try { - val response = apiCall.clone().awaitResponse() - if (response.isSuccessful) { - response.body() - ?: throw IllegalStateException("The request returned a null body") - } else { - throw response.toFailure(globalErrorReceiver) + try { + requestBlock() + } catch (exception: Throwable) { + throw when (exception) { + is KotlinNullPointerException -> IllegalStateException("The request returned a null body") + is HttpException -> exception.toFailure(globalErrorReceiver) + else -> exception + } } } catch (exception: Throwable) { - // Log some details about the request which has failed - Timber.e("Exception when executing request ${apiCall.request().method} ${apiCall.request().url.toString().substringBefore("?")}") + // Log some details about the request which has failed. This is less useful than before... + // Timber.e("Exception when executing request ${apiCall.request().method} ${apiCall.request().url.toString().substringBefore("?")}") + Timber.e("Exception when executing request") // Check if this is a certificateException CertUtil.getCertificateException(exception) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/RetrofitExtensions.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/RetrofitExtensions.kt index dd5a69dd3c..7132b4ff7a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/RetrofitExtensions.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/RetrofitExtensions.kt @@ -25,6 +25,7 @@ import org.matrix.android.sdk.api.failure.MatrixError import org.matrix.android.sdk.internal.di.MoshiProvider import kotlinx.coroutines.suspendCancellableCoroutine import okhttp3.ResponseBody +import retrofit2.HttpException import retrofit2.Response import timber.log.Timber import java.io.IOException @@ -57,6 +58,13 @@ internal fun Response.toFailure(globalErrorReceiver: GlobalErrorReceiver? return toFailure(errorBody(), code(), globalErrorReceiver) } +/** + * Convert a HttpException to a Failure, and eventually parse errorBody to convert it to a MatrixError + */ +internal fun HttpException.toFailure(globalErrorReceiver: GlobalErrorReceiver?): Failure { + return toFailure(response()?.errorBody(), code(), globalErrorReceiver) +} + /** * Convert a okhttp3 Response to a Failure, and eventually parse errorBody to convert it to a MatrixError */ diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/raw/GetUrlTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/raw/GetUrlTask.kt index 16633d90ef..d0e2534e7a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/raw/GetUrlTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/raw/GetUrlTask.kt @@ -17,7 +17,6 @@ package org.matrix.android.sdk.internal.raw import com.zhuinden.monarchy.Monarchy -import okhttp3.ResponseBody import org.matrix.android.sdk.api.cache.CacheStrategy import org.matrix.android.sdk.internal.database.model.RawCacheEntity import org.matrix.android.sdk.internal.database.query.get @@ -58,8 +57,8 @@ internal class DefaultGetUrlTask @Inject constructor( } private suspend fun doRequest(url: String): String { - return executeRequest(null) { - apiCall = rawAPI.getUrl(url) + return executeRequest(null) { + rawAPI.getUrl(url) } .string() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/raw/RawAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/raw/RawAPI.kt index 4b08afd711..338d94781b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/raw/RawAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/raw/RawAPI.kt @@ -18,11 +18,10 @@ package org.matrix.android.sdk.internal.raw import okhttp3.ResponseBody -import retrofit2.Call import retrofit2.http.GET import retrofit2.http.Url internal interface RawAPI { @GET - fun getUrl(@Url url: String): Call + suspend fun getUrl(@Url url: String): ResponseBody } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/AccountAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/AccountAPI.kt index 1db9d121a6..a04d0f2686 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/AccountAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/AccountAPI.kt @@ -17,7 +17,6 @@ package org.matrix.android.sdk.internal.session.account import org.matrix.android.sdk.internal.network.NetworkConstants -import retrofit2.Call import retrofit2.http.Body import retrofit2.http.POST @@ -28,7 +27,7 @@ internal interface AccountAPI { * @param params parameters to change password. */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/password") - fun changePassword(@Body params: ChangePasswordParams): Call + suspend fun changePassword(@Body params: ChangePasswordParams) /** * Deactivate the user account @@ -36,5 +35,5 @@ internal interface AccountAPI { * @param params the deactivate account params */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/deactivate") - fun deactivate(@Body params: DeactivateAccountParams): Call + suspend fun deactivate(@Body params: DeactivateAccountParams) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/ChangePasswordTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/ChangePasswordTask.kt index 1f043b0a9d..02c3735998 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/ChangePasswordTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/ChangePasswordTask.kt @@ -39,8 +39,8 @@ internal class DefaultChangePasswordTask @Inject constructor( override suspend fun execute(params: ChangePasswordTask.Params) { val changePasswordParams = ChangePasswordParams.create(userId, params.password, params.newPassword) try { - executeRequest(globalErrorReceiver) { - apiCall = accountAPI.changePassword(changePasswordParams) + executeRequest(globalErrorReceiver) { + accountAPI.changePassword(changePasswordParams) } } catch (throwable: Throwable) { val registrationFlowResponse = throwable.toRegistrationFlowResponse() @@ -49,8 +49,8 @@ internal class DefaultChangePasswordTask @Inject constructor( /* Avoid infinite loop */ && changePasswordParams.auth?.session == null) { // Retry with authentication - executeRequest(globalErrorReceiver) { - apiCall = accountAPI.changePassword( + executeRequest(globalErrorReceiver) { + accountAPI.changePassword( changePasswordParams.copy(auth = changePasswordParams.auth?.copy(session = registrationFlowResponse.session)) ) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/DeactivateAccountTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/DeactivateAccountTask.kt index ca6b0554a9..1a8e80ab68 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/DeactivateAccountTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/DeactivateAccountTask.kt @@ -46,8 +46,8 @@ internal class DefaultDeactivateAccountTask @Inject constructor( val deactivateAccountParams = DeactivateAccountParams.create(params.userAuthParam, params.eraseAllData) val canCleanup = try { - executeRequest(globalErrorReceiver) { - apiCall = accountAPI.deactivate(deactivateAccountParams) + executeRequest(globalErrorReceiver) { + accountAPI.deactivate(deactivateAccountParams) } true } catch (throwable: Throwable) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/GetTurnServerTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/GetTurnServerTask.kt index b21ec1113a..d53ddb7371 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/GetTurnServerTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/GetTurnServerTask.kt @@ -31,7 +31,7 @@ internal class DefaultGetTurnServerTask @Inject constructor(private val voipAPI: override suspend fun execute(params: Params): TurnServerResponse { return executeRequest(globalErrorReceiver) { - apiCall = voipAPI.getTurnServer() + voipAPI.getTurnServer() } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/VoipApi.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/VoipApi.kt index 72c6c58f27..469faaae74 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/VoipApi.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/VoipApi.kt @@ -18,11 +18,10 @@ package org.matrix.android.sdk.internal.session.call import org.matrix.android.sdk.api.session.call.TurnServerResponse import org.matrix.android.sdk.internal.network.NetworkConstants -import retrofit2.Call import retrofit2.http.GET internal interface VoipApi { @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "voip/turnServer") - fun getTurnServer(): Call + suspend fun getTurnServer(): TurnServerResponse } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/directory/DirectoryAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/directory/DirectoryAPI.kt index 6a50f3ee37..19bc7e1908 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/directory/DirectoryAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/directory/DirectoryAPI.kt @@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.session.directory import org.matrix.android.sdk.internal.network.NetworkConstants import org.matrix.android.sdk.internal.session.room.alias.AddRoomAliasBody import org.matrix.android.sdk.internal.session.room.alias.RoomAliasDescription -import retrofit2.Call import retrofit2.http.Body import retrofit2.http.DELETE import retrofit2.http.GET @@ -33,7 +32,7 @@ internal interface DirectoryAPI { * @param roomAlias the room alias. */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "directory/room/{roomAlias}") - fun getRoomIdByAlias(@Path("roomAlias") roomAlias: String): Call + suspend fun getRoomIdByAlias(@Path("roomAlias") roomAlias: String): RoomAliasDescription /** * Get the room directory visibility. @@ -41,7 +40,7 @@ internal interface DirectoryAPI { * @param roomId the room id. */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "directory/list/room/{roomId}") - fun getRoomDirectoryVisibility(@Path("roomId") roomId: String): Call + suspend fun getRoomDirectoryVisibility(@Path("roomId") roomId: String): RoomDirectoryVisibilityJson /** * Set the room directory visibility. @@ -50,21 +49,21 @@ internal interface DirectoryAPI { * @param body the body containing the new directory visibility */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "directory/list/room/{roomId}") - fun setRoomDirectoryVisibility(@Path("roomId") roomId: String, - @Body body: RoomDirectoryVisibilityJson): Call + suspend fun setRoomDirectoryVisibility(@Path("roomId") roomId: String, + @Body body: RoomDirectoryVisibilityJson) /** * Add alias to the room. * @param roomAlias the room alias. */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "directory/room/{roomAlias}") - fun addRoomAlias(@Path("roomAlias") roomAlias: String, - @Body body: AddRoomAliasBody): Call + suspend fun addRoomAlias(@Path("roomAlias") roomAlias: String, + @Body body: AddRoomAliasBody) /** * Delete a room alias * @param roomAlias the room alias. */ @DELETE(NetworkConstants.URI_API_PREFIX_PATH_R0 + "directory/room/{roomAlias}") - fun deleteRoomAlias(@Path("roomAlias") roomAlias: String): Call + suspend fun deleteRoomAlias(@Path("roomAlias") roomAlias: String) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/filter/FilterApi.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/filter/FilterApi.kt index 285bd51d38..2809dea23b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/filter/FilterApi.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/filter/FilterApi.kt @@ -17,7 +17,6 @@ package org.matrix.android.sdk.internal.session.filter import org.matrix.android.sdk.internal.network.NetworkConstants -import retrofit2.Call import retrofit2.http.Body import retrofit2.http.GET import retrofit2.http.POST @@ -32,8 +31,8 @@ internal interface FilterApi { * @param body the Json representation of a FilterBody object */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "user/{userId}/filter") - fun uploadFilter(@Path("userId") userId: String, - @Body body: Filter): Call + suspend fun uploadFilter(@Path("userId") userId: String, + @Body body: Filter): FilterResponse /** * Gets a filter with a given filterId from the homeserver @@ -43,6 +42,6 @@ internal interface FilterApi { * @return Filter */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "user/{userId}/filter/{filterId}") - fun getFilterById(@Path("userId") userId: String, - @Path("filterId") filterId: String): Call + suspend fun getFilterById(@Path("userId") userId: String, + @Path("filterId") filterId: String): Filter } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/filter/SaveFilterTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/filter/SaveFilterTask.kt index d42962d54a..3cac89ce28 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/filter/SaveFilterTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/filter/SaveFilterTask.kt @@ -59,9 +59,9 @@ internal class DefaultSaveFilterTask @Inject constructor( } val updated = filterRepository.storeFilter(filterBody, roomFilter) if (updated) { - val filterResponse = executeRequest(globalErrorReceiver) { + val filterResponse = executeRequest(globalErrorReceiver) { // TODO auto retry - apiCall = filterAPI.uploadFilter(userId, filterBody) + filterAPI.uploadFilter(userId, filterBody) } filterRepository.storeFilterId(filterBody, filterResponse.filterId) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/group/GetGroupDataTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/group/GetGroupDataTask.kt index 9836164aec..4e0ee3422b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/group/GetGroupDataTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/group/GetGroupDataTask.kt @@ -64,14 +64,14 @@ internal class DefaultGetGroupDataTask @Inject constructor( } Timber.v("Fetch data for group with ids: ${groupIds.joinToString(";")}") val data = groupIds.map { groupId -> - val groupSummary = executeRequest(globalErrorReceiver) { - apiCall = groupAPI.getSummary(groupId) + val groupSummary = executeRequest(globalErrorReceiver) { + groupAPI.getSummary(groupId) } - val groupRooms = executeRequest(globalErrorReceiver) { - apiCall = groupAPI.getRooms(groupId) + val groupRooms = executeRequest(globalErrorReceiver) { + groupAPI.getRooms(groupId) } - val groupUsers = executeRequest(globalErrorReceiver) { - apiCall = groupAPI.getUsers(groupId) + val groupUsers = executeRequest(globalErrorReceiver) { + groupAPI.getUsers(groupId) } GroupData(groupId, groupSummary, groupRooms, groupUsers) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/group/GroupAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/group/GroupAPI.kt index 004112578c..58dcc57dd6 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/group/GroupAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/group/GroupAPI.kt @@ -20,7 +20,6 @@ import org.matrix.android.sdk.internal.network.NetworkConstants import org.matrix.android.sdk.internal.session.group.model.GroupRooms import org.matrix.android.sdk.internal.session.group.model.GroupSummaryResponse import org.matrix.android.sdk.internal.session.group.model.GroupUsers -import retrofit2.Call import retrofit2.http.GET import retrofit2.http.Path @@ -32,7 +31,7 @@ internal interface GroupAPI { * @param groupId the group id */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "groups/{groupId}/summary") - fun getSummary(@Path("groupId") groupId: String): Call + suspend fun getSummary(@Path("groupId") groupId: String): GroupSummaryResponse /** * Request the rooms list. @@ -40,7 +39,7 @@ internal interface GroupAPI { * @param groupId the group id */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "groups/{groupId}/rooms") - fun getRooms(@Path("groupId") groupId: String): Call + suspend fun getRooms(@Path("groupId") groupId: String): GroupRooms /** * Request the users list. @@ -48,5 +47,5 @@ internal interface GroupAPI { * @param groupId the group id */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "groups/{groupId}/users") - fun getUsers(@Path("groupId") groupId: String): Call + suspend fun getUsers(@Path("groupId") groupId: String): GroupUsers } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/CapabilitiesAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/CapabilitiesAPI.kt index 8242edac84..7de0cc9592 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/CapabilitiesAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/CapabilitiesAPI.kt @@ -18,7 +18,6 @@ package org.matrix.android.sdk.internal.session.homeserver import org.matrix.android.sdk.internal.auth.version.Versions import org.matrix.android.sdk.internal.network.NetworkConstants -import retrofit2.Call import retrofit2.http.GET internal interface CapabilitiesAPI { @@ -26,17 +25,17 @@ internal interface CapabilitiesAPI { * Request the homeserver capabilities */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "capabilities") - fun getCapabilities(): Call + suspend fun getCapabilities(): GetCapabilitiesResult /** * Request the versions */ @GET(NetworkConstants.URI_API_PREFIX_PATH_ + "versions") - fun getVersions(): Call + suspend fun getVersions(): Versions /** * Ping the homeserver. We do not care about the returned data, so there is no use to parse them */ @GET(NetworkConstants.URI_API_PREFIX_PATH_ + "versions") - fun ping(): Call + suspend fun ping() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt index 84c9132d61..740370123f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt @@ -71,20 +71,20 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor( } val capabilities = runCatching { - executeRequest(globalErrorReceiver) { - apiCall = capabilitiesAPI.getCapabilities() + executeRequest(globalErrorReceiver) { + capabilitiesAPI.getCapabilities() } }.getOrNull() val mediaConfig = runCatching { - executeRequest(globalErrorReceiver) { - apiCall = mediaAPI.getMediaConfig() + executeRequest(globalErrorReceiver) { + mediaAPI.getMediaConfig() } }.getOrNull() val versions = runCatching { - executeRequest(null) { - apiCall = capabilitiesAPI.getVersions() + executeRequest(null) { + capabilitiesAPI.getVersions() } }.getOrNull() diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/HomeServerPinger.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/HomeServerPinger.kt index 522097acbf..bb526adf4a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/HomeServerPinger.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/HomeServerPinger.kt @@ -34,8 +34,8 @@ internal class HomeServerPinger @Inject constructor(private val taskExecutor: Ta suspend fun canReachHomeServer(): Boolean { return try { - executeRequest(null) { - apiCall = capabilitiesAPI.ping() + executeRequest(null) { + capabilitiesAPI.ping() } true } catch (throwable: Throwable) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityAPI.kt index 7e2702e70d..e9e4d17e3a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityAPI.kt @@ -26,7 +26,6 @@ import org.matrix.android.sdk.internal.session.identity.model.IdentityRequestOwn import org.matrix.android.sdk.internal.session.identity.model.IdentityRequestTokenForEmailBody import org.matrix.android.sdk.internal.session.identity.model.IdentityRequestTokenForMsisdnBody import org.matrix.android.sdk.internal.session.identity.model.IdentityRequestTokenResponse -import retrofit2.Call import retrofit2.http.Body import retrofit2.http.GET import retrofit2.http.POST @@ -43,20 +42,20 @@ internal interface IdentityAPI { * Ref: https://matrix.org/docs/spec/identity_service/latest#get-matrix-identity-v2-account */ @GET(NetworkConstants.URI_IDENTITY_PATH_V2 + "account") - fun getAccount(): Call + suspend fun getAccount(): IdentityAccountResponse /** * Logs out the access token, preventing it from being used to authenticate future requests to the server. */ @POST(NetworkConstants.URI_IDENTITY_PATH_V2 + "account/logout") - fun logout(): Call + suspend fun logout() /** * Request the hash detail to request a bunch of 3PIDs * Ref: https://matrix.org/docs/spec/identity_service/latest#get-matrix-identity-v2-hash-details */ @GET(NetworkConstants.URI_IDENTITY_PATH_V2 + "hash_details") - fun hashDetails(): Call + suspend fun hashDetails(): IdentityHashDetailResponse /** * Request a bunch of 3PIDs @@ -65,7 +64,7 @@ internal interface IdentityAPI { * @param body the body request */ @POST(NetworkConstants.URI_IDENTITY_PATH_V2 + "lookup") - fun lookup(@Body body: IdentityLookUpParams): Call + suspend fun lookup(@Body body: IdentityLookUpParams): IdentityLookUpResponse /** * Create a session to change the bind status of an email to an identity server @@ -75,7 +74,7 @@ internal interface IdentityAPI { * @return the sid */ @POST(NetworkConstants.URI_IDENTITY_PATH_V2 + "validate/email/requestToken") - fun requestTokenToBindEmail(@Body body: IdentityRequestTokenForEmailBody): Call + suspend fun requestTokenToBindEmail(@Body body: IdentityRequestTokenForEmailBody): IdentityRequestTokenResponse /** * Create a session to change the bind status of an phone number to an identity server @@ -85,7 +84,7 @@ internal interface IdentityAPI { * @return the sid */ @POST(NetworkConstants.URI_IDENTITY_PATH_V2 + "validate/msisdn/requestToken") - fun requestTokenToBindMsisdn(@Body body: IdentityRequestTokenForMsisdnBody): Call + suspend fun requestTokenToBindMsisdn(@Body body: IdentityRequestTokenForMsisdnBody): IdentityRequestTokenResponse /** * Validate ownership of an email address, or a phone number. @@ -94,6 +93,6 @@ internal interface IdentityAPI { * - https://matrix.org/docs/spec/identity_service/latest#post-matrix-identity-v2-validate-email-submittoken */ @POST(NetworkConstants.URI_IDENTITY_PATH_V2 + "validate/{medium}/submitToken") - fun submitToken(@Path("medium") medium: String, - @Body body: IdentityRequestOwnershipParams): Call + suspend fun submitToken(@Path("medium") medium: String, + @Body body: IdentityRequestOwnershipParams): SuccessResult } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityAuthAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityAuthAPI.kt index fd6e1163ef..1671859585 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityAuthAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityAuthAPI.kt @@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.session.identity import org.matrix.android.sdk.internal.network.NetworkConstants import org.matrix.android.sdk.internal.session.identity.model.IdentityRegisterResponse import org.matrix.android.sdk.internal.session.openid.RequestOpenIdTokenResponse -import retrofit2.Call import retrofit2.http.Body import retrofit2.http.GET import retrofit2.http.POST @@ -40,18 +39,18 @@ internal interface IdentityAuthAPI { * @return 200 in case of success */ @GET(NetworkConstants.URI_IDENTITY_PREFIX_PATH) - fun ping(): Call + suspend fun ping() /** * Ping v1 will be used to check outdated Identity server */ @GET("_matrix/identity/api/v1") - fun pingV1(): Call + suspend fun pingV1() /** * Exchanges an OpenID token from the homeserver for an access token to access the identity server. * The request body is the same as the values returned by /openid/request_token in the Client-Server API. */ @POST(NetworkConstants.URI_IDENTITY_PATH_V2 + "account/register") - fun register(@Body openIdToken: RequestOpenIdTokenResponse): Call + suspend fun register(@Body openIdToken: RequestOpenIdTokenResponse): IdentityRegisterResponse } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityBulkLookupTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityBulkLookupTask.kt index 67f3b2aa56..4f6e906766 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityBulkLookupTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityBulkLookupTask.kt @@ -83,7 +83,7 @@ internal class DefaultIdentityBulkLookupTask @Inject constructor( return try { LookUpData(hashedAddresses, executeRequest(null) { - apiCall = identityAPI.lookup(IdentityLookUpParams( + identityAPI.lookup(IdentityLookUpParams( hashedAddresses, IdentityHashDetailResponse.ALGORITHM_SHA256, hashDetailResponse.pepper @@ -126,7 +126,7 @@ internal class DefaultIdentityBulkLookupTask @Inject constructor( private suspend fun fetchHashDetails(identityAPI: IdentityAPI): IdentityHashDetailResponse { return executeRequest(null) { - apiCall = identityAPI.hashDetails() + identityAPI.hashDetails() } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityDisconnectTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityDisconnectTask.kt index 50e24f1245..fc84a144fe 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityDisconnectTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityDisconnectTask.kt @@ -42,8 +42,8 @@ internal class DefaultIdentityDisconnectTask @Inject constructor( return } - executeRequest(null) { - apiCall = identityAPI.logout() + executeRequest(null) { + identityAPI.logout() } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityPingTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityPingTask.kt index b0d33811bd..fca9408d9c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityPingTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityPingTask.kt @@ -33,14 +33,14 @@ internal class DefaultIdentityPingTask @Inject constructor() : IdentityPingTask override suspend fun execute(params: IdentityPingTask.Params) { try { - executeRequest(null) { - apiCall = params.identityAuthAPI.ping() + executeRequest(null) { + params.identityAuthAPI.ping() } } catch (throwable: Throwable) { if (throwable is Failure.ServerError && throwable.httpCode == HttpsURLConnection.HTTP_NOT_FOUND /* 404 */) { // Check if API v1 is available - executeRequest(null) { - apiCall = params.identityAuthAPI.pingV1() + executeRequest(null) { + params.identityAuthAPI.pingV1() } // API V1 is responding, but not V2 -> Outdated throw IdentityServiceError.OutdatedIdentityServer diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityRegisterTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityRegisterTask.kt index 19215f353a..8cc854bd94 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityRegisterTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityRegisterTask.kt @@ -33,7 +33,7 @@ internal class DefaultIdentityRegisterTask @Inject constructor() : IdentityRegis override suspend fun execute(params: IdentityRegisterTask.Params): IdentityRegisterResponse { return executeRequest(null) { - apiCall = params.identityAuthAPI.register(params.openIdTokenResponse) + params.identityAuthAPI.register(params.openIdTokenResponse) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityRequestTokenForBindingTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityRequestTokenForBindingTask.kt index bd4cd763f0..9c89048176 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityRequestTokenForBindingTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityRequestTokenForBindingTask.kt @@ -25,7 +25,6 @@ import org.matrix.android.sdk.internal.session.identity.data.IdentityPendingBind import org.matrix.android.sdk.internal.session.identity.data.IdentityStore import org.matrix.android.sdk.internal.session.identity.model.IdentityRequestTokenForEmailBody import org.matrix.android.sdk.internal.session.identity.model.IdentityRequestTokenForMsisdnBody -import org.matrix.android.sdk.internal.session.identity.model.IdentityRequestTokenResponse import org.matrix.android.sdk.internal.task.Task import java.util.UUID import javax.inject.Inject @@ -56,8 +55,8 @@ internal class DefaultIdentityRequestTokenForBindingTask @Inject constructor( val clientSecret = identityPendingBinding?.clientSecret ?: UUID.randomUUID().toString() val sendAttempt = identityPendingBinding?.sendAttempt?.inc() ?: 1 - val tokenResponse = executeRequest(null) { - apiCall = when (params.threePid) { + val tokenResponse = executeRequest(null) { + when (params.threePid) { is ThreePid.Email -> identityAPI.requestTokenToBindEmail(IdentityRequestTokenForEmailBody( clientSecret = clientSecret, sendAttempt = sendAttempt, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentitySubmitTokenForBindingTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentitySubmitTokenForBindingTask.kt index ebc71c715d..f884e2816d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentitySubmitTokenForBindingTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentitySubmitTokenForBindingTask.kt @@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.session.identity import org.matrix.android.sdk.api.session.identity.IdentityServiceError import org.matrix.android.sdk.api.session.identity.ThreePid import org.matrix.android.sdk.api.session.identity.toMedium -import org.matrix.android.sdk.internal.auth.registration.SuccessResult import org.matrix.android.sdk.internal.di.UserId import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.identity.data.IdentityStore @@ -44,8 +43,8 @@ internal class DefaultIdentitySubmitTokenForBindingTask @Inject constructor( val identityAPI = getIdentityApiAndEnsureTerms(identityApiProvider, userId) val identityPendingBinding = identityStore.getPendingBinding(params.threePid) ?: throw IdentityServiceError.NoCurrentBindingError - val tokenResponse = executeRequest(null) { - apiCall = identityAPI.submitToken( + val tokenResponse = executeRequest(null) { + identityAPI.submitToken( params.threePid.toMedium(), IdentityRequestOwnershipParams( clientSecret = identityPendingBinding.clientSecret, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityTaskHelper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityTaskHelper.kt index d3aecce381..d06b157f22 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityTaskHelper.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/IdentityTaskHelper.kt @@ -18,14 +18,13 @@ package org.matrix.android.sdk.internal.session.identity import org.matrix.android.sdk.api.session.identity.IdentityServiceError import org.matrix.android.sdk.internal.network.executeRequest -import org.matrix.android.sdk.internal.session.identity.model.IdentityAccountResponse internal suspend fun getIdentityApiAndEnsureTerms(identityApiProvider: IdentityApiProvider, userId: String): IdentityAPI { val identityAPI = identityApiProvider.identityApi ?: throw IdentityServiceError.NoIdentityServerConfigured // Always check that we have access to the service (regarding terms) - val identityAccountResponse = executeRequest(null) { - apiCall = identityAPI.getAccount() + val identityAccountResponse = executeRequest(null) { + identityAPI.getAccount() } assert(userId == identityAccountResponse.userId) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetPreviewUrlTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetPreviewUrlTask.kt index d85e471f1d..e707c2351c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetPreviewUrlTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetPreviewUrlTask.kt @@ -65,8 +65,8 @@ internal class DefaultGetPreviewUrlTask @Inject constructor( } private suspend fun doRequest(url: String, timestamp: Long?): PreviewUrlData { - return executeRequest(globalErrorReceiver) { - apiCall = mediaAPI.getPreviewUrlData(url, timestamp) + return executeRequest(globalErrorReceiver) { + mediaAPI.getPreviewUrlData(url, timestamp) } .toPreviewUrlData(url) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetRawPreviewUrlTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetRawPreviewUrlTask.kt index 32305cd4e4..fd906f0dc8 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetRawPreviewUrlTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetRawPreviewUrlTask.kt @@ -36,7 +36,7 @@ internal class DefaultGetRawPreviewUrlTask @Inject constructor( override suspend fun execute(params: GetRawPreviewUrlTask.Params): JsonDict { return executeRequest(globalErrorReceiver) { - apiCall = mediaAPI.getPreviewUrlData(params.url, params.timestamp) + mediaAPI.getPreviewUrlData(params.url, params.timestamp) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/MediaAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/MediaAPI.kt index bbb4f1e06a..9ee1d26cdc 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/MediaAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/MediaAPI.kt @@ -18,7 +18,6 @@ package org.matrix.android.sdk.internal.session.media import org.matrix.android.sdk.api.util.JsonDict import org.matrix.android.sdk.internal.network.NetworkConstants -import retrofit2.Call import retrofit2.http.GET import retrofit2.http.Query @@ -28,7 +27,7 @@ internal interface MediaAPI { * Ref: https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-media-r0-config */ @GET(NetworkConstants.URI_API_MEDIA_PREFIX_PATH_R0 + "config") - fun getMediaConfig(): Call + suspend fun getMediaConfig(): GetMediaConfigResult /** * Get information about a URL for the client. Typically this is called when a client @@ -39,5 +38,5 @@ internal interface MediaAPI { * if it does not have the requested version available. */ @GET(NetworkConstants.URI_API_MEDIA_PREFIX_PATH_R0 + "preview_url") - fun getPreviewUrlData(@Query("url") url: String, @Query("ts") ts: Long?): Call + suspend fun getPreviewUrlData(@Query("url") url: String, @Query("ts") ts: Long?): JsonDict } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/openid/GetOpenIdTokenTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/openid/GetOpenIdTokenTask.kt index f83c6b770a..8481a6ab93 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/openid/GetOpenIdTokenTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/openid/GetOpenIdTokenTask.kt @@ -31,7 +31,7 @@ internal class DefaultGetOpenIdTokenTask @Inject constructor( override suspend fun execute(params: Unit): RequestOpenIdTokenResponse { return executeRequest(globalErrorReceiver) { - apiCall = openIdAPI.openIdToken(userId) + openIdAPI.openIdToken(userId) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/openid/OpenIdAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/openid/OpenIdAPI.kt index 4614d82453..ed090b845d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/openid/OpenIdAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/openid/OpenIdAPI.kt @@ -18,7 +18,6 @@ package org.matrix.android.sdk.internal.session.openid import org.matrix.android.sdk.api.util.JsonDict import org.matrix.android.sdk.internal.network.NetworkConstants -import retrofit2.Call import retrofit2.http.Body import retrofit2.http.POST import retrofit2.http.Path @@ -34,6 +33,6 @@ internal interface OpenIdAPI { * @param userId the user id */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "user/{userId}/openid/request_token") - fun openIdToken(@Path("userId") userId: String, - @Body body: JsonDict = emptyMap()): Call + suspend fun openIdToken(@Path("userId") userId: String, + @Body body: JsonDict = emptyMap()): RequestOpenIdTokenResponse } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/AddThreePidTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/AddThreePidTask.kt index 6d6d70bb0d..678d399428 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/AddThreePidTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/AddThreePidTask.kt @@ -50,13 +50,14 @@ internal class DefaultAddThreePidTask @Inject constructor( val clientSecret = UUID.randomUUID().toString() val sendAttempt = 1 - val result = executeRequest(globalErrorReceiver) { - val body = AddEmailBody( - clientSecret = clientSecret, - email = threePid.email, - sendAttempt = sendAttempt - ) - apiCall = profileAPI.addEmail(body) + val body = AddEmailBody( + clientSecret = clientSecret, + email = threePid.email, + sendAttempt = sendAttempt + ) + + val result = executeRequest(globalErrorReceiver) { + profileAPI.addEmail(body) } // Store as a pending three pid @@ -84,14 +85,15 @@ internal class DefaultAddThreePidTask @Inject constructor( val countryCode = parsedNumber.countryCode val country = phoneNumberUtil.getRegionCodeForCountryCode(countryCode) - val result = executeRequest(globalErrorReceiver) { - val body = AddMsisdnBody( - clientSecret = clientSecret, - country = country, - phoneNumber = parsedNumber.nationalNumber.toString(), - sendAttempt = sendAttempt - ) - apiCall = profileAPI.addMsisdn(body) + val body = AddMsisdnBody( + clientSecret = clientSecret, + country = country, + phoneNumber = parsedNumber.nationalNumber.toString(), + sendAttempt = sendAttempt + ) + + val result = executeRequest(globalErrorReceiver) { + profileAPI.addMsisdn(body) } // Store as a pending three pid diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/BindThreePidsTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/BindThreePidsTask.kt index a37e5380bc..87e51181e6 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/BindThreePidsTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/BindThreePidsTask.kt @@ -43,8 +43,8 @@ internal class DefaultBindThreePidsTask @Inject constructor(private val profileA val identityServerAccessToken = accessTokenProvider.getToken() ?: throw IdentityServiceError.NoIdentityServerConfigured val identityPendingBinding = identityStore.getPendingBinding(params.threePid) ?: throw IdentityServiceError.NoCurrentBindingError - executeRequest(globalErrorReceiver) { - apiCall = profileAPI.bindThreePid( + executeRequest(globalErrorReceiver) { + profileAPI.bindThreePid( BindThreePidBody( clientSecret = identityPendingBinding.clientSecret, identityServerUrlWithoutProtocol = identityServerUrlWithoutProtocol, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/DeleteThreePidTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/DeleteThreePidTask.kt index 3549f3613f..7b7617aa80 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/DeleteThreePidTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/DeleteThreePidTask.kt @@ -34,12 +34,12 @@ internal class DefaultDeleteThreePidTask @Inject constructor( private val globalErrorReceiver: GlobalErrorReceiver) : DeleteThreePidTask() { override suspend fun execute(params: Params) { - executeRequest(globalErrorReceiver) { - val body = DeleteThreePidBody( - medium = params.threePid.toMedium(), - address = params.threePid.value - ) - apiCall = profileAPI.deleteThreePid(body) + val body = DeleteThreePidBody( + medium = params.threePid.toMedium(), + address = params.threePid.value + ) + executeRequest(globalErrorReceiver) { + profileAPI.deleteThreePid(body) } // We do not really care about the result for the moment diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/FinalizeAddingThreePidTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/FinalizeAddingThreePidTask.kt index c2a38af093..5f063365e0 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/FinalizeAddingThreePidTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/FinalizeAddingThreePidTask.kt @@ -61,13 +61,13 @@ internal class DefaultFinalizeAddingThreePidTask @Inject constructor( ?: throw IllegalArgumentException("unknown threepid") try { - executeRequest(globalErrorReceiver) { + executeRequest(globalErrorReceiver) { val body = FinalizeAddThreePidBody( clientSecret = pendingThreePids.clientSecret, sid = pendingThreePids.sid, auth = params.userAuthParam?.asMap() ) - apiCall = profileAPI.finalizeAddThreePid(body) + profileAPI.finalizeAddThreePid(body) } true } catch (throwable: Throwable) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/GetProfileInfoTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/GetProfileInfoTask.kt index ed60c4a368..fed4288f84 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/GetProfileInfoTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/GetProfileInfoTask.kt @@ -34,7 +34,7 @@ internal class DefaultGetProfileInfoTask @Inject constructor(private val profile override suspend fun execute(params: Params): JsonDict { return executeRequest(globalErrorReceiver) { - apiCall = profileAPI.getProfile(params.userId) + profileAPI.getProfile(params.userId) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/ProfileAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/ProfileAPI.kt index 7794f578b0..5113b821e8 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/ProfileAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/ProfileAPI.kt @@ -21,7 +21,6 @@ import org.matrix.android.sdk.api.util.JsonDict import org.matrix.android.sdk.internal.auth.registration.SuccessResult import org.matrix.android.sdk.internal.auth.registration.ValidationCodeBody import org.matrix.android.sdk.internal.network.NetworkConstants -import retrofit2.Call import retrofit2.http.Body import retrofit2.http.GET import retrofit2.http.POST @@ -37,70 +36,70 @@ internal interface ProfileAPI { * @param userId the user id to fetch profile info */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "profile/{userId}") - fun getProfile(@Path("userId") userId: String): Call + suspend fun getProfile(@Path("userId") userId: String): JsonDict /** * List all 3PIDs linked to the Matrix user account. */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/3pid") - fun getThreePIDs(): Call + suspend fun getThreePIDs(): AccountThreePidsResponse /** * Change user display name */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "profile/{userId}/displayname") - fun setDisplayName(@Path("userId") userId: String, - @Body body: SetDisplayNameBody): Call + suspend fun setDisplayName(@Path("userId") userId: String, + @Body body: SetDisplayNameBody) /** * Change user avatar url. */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "profile/{userId}/avatar_url") - fun setAvatarUrl(@Path("userId") userId: String, - @Body body: SetAvatarUrlBody): Call + suspend fun setAvatarUrl(@Path("userId") userId: String, + @Body body: SetAvatarUrlBody) /** * Bind a threePid * Ref: https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-account-3pid-bind */ @POST(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "account/3pid/bind") - fun bindThreePid(@Body body: BindThreePidBody): Call + suspend fun bindThreePid(@Body body: BindThreePidBody) /** * Unbind a threePid * Ref: https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-account-3pid-unbind */ @POST(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "account/3pid/unbind") - fun unbindThreePid(@Body body: UnbindThreePidBody): Call + suspend fun unbindThreePid(@Body body: UnbindThreePidBody): UnbindThreePidResponse /** * Ref: https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-account-3pid-email-requesttoken */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/3pid/email/requestToken") - fun addEmail(@Body body: AddEmailBody): Call + suspend fun addEmail(@Body body: AddEmailBody): AddEmailResponse /** * Ref: https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-account-3pid-msisdn-requesttoken */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/3pid/msisdn/requestToken") - fun addMsisdn(@Body body: AddMsisdnBody): Call + suspend fun addMsisdn(@Body body: AddMsisdnBody): AddMsisdnResponse /** * Validate Msisdn code (same model than for Identity server API) */ @POST - fun validateMsisdn(@Url url: String, - @Body params: ValidationCodeBody): Call + suspend fun validateMsisdn(@Url url: String, + @Body params: ValidationCodeBody): SuccessResult /** * Ref: https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-account-3pid-add */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/3pid/add") - fun finalizeAddThreePid(@Body body: FinalizeAddThreePidBody): Call + suspend fun finalizeAddThreePid(@Body body: FinalizeAddThreePidBody) /** * Ref: https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-account-3pid-delete */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "account/3pid/delete") - fun deleteThreePid(@Body body: DeleteThreePidBody): Call + suspend fun deleteThreePid(@Body body: DeleteThreePidBody): DeleteThreePidResponse } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/RefreshUserThreePidsTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/RefreshUserThreePidsTask.kt index 552ad874ee..8a064b4fd1 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/RefreshUserThreePidsTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/RefreshUserThreePidsTask.kt @@ -33,8 +33,8 @@ internal class DefaultRefreshUserThreePidsTask @Inject constructor(private val p private val globalErrorReceiver: GlobalErrorReceiver) : RefreshUserThreePidsTask() { override suspend fun execute(params: Unit) { - val accountThreePidsResponse = executeRequest(globalErrorReceiver) { - apiCall = profileAPI.getThreePIDs() + val accountThreePidsResponse = executeRequest(globalErrorReceiver) { + profileAPI.getThreePIDs() } Timber.d("Get ${accountThreePidsResponse.threePids?.size} threePids") diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetAvatarUrlTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetAvatarUrlTask.kt index b29153d665..a7d116d919 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetAvatarUrlTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetAvatarUrlTask.kt @@ -33,11 +33,11 @@ internal class DefaultSetAvatarUrlTask @Inject constructor( private val globalErrorReceiver: GlobalErrorReceiver) : SetAvatarUrlTask() { override suspend fun execute(params: Params) { + val body = SetAvatarUrlBody( + avatarUrl = params.newAvatarUrl + ) return executeRequest(globalErrorReceiver) { - val body = SetAvatarUrlBody( - avatarUrl = params.newAvatarUrl - ) - apiCall = profileAPI.setAvatarUrl(params.userId, body) + profileAPI.setAvatarUrl(params.userId, body) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetDisplayNameTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetDisplayNameTask.kt index 3f236bc589..61d3042310 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetDisplayNameTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetDisplayNameTask.kt @@ -33,11 +33,11 @@ internal class DefaultSetDisplayNameTask @Inject constructor( private val globalErrorReceiver: GlobalErrorReceiver) : SetDisplayNameTask() { override suspend fun execute(params: Params) { + val body = SetDisplayNameBody( + displayName = params.newDisplayName + ) return executeRequest(globalErrorReceiver) { - val body = SetDisplayNameBody( - displayName = params.newDisplayName - ) - apiCall = profileAPI.setDisplayName(params.userId, body) + profileAPI.setDisplayName(params.userId, body) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/UnbindThreePidsTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/UnbindThreePidsTask.kt index 3439f6f840..df8a1c97ff 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/UnbindThreePidsTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/UnbindThreePidsTask.kt @@ -39,8 +39,8 @@ internal class DefaultUnbindThreePidsTask @Inject constructor(private val profil val identityServerUrlWithoutProtocol = identityStore.getIdentityServerUrlWithoutProtocol() ?: throw IdentityServiceError.NoIdentityServerConfigured - return executeRequest(globalErrorReceiver) { - apiCall = profileAPI.unbindThreePid( + return executeRequest(globalErrorReceiver) { + profileAPI.unbindThreePid( UnbindThreePidBody( identityServerUrlWithoutProtocol, params.threePid.toMedium(), diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/ValidateSmsCodeTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/ValidateSmsCodeTask.kt index efb6c6e836..c898fc6c5c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/ValidateSmsCodeTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/ValidateSmsCodeTask.kt @@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.session.profile import com.zhuinden.monarchy.Monarchy import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.session.identity.ThreePid -import org.matrix.android.sdk.internal.auth.registration.SuccessResult import org.matrix.android.sdk.internal.auth.registration.ValidationCodeBody import org.matrix.android.sdk.internal.database.model.PendingThreePidEntity import org.matrix.android.sdk.internal.di.SessionDatabase @@ -58,8 +57,8 @@ internal class DefaultValidateSmsCodeTask @Inject constructor( sid = pendingThreePids.sid, code = params.code ) - val result = executeRequest(globalErrorReceiver) { - apiCall = profileAPI.validateMsisdn(url, body) + val result = executeRequest(globalErrorReceiver) { + profileAPI.validateMsisdn(url, body) } if (!result.isSuccess()) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddHttpPusherWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddHttpPusherWorker.kt index d0f7cbfca3..c9d7ad2193 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddHttpPusherWorker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddHttpPusherWorker.kt @@ -81,8 +81,8 @@ internal class AddHttpPusherWorker(context: Context, params: WorkerParameters) } private suspend fun setPusher(pusher: JsonPusher) { - executeRequest(globalErrorReceiver) { - apiCall = pushersAPI.setPusher(pusher) + executeRequest(globalErrorReceiver) { + pushersAPI.setPusher(pusher) } monarchy.awaitTransaction { realm -> val echo = PusherEntity.where(realm, pusher.pushKey).findFirst() diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPushRuleTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPushRuleTask.kt index 03748b1528..b217687168 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPushRuleTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPushRuleTask.kt @@ -36,7 +36,7 @@ internal class DefaultAddPushRuleTask @Inject constructor( override suspend fun execute(params: AddPushRuleTask.Params) { return executeRequest(globalErrorReceiver) { - apiCall = pushRulesApi.addRule(params.kind.value, params.pushRule.ruleId, params.pushRule) + pushRulesApi.addRule(params.kind.value, params.pushRule.ruleId, params.pushRule) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushRulesTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushRulesTask.kt index 9fb2d51664..8cf861d285 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushRulesTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushRulesTask.kt @@ -15,7 +15,6 @@ */ package org.matrix.android.sdk.internal.session.pushers -import org.matrix.android.sdk.api.pushrules.rest.GetPushRulesResponse import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task @@ -35,8 +34,8 @@ internal class DefaultGetPushRulesTask @Inject constructor( ) : GetPushRulesTask { override suspend fun execute(params: GetPushRulesTask.Params) { - val response = executeRequest(globalErrorReceiver) { - apiCall = pushRulesApi.getAllRules() + val response = executeRequest(globalErrorReceiver) { + pushRulesApi.getAllRules() } savePushRulesTask.execute(SavePushRulesTask.Params(response)) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushersTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushersTask.kt index 125c8f0022..ba413a34db 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushersTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushersTask.kt @@ -36,8 +36,8 @@ internal class DefaultGetPushersTask @Inject constructor( ) : GetPushersTask { override suspend fun execute(params: Unit) { - val response = executeRequest(globalErrorReceiver) { - apiCall = pushersAPI.getPushers() + val response = executeRequest(globalErrorReceiver) { + pushersAPI.getPushers() } monarchy.awaitTransaction { realm -> // clear existings? diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/PushRulesApi.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/PushRulesApi.kt index cbcb7d2b37..daf9397ce8 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/PushRulesApi.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/PushRulesApi.kt @@ -18,7 +18,6 @@ package org.matrix.android.sdk.internal.session.pushers import org.matrix.android.sdk.api.pushrules.rest.GetPushRulesResponse import org.matrix.android.sdk.api.pushrules.rest.PushRule import org.matrix.android.sdk.internal.network.NetworkConstants -import retrofit2.Call import retrofit2.http.Body import retrofit2.http.DELETE import retrofit2.http.GET @@ -30,7 +29,7 @@ internal interface PushRulesApi { * Get all push rules */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/") - fun getAllRules(): Call + suspend fun getAllRules(): GetPushRulesResponse /** * Update the ruleID enable status @@ -40,10 +39,9 @@ internal interface PushRulesApi { * @param enable the new enable status */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}/enabled") - fun updateEnableRuleStatus(@Path("kind") kind: String, - @Path("ruleId") ruleId: String, - @Body enable: Boolean?) - : Call + suspend fun updateEnableRuleStatus(@Path("kind") kind: String, + @Path("ruleId") ruleId: String, + @Body enable: Boolean?) /** * Update the ruleID action @@ -54,10 +52,9 @@ internal interface PushRulesApi { * @param actions the actions */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}/actions") - fun updateRuleActions(@Path("kind") kind: String, - @Path("ruleId") ruleId: String, - @Body actions: Any) - : Call + suspend fun updateRuleActions(@Path("kind") kind: String, + @Path("ruleId") ruleId: String, + @Body actions: Any) /** * Delete a rule @@ -66,9 +63,8 @@ internal interface PushRulesApi { * @param ruleId the ruleId */ @DELETE(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}") - fun deleteRule(@Path("kind") kind: String, - @Path("ruleId") ruleId: String) - : Call + suspend fun deleteRule(@Path("kind") kind: String, + @Path("ruleId") ruleId: String) /** * Add the ruleID enable status @@ -78,8 +74,7 @@ internal interface PushRulesApi { * @param rule the rule to add. */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}") - fun addRule(@Path("kind") kind: String, - @Path("ruleId") ruleId: String, - @Body rule: PushRule) - : Call + suspend fun addRule(@Path("kind") kind: String, + @Path("ruleId") ruleId: String, + @Body rule: PushRule) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/PushersAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/PushersAPI.kt index ed4fb73e1b..0afea6996d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/PushersAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/PushersAPI.kt @@ -16,7 +16,6 @@ package org.matrix.android.sdk.internal.session.pushers import org.matrix.android.sdk.internal.network.NetworkConstants -import retrofit2.Call import retrofit2.http.Body import retrofit2.http.GET import retrofit2.http.POST @@ -29,7 +28,7 @@ internal interface PushersAPI { * Ref: https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushers */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushers") - fun getPushers(): Call + suspend fun getPushers(): GetPushersResponse /** * This endpoint allows the creation, modification and deletion of pushers for this user ID. @@ -38,5 +37,5 @@ internal interface PushersAPI { * Ref: https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-pushers-set */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushers/set") - fun setPusher(@Body jsonPusher: JsonPusher): Call + suspend fun setPusher(@Body jsonPusher: JsonPusher) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePushRuleTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePushRuleTask.kt index ff3122f566..23d0515f41 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePushRuleTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePushRuleTask.kt @@ -36,7 +36,7 @@ internal class DefaultRemovePushRuleTask @Inject constructor( override suspend fun execute(params: RemovePushRuleTask.Params) { return executeRequest(globalErrorReceiver) { - apiCall = pushRulesApi.deleteRule(params.kind.value, params.pushRule.ruleId) + pushRulesApi.deleteRule(params.kind.value, params.pushRule.ruleId) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePusherTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePusherTask.kt index e3f4fdb789..3a2ebf40c2 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePusherTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePusherTask.kt @@ -62,8 +62,8 @@ internal class DefaultRemovePusherTask @Inject constructor( data = JsonPusherData(existing.data.url, existing.data.format), append = false ) - executeRequest(globalErrorReceiver) { - apiCall = pushersAPI.setPusher(deleteBody) + executeRequest(globalErrorReceiver) { + pushersAPI.setPusher(deleteBody) } monarchy.awaitTransaction { PusherEntity.where(it, params.pushKey).findFirst()?.deleteFromRealm() diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleActionsTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleActionsTask.kt index a5c220e662..2a24aee892 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleActionsTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleActionsTask.kt @@ -38,8 +38,8 @@ internal class DefaultUpdatePushRuleActionsTask @Inject constructor( override suspend fun execute(params: UpdatePushRuleActionsTask.Params) { if (params.oldPushRule.enabled != params.newPushRule.enabled) { // First change enabled state - executeRequest(globalErrorReceiver) { - apiCall = pushRulesApi.updateEnableRuleStatus(params.kind.value, params.newPushRule.ruleId, params.newPushRule.enabled) + executeRequest(globalErrorReceiver) { + pushRulesApi.updateEnableRuleStatus(params.kind.value, params.newPushRule.ruleId, params.newPushRule.enabled) } } @@ -47,8 +47,8 @@ internal class DefaultUpdatePushRuleActionsTask @Inject constructor( // Also ensure the actions are up to date val body = mapOf("actions" to params.newPushRule.actions) - executeRequest(globalErrorReceiver) { - apiCall = pushRulesApi.updateRuleActions(params.kind.value, params.newPushRule.ruleId, body) + executeRequest(globalErrorReceiver) { + pushRulesApi.updateRuleActions(params.kind.value, params.newPushRule.ruleId, body) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleEnableStatusTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleEnableStatusTask.kt index f36b5c55fb..9d7a46bede 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleEnableStatusTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleEnableStatusTask.kt @@ -35,7 +35,7 @@ internal class DefaultUpdatePushRuleEnableStatusTask @Inject constructor( override suspend fun execute(params: UpdatePushRuleEnableStatusTask.Params) { return executeRequest(globalErrorReceiver) { - apiCall = pushRulesApi.updateEnableRuleStatus(params.kind.value, params.pushRule.ruleId, params.enabled) + pushRulesApi.updateEnableRuleStatus(params.kind.value, params.pushRule.ruleId, params.enabled) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/gateway/PushGatewayAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/gateway/PushGatewayAPI.kt index d95587fc22..4333d6c7b8 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/gateway/PushGatewayAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/gateway/PushGatewayAPI.kt @@ -16,7 +16,6 @@ package org.matrix.android.sdk.internal.session.pushers.gateway import org.matrix.android.sdk.internal.network.NetworkConstants -import retrofit2.Call import retrofit2.http.Body import retrofit2.http.POST @@ -27,5 +26,5 @@ internal interface PushGatewayAPI { * Ref: https://matrix.org/docs/spec/push_gateway/r0.1.1#post-matrix-push-v1-notify */ @POST(NetworkConstants.URI_PUSH_GATEWAY_PREFIX_PATH + "notify") - fun notify(@Body body: PushGatewayNotifyBody): Call + suspend fun notify(@Body body: PushGatewayNotifyBody): PushGatewayNotifyResponse } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/gateway/PushGatewayNotifyTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/gateway/PushGatewayNotifyTask.kt index df6f46fa81..316e221b32 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/gateway/PushGatewayNotifyTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/gateway/PushGatewayNotifyTask.kt @@ -45,8 +45,8 @@ internal class DefaultPushGatewayNotifyTask @Inject constructor( ) .create(PushGatewayAPI::class.java) - val response = executeRequest(null) { - apiCall = sygnalApi.notify( + val response = executeRequest(null) { + sygnalApi.notify( PushGatewayNotifyBody( PushGatewayNotification( eventId = params.eventId, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/RoomAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/RoomAPI.kt index b065a30fc9..ad699af6f4 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/RoomAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/RoomAPI.kt @@ -38,7 +38,6 @@ import org.matrix.android.sdk.internal.session.room.tags.TagBody import org.matrix.android.sdk.internal.session.room.timeline.EventContextResponse import org.matrix.android.sdk.internal.session.room.timeline.PaginationResponse import org.matrix.android.sdk.internal.session.room.typing.TypingBody -import retrofit2.Call import retrofit2.http.Body import retrofit2.http.DELETE import retrofit2.http.GET @@ -57,9 +56,9 @@ internal interface RoomAPI { * Ref: https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-publicrooms */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "publicRooms") - fun publicRooms(@Query("server") server: String?, - @Body publicRoomsParams: PublicRoomsParams - ): Call + suspend fun publicRooms(@Query("server") server: String?, + @Body publicRoomsParams: PublicRoomsParams + ): PublicRoomsResponse /** * Create a room. @@ -71,7 +70,7 @@ internal interface RoomAPI { */ @Headers("CONNECT_TIMEOUT:60000", "READ_TIMEOUT:60000", "WRITE_TIMEOUT:60000") @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "createRoom") - fun createRoom(@Body param: CreateRoomBody): Call + suspend fun createRoom(@Body param: CreateRoomBody): CreateRoomResponse /** * Get a list of messages starting from a reference. @@ -83,12 +82,12 @@ internal interface RoomAPI { * @param filter A JSON RoomEventFilter to filter returned events with. Optional. */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/messages") - fun getRoomMessagesFrom(@Path("roomId") roomId: String, - @Query("from") from: String, - @Query("dir") dir: String, - @Query("limit") limit: Int, - @Query("filter") filter: String? - ): Call + suspend fun getRoomMessagesFrom(@Path("roomId") roomId: String, + @Query("from") from: String, + @Query("dir") dir: String, + @Query("limit") limit: Int, + @Query("filter") filter: String? + ): PaginationResponse /** * Get all members of a room @@ -99,11 +98,11 @@ internal interface RoomAPI { * @param notMembership to exclude one type of membership (optional) */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/members") - fun getMembers(@Path("roomId") roomId: String, - @Query("at") syncToken: String?, - @Query("membership") membership: Membership?, - @Query("not_membership") notMembership: Membership? - ): Call + suspend fun getMembers(@Path("roomId") roomId: String, + @Query("at") syncToken: String?, + @Query("membership") membership: Membership?, + @Query("not_membership") notMembership: Membership? + ): RoomMembersResponse /** * Send an event to a room. @@ -114,11 +113,11 @@ internal interface RoomAPI { * @param content the event content */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/send/{eventType}/{txId}") - fun send(@Path("txId") txId: String, - @Path("roomId") roomId: String, - @Path("eventType") eventType: String, - @Body content: Content? - ): Call + suspend fun send(@Path("txId") txId: String, + @Path("roomId") roomId: String, + @Path("eventType") eventType: String, + @Body content: Content? + ): SendResponse /** * Get the context surrounding an event. @@ -129,10 +128,10 @@ internal interface RoomAPI { * @param filter A JSON RoomEventFilter to filter returned events with. Optional. */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/context/{eventId}") - fun getContextOfEvent(@Path("roomId") roomId: String, - @Path("eventId") eventId: String, - @Query("limit") limit: Int, - @Query("filter") filter: String? = null): Call + suspend fun getContextOfEvent(@Path("roomId") roomId: String, + @Path("eventId") eventId: String, + @Query("limit") limit: Int, + @Query("filter") filter: String? = null): EventContextResponse /** * Retrieve an event from its room id / events id @@ -141,8 +140,8 @@ internal interface RoomAPI { * @param eventId the event Id */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/event/{eventId}") - fun getEvent(@Path("roomId") roomId: String, - @Path("eventId") eventId: String): Call + suspend fun getEvent(@Path("roomId") roomId: String, + @Path("eventId") eventId: String): Event /** * Send read markers. @@ -151,8 +150,8 @@ internal interface RoomAPI { * @param markers the read markers */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/read_markers") - fun sendReadMarker(@Path("roomId") roomId: String, - @Body markers: Map): Call + suspend fun sendReadMarker(@Path("roomId") roomId: String, + @Body markers: Map) /** * Invite a user to the given room. @@ -162,8 +161,8 @@ internal interface RoomAPI { * @param body a object that just contains a user id */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/invite") - fun invite(@Path("roomId") roomId: String, - @Body body: InviteBody): Call + suspend fun invite(@Path("roomId") roomId: String, + @Body body: InviteBody) /** * Invite a user to a room, using a ThreePid @@ -171,8 +170,8 @@ internal interface RoomAPI { * @param roomId Required. The room identifier (not alias) to which to invite the user. */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/invite") - fun invite3pid(@Path("roomId") roomId: String, - @Body body: ThreePidInviteBody): Call + suspend fun invite3pid(@Path("roomId") roomId: String, + @Body body: ThreePidInviteBody) /** * Send a generic state event @@ -182,9 +181,9 @@ internal interface RoomAPI { * @param params the request parameters */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/state/{state_event_type}") - fun sendStateEvent(@Path("roomId") roomId: String, - @Path("state_event_type") stateEventType: String, - @Body params: JsonDict): Call + suspend fun sendStateEvent(@Path("roomId") roomId: String, + @Path("state_event_type") stateEventType: String, + @Body params: JsonDict) /** * Send a generic state event @@ -195,17 +194,17 @@ internal interface RoomAPI { * @param params the request parameters */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/state/{state_event_type}/{state_key}") - fun sendStateEvent(@Path("roomId") roomId: String, - @Path("state_event_type") stateEventType: String, - @Path("state_key") stateKey: String, - @Body params: JsonDict): Call + suspend fun sendStateEvent(@Path("roomId") roomId: String, + @Path("state_event_type") stateEventType: String, + @Path("state_key") stateKey: String, + @Body params: JsonDict) /** * Get state events of a room * Ref: https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-rooms-roomid-state */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/state") - fun getRoomState(@Path("roomId") roomId: String) : Call> + suspend fun getRoomState(@Path("roomId") roomId: String): List /** * Send a relation event to a room. @@ -216,12 +215,12 @@ internal interface RoomAPI { * @param content the event content */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/send_relation/{parent_id}/{relation_type}/{event_type}") - fun sendRelation(@Path("roomId") roomId: String, - @Path("parent_id") parentId: String, - @Path("relation_type") relationType: String, - @Path("event_type") eventType: String, - @Body content: Content? - ): Call + suspend fun sendRelation(@Path("roomId") roomId: String, + @Path("parent_id") parentId: String, + @Path("relation_type") relationType: String, + @Path("event_type") eventType: String, + @Body content: Content? + ): SendResponse /** * Paginate relations for event based in normal topological order @@ -230,11 +229,11 @@ internal interface RoomAPI { * @param eventType filter for this event type */ @GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "rooms/{roomId}/relations/{eventId}/{relationType}/{eventType}") - fun getRelations(@Path("roomId") roomId: String, - @Path("eventId") eventId: String, - @Path("relationType") relationType: String, - @Path("eventType") eventType: String - ): Call + suspend fun getRelations(@Path("roomId") roomId: String, + @Path("eventId") eventId: String, + @Path("relationType") relationType: String, + @Path("eventType") eventType: String + ): RelationsResponse /** * Join the given room. @@ -244,9 +243,9 @@ internal interface RoomAPI { * @param params the request body */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "join/{roomIdOrAlias}") - fun join(@Path("roomIdOrAlias") roomIdOrAlias: String, - @Query("server_name") viaServers: List, - @Body params: Map): Call + suspend fun join(@Path("roomIdOrAlias") roomIdOrAlias: String, + @Query("server_name") viaServers: List, + @Body params: Map): JoinRoomResponse /** * Leave the given room. @@ -255,8 +254,8 @@ internal interface RoomAPI { * @param params the request body */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/leave") - fun leave(@Path("roomId") roomId: String, - @Body params: Map): Call + suspend fun leave(@Path("roomId") roomId: String, + @Body params: Map) /** * Ban a user from the given room. @@ -265,8 +264,8 @@ internal interface RoomAPI { * @param userIdAndReason the banned user object (userId and reason for ban) */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/ban") - fun ban(@Path("roomId") roomId: String, - @Body userIdAndReason: UserIdAndReason): Call + suspend fun ban(@Path("roomId") roomId: String, + @Body userIdAndReason: UserIdAndReason) /** * unban a user from the given room. @@ -275,8 +274,8 @@ internal interface RoomAPI { * @param userIdAndReason the unbanned user object (userId and reason for unban) */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/unban") - fun unban(@Path("roomId") roomId: String, - @Body userIdAndReason: UserIdAndReason): Call + suspend fun unban(@Path("roomId") roomId: String, + @Body userIdAndReason: UserIdAndReason) /** * Kick a user from the given room. @@ -285,8 +284,8 @@ internal interface RoomAPI { * @param userIdAndReason the kicked user object (userId and reason for kicking) */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/kick") - fun kick(@Path("roomId") roomId: String, - @Body userIdAndReason: UserIdAndReason): Call + suspend fun kick(@Path("roomId") roomId: String, + @Body userIdAndReason: UserIdAndReason) /** * Strips all information out of an event which isn't critical to the integrity of the server-side representation of the room. @@ -299,12 +298,12 @@ internal interface RoomAPI { * @param reason json containing reason key {"reason": "Indecent material"} */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/redact/{eventId}/{txnId}") - fun redactEvent( + suspend fun redactEvent( @Path("txnId") txId: String, @Path("roomId") roomId: String, @Path("eventId") eventId: String, @Body reason: Map - ): Call + ): SendResponse /** * Reports an event as inappropriate to the server, which may then notify the appropriate people. @@ -314,24 +313,24 @@ internal interface RoomAPI { * @param body body containing score and reason */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/report/{eventId}") - fun reportContent(@Path("roomId") roomId: String, - @Path("eventId") eventId: String, - @Body body: ReportContentBody): Call + suspend fun reportContent(@Path("roomId") roomId: String, + @Path("eventId") eventId: String, + @Body body: ReportContentBody) /** * Get a list of aliases maintained by the local server for the given room. * Ref: https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-rooms-roomid-aliases */ @GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "org.matrix.msc2432/rooms/{roomId}/aliases") - fun getAliases(@Path("roomId") roomId: String): Call + suspend fun getAliases(@Path("roomId") roomId: String): GetAliasesResponse /** * Inform that the user is starting to type or has stopped typing */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/typing/{userId}") - fun sendTypingState(@Path("roomId") roomId: String, - @Path("userId") userId: String, - @Body body: TypingBody): Call + suspend fun sendTypingState(@Path("roomId") roomId: String, + @Path("userId") userId: String, + @Body body: TypingBody) /** * Room tagging @@ -341,16 +340,16 @@ internal interface RoomAPI { * Add a tag to a room. */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "user/{userId}/rooms/{roomId}/tags/{tag}") - fun putTag(@Path("userId") userId: String, - @Path("roomId") roomId: String, - @Path("tag") tag: String, - @Body body: TagBody): Call + suspend fun putTag(@Path("userId") userId: String, + @Path("roomId") roomId: String, + @Path("tag") tag: String, + @Body body: TagBody) /** * Delete a tag from a room. */ @DELETE(NetworkConstants.URI_API_PREFIX_PATH_R0 + "user/{userId}/rooms/{roomId}/tags/{tag}") - fun deleteTag(@Path("userId") userId: String, - @Path("roomId") roomId: String, - @Path("tag") tag: String): Call + suspend fun deleteTag(@Path("userId") userId: String, + @Path("roomId") roomId: String, + @Path("tag") tag: String) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/AddRoomAliasTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/AddRoomAliasTask.kt index 9e4ec6f777..97ea1d6ad1 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/AddRoomAliasTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/AddRoomAliasTask.kt @@ -45,8 +45,8 @@ internal class DefaultAddRoomAliasTask @Inject constructor( override suspend fun execute(params: AddRoomAliasTask.Params) { aliasAvailabilityChecker.check(params.aliasLocalPart) - executeRequest(globalErrorReceiver) { - apiCall = directoryAPI.addRoomAlias( + executeRequest(globalErrorReceiver) { + directoryAPI.addRoomAlias( roomAlias = params.aliasLocalPart.toFullLocalAlias(userId), body = AddRoomAliasBody( roomId = params.roomId diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/DeleteRoomAliasTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/DeleteRoomAliasTask.kt index 6ad3db90a9..01ac3fcec8 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/DeleteRoomAliasTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/DeleteRoomAliasTask.kt @@ -34,8 +34,8 @@ internal class DefaultDeleteRoomAliasTask @Inject constructor( ) : DeleteRoomAliasTask { override suspend fun execute(params: DeleteRoomAliasTask.Params) { - executeRequest(globalErrorReceiver) { - apiCall = directoryAPI.deleteRoomAlias( + executeRequest(globalErrorReceiver) { + directoryAPI.deleteRoomAlias( roomAlias = params.roomAlias ) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomIdByAliasTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomIdByAliasTask.kt index a53ffc4fcd..71c8c9cd38 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomIdByAliasTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomIdByAliasTask.kt @@ -52,8 +52,8 @@ internal class DefaultGetRoomIdByAliasTask @Inject constructor( Optional.from(null) } else { val description = tryOrNull("## Failed to get roomId from alias") { - executeRequest(globalErrorReceiver) { - apiCall = directoryAPI.getRoomIdByAlias(params.roomAlias) + executeRequest(globalErrorReceiver) { + directoryAPI.getRoomIdByAlias(params.roomAlias) } } Optional.from(description) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomLocalAliasesTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomLocalAliasesTask.kt index 202cb1f6de..1ff4156ed3 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomLocalAliasesTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomLocalAliasesTask.kt @@ -35,8 +35,8 @@ internal class DefaultGetRoomLocalAliasesTask @Inject constructor( override suspend fun execute(params: GetRoomLocalAliasesTask.Params): List { // We do not check for "org.matrix.msc2432", so the API may be missing - val response = executeRequest(globalErrorReceiver) { - apiCall = roomAPI.getAliases(roomId = params.roomId) + val response = executeRequest(globalErrorReceiver) { + roomAPI.getAliases(roomId = params.roomId) } return response.aliases diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/RoomAliasAvailabilityChecker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/RoomAliasAvailabilityChecker.kt index 51a849a35e..9faf50dd8b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/RoomAliasAvailabilityChecker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/RoomAliasAvailabilityChecker.kt @@ -41,8 +41,8 @@ internal class RoomAliasAvailabilityChecker @Inject constructor( // Check alias availability val fullAlias = aliasLocalPart.toFullLocalAlias(userId) try { - executeRequest(globalErrorReceiver) { - apiCall = directoryAPI.getRoomIdByAlias(fullAlias) + executeRequest(globalErrorReceiver) { + directoryAPI.getRoomIdByAlias(fullAlias) } } catch (throwable: Throwable) { if (throwable is Failure.ServerError && throwable.httpCode == 404) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateRoomTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateRoomTask.kt index 9c16bd1b0f..fb3182d28b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateRoomTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateRoomTask.kt @@ -75,8 +75,8 @@ internal class DefaultCreateRoomTask @Inject constructor( val createRoomBody = createRoomBodyBuilder.build(params) val createRoomResponse = try { - executeRequest(globalErrorReceiver) { - apiCall = roomAPI.createRoom(createRoomBody) + executeRequest(globalErrorReceiver) { + roomAPI.createRoom(createRoomBody) } } catch (throwable: Throwable) { if (throwable is Failure.ServerError) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetPublicRoomTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetPublicRoomTask.kt index edd8ae9b0d..4a6b0703c5 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetPublicRoomTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetPublicRoomTask.kt @@ -38,7 +38,7 @@ internal class DefaultGetPublicRoomTask @Inject constructor( override suspend fun execute(params: GetPublicRoomTask.Params): PublicRoomsResponse { return executeRequest(globalErrorReceiver) { - apiCall = roomAPI.publicRooms(params.server, params.publicRoomsParams) + roomAPI.publicRooms(params.server, params.publicRoomsParams) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetRoomDirectoryVisibilityTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetRoomDirectoryVisibilityTask.kt index 8d71001ef9..77492e429f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetRoomDirectoryVisibilityTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetRoomDirectoryVisibilityTask.kt @@ -20,7 +20,6 @@ import org.matrix.android.sdk.api.session.room.model.RoomDirectoryVisibility import org.matrix.android.sdk.internal.network.GlobalErrorReceiver import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.directory.DirectoryAPI -import org.matrix.android.sdk.internal.session.directory.RoomDirectoryVisibilityJson import org.matrix.android.sdk.internal.task.Task import javax.inject.Inject @@ -36,8 +35,8 @@ internal class DefaultGetRoomDirectoryVisibilityTask @Inject constructor( ) : GetRoomDirectoryVisibilityTask { override suspend fun execute(params: GetRoomDirectoryVisibilityTask.Params): RoomDirectoryVisibility { - return executeRequest(globalErrorReceiver) { - apiCall = directoryAPI.getRoomDirectoryVisibility(params.roomId) + return executeRequest(globalErrorReceiver) { + directoryAPI.getRoomDirectoryVisibility(params.roomId) } .visibility } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/SetRoomDirectoryVisibilityTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/SetRoomDirectoryVisibilityTask.kt index cbb0b6d5d1..f46d06bd5c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/SetRoomDirectoryVisibilityTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/SetRoomDirectoryVisibilityTask.kt @@ -37,8 +37,8 @@ internal class DefaultSetRoomDirectoryVisibilityTask @Inject constructor( ) : SetRoomDirectoryVisibilityTask { override suspend fun execute(params: SetRoomDirectoryVisibilityTask.Params) { - executeRequest(globalErrorReceiver) { - apiCall = directoryAPI.setRoomDirectoryVisibility( + executeRequest(globalErrorReceiver) { + directoryAPI.setRoomDirectoryVisibility( params.roomId, RoomDirectoryVisibilityJson(visibility = params.roomDirectoryVisibility) ) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/LoadRoomMembersTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/LoadRoomMembersTask.kt index 6adf3c59d1..3d0f51b831 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/LoadRoomMembersTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/LoadRoomMembersTask.kt @@ -90,8 +90,8 @@ internal class DefaultLoadRoomMembersTask @Inject constructor( val lastToken = syncTokenStore.getLastToken() val response = try { - executeRequest(globalErrorReceiver) { - apiCall = roomAPI.getMembers(params.roomId, lastToken, null, params.excludeMembership) + executeRequest(globalErrorReceiver) { + roomAPI.getMembers(params.roomId, lastToken, null, params.excludeMembership) } } catch (throwable: Throwable) { // Revert status to NONE diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/admin/MembershipAdminTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/admin/MembershipAdminTask.kt index 4654a28536..d2c21f3520 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/admin/MembershipAdminTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/admin/MembershipAdminTask.kt @@ -41,8 +41,8 @@ internal class DefaultMembershipAdminTask @Inject constructor(private val roomAP override suspend fun execute(params: MembershipAdminTask.Params) { val userIdAndReason = UserIdAndReason(params.userId, params.reason) - executeRequest(null) { - apiCall = when (params.type) { + executeRequest(null) { + when (params.type) { MembershipAdminTask.Type.BAN -> roomAPI.ban(params.roomId, userIdAndReason) MembershipAdminTask.Type.UNBAN -> roomAPI.unban(params.roomId, userIdAndReason) MembershipAdminTask.Type.KICK -> roomAPI.kick(params.roomId, userIdAndReason) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/InviteTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/InviteTask.kt index 05503bd643..0f141c344a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/InviteTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/InviteTask.kt @@ -36,11 +36,13 @@ internal class DefaultInviteTask @Inject constructor( ) : InviteTask { override suspend fun execute(params: InviteTask.Params) { - return executeRequest(globalErrorReceiver) { - val body = InviteBody(params.userId, params.reason) - apiCall = roomAPI.invite(params.roomId, body) - isRetryable = true - maxRetryCount = 3 - } + val body = InviteBody(params.userId, params.reason) + return executeRequest(globalErrorReceiver, + { roomAPI.invite(params.roomId, body) }, + { + isRetryable = true + maxRetryCount = 3 + } + ) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/JoinRoomTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/JoinRoomTask.kt index 3b7639d42f..9fd4d95d9e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/JoinRoomTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/JoinRoomTask.kt @@ -24,7 +24,6 @@ import org.matrix.android.sdk.internal.database.model.RoomEntityFields import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.room.RoomAPI -import org.matrix.android.sdk.internal.session.room.create.JoinRoomResponse import org.matrix.android.sdk.internal.session.room.membership.RoomChangeMembershipStateDataSource import org.matrix.android.sdk.internal.session.room.read.SetReadMarkersTask import org.matrix.android.sdk.internal.task.Task @@ -54,8 +53,8 @@ internal class DefaultJoinRoomTask @Inject constructor( override suspend fun execute(params: JoinRoomTask.Params) { roomChangeMembershipStateDataSource.updateState(params.roomIdOrAlias, ChangeMembershipState.Joining) val joinRoomResponse = try { - executeRequest(globalErrorReceiver) { - apiCall = roomAPI.join( + executeRequest(globalErrorReceiver) { + roomAPI.join( roomIdOrAlias = params.roomIdOrAlias, viaServers = params.viaServers.take(3), params = mapOf("reason" to params.reason) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/leaving/LeaveRoomTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/leaving/LeaveRoomTask.kt index 37bb7570d1..1b836e36a6 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/leaving/LeaveRoomTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/leaving/LeaveRoomTask.kt @@ -68,8 +68,8 @@ internal class DefaultLeaveRoomTask @Inject constructor( leaveRoom(predecessorRoomId, reason) } try { - executeRequest(globalErrorReceiver) { - apiCall = roomAPI.leave(roomId, mapOf("reason" to reason)) + executeRequest(globalErrorReceiver) { + roomAPI.leave(roomId, mapOf("reason" to reason)) } } catch (failure: Throwable) { roomChangeMembershipStateDataSource.updateState(roomId, ChangeMembershipState.FailedLeaving(failure)) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/threepid/InviteThreePidTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/threepid/InviteThreePidTask.kt index d237ec795e..fa0a2d608a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/threepid/InviteThreePidTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/threepid/InviteThreePidTask.kt @@ -59,7 +59,7 @@ internal class DefaultInviteThreePidTask @Inject constructor( medium = params.threePid.toMedium(), address = params.threePid.value ) - apiCall = roomAPI.invite3pid(params.roomId, body) + roomAPI.invite3pid(params.roomId, body) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/peeking/ResolveRoomStateTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/peeking/ResolveRoomStateTask.kt index dbec6b555c..64cbef23ec 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/peeking/ResolveRoomStateTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/peeking/ResolveRoomStateTask.kt @@ -36,7 +36,7 @@ internal class DefaultResolveRoomStateTask @Inject constructor( override suspend fun execute(params: ResolveRoomStateTask.Params): List { return executeRequest(globalErrorReceiver) { - apiCall = roomAPI.getRoomState(params.roomId) + roomAPI.getRoomState(params.roomId) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/SetReadMarkersTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/SetReadMarkersTask.kt index 54d2307dd4..23a3f2d36c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/SetReadMarkersTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/SetReadMarkersTask.kt @@ -96,10 +96,10 @@ internal class DefaultSetReadMarkersTask @Inject constructor( updateDatabase(params.roomId, markers, shouldUpdateRoomSummary) } if (markers.isNotEmpty()) { - executeRequest(globalErrorReceiver) { - isRetryable = true - apiCall = roomAPI.sendReadMarker(params.roomId, markers) - } + executeRequest(globalErrorReceiver, + { roomAPI.sendReadMarker(params.roomId, markers) }, + { isRetryable = true } + ) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/FetchEditHistoryTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/FetchEditHistoryTask.kt index f9fd5f9348..5f5c000171 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/FetchEditHistoryTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/FetchEditHistoryTask.kt @@ -40,8 +40,8 @@ internal class DefaultFetchEditHistoryTask @Inject constructor( override suspend fun execute(params: FetchEditHistoryTask.Params): List { val isRoomEncrypted = cryptoSessionInfoProvider.isRoomEncrypted(params.roomId) - val response = executeRequest(globalErrorReceiver) { - apiCall = roomAPI.getRelations( + val response = executeRequest(globalErrorReceiver) { + roomAPI.getRelations( roomId = params.roomId, eventId = params.eventId, relationType = RelationType.REPLACE, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/SendRelationWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/SendRelationWorker.kt index 403aa274fe..5d0879d706 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/SendRelationWorker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/SendRelationWorker.kt @@ -28,7 +28,6 @@ import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.SessionComponent import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.session.room.send.LocalEchoRepository -import org.matrix.android.sdk.internal.session.room.send.SendResponse import org.matrix.android.sdk.internal.worker.SessionSafeCoroutineWorker import org.matrix.android.sdk.internal.worker.SessionWorkerParams import javax.inject.Inject @@ -84,8 +83,8 @@ internal class SendRelationWorker(context: Context, params: WorkerParameters) } private suspend fun sendRelation(roomId: String, relationType: String, relatedEventId: String, localEvent: Event) { - executeRequest(globalErrorReceiver) { - apiCall = roomAPI.sendRelation( + executeRequest(globalErrorReceiver) { + roomAPI.sendRelation( roomId = roomId, parentId = relatedEventId, relationType = relationType, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/reporting/ReportContentTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/reporting/ReportContentTask.kt index 9c6e9907a4..29d507dfc5 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/reporting/ReportContentTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/reporting/ReportContentTask.kt @@ -38,7 +38,7 @@ internal class DefaultReportContentTask @Inject constructor( override suspend fun execute(params: ReportContentTask.Params) { return executeRequest(globalErrorReceiver) { - apiCall = roomAPI.reportContent(params.roomId, params.eventId, ReportContentBody(params.score, params.reason)) + roomAPI.reportContent(params.roomId, params.eventId, ReportContentBody(params.score, params.reason)) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/RedactEventWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/RedactEventWorker.kt index c901c7e18e..306f865408 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/RedactEventWorker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/RedactEventWorker.kt @@ -55,8 +55,8 @@ internal class RedactEventWorker(context: Context, params: WorkerParameters) override suspend fun doSafeWork(params: Params): Result { val eventId = params.eventId return runCatching { - executeRequest(globalErrorReceiver) { - apiCall = roomAPI.redactEvent( + executeRequest(globalErrorReceiver) { + roomAPI.redactEvent( params.txID, params.roomId, eventId, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/SendStateTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/SendStateTask.kt index 63691d9207..998e116a0e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/SendStateTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/SendStateTask.kt @@ -39,7 +39,7 @@ internal class DefaultSendStateTask @Inject constructor( override suspend fun execute(params: SendStateTask.Params) { return executeRequest(globalErrorReceiver) { - apiCall = if (params.stateKey == null) { + if (params.stateKey == null) { roomAPI.sendStateEvent( roomId = params.roomId, stateEventType = params.eventType, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/AddTagToRoomTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/AddTagToRoomTask.kt index c3b5c3f78f..3e82d674ce 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/AddTagToRoomTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/AddTagToRoomTask.kt @@ -39,8 +39,8 @@ internal class DefaultAddTagToRoomTask @Inject constructor( ) : AddTagToRoomTask { override suspend fun execute(params: AddTagToRoomTask.Params) { - executeRequest(globalErrorReceiver) { - apiCall = roomAPI.putTag( + executeRequest(globalErrorReceiver) { + roomAPI.putTag( userId = userId, roomId = params.roomId, tag = params.tag, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/DeleteTagFromRoomTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/DeleteTagFromRoomTask.kt index d578d21fde..ae2a050659 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/DeleteTagFromRoomTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/DeleteTagFromRoomTask.kt @@ -38,8 +38,8 @@ internal class DefaultDeleteTagFromRoomTask @Inject constructor( ) : DeleteTagFromRoomTask { override suspend fun execute(params: DeleteTagFromRoomTask.Params) { - executeRequest(globalErrorReceiver) { - apiCall = roomAPI.deleteTag( + executeRequest(globalErrorReceiver) { + roomAPI.deleteTag( userId = userId, roomId = params.roomId, tag = params.tag diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/FetchTokenAndPaginateTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/FetchTokenAndPaginateTask.kt index 76c4b3812c..96646b42ed 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/FetchTokenAndPaginateTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/FetchTokenAndPaginateTask.kt @@ -48,8 +48,8 @@ internal class DefaultFetchTokenAndPaginateTask @Inject constructor( override suspend fun execute(params: FetchTokenAndPaginateTask.Params): TokenChunkEventPersistor.Result { val filter = filterRepository.getRoomFilter() - val response = executeRequest(globalErrorReceiver) { - apiCall = roomAPI.getContextOfEvent(params.roomId, params.lastKnownEventId, 0, filter) + val response = executeRequest(globalErrorReceiver) { + roomAPI.getContextOfEvent(params.roomId, params.lastKnownEventId, 0, filter) } val fromToken = if (params.direction == PaginationDirection.FORWARDS) { response.end diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetContextOfEventTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetContextOfEventTask.kt index d02a7bafe9..015e55f070 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetContextOfEventTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetContextOfEventTask.kt @@ -40,9 +40,9 @@ internal class DefaultGetContextOfEventTask @Inject constructor( override suspend fun execute(params: GetContextOfEventTask.Params): TokenChunkEventPersistor.Result { val filter = filterRepository.getRoomFilter() - val response = executeRequest(globalErrorReceiver) { + val response = executeRequest(globalErrorReceiver) { // We are limiting the response to the event with eventId to be sure we don't have any issue with potential merging process. - apiCall = roomAPI.getContextOfEvent(params.roomId, params.eventId, 0, filter) + roomAPI.getContextOfEvent(params.roomId, params.eventId, 0, filter) } return tokenChunkEventPersistor.insertInDb(response, params.roomId, PaginationDirection.FORWARDS) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetEventTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetEventTask.kt index b8585b1e74..a9b8683a28 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetEventTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetEventTask.kt @@ -37,7 +37,7 @@ internal class GetEventTask @Inject constructor( override suspend fun execute(params: Params): Event { return executeRequest(globalErrorReceiver) { - apiCall = roomAPI.getEvent(params.roomId, params.eventId) + roomAPI.getEvent(params.roomId, params.eventId) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/PaginationTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/PaginationTask.kt index 1f99893e17..b1ce5c1f26 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/PaginationTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/PaginationTask.kt @@ -42,10 +42,10 @@ internal class DefaultPaginationTask @Inject constructor( override suspend fun execute(params: PaginationTask.Params): TokenChunkEventPersistor.Result { val filter = filterRepository.getRoomFilter() - val chunk = executeRequest(globalErrorReceiver) { - isRetryable = true - apiCall = roomAPI.getRoomMessagesFrom(params.roomId, params.from, params.direction.value, params.limit, filter) - } + val chunk = executeRequest(globalErrorReceiver, + { roomAPI.getRoomMessagesFrom(params.roomId, params.from, params.direction.value, params.limit, filter) }, + { isRetryable = true } + ) return tokenChunkEventPersistor.insertInDb(chunk, params.roomId, params.direction) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/typing/SendTypingTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/typing/SendTypingTask.kt index 3b56d04872..0b0df74311 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/typing/SendTypingTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/typing/SendTypingTask.kt @@ -44,8 +44,8 @@ internal class DefaultSendTypingTask @Inject constructor( override suspend fun execute(params: SendTypingTask.Params) { delay(params.delay ?: -1) - executeRequest(globalErrorReceiver) { - apiCall = roomAPI.sendTypingState( + executeRequest(globalErrorReceiver) { + roomAPI.sendTypingState( params.roomId, userId, TypingBody(params.isTyping, params.typingTimeoutMillis?.takeIf { params.isTyping }) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/uploads/GetUploadsTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/uploads/GetUploadsTask.kt index b3e4a5aa05..028c3e9193 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/uploads/GetUploadsTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/uploads/GetUploadsTask.kt @@ -37,7 +37,6 @@ import org.matrix.android.sdk.internal.session.filter.FilterFactory import org.matrix.android.sdk.internal.session.room.RoomAPI import org.matrix.android.sdk.internal.session.room.membership.RoomMemberHelper import org.matrix.android.sdk.internal.session.room.timeline.PaginationDirection -import org.matrix.android.sdk.internal.session.room.timeline.PaginationResponse import org.matrix.android.sdk.internal.session.sync.SyncTokenStore import org.matrix.android.sdk.internal.task.Task import javax.inject.Inject @@ -86,8 +85,8 @@ internal class DefaultGetUploadsTask @Inject constructor( val since = params.since ?: tokenStore.getLastToken() ?: throw IllegalStateException("No token available") val filter = FilterFactory.createUploadsFilter(params.numberOfEvents).toJSONString() - val chunk = executeRequest(globalErrorReceiver) { - apiCall = roomAPI.getRoomMessagesFrom(params.roomId, since, PaginationDirection.BACKWARDS.value, params.numberOfEvents, filter) + val chunk = executeRequest(globalErrorReceiver) { + roomAPI.getRoomMessagesFrom(params.roomId, since, PaginationDirection.BACKWARDS.value, params.numberOfEvents, filter) } result = GetUploadsResult( diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/search/SearchAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/search/SearchAPI.kt index 4a74b0a023..b5099e7238 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/search/SearchAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/search/SearchAPI.kt @@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.session.search import org.matrix.android.sdk.internal.network.NetworkConstants import org.matrix.android.sdk.internal.session.search.request.SearchRequestBody import org.matrix.android.sdk.internal.session.search.response.SearchResponse -import retrofit2.Call import retrofit2.http.Body import retrofit2.http.POST import retrofit2.http.Query @@ -31,6 +30,6 @@ internal interface SearchAPI { * Ref: https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-search */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "search") - fun search(@Query("next_batch") nextBatch: String?, - @Body body: SearchRequestBody): Call + suspend fun search(@Query("next_batch") nextBatch: String?, + @Body body: SearchRequestBody): SearchResponse } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/search/SearchTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/search/SearchTask.kt index 402602e4d5..8de762ee1b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/search/SearchTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/search/SearchTask.kt @@ -51,25 +51,25 @@ internal class DefaultSearchTask @Inject constructor( ) : SearchTask { override suspend fun execute(params: SearchTask.Params): SearchResult { - return executeRequest(globalErrorReceiver) { - val searchRequestBody = SearchRequestBody( - searchCategories = SearchRequestCategories( - roomEvents = SearchRequestRoomEvents( - searchTerm = params.searchTerm, - orderBy = if (params.orderByRecent) SearchRequestOrder.RECENT else SearchRequestOrder.RANK, - filter = SearchRequestFilter( - limit = params.limit, - rooms = listOf(params.roomId) - ), - eventContext = SearchRequestEventContext( - beforeLimit = params.beforeLimit, - afterLimit = params.afterLimit, - includeProfile = params.includeProfile - ) - ) - ) - ) - apiCall = searchAPI.search(params.nextBatch, searchRequestBody) + val searchRequestBody = SearchRequestBody( + searchCategories = SearchRequestCategories( + roomEvents = SearchRequestRoomEvents( + searchTerm = params.searchTerm, + orderBy = if (params.orderByRecent) SearchRequestOrder.RECENT else SearchRequestOrder.RANK, + filter = SearchRequestFilter( + limit = params.limit, + rooms = listOf(params.roomId) + ), + eventContext = SearchRequestEventContext( + beforeLimit = params.beforeLimit, + afterLimit = params.afterLimit, + includeProfile = params.includeProfile + ) + ) + ) + ) + return executeRequest(globalErrorReceiver) { + searchAPI.search(params.nextBatch, searchRequestBody) }.toDomain() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/signout/SignInAgainTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/signout/SignInAgainTask.kt index 2c3cd5d270..563e85aefc 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/signout/SignInAgainTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/signout/SignInAgainTask.kt @@ -16,7 +16,6 @@ package org.matrix.android.sdk.internal.session.signout -import org.matrix.android.sdk.api.auth.data.Credentials import org.matrix.android.sdk.api.auth.data.SessionParams import org.matrix.android.sdk.internal.auth.SessionParamsStore import org.matrix.android.sdk.internal.auth.data.PasswordLoginParams @@ -39,8 +38,8 @@ internal class DefaultSignInAgainTask @Inject constructor( ) : SignInAgainTask { override suspend fun execute(params: SignInAgainTask.Params) { - val newCredentials = executeRequest(globalErrorReceiver) { - apiCall = signOutAPI.loginAgain( + val newCredentials = executeRequest(globalErrorReceiver) { + signOutAPI.loginAgain( PasswordLoginParams.userIdentifier( // Reuse the same userId sessionParams.userId, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/signout/SignOutAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/signout/SignOutAPI.kt index 4c92938b77..a56362e587 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/signout/SignOutAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/signout/SignOutAPI.kt @@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.session.signout import org.matrix.android.sdk.api.auth.data.Credentials import org.matrix.android.sdk.internal.auth.data.PasswordLoginParams import org.matrix.android.sdk.internal.network.NetworkConstants -import retrofit2.Call import retrofit2.http.Body import retrofit2.http.Headers import retrofit2.http.POST @@ -35,11 +34,11 @@ internal interface SignOutAPI { */ @Headers("CONNECT_TIMEOUT:60000", "READ_TIMEOUT:60000", "WRITE_TIMEOUT:60000") @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "login") - fun loginAgain(@Body loginParams: PasswordLoginParams): Call + suspend fun loginAgain(@Body loginParams: PasswordLoginParams): Credentials /** * Invalidate the access token, so that it can no longer be used for authorization. */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "logout") - fun signOut(): Call + suspend fun signOut() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/signout/SignOutTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/signout/SignOutTask.kt index 0cb8704782..9c25eccb3a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/signout/SignOutTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/signout/SignOutTask.kt @@ -45,8 +45,8 @@ internal class DefaultSignOutTask @Inject constructor( if (params.signOutFromHomeserver) { Timber.d("SignOut: send request...") try { - executeRequest(globalErrorReceiver) { - apiCall = signOutAPI.signOut() + executeRequest(globalErrorReceiver) { + signOutAPI.signOut() } } catch (throwable: Throwable) { // Maybe due to https://github.com/matrix-org/synapse/issues/5756 diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncAPI.kt index 8e3523bc57..2616803463 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncAPI.kt @@ -31,11 +31,11 @@ internal interface SyncAPI { * Set all the timeouts to 1 minute by default */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "sync") - fun sync(@QueryMap params: Map, - @Header(TimeOutInterceptor.CONNECT_TIMEOUT) connectTimeOut: Long = TimeOutInterceptor.DEFAULT_LONG_TIMEOUT, - @Header(TimeOutInterceptor.READ_TIMEOUT) readTimeOut: Long = TimeOutInterceptor.DEFAULT_LONG_TIMEOUT, - @Header(TimeOutInterceptor.WRITE_TIMEOUT) writeTimeOut: Long = TimeOutInterceptor.DEFAULT_LONG_TIMEOUT - ): Call + suspend fun sync(@QueryMap params: Map, + @Header(TimeOutInterceptor.CONNECT_TIMEOUT) connectTimeOut: Long = TimeOutInterceptor.DEFAULT_LONG_TIMEOUT, + @Header(TimeOutInterceptor.READ_TIMEOUT) readTimeOut: Long = TimeOutInterceptor.DEFAULT_LONG_TIMEOUT, + @Header(TimeOutInterceptor.WRITE_TIMEOUT) writeTimeOut: Long = TimeOutInterceptor.DEFAULT_LONG_TIMEOUT + ): SyncResponse /** * Set all the timeouts to 1 minute by default diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncTask.kt index 8d8d69be1e..83a2ffc446 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncTask.kt @@ -29,7 +29,6 @@ import org.matrix.android.sdk.internal.session.homeserver.GetHomeServerCapabilit import org.matrix.android.sdk.internal.session.initsync.DefaultInitialSyncProgressService import org.matrix.android.sdk.internal.session.initsync.reportSubtask import org.matrix.android.sdk.internal.session.sync.model.LazyRoomSyncEphemeral -import org.matrix.android.sdk.internal.session.sync.model.SyncResponse import org.matrix.android.sdk.internal.session.sync.parsing.InitialSyncResponseParser import org.matrix.android.sdk.internal.session.user.UserStore import org.matrix.android.sdk.internal.task.Task @@ -115,8 +114,8 @@ internal class DefaultSyncTask @Inject constructor( workingDir.deleteRecursively() } else { val syncResponse = logDuration("INIT_SYNC Request") { - executeRequest(globalErrorReceiver) { - apiCall = syncAPI.sync( + executeRequest(globalErrorReceiver) { + syncAPI.sync( params = requestParams, readTimeOut = readTimeOut ) @@ -130,8 +129,8 @@ internal class DefaultSyncTask @Inject constructor( } initialSyncProgressService.endAll() } else { - val syncResponse = executeRequest(globalErrorReceiver) { - apiCall = syncAPI.sync( + val syncResponse = executeRequest(globalErrorReceiver) { + syncAPI.sync( params = requestParams, readTimeOut = readTimeOut ) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/terms/DefaultTermsService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/terms/DefaultTermsService.kt index 41914cc799..73545205d1 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/terms/DefaultTermsService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/terms/DefaultTermsService.kt @@ -24,7 +24,6 @@ import org.matrix.android.sdk.api.session.terms.TermsService import org.matrix.android.sdk.internal.di.UnauthenticatedWithCertificate import org.matrix.android.sdk.internal.network.NetworkConstants import org.matrix.android.sdk.internal.network.RetrofitFactory -import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.identity.IdentityAuthAPI import org.matrix.android.sdk.internal.session.identity.IdentityRegisterTask import org.matrix.android.sdk.internal.session.openid.GetOpenIdTokenTask @@ -35,6 +34,7 @@ import org.matrix.android.sdk.internal.session.user.accountdata.UpdateUserAccoun import org.matrix.android.sdk.internal.util.MatrixCoroutineDispatchers import org.matrix.android.sdk.internal.util.ensureTrailingSlash import okhttp3.OkHttpClient +import org.matrix.android.sdk.internal.network.executeRequest import javax.inject.Inject internal class DefaultTermsService @Inject constructor( @@ -50,10 +50,10 @@ internal class DefaultTermsService @Inject constructor( ) : TermsService { override suspend fun getTerms(serviceType: TermsService.ServiceType, baseUrl: String): GetTermsResponse { - return withContext(coroutineDispatchers.main) { + return withContext(coroutineDispatchers.io) { val url = buildUrl(baseUrl, serviceType) - val termsResponse = executeRequest(null) { - apiCall = termsAPI.getTerms("${url}terms") + val termsResponse = executeRequest(null) { + termsAPI.getTerms("${url}terms") } GetTermsResponse(termsResponse, getAlreadyAcceptedTermUrlsFromAccountData()) } @@ -63,12 +63,12 @@ internal class DefaultTermsService @Inject constructor( baseUrl: String, agreedUrls: List, token: String?) { - withContext(coroutineDispatchers.main) { + withContext(coroutineDispatchers.io) { val url = buildUrl(baseUrl, serviceType) val tokenToUse = token?.takeIf { it.isNotEmpty() } ?: getToken(baseUrl) - executeRequest(null) { - apiCall = termsAPI.agreeToTerms("${url}terms", AcceptTermsBody(agreedUrls), "Bearer $tokenToUse") + executeRequest(null) { + termsAPI.agreeToTerms("${url}terms", AcceptTermsBody(agreedUrls), "Bearer $tokenToUse") } // client SHOULD update this account data section adding any the URLs diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/terms/TermsAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/terms/TermsAPI.kt index 4c97f462eb..91d27030de 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/terms/TermsAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/terms/TermsAPI.kt @@ -17,7 +17,6 @@ package org.matrix.android.sdk.internal.session.terms import org.matrix.android.sdk.internal.network.HttpHeaders -import retrofit2.Call import retrofit2.http.Body import retrofit2.http.GET import retrofit2.http.Header @@ -29,13 +28,13 @@ internal interface TermsAPI { * This request does not require authentication */ @GET - fun getTerms(@Url url: String): Call + suspend fun getTerms(@Url url: String): TermsResponse /** * This request requires authentication */ @POST - fun agreeToTerms(@Url url: String, - @Body params: AcceptTermsBody, - @Header(HttpHeaders.Authorization) token: String): Call + suspend fun agreeToTerms(@Url url: String, + @Body params: AcceptTermsBody, + @Header(HttpHeaders.Authorization) token: String) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/thirdparty/GetThirdPartyProtocolsTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/thirdparty/GetThirdPartyProtocolsTask.kt index fd1ed741e9..026e17b513 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/thirdparty/GetThirdPartyProtocolsTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/thirdparty/GetThirdPartyProtocolsTask.kt @@ -31,7 +31,7 @@ internal class DefaultGetThirdPartyProtocolsTask @Inject constructor( override suspend fun execute(params: Unit): Map { return executeRequest(globalErrorReceiver) { - apiCall = thirdPartyAPI.thirdPartyProtocols() + thirdPartyAPI.thirdPartyProtocols() } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/thirdparty/GetThirdPartyUserTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/thirdparty/GetThirdPartyUserTask.kt index 01a8b57678..f541dcb814 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/thirdparty/GetThirdPartyUserTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/thirdparty/GetThirdPartyUserTask.kt @@ -37,7 +37,7 @@ internal class DefaultGetThirdPartyUserTask @Inject constructor( override suspend fun execute(params: GetThirdPartyUserTask.Params): List { return executeRequest(globalErrorReceiver) { - apiCall = thirdPartyAPI.getThirdPartyUser(params.protocol, params.fields) + thirdPartyAPI.getThirdPartyUser(params.protocol, params.fields) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/thirdparty/ThirdPartyAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/thirdparty/ThirdPartyAPI.kt index 0c60a27341..2e03bc7a86 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/thirdparty/ThirdPartyAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/thirdparty/ThirdPartyAPI.kt @@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.session.thirdparty import org.matrix.android.sdk.api.session.room.model.thirdparty.ThirdPartyProtocol import org.matrix.android.sdk.api.session.thirdparty.model.ThirdPartyUser import org.matrix.android.sdk.internal.network.NetworkConstants -import retrofit2.Call import retrofit2.http.GET import retrofit2.http.Path import retrofit2.http.QueryMap @@ -32,7 +31,7 @@ internal interface ThirdPartyAPI { * Ref: https://matrix.org/docs/spec/client_server/r0.6.1.html#get-matrix-client-r0-thirdparty-protocols */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "thirdparty/protocols") - fun thirdPartyProtocols(): Call> + suspend fun thirdPartyProtocols(): Map /** * Retrieve a Matrix User ID linked to a user on the third party service, given a set of user parameters. @@ -40,5 +39,6 @@ internal interface ThirdPartyAPI { * Ref: https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-thirdparty-user-protocol */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "thirdparty/protocols/user/{protocol}") - fun getThirdPartyUser(@Path("protocol") protocol: String, @QueryMap params: Map?): Call> + suspend fun getThirdPartyUser(@Path("protocol") protocol: String, + @QueryMap params: Map?): List } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/SearchUserAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/SearchUserAPI.kt index c5c546bbed..e03d406639 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/SearchUserAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/SearchUserAPI.kt @@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.session.user import org.matrix.android.sdk.internal.network.NetworkConstants import org.matrix.android.sdk.internal.session.user.model.SearchUsersParams import org.matrix.android.sdk.internal.session.user.model.SearchUsersResponse -import retrofit2.Call import retrofit2.http.Body import retrofit2.http.POST @@ -31,5 +30,5 @@ internal interface SearchUserAPI { * @param searchUsersParams the search params. */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "user_directory/search") - fun searchUsers(@Body searchUsersParams: SearchUsersParams): Call + suspend fun searchUsers(@Body searchUsersParams: SearchUsersParams): SearchUsersResponse } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/AccountDataAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/AccountDataAPI.kt index 3de484fab3..cc5625b255 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/AccountDataAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/AccountDataAPI.kt @@ -17,7 +17,6 @@ package org.matrix.android.sdk.internal.session.user.accountdata import org.matrix.android.sdk.internal.network.NetworkConstants -import retrofit2.Call import retrofit2.http.Body import retrofit2.http.PUT import retrofit2.http.Path @@ -32,7 +31,7 @@ interface AccountDataAPI { * @param params the put params */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "user/{userId}/account_data/{type}") - fun setAccountData(@Path("userId") userId: String, - @Path("type") type: String, - @Body params: Any): Call + suspend fun setAccountData(@Path("userId") userId: String, + @Path("type") type: String, + @Body params: Any) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateIgnoredUserIdsTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateIgnoredUserIdsTask.kt index 26e8d3380a..445b78104c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateIgnoredUserIdsTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateIgnoredUserIdsTask.kt @@ -63,8 +63,8 @@ internal class DefaultUpdateIgnoredUserIdsTask @Inject constructor( val list = ignoredUserIds.toList() val body = IgnoredUsersContent.createWithUserIds(list) - executeRequest(globalErrorReceiver) { - apiCall = accountDataApi.setAccountData(userId, UserAccountDataTypes.TYPE_IGNORED_USER_LIST, body) + executeRequest(globalErrorReceiver) { + accountDataApi.setAccountData(userId, UserAccountDataTypes.TYPE_IGNORED_USER_LIST, body) } // Update the DB right now (do not wait for the sync to come back with updated data, for a faster UI update) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateUserAccountDataTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateUserAccountDataTask.kt index dba28253a7..1a588d2245 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateUserAccountDataTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateUserAccountDataTask.kt @@ -105,7 +105,7 @@ internal class DefaultUpdateUserAccountDataTask @Inject constructor( override suspend fun execute(params: UpdateUserAccountDataTask.Params) { return executeRequest(globalErrorReceiver) { - apiCall = accountDataApi.setAccountData(userId, params.type, params.getData()) + accountDataApi.setAccountData(userId, params.type, params.getData()) } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/model/SearchUserTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/model/SearchUserTask.kt index 380fa6e209..5a8779f40f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/model/SearchUserTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/model/SearchUserTask.kt @@ -38,8 +38,8 @@ internal class DefaultSearchUserTask @Inject constructor( ) : SearchUserTask { override suspend fun execute(params: SearchUserTask.Params): List { - val response = executeRequest(globalErrorReceiver) { - apiCall = searchUserAPI.searchUsers(SearchUsersParams(params.search, params.limit)) + val response = executeRequest(globalErrorReceiver) { + searchUserAPI.searchUsers(SearchUsersParams(params.search, params.limit)) } return response.users.map { User(it.userId, it.displayName, it.avatarUrl) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/widgets/CreateWidgetTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/widgets/CreateWidgetTask.kt index ae807ce30f..18a043be45 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/widgets/CreateWidgetTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/widgets/CreateWidgetTask.kt @@ -46,8 +46,8 @@ internal class DefaultCreateWidgetTask @Inject constructor(@SessionDatabase priv private val globalErrorReceiver: GlobalErrorReceiver) : CreateWidgetTask { override suspend fun execute(params: CreateWidgetTask.Params) { - executeRequest(globalErrorReceiver) { - apiCall = roomAPI.sendStateEvent( + executeRequest(globalErrorReceiver) { + roomAPI.sendStateEvent( roomId = params.roomId, stateEventType = EventType.STATE_ROOM_WIDGET_LEGACY, stateKey = params.widgetId, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/widgets/WidgetsAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/widgets/WidgetsAPI.kt index 1fece8b580..6652628026 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/widgets/WidgetsAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/widgets/WidgetsAPI.kt @@ -16,7 +16,6 @@ package org.matrix.android.sdk.internal.session.widgets import org.matrix.android.sdk.internal.session.openid.RequestOpenIdTokenResponse -import retrofit2.Call import retrofit2.http.Body import retrofit2.http.GET import retrofit2.http.POST @@ -30,10 +29,10 @@ internal interface WidgetsAPI { * @param body the body content (Ref: https://github.com/matrix-org/matrix-doc/pull/1961) */ @POST("register") - fun register(@Body body: RequestOpenIdTokenResponse, - @Query("v") version: String?): Call + suspend fun register(@Body body: RequestOpenIdTokenResponse, + @Query("v") version: String?): RegisterWidgetResponse @GET("account") - fun validateToken(@Query("scalar_token") scalarToken: String?, - @Query("v") version: String?): Call + suspend fun validateToken(@Query("scalar_token") scalarToken: String?, + @Query("v") version: String?) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/widgets/token/GetScalarTokenTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/widgets/token/GetScalarTokenTask.kt index 6db79da35f..78a40d1977 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/widgets/token/GetScalarTokenTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/widgets/token/GetScalarTokenTask.kt @@ -20,7 +20,6 @@ import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.failure.MatrixError import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.session.openid.GetOpenIdTokenTask -import org.matrix.android.sdk.internal.session.widgets.RegisterWidgetResponse import org.matrix.android.sdk.api.session.widgets.WidgetManagementFailure import org.matrix.android.sdk.internal.session.widgets.WidgetsAPI import org.matrix.android.sdk.internal.session.widgets.WidgetsAPIProvider @@ -59,8 +58,8 @@ internal class DefaultGetScalarTokenTask @Inject constructor(private val widgets private suspend fun getNewScalarToken(widgetsAPI: WidgetsAPI, serverUrl: String): String { val openId = getOpenIdTokenTask.execute(Unit) - val registerWidgetResponse = executeRequest(null) { - apiCall = widgetsAPI.register(openId, WIDGET_API_VERSION) + val registerWidgetResponse = executeRequest(null) { + widgetsAPI.register(openId, WIDGET_API_VERSION) } if (registerWidgetResponse.scalarToken == null) { // Should not happen @@ -72,8 +71,8 @@ internal class DefaultGetScalarTokenTask @Inject constructor(private val widgets private suspend fun validateToken(widgetsAPI: WidgetsAPI, serverUrl: String, scalarToken: String): String { return try { - executeRequest(null) { - apiCall = widgetsAPI.validateToken(scalarToken, WIDGET_API_VERSION) + executeRequest(null) { + widgetsAPI.validateToken(scalarToken, WIDGET_API_VERSION) } scalarToken } catch (failure: Throwable) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/wellknown/GetWellknownTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/wellknown/GetWellknownTask.kt index 3f0e27f410..7a9beac8c0 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/wellknown/GetWellknownTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/wellknown/GetWellknownTask.kt @@ -89,8 +89,8 @@ internal class DefaultGetWellknownTask @Inject constructor( .create(WellKnownAPI::class.java) return try { - val wellKnown = executeRequest(null) { - apiCall = wellKnownAPI.getWellKnown(domain) + val wellKnown = executeRequest(null) { + wellKnownAPI.getWellKnown(domain) } // Success @@ -140,8 +140,8 @@ internal class DefaultGetWellknownTask @Inject constructor( .create(CapabilitiesAPI::class.java) try { - executeRequest(null) { - apiCall = capabilitiesAPI.ping() + executeRequest(null) { + capabilitiesAPI.ping() } } catch (throwable: Throwable) { return WellknownResult.FailError @@ -178,8 +178,8 @@ internal class DefaultGetWellknownTask @Inject constructor( .create(IdentityAuthAPI::class.java) return try { - executeRequest(null) { - apiCall = identityPingApi.ping() + executeRequest(null) { + identityPingApi.ping() } true diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/wellknown/WellKnownAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/wellknown/WellKnownAPI.kt index 981d013f49..428f7f65c0 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/wellknown/WellKnownAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/wellknown/WellKnownAPI.kt @@ -16,11 +16,10 @@ package org.matrix.android.sdk.internal.wellknown import org.matrix.android.sdk.api.auth.data.WellKnown -import retrofit2.Call import retrofit2.http.GET import retrofit2.http.Path internal interface WellKnownAPI { @GET("https://{domain}/.well-known/matrix/client") - fun getWellKnown(@Path("domain") domain: String): Call + suspend fun getWellKnown(@Path("domain") domain: String): WellKnown }