1
Fork 0
mirror of https://github.com/Steffo99/twom.git synced 2024-11-21 23:54:26 +00:00

So close, yet so far away

This commit is contained in:
Steffo 2023-11-29 17:29:29 +01:00
parent 38f0ecbf1c
commit 51d2a83ee6
Signed by: steffo
GPG key ID: 2A24051445686895

View file

@ -0,0 +1,39 @@
package eu.steffo.twom.matrix
import android.util.Log
import androidx.compose.foundation.Image
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import org.matrix.android.sdk.api.session.Session
@Composable
fun UserAvatar(
session: Session,
userId: String,
contentDescription: String,
) {
var avatarUrl by rememberSaveable { mutableStateOf<String?>(null) }
LaunchedEffect(session, userId) GetAvatarUrl@{
Log.d("UserAvatar", "Retrieving avatar url for: $userId...")
avatarUrl = session.profileService().getAvatarUrl(userId).getOrNull()
Log.d("UserAvatar", "Retrieved avatar url for $userId: $avatarUrl")
}
if (avatarUrl == null) {
Image(
bitmap = TwoMMatrix.defaultAvatar,
contentDescription = contentDescription,
)
} else {
Avatar(
session = session,
url = avatarUrl!!,
contentDescription = contentDescription,
)
}
}