mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-16 20:10:04 +03:00
lifting the request executor to its own file in the network package
- also creates a dedicated RequestModule instead of providing the executor via the pushers module
This commit is contained in:
parent
aff787bb29
commit
69bb554e20
6 changed files with 70 additions and 26 deletions
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright 2021 The Matrix.org Foundation C.I.C.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.network
|
||||
import org.matrix.android.sdk.internal.network.executeRequest as internalExecuteRequest
|
||||
|
||||
internal interface RequestExecutor {
|
||||
suspend fun <DATA> executeRequest(globalErrorReceiver: GlobalErrorReceiver?,
|
||||
canRetry: Boolean = false,
|
||||
maxDelayBeforeRetry: Long = 32_000L,
|
||||
maxRetriesCount: Int = 4,
|
||||
requestBlock: suspend () -> DATA): DATA
|
||||
}
|
||||
|
||||
internal object DefaultRequestExecutor : RequestExecutor {
|
||||
override suspend fun <DATA> executeRequest(globalErrorReceiver: GlobalErrorReceiver?,
|
||||
canRetry: Boolean,
|
||||
maxDelayBeforeRetry: Long,
|
||||
maxRetriesCount: Int,
|
||||
requestBlock: suspend () -> DATA): DATA {
|
||||
return internalExecuteRequest(globalErrorReceiver, canRetry, maxDelayBeforeRetry, maxRetriesCount, requestBlock)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright 2021 The Matrix.org Foundation C.I.C.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.network
|
||||
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
|
||||
@Module
|
||||
internal object RequestModule {
|
||||
|
||||
@Provides
|
||||
fun providesRequestExecutor(): RequestExecutor {
|
||||
return DefaultRequestExecutor
|
||||
}
|
||||
}
|
|
@ -29,6 +29,7 @@ import org.matrix.android.sdk.internal.crypto.verification.SendVerificationMessa
|
|||
import org.matrix.android.sdk.internal.di.MatrixComponent
|
||||
import org.matrix.android.sdk.internal.federation.FederationModule
|
||||
import org.matrix.android.sdk.internal.network.NetworkConnectivityChecker
|
||||
import org.matrix.android.sdk.internal.network.RequestModule
|
||||
import org.matrix.android.sdk.internal.session.account.AccountModule
|
||||
import org.matrix.android.sdk.internal.session.cache.CacheModule
|
||||
import org.matrix.android.sdk.internal.session.call.CallModule
|
||||
|
@ -94,7 +95,8 @@ import org.matrix.android.sdk.internal.util.system.SystemModule
|
|||
CallModule::class,
|
||||
SearchModule::class,
|
||||
ThirdPartyModule::class,
|
||||
SpaceModule::class
|
||||
SpaceModule::class,
|
||||
RequestModule::class
|
||||
]
|
||||
)
|
||||
@SessionScope
|
||||
|
|
|
@ -23,6 +23,7 @@ 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.RequestExecutor
|
||||
import org.matrix.android.sdk.internal.task.Task
|
||||
import org.matrix.android.sdk.internal.util.awaitTransaction
|
||||
import javax.inject.Inject
|
||||
|
@ -75,21 +76,3 @@ internal class DefaultAddPusherTask @Inject constructor(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal interface RequestExecutor {
|
||||
suspend fun <DATA> executeRequest(globalErrorReceiver: GlobalErrorReceiver?,
|
||||
canRetry: Boolean = false,
|
||||
maxDelayBeforeRetry: Long = 32_000L,
|
||||
maxRetriesCount: Int = 4,
|
||||
requestBlock: suspend () -> DATA): DATA
|
||||
}
|
||||
|
||||
internal object DefaultRequestExecutor : RequestExecutor {
|
||||
override suspend fun <DATA> executeRequest(globalErrorReceiver: GlobalErrorReceiver?,
|
||||
canRetry: Boolean,
|
||||
maxDelayBeforeRetry: Long,
|
||||
maxRetriesCount: Int,
|
||||
requestBlock: suspend () -> DATA): DATA {
|
||||
return executeRequest(globalErrorReceiver, canRetry, maxDelayBeforeRetry, maxRetriesCount, requestBlock)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,12 +48,6 @@ internal abstract class PushersModule {
|
|||
fun providesPushRulesApi(retrofit: Retrofit): PushRulesApi {
|
||||
return retrofit.create(PushRulesApi::class.java)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@JvmStatic
|
||||
fun providesRequestExecutor(): RequestExecutor {
|
||||
return DefaultRequestExecutor
|
||||
}
|
||||
}
|
||||
|
||||
@Binds
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.matrix.android.sdk.test.fakes
|
||||
|
||||
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
|
||||
import org.matrix.android.sdk.internal.session.pushers.RequestExecutor
|
||||
import org.matrix.android.sdk.internal.network.RequestExecutor
|
||||
|
||||
internal class FakeRequestExecutor : RequestExecutor {
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue