Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ fun PreviewSelfQRCodeContent() {
SelfQRCodeState(
userId = UserId("userId", "wire.com"),
handle = "userid",
userProfileLink = "https://account.wire.com/user-profile/?id=aaaaaaa-222-3333-4444-55555555"
userProfileLink = "wire://user/wire.com/aaaaaaa-222-3333-4444-55555555",
userAccountProfileLink = "https://account.wire.com/user-profile/?id=aaaaaaa-222-3333-4444-55555555@wire.com"
),
{ "".toUri() },
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class SelfQRCodeViewModel @Inject constructor(

private fun generateSelfUserUrls(accountsUrl: String): SelfQRCodeState =
selfQRCodeState.copy(
userAccountProfileLink = String.format(BASE_USER_PROFILE_URL, accountsUrl, selfUserId.value),
userAccountProfileLink = String.format(BASE_USER_PROFILE_URL, accountsUrl, selfUserId),
userProfileLink = String.format(DIRECT_BASE_USER_PROFILE_URL, selfUserId.domain, selfUserId.value)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,32 @@
}
}

/**
* Format of deeplink to parse: wire://user/domain/user-id
*/
private fun getConnectingUserProfile(uri: Uri, switchedAccount: Boolean, accountInfo: AccountInfo.Valid): DeepLinkResult {
// todo. handle with domain case, before lastPathSegment. format of deeplink wire://user/domain/user-id
return uri.lastPathSegment?.toDefaultQualifiedId(accountInfo.userId.domain)?.let {
DeepLinkResult.OpenOtherUserProfile(it, switchedAccount)
} ?: return DeepLinkResult.Unknown
val segments = uri.pathSegments
segments.takeLast(2).let { domainAndUserId ->
return if (domainAndUserId.size == 2) {
val userId = domainAndUserId[1]
val domain = domainAndUserId[0]
userId.toDefaultQualifiedId(domain).let {
DeepLinkResult.OpenOtherUserProfile(it, switchedAccount)
}
} else {
uri.lastPathSegment?.toDefaultQualifiedId(accountInfo.userId.domain)?.let {
DeepLinkResult.OpenOtherUserProfile(it, switchedAccount)
} ?: DeepLinkResult.Unknown

Check warning on line 163 in app/src/main/kotlin/com/wire/android/util/deeplink/DeepLinkProcessor.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/util/deeplink/DeepLinkProcessor.kt#L162-L163

Added lines #L162 - L163 were not covered by tests
}
}
}

/**
* Converts the string to a [QualifiedID] with the current user domain or default, to preserve retro compatibility.
* When implementing Milestone 2 this should be replaced with a new qualifiedIdMapper, implementing wire://user/domain/user-id
*
* - new mapper should follow "domain/user-id" parsing.
* Converts the string to a [QualifiedID] with the current user domain or default.
* IMPORTANT! This also handles the special case where iOS is sending the ID in uppercase.
*/
private fun String.toDefaultQualifiedId(currentUserDomain: String?): QualifiedID {
val domain = currentUserDomain ?: "wire.com"
// TODO. This lowercase is important, since web/iOS is sending/handling this as uppercase!!
return QualifiedID(this.lowercase(), domain)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SelfQRCodeViewModelTest {
)

assertEquals(
expected = "${ServerConfig.STAGING.accounts}/user-profile/?id=${TestUser.SELF_USER.id.value}",
expected = "${ServerConfig.STAGING.accounts}/user-profile/?id=${TestUser.SELF_USER.id}",
actual = viewModel.selfQRCodeState.userAccountProfileLink,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class DeepLinkProcessorTest {
val conversationResult = deepLinkProcessor(arrangement.uri)
assertInstanceOf(DeepLinkResult.OpenOtherUserProfile::class.java, conversationResult)
assertEquals(
DeepLinkResult.OpenOtherUserProfile(UserId("other_user", "domain"), false),
DeepLinkResult.OpenOtherUserProfile(UserId("other_user", "other_domain"), false),
conversationResult
)
}
Expand Down Expand Up @@ -387,7 +387,7 @@ class DeepLinkProcessorTest {

fun withOtherUserProfileQRDeepLink(userIdToOpen: UserId = OTHER_USER_ID, userId: UserId = CURRENT_USER_ID) = apply {
coEvery { uri.host } returns DeepLinkProcessor.OPEN_USER_PROFILE_DEEPLINK_HOST
coEvery { uri.lastPathSegment } returns userIdToOpen.value
coEvery { uri.pathSegments } returns listOf(userIdToOpen.domain, userIdToOpen.value)
coEvery { uri.getQueryParameter(DeepLinkProcessor.USER_TO_USE_QUERY_PARAM) } returns userId.toString()
}

Expand Down
Loading