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.MatrixPatterns.getServerName
|
||||||
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
|
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
|
||||||
import org.matrix.android.sdk.api.auth.wellknown.WellknownResult
|
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.extensions.orTrue
|
||||||
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities
|
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities
|
||||||
import org.matrix.android.sdk.internal.auth.version.Versions
|
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.GlobalErrorReceiver
|
||||||
import org.matrix.android.sdk.internal.network.executeRequest
|
import org.matrix.android.sdk.internal.network.executeRequest
|
||||||
import org.matrix.android.sdk.internal.session.integrationmanager.IntegrationManagerConfigExtractor
|
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.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.task.Task
|
||||||
import org.matrix.android.sdk.internal.util.awaitTransaction
|
import org.matrix.android.sdk.internal.util.awaitTransaction
|
||||||
import org.matrix.android.sdk.internal.wellknown.GetWellknownTask
|
import org.matrix.android.sdk.internal.wellknown.GetWellknownTask
|
||||||
|
@ -56,7 +58,8 @@ internal interface GetHomeServerCapabilitiesTask : Task<GetHomeServerCapabilitie
|
||||||
|
|
||||||
internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
|
internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
|
||||||
private val capabilitiesAPI: CapabilitiesAPI,
|
private val capabilitiesAPI: CapabilitiesAPI,
|
||||||
private val mediaAPIProvider: MediaAPIProvider,
|
private val unauthenticatedMediaAPI: UnauthenticatedMediaAPI,
|
||||||
|
private val authenticatedMediaAPI: AuthenticatedMediaAPI,
|
||||||
@SessionDatabase private val monarchy: Monarchy,
|
@SessionDatabase private val monarchy: Monarchy,
|
||||||
private val globalErrorReceiver: GlobalErrorReceiver,
|
private val globalErrorReceiver: GlobalErrorReceiver,
|
||||||
private val getWellknownTask: GetWellknownTask,
|
private val getWellknownTask: GetWellknownTask,
|
||||||
|
@ -85,18 +88,22 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
|
||||||
}
|
}
|
||||||
}.getOrNull()
|
}.getOrNull()
|
||||||
|
|
||||||
val mediaConfig = runCatching {
|
|
||||||
executeRequest(globalErrorReceiver) {
|
|
||||||
mediaAPIProvider.getMediaAPI().getMediaConfig()
|
|
||||||
}
|
|
||||||
}.getOrNull()
|
|
||||||
|
|
||||||
val versions = runCatching {
|
val versions = runCatching {
|
||||||
executeRequest(null) {
|
executeRequest(null) {
|
||||||
capabilitiesAPI.getVersions()
|
capabilitiesAPI.getVersions()
|
||||||
}
|
}
|
||||||
}.getOrNull()
|
}.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)
|
// 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
|
// 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.
|
// 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>) {
|
override fun onChange(results: RealmResults<HomeServerCapabilitiesEntity>) {
|
||||||
Timber.d("HomeServerCapabilitiesEntity updated.")
|
|
||||||
canUseAuthenticatedMedia = results.canUseAuthenticatedMedia()
|
canUseAuthenticatedMedia = results.canUseAuthenticatedMedia()
|
||||||
Timber.d("canUseAuthenticatedMedia: $canUseAuthenticatedMedia")
|
Timber.d("canUseAuthenticatedMedia: $canUseAuthenticatedMedia")
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,13 +30,13 @@ internal interface GetRawPreviewUrlTask : Task<GetRawPreviewUrlTask.Params, Json
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class DefaultGetRawPreviewUrlTask @Inject constructor(
|
internal class DefaultGetRawPreviewUrlTask @Inject constructor(
|
||||||
private val mediaAPI: UnauthenticatedMediaAPI,
|
private val mediaAPIProvider: MediaAPIProvider,
|
||||||
private val globalErrorReceiver: GlobalErrorReceiver
|
private val globalErrorReceiver: GlobalErrorReceiver
|
||||||
) : GetRawPreviewUrlTask {
|
) : GetRawPreviewUrlTask {
|
||||||
|
|
||||||
override suspend fun execute(params: GetRawPreviewUrlTask.Params): JsonDict {
|
override suspend fun execute(params: GetRawPreviewUrlTask.Params): JsonDict {
|
||||||
return executeRequest(globalErrorReceiver) {
|
return executeRequest(globalErrorReceiver) {
|
||||||
mediaAPI.getPreviewUrlData(params.url, params.timestamp)
|
mediaAPIProvider.getMediaAPI().getPreviewUrlData(params.url, params.timestamp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue