mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-16 03:08:58 +03:00
Create FederationModule
This commit is contained in:
parent
14fc31be07
commit
a8be5ed6b0
11 changed files with 252 additions and 0 deletions
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 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.api.federation
|
||||
|
||||
interface FederationService {
|
||||
/**
|
||||
* Get information about the homeserver
|
||||
*/
|
||||
suspend fun getFederationVersion(): FederationVersion
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 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.api.federation
|
||||
|
||||
/**
|
||||
* Ref: https://matrix.org/docs/spec/server_server/latest#get-matrix-federation-v1-version
|
||||
*/
|
||||
data class FederationVersion(
|
||||
/**
|
||||
* Arbitrary name that identify this implementation.
|
||||
*/
|
||||
val name: String?,
|
||||
/**
|
||||
* Version of this implementation. The version format depends on the implementation.
|
||||
*/
|
||||
val version: String?
|
||||
)
|
|
@ -21,6 +21,7 @@ import androidx.lifecycle.LiveData
|
|||
import okhttp3.OkHttpClient
|
||||
import org.matrix.android.sdk.api.auth.data.SessionParams
|
||||
import org.matrix.android.sdk.api.failure.GlobalError
|
||||
import org.matrix.android.sdk.api.federation.FederationService
|
||||
import org.matrix.android.sdk.api.pushrules.PushRuleService
|
||||
import org.matrix.android.sdk.api.session.account.AccountService
|
||||
import org.matrix.android.sdk.api.session.accountdata.AccountDataService
|
||||
|
@ -213,6 +214,11 @@ interface Session :
|
|||
*/
|
||||
fun searchService(): SearchService
|
||||
|
||||
/**
|
||||
* Returns the federation service associated with the session
|
||||
*/
|
||||
fun federationService(): FederationService
|
||||
|
||||
/**
|
||||
* Returns the third party service associated with the session
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 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.federation
|
||||
|
||||
import org.matrix.android.sdk.api.federation.FederationService
|
||||
import org.matrix.android.sdk.api.federation.FederationVersion
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class DefaultFederationService @Inject constructor(
|
||||
private val getFederationVersionTask: GetFederationVersionTask
|
||||
) : FederationService {
|
||||
override suspend fun getFederationVersion(): FederationVersion {
|
||||
return getFederationVersionTask.execute(Unit)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 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.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<FederationGetVersionResult>
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 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.federation
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
/**
|
||||
* Ref: https://matrix.org/docs/spec/server_server/latest#get-matrix-federation-v1-version
|
||||
*/
|
||||
@JsonClass(generateAdapter = true)
|
||||
internal data class FederationGetVersionResult(
|
||||
/**
|
||||
* Arbitrary name that identify this implementation.
|
||||
*/
|
||||
@Json(name = "name")
|
||||
val name: String?,
|
||||
/**
|
||||
* Version of this implementation. The version format depends on the implementation.
|
||||
*/
|
||||
@Json(name = "version")
|
||||
val version: String?
|
||||
)
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 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.federation
|
||||
|
||||
import dagger.Binds
|
||||
import dagger.Lazy
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import okhttp3.OkHttpClient
|
||||
import org.matrix.android.sdk.api.auth.data.SessionParams
|
||||
import org.matrix.android.sdk.api.federation.FederationService
|
||||
import org.matrix.android.sdk.internal.di.Unauthenticated
|
||||
import org.matrix.android.sdk.internal.network.RetrofitFactory
|
||||
|
||||
@Module
|
||||
internal abstract class FederationModule {
|
||||
|
||||
@Module
|
||||
companion object {
|
||||
@Provides
|
||||
@JvmStatic
|
||||
fun providesFederationAPI(@Unauthenticated okHttpClient: Lazy<OkHttpClient>,
|
||||
sessionParams: SessionParams,
|
||||
retrofitFactory: RetrofitFactory): FederationAPI {
|
||||
return retrofitFactory.create(okHttpClient, sessionParams.homeServerUrl).create(FederationAPI::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
@Binds
|
||||
abstract fun bindFederationService(service: DefaultFederationService): FederationService
|
||||
|
||||
@Binds
|
||||
abstract fun bindGetFederationVersionTask(task: DefaultGetFederationVersionTask): GetFederationVersionTask
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 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.federation
|
||||
|
||||
import org.matrix.android.sdk.api.federation.FederationVersion
|
||||
import org.matrix.android.sdk.internal.network.executeRequest
|
||||
import org.matrix.android.sdk.internal.task.Task
|
||||
import javax.inject.Inject
|
||||
|
||||
internal interface GetFederationVersionTask : Task<Unit, FederationVersion>
|
||||
|
||||
internal class DefaultGetFederationVersionTask @Inject constructor(
|
||||
private val federationAPI: FederationAPI
|
||||
) : GetFederationVersionTask {
|
||||
|
||||
override suspend fun execute(params: Unit): FederationVersion {
|
||||
val result = executeRequest<FederationGetVersionResult>(null) {
|
||||
apiCall = federationAPI.getVersion()
|
||||
}
|
||||
|
||||
return FederationVersion(
|
||||
name = result.name,
|
||||
version = result.version
|
||||
)
|
||||
}
|
||||
}
|
|
@ -36,4 +36,7 @@ internal object NetworkConstants {
|
|||
|
||||
// Integration
|
||||
const val URI_INTEGRATION_MANAGER_PATH = "_matrix/integrations/v1/"
|
||||
|
||||
// Federation
|
||||
const val URI_FEDERATION_PATH = "_matrix/federation/v1/"
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import io.realm.RealmConfiguration
|
|||
import okhttp3.OkHttpClient
|
||||
import org.matrix.android.sdk.api.auth.data.SessionParams
|
||||
import org.matrix.android.sdk.api.failure.GlobalError
|
||||
import org.matrix.android.sdk.api.federation.FederationService
|
||||
import org.matrix.android.sdk.api.pushrules.PushRuleService
|
||||
import org.matrix.android.sdk.api.session.InitialSyncProgressService
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
|
@ -88,6 +89,7 @@ internal class DefaultSession @Inject constructor(
|
|||
private val groupService: Lazy<GroupService>,
|
||||
private val userService: Lazy<UserService>,
|
||||
private val filterService: Lazy<FilterService>,
|
||||
private val federationService: Lazy<FederationService>,
|
||||
private val cacheService: Lazy<CacheService>,
|
||||
private val signOutService: Lazy<SignOutService>,
|
||||
private val pushRuleService: Lazy<PushRuleService>,
|
||||
|
@ -260,6 +262,8 @@ internal class DefaultSession @Inject constructor(
|
|||
|
||||
override fun searchService(): SearchService = searchService.get()
|
||||
|
||||
override fun federationService(): FederationService = federationService.get()
|
||||
|
||||
override fun thirdPartyService(): ThirdPartyService = thirdPartyService.get()
|
||||
|
||||
override fun getOkHttpClient(): OkHttpClient {
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.matrix.android.sdk.internal.crypto.SendGossipWorker
|
|||
import org.matrix.android.sdk.internal.crypto.crosssigning.UpdateTrustWorker
|
||||
import org.matrix.android.sdk.internal.crypto.verification.SendVerificationMessageWorker
|
||||
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.session.account.AccountModule
|
||||
import org.matrix.android.sdk.internal.session.cache.CacheModule
|
||||
|
@ -87,6 +88,7 @@ import org.matrix.android.sdk.internal.util.MatrixCoroutineDispatchers
|
|||
AccountDataModule::class,
|
||||
ProfileModule::class,
|
||||
AccountModule::class,
|
||||
FederationModule::class,
|
||||
CallModule::class,
|
||||
SearchModule::class,
|
||||
ThirdPartyModule::class
|
||||
|
|
Loading…
Add table
Reference in a new issue