Skip to content
Snippets Groups Projects
Commit 1e398e01 authored by Taras's avatar Taras
Browse files

Add matrix session extensions

parent 12d73391
No related branches found
No related tags found
No related merge requests found
package com.futo.circles.extensions
import com.bumptech.glide.request.target.Target
import com.futo.circles.provider.MatrixSessionProvider
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.content.ContentUrlResolver
private val sessionCoroutineScopes = HashMap<String, CoroutineScope>(1)
val Session.coroutineScope: CoroutineScope
get() {
return synchronized(sessionCoroutineScopes) {
sessionCoroutineScopes.getOrPut(sessionId) {
CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
}
}
}
fun Session.resolveUrl(url: String?, size: Int = Target.SIZE_ORIGINAL): String? {
val resolver = MatrixSessionProvider.currentSession?.contentUrlResolver()
return if (size == Target.SIZE_ORIGINAL) {
resolver?.resolveFullSize(url)
} else {
resolver?.resolveThumbnail(
url,
size, size,
ContentUrlResolver.ThumbnailMethod.SCALE
)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment