mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-01-01 12:28:33 +01:00
Fix issue with Avatar URL
This commit is contained in:
parent
dde94c0d0f
commit
8f2754493c
@ -21,10 +21,19 @@ import im.vector.matrix.android.api.session.content.ContentUrlResolver
|
||||
|
||||
|
||||
private const val MATRIX_CONTENT_URI_SCHEME = "mxc://"
|
||||
internal const val URI_PREFIX_CONTENT_API = "_matrix/media/v1/"
|
||||
private const val URI_PREFIX_CONTENT_API = "_matrix/media/v1/"
|
||||
|
||||
internal class DefaultContentUrlResolver(private val homeServerConnectionConfig: HomeServerConnectionConfig) : ContentUrlResolver {
|
||||
|
||||
companion object {
|
||||
fun getUploadUrl(homeServerConnectionConfig: HomeServerConnectionConfig): String {
|
||||
val baseUrl = homeServerConnectionConfig.homeServerUri.toString()
|
||||
val sep = if (baseUrl.endsWith("/")) "" else "/"
|
||||
|
||||
return baseUrl + sep + URI_PREFIX_CONTENT_API + "upload"
|
||||
}
|
||||
}
|
||||
|
||||
override fun resolveFullSize(contentUrl: String?): String? {
|
||||
if (contentUrl?.isValidMatrixContentUrl() == true) {
|
||||
val baseUrl = homeServerConnectionConfig.homeServerUri.toString()
|
||||
@ -57,7 +66,10 @@ internal class DefaultContentUrlResolver(private val homeServerConnectionConfig:
|
||||
fragment = serverAndMediaId.substring(fragmentOffset)
|
||||
serverAndMediaId = serverAndMediaId.substring(0, fragmentOffset)
|
||||
}
|
||||
return baseUrl + prefix + serverAndMediaId + (params ?: "") + fragment
|
||||
|
||||
val sep = if (baseUrl.endsWith("/")) "" else "/"
|
||||
|
||||
return baseUrl + sep + prefix + serverAndMediaId + (params ?: "") + fragment
|
||||
}
|
||||
|
||||
private fun String.isValidMatrixContentUrl(): Boolean {
|
||||
|
@ -21,19 +21,15 @@ import arrow.core.Try.Companion.raise
|
||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
||||
import im.vector.matrix.android.internal.di.MoshiProvider
|
||||
import im.vector.matrix.android.internal.network.ProgressRequestBody
|
||||
import okhttp3.HttpUrl
|
||||
import okhttp3.MediaType
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.RequestBody
|
||||
import okhttp3.*
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
|
||||
internal class FileUploader(private val okHttpClient: OkHttpClient,
|
||||
private val sessionParams: SessionParams) {
|
||||
sessionParams: SessionParams) {
|
||||
|
||||
private val uploadUrl = sessionParams.homeServerConnectionConfig.homeServerUri.toString() + URI_PREFIX_CONTENT_API + "upload"
|
||||
private val uploadUrl = DefaultContentUrlResolver.getUploadUrl(sessionParams.homeServerConnectionConfig)
|
||||
|
||||
private val moshi = MoshiProvider.providesMoshi()
|
||||
private val responseAdapter = moshi.adapter(ContentUploadResponse::class.java)
|
||||
@ -82,7 +78,7 @@ internal class FileUploader(private val okHttpClient: OkHttpClient,
|
||||
response.body()?.source()?.let {
|
||||
responseAdapter.fromJson(it)
|
||||
}
|
||||
?: throw IOException()
|
||||
?: throw IOException()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user