mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Rename 'getDomain' to 'getServerName'.
In the context of matrix IDs, this removes the leading @name: leaving the hostname or hostname and port.
This commit is contained in:
parent
7efd41e17a
commit
e66284fbd3
@ -177,7 +177,7 @@ object MatrixPatterns {
|
||||
* - "@alice:domain.org".getDomain() will return "domain.org"
|
||||
* - "@bob:domain.org:3455".getDomain() will return "domain.org:3455"
|
||||
*/
|
||||
fun String.getDomain(): String {
|
||||
fun String.getServerName(): String {
|
||||
if (BuildConfig.DEBUG && !isUserId(this)) {
|
||||
// They are some invalid userId localpart in the wild, but the domain part should be there anyway
|
||||
Timber.w("Not a valid user ID: $this")
|
||||
|
@ -20,7 +20,7 @@ import android.net.Uri
|
||||
import dagger.Lazy
|
||||
import okhttp3.OkHttpClient
|
||||
import org.matrix.android.sdk.api.MatrixPatterns
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getDomain
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getServerName
|
||||
import org.matrix.android.sdk.api.auth.AuthenticationService
|
||||
import org.matrix.android.sdk.api.auth.data.Credentials
|
||||
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
|
||||
@ -381,7 +381,7 @@ internal class DefaultAuthenticationService @Inject constructor(
|
||||
|
||||
return getWellknownTask.execute(
|
||||
GetWellknownTask.Params(
|
||||
domain = matrixId.getDomain().substringBeforeLast(":"),
|
||||
domain = matrixId.getServerName().substringBeforeLast(":"),
|
||||
homeServerConnectionConfig = homeServerConnectionConfig.orWellKnownDefaults()
|
||||
)
|
||||
)
|
||||
|
@ -17,7 +17,7 @@
|
||||
package org.matrix.android.sdk.internal.session.homeserver
|
||||
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getDomain
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getServerName
|
||||
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
|
||||
import org.matrix.android.sdk.api.auth.wellknown.WellknownResult
|
||||
import org.matrix.android.sdk.api.extensions.orFalse
|
||||
@ -100,7 +100,7 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
|
||||
val wellknownResult = runCatching {
|
||||
getWellknownTask.execute(
|
||||
GetWellknownTask.Params(
|
||||
domain = userId.getDomain().substringBeforeLast(":"),
|
||||
domain = userId.getServerName().substringBeforeLast(":"),
|
||||
homeServerConnectionConfig = homeServerConnectionConfig
|
||||
)
|
||||
)
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.session.permalinks
|
||||
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getDomain
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getServerName
|
||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||
@ -55,9 +55,9 @@ internal class ViaParameterFinder @Inject constructor(
|
||||
}
|
||||
|
||||
fun computeViaParams(userId: String, roomId: String, max: Int): List<String> {
|
||||
val userHomeserver = userId.getDomain()
|
||||
val userHomeserver = userId.getServerName()
|
||||
return getUserIdsOfJoinedMembers(roomId)
|
||||
.map { it.getDomain() }
|
||||
.map { it.getServerName() }
|
||||
.groupBy { it }
|
||||
.mapValues { it.value.size }
|
||||
.toMutableMap()
|
||||
@ -92,7 +92,7 @@ internal class ViaParameterFinder @Inject constructor(
|
||||
.orEmpty()
|
||||
.toSet()
|
||||
|
||||
return userThatCanInvite.map { it.getDomain() }
|
||||
return userThatCanInvite.map { it.getServerName() }
|
||||
.groupBy { it }
|
||||
.mapValues { it.value.size }
|
||||
.toMutableMap()
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.session.room.alias
|
||||
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getDomain
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getServerName
|
||||
import org.matrix.android.sdk.api.failure.Failure
|
||||
import org.matrix.android.sdk.api.session.room.alias.RoomAliasError
|
||||
import org.matrix.android.sdk.internal.di.UserId
|
||||
@ -65,6 +65,6 @@ internal class RoomAliasAvailabilityChecker @Inject constructor(
|
||||
}
|
||||
|
||||
companion object {
|
||||
internal fun String.toFullLocalAlias(userId: String) = "#" + this + ":" + userId.getDomain()
|
||||
internal fun String.toFullLocalAlias(userId: String) = "#" + this + ":" + userId.getServerName()
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ import im.vector.app.core.resources.StringProvider
|
||||
import im.vector.app.core.utils.ensureTrailingSlash
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getDomain
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getServerName
|
||||
import org.matrix.android.sdk.api.auth.AuthenticationService
|
||||
import org.matrix.android.sdk.api.auth.HomeServerHistoryService
|
||||
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
|
||||
@ -607,7 +607,7 @@ class LoginViewModel @AssistedInject constructor(
|
||||
identityServerUri = wellKnownPrompt.identityServerUrl?.let { Uri.parse(it) }
|
||||
)
|
||||
?: HomeServerConnectionConfig(
|
||||
homeServerUri = Uri.parse("https://${action.username.getDomain()}"),
|
||||
homeServerUri = Uri.parse("https://${action.username.getServerName()}"),
|
||||
homeServerUriBase = Uri.parse(wellKnownPrompt.homeServerUrl),
|
||||
identityServerUri = wellKnownPrompt.identityServerUrl?.let { Uri.parse(it) }
|
||||
)
|
||||
|
@ -38,7 +38,7 @@ import im.vector.app.features.login.LoginMode
|
||||
import im.vector.app.features.login.ReAuthHelper
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getDomain
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getServerName
|
||||
import org.matrix.android.sdk.api.auth.AuthenticationService
|
||||
import org.matrix.android.sdk.api.auth.HomeServerHistoryService
|
||||
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
|
||||
@ -640,7 +640,7 @@ class LoginViewModel2 @AssistedInject constructor(
|
||||
}
|
||||
viewEvent?.let { _viewEvents.post(it) }
|
||||
|
||||
val urlFromUser = action.username.getDomain()
|
||||
val urlFromUser = action.username.getServerName()
|
||||
setState {
|
||||
copy(
|
||||
isLoading = false,
|
||||
|
@ -20,7 +20,7 @@ import im.vector.app.R
|
||||
import im.vector.app.core.extensions.andThen
|
||||
import im.vector.app.core.resources.StringProvider
|
||||
import im.vector.app.features.onboarding.OnboardingAction.LoginOrRegister
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getDomain
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getServerName
|
||||
import org.matrix.android.sdk.api.auth.AuthenticationService
|
||||
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
|
||||
import org.matrix.android.sdk.api.auth.wellknown.WellknownResult
|
||||
@ -75,7 +75,7 @@ class DirectLoginUseCase @Inject constructor(
|
||||
)
|
||||
|
||||
private fun fallbackConfig(action: LoginOrRegister, wellKnownPrompt: WellknownResult.Prompt) = HomeServerConnectionConfig(
|
||||
homeServerUri = uriFactory.parse("https://${action.username.getDomain()}"),
|
||||
homeServerUri = uriFactory.parse("https://${action.username.getServerName()}"),
|
||||
homeServerUriBase = uriFactory.parse(wellKnownPrompt.homeServerUrl),
|
||||
identityServerUri = wellKnownPrompt.identityServerUrl?.let { uriFactory.parse(it) }
|
||||
)
|
||||
|
@ -16,14 +16,14 @@
|
||||
|
||||
package im.vector.app.features.raw.wellknown
|
||||
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getDomain
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getServerName
|
||||
import org.matrix.android.sdk.api.auth.data.SessionParams
|
||||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||
import org.matrix.android.sdk.api.raw.RawService
|
||||
|
||||
suspend fun RawService.getElementWellknown(sessionParams: SessionParams): ElementWellKnown? {
|
||||
// By default we use the domain of the userId to retrieve the .well-known data
|
||||
val domain = sessionParams.userId.getDomain()
|
||||
val domain = sessionParams.userId.getServerName()
|
||||
return tryOrNull { getWellknown(domain) }
|
||||
?.let { ElementWellKnownMapper.from(it) }
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ import im.vector.app.features.raw.wellknown.getElementWellknown
|
||||
import im.vector.app.features.raw.wellknown.isE2EByDefault
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getDomain
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getServerName
|
||||
import org.matrix.android.sdk.api.extensions.orFalse
|
||||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||
import org.matrix.android.sdk.api.raw.RawService
|
||||
@ -98,7 +98,7 @@ class CreateRoomViewModel @AssistedInject constructor(
|
||||
private fun initHomeServerName() {
|
||||
setState {
|
||||
copy(
|
||||
homeServerName = session.myUserId.getDomain()
|
||||
homeServerName = session.myUserId.getServerName()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import im.vector.app.R
|
||||
import im.vector.app.core.resources.StringArrayProvider
|
||||
import im.vector.app.features.roomdirectory.RoomDirectoryData
|
||||
import im.vector.app.features.roomdirectory.RoomDirectoryServer
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getDomain
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getServerName
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.room.model.thirdparty.ThirdPartyProtocol
|
||||
import javax.inject.Inject
|
||||
@ -37,7 +37,7 @@ class RoomDirectoryListCreator @Inject constructor(
|
||||
val protocols = ArrayList<RoomDirectoryData>()
|
||||
|
||||
// Add user homeserver name
|
||||
val userHsName = session.myUserId.getDomain()
|
||||
val userHsName = session.myUserId.getServerName()
|
||||
|
||||
// Add default protocol
|
||||
protocols.add(
|
||||
|
@ -31,7 +31,7 @@ import im.vector.app.features.powerlevel.PowerLevelsFlowFactory
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getDomain
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getServerName
|
||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||
@ -96,7 +96,7 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
|
||||
private fun initHomeServerName() {
|
||||
setState {
|
||||
copy(
|
||||
homeServerName = session.myUserId.getDomain()
|
||||
homeServerName = session.myUserId.getServerName()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ import im.vector.app.core.resources.StringProvider
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import org.matrix.android.sdk.api.MatrixPatterns
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getDomain
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getServerName
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.identity.IdentityServiceListener
|
||||
import org.matrix.android.sdk.api.session.room.AliasAvailabilityResult
|
||||
@ -66,7 +66,7 @@ class CreateSpaceViewModel @AssistedInject constructor(
|
||||
val identityServerUrl = identityService.getCurrentIdentityServerUrl()
|
||||
setState {
|
||||
copy(
|
||||
homeServerName = session.myUserId.getDomain(),
|
||||
homeServerName = session.myUserId.getServerName(),
|
||||
canInviteByMail = identityServerUrl != null
|
||||
)
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ import kotlinx.coroutines.test.runTest
|
||||
import org.amshove.kluent.should
|
||||
import org.amshove.kluent.shouldBeEqualTo
|
||||
import org.junit.Test
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getDomain
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getServerName
|
||||
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
|
||||
import org.matrix.android.sdk.api.auth.data.WellKnown
|
||||
import org.matrix.android.sdk.api.auth.wellknown.WellknownResult
|
||||
@ -38,7 +38,7 @@ private val A_WELLKNOWN_FAILED_WITH_CONTENT_RESULT = WellknownResult.FailPrompt(
|
||||
private val A_WELLKNOWN_FAILED_WITHOUT_CONTENT_RESULT = WellknownResult.FailPrompt(null, null)
|
||||
private val NO_HOMESERVER_CONFIG: HomeServerConnectionConfig? = null
|
||||
private val A_FALLBACK_CONFIG: HomeServerConnectionConfig = HomeServerConnectionConfig(
|
||||
homeServerUri = FakeUri("https://${A_LOGIN_OR_REGISTER_ACTION.username.getDomain()}").instance,
|
||||
homeServerUri = FakeUri("https://${A_LOGIN_OR_REGISTER_ACTION.username.getServerName()}").instance,
|
||||
homeServerUriBase = FakeUri(A_WELLKNOWN_SUCCESS_RESULT.homeServerUrl).instance,
|
||||
identityServerUri = null
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user