diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPusherTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPusherTask.kt index 431a009844..2929e09a1f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPusherTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPusherTask.kt @@ -23,7 +23,6 @@ import org.matrix.android.sdk.internal.database.model.PusherEntity import org.matrix.android.sdk.internal.database.query.where import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.network.GlobalErrorReceiver -import org.matrix.android.sdk.internal.network.executeRequest import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.util.awaitTransaction import javax.inject.Inject @@ -35,6 +34,7 @@ internal interface AddPusherTask : Task { internal class DefaultAddPusherTask @Inject constructor( private val pushersAPI: PushersAPI, @SessionDatabase private val monarchy: Monarchy, + private val requestExecutor: RequestExecutor, private val globalErrorReceiver: GlobalErrorReceiver ) : AddPusherTask { override suspend fun execute(params: AddPusherTask.Params) { @@ -52,7 +52,7 @@ internal class DefaultAddPusherTask @Inject constructor( } private suspend fun setPusher(pusher: JsonPusher) { - executeRequest(globalErrorReceiver) { + requestExecutor.executeRequest(globalErrorReceiver) { pushersAPI.setPusher(pusher) } monarchy.awaitTransaction { realm -> @@ -75,3 +75,17 @@ internal class DefaultAddPusherTask @Inject constructor( } } } + +internal interface RequestExecutor { + suspend fun executeRequest(globalErrorReceiver: GlobalErrorReceiver?, + canRetry: Boolean = false, + maxDelayBeforeRetry: Long = 32_000L, + maxRetriesCount: Int = 4, + requestBlock: suspend () -> DATA): DATA +} + +internal object DefaultRequestExecutor : RequestExecutor { + override suspend fun executeRequest(globalErrorReceiver: GlobalErrorReceiver?, canRetry: Boolean, maxDelayBeforeRetry: Long, maxRetriesCount: Int, requestBlock: suspend () -> DATA): DATA { + return executeRequest(globalErrorReceiver, canRetry, maxDelayBeforeRetry, maxRetriesCount, requestBlock) + } +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/PushersModule.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/PushersModule.kt index d53a4eed65..8cf4d9fcf0 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/PushersModule.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/PushersModule.kt @@ -30,6 +30,7 @@ import org.matrix.android.sdk.internal.session.pushers.gateway.PushGatewayNotify import org.matrix.android.sdk.internal.session.room.notification.DefaultSetRoomNotificationStateTask import org.matrix.android.sdk.internal.session.room.notification.SetRoomNotificationStateTask import retrofit2.Retrofit +import javax.inject.Singleton @Module internal abstract class PushersModule { @@ -48,6 +49,12 @@ internal abstract class PushersModule { fun providesPushRulesApi(retrofit: Retrofit): PushRulesApi { return retrofit.create(PushRulesApi::class.java) } + + @Provides + @JvmStatic + fun providesRequestExecutor(): RequestExecutor { + return DefaultRequestExecutor + } } @Binds