@@ -19,22 +19,35 @@ package im.vector.app.features.discovery
19
19
import im.vector.app.core.utils.ensureProtocol
20
20
import org.matrix.android.sdk.api.session.Session
21
21
import org.matrix.android.sdk.api.session.terms.TermsService
22
+ import org.matrix.android.sdk.internal.session.terms.TermsResponse
22
23
23
- suspend fun Session.fetchIdentityServerWithTerms (userLanguage : String ): IdentityServerWithTerms ? {
24
- val identityServerUrl = identityService().getCurrentIdentityServerUrl()
25
- return identityServerUrl?.let {
26
- val terms = getTerms(TermsService .ServiceType .IdentityService , identityServerUrl.ensureProtocol())
27
- .serverResponse
28
- .getLocalizedTerms(userLanguage)
29
- val policyUrls = terms.mapNotNull {
30
- val name = it.localizedName ? : it.policyName
31
- val url = it.localizedUrl
32
- if (name == null || url == null ) {
33
- null
34
- } else {
35
- IdentityServerPolicy (name = name, url = url)
24
+ suspend fun Session.fetchIdentityServerWithTerms (userLanguage : String ): ServerAndPolicies ? {
25
+ return identityService().getCurrentIdentityServerUrl()
26
+ ?.let { identityServerUrl ->
27
+ val termsResponse = getTerms(TermsService .ServiceType .IdentityService , identityServerUrl.ensureProtocol())
28
+ .serverResponse
29
+ buildServerAndPolicies(identityServerUrl, termsResponse, userLanguage)
36
30
}
31
+ }
32
+
33
+ suspend fun Session.fetchHomeserverWithTerms (userLanguage : String ): ServerAndPolicies {
34
+ val homeserverUrl = sessionParams.homeServerUrl
35
+ val terms = getHomeserverTerms(homeserverUrl.ensureProtocol())
36
+ return buildServerAndPolicies(homeserverUrl, terms, userLanguage)
37
+ }
38
+
39
+ private fun buildServerAndPolicies (serviceUrl : String ,
40
+ termsResponse : TermsResponse ,
41
+ userLanguage : String ): ServerAndPolicies {
42
+ val terms = termsResponse.getLocalizedTerms(userLanguage)
43
+ val policyUrls = terms.mapNotNull {
44
+ val name = it.localizedName ? : it.policyName
45
+ val url = it.localizedUrl
46
+ if (name == null || url == null ) {
47
+ null
48
+ } else {
49
+ ServerPolicy (name = name, url = url)
37
50
}
38
- IdentityServerWithTerms (identityServerUrl, policyUrls)
39
51
}
52
+ return ServerAndPolicies (serviceUrl, policyUrls)
40
53
}
0 commit comments