mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-28 02:20:10 +01:00
Authenticated media : fix pr remarks
This commit is contained in:
parent
669a80e8e4
commit
497f422b2b
@ -20,6 +20,7 @@ import com.zhuinden.monarchy.Monarchy
|
||||
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
|
||||
import org.matrix.android.sdk.api.extensions.orTrue
|
||||
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities
|
||||
import org.matrix.android.sdk.internal.auth.version.Versions
|
||||
@ -39,8 +40,9 @@ import org.matrix.android.sdk.internal.di.UserId
|
||||
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
|
||||
import org.matrix.android.sdk.internal.network.executeRequest
|
||||
import org.matrix.android.sdk.internal.session.integrationmanager.IntegrationManagerConfigExtractor
|
||||
import org.matrix.android.sdk.internal.session.media.AuthenticatedMediaAPI
|
||||
import org.matrix.android.sdk.internal.session.media.GetMediaConfigResult
|
||||
import org.matrix.android.sdk.internal.session.media.MediaAPIProvider
|
||||
import org.matrix.android.sdk.internal.session.media.UnauthenticatedMediaAPI
|
||||
import org.matrix.android.sdk.internal.task.Task
|
||||
import org.matrix.android.sdk.internal.util.awaitTransaction
|
||||
import org.matrix.android.sdk.internal.wellknown.GetWellknownTask
|
||||
@ -56,7 +58,8 @@ internal interface GetHomeServerCapabilitiesTask : Task<GetHomeServerCapabilitie
|
||||
|
||||
internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
|
||||
private val capabilitiesAPI: CapabilitiesAPI,
|
||||
private val mediaAPIProvider: MediaAPIProvider,
|
||||
private val unauthenticatedMediaAPI: UnauthenticatedMediaAPI,
|
||||
private val authenticatedMediaAPI: AuthenticatedMediaAPI,
|
||||
@SessionDatabase private val monarchy: Monarchy,
|
||||
private val globalErrorReceiver: GlobalErrorReceiver,
|
||||
private val getWellknownTask: GetWellknownTask,
|
||||
@ -85,18 +88,22 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
|
||||
}
|
||||
}.getOrNull()
|
||||
|
||||
val mediaConfig = runCatching {
|
||||
executeRequest(globalErrorReceiver) {
|
||||
mediaAPIProvider.getMediaAPI().getMediaConfig()
|
||||
}
|
||||
}.getOrNull()
|
||||
|
||||
val versions = runCatching {
|
||||
executeRequest(null) {
|
||||
capabilitiesAPI.getVersions()
|
||||
}
|
||||
}.getOrNull()
|
||||
|
||||
val mediaConfig = runCatching {
|
||||
executeRequest(globalErrorReceiver) {
|
||||
if (versions?.doesServerSupportAuthenticatedMedia().orFalse()) {
|
||||
authenticatedMediaAPI.getMediaConfig()
|
||||
} else {
|
||||
unauthenticatedMediaAPI.getMediaConfig()
|
||||
}
|
||||
}
|
||||
}.getOrNull()
|
||||
|
||||
// Domain may include a port (eg, matrix.org:8080)
|
||||
// Per https://spec.matrix.org/latest/client-server-api/#well-known-uri we should extract the hostname from the server name
|
||||
// So we take everything before the last : as the domain for the well-known task.
|
||||
|
@ -42,7 +42,6 @@ internal class DefaultIsAuthenticatedMediaSupported @Inject constructor(
|
||||
}
|
||||
|
||||
override fun onChange(results: RealmResults<HomeServerCapabilitiesEntity>) {
|
||||
Timber.d("HomeServerCapabilitiesEntity updated.")
|
||||
canUseAuthenticatedMedia = results.canUseAuthenticatedMedia()
|
||||
Timber.d("canUseAuthenticatedMedia: $canUseAuthenticatedMedia")
|
||||
}
|
||||
|
@ -30,13 +30,13 @@ internal interface GetRawPreviewUrlTask : Task<GetRawPreviewUrlTask.Params, Json
|
||||
}
|
||||
|
||||
internal class DefaultGetRawPreviewUrlTask @Inject constructor(
|
||||
private val mediaAPI: UnauthenticatedMediaAPI,
|
||||
private val mediaAPIProvider: MediaAPIProvider,
|
||||
private val globalErrorReceiver: GlobalErrorReceiver
|
||||
) : GetRawPreviewUrlTask {
|
||||
|
||||
override suspend fun execute(params: GetRawPreviewUrlTask.Params): JsonDict {
|
||||
return executeRequest(globalErrorReceiver) {
|
||||
mediaAPI.getPreviewUrlData(params.url, params.timestamp)
|
||||
mediaAPIProvider.getMediaAPI().getPreviewUrlData(params.url, params.timestamp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user