Compute via param from list utility method

This commit is contained in:
Valere 2021-05-26 11:19:56 +02:00
parent b75d0cbfc6
commit d04cbadd04
2 changed files with 5 additions and 2 deletions

View File

@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.session.permalinks
import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.permalinks.PermalinkService.Companion.MATRIX_TO_URL_BASE import org.matrix.android.sdk.api.session.permalinks.PermalinkService.Companion.MATRIX_TO_URL_BASE
import org.matrix.android.sdk.internal.di.UserId import org.matrix.android.sdk.internal.di.UserId
import java.net.URLEncoder
import javax.inject.Inject import javax.inject.Inject
internal class PermalinkFactory @Inject constructor( internal class PermalinkFactory @Inject constructor(
@ -49,7 +48,7 @@ internal class PermalinkFactory @Inject constructor(
append(MATRIX_TO_URL_BASE) append(MATRIX_TO_URL_BASE)
append(escape(roomId)) append(escape(roomId))
append( append(
via?.joinToString(prefix = "?via=", separator = "&via=") { URLEncoder.encode(it, "utf-8") } via?.takeIf { it.isNotEmpty() }?.let { viaParameterFinder.computeViaParams(it) }
?: viaParameterFinder.computeViaParams(userId, roomId) ?: viaParameterFinder.computeViaParams(userId, roomId)
) )
} }

View File

@ -43,6 +43,10 @@ internal class ViaParameterFinder @Inject constructor(
.joinToString(prefix = "?via=", separator = "&via=") { URLEncoder.encode(it, "utf-8") } .joinToString(prefix = "?via=", separator = "&via=") { URLEncoder.encode(it, "utf-8") }
} }
fun computeViaParams(viaList: List<String>): String {
return viaList.joinToString(prefix = "?via=", separator = "&via=") { URLEncoder.encode(it, "utf-8") }
}
fun computeViaParams(userId: String, roomId: String, max: Int): List<String> { fun computeViaParams(userId: String, roomId: String, max: Int): List<String> {
val userHomeserver = userId.substringAfter(":") val userHomeserver = userId.substringAfter(":")
return getUserIdsOfJoinedMembers(roomId) return getUserIdsOfJoinedMembers(roomId)