fix: load caller name and profile picture in call notification

Both CallController and EventNotificationConsumer now load the
caller's profile picture via Coil before showing the notification,
so the large icon displays the caller's avatar instead of being
empty. The caller name was already loaded from LocalCache but now
the bitmap accompanies it.

https://claude.ai/code/session_01Ak5tTkujpjNG1r5ASuPipZ
This commit is contained in:
Claude
2026-04-02 20:34:07 +00:00
parent 7024994b9a
commit dbdd53c6c3
2 changed files with 37 additions and 4 deletions
@@ -22,6 +22,9 @@ package com.vitorpamplona.amethyst.service.call
import android.content.Context
import android.content.Intent
import coil3.ImageLoader
import coil3.asDrawable
import coil3.request.ImageRequest
import com.vitorpamplona.amethyst.commons.call.CallManager
import com.vitorpamplona.amethyst.commons.call.CallState
import com.vitorpamplona.amethyst.model.LocalCache
@@ -462,14 +465,27 @@ class CallController(
}
}
private fun showIncomingCallNotification(callerPubKey: String) {
private suspend fun showIncomingCallNotification(callerPubKey: String) {
val callerUser = LocalCache.getUserIfExists(callerPubKey)
val callerName = callerUser?.toBestDisplayName() ?: callerPubKey.take(8) + "..."
val uri = "nostr:${callerPubKey.hexToByteArray().toNpub()}"
val callerBitmap =
callerUser?.profilePicture()?.let { pictureUrl ->
withContext(Dispatchers.IO) {
try {
val request = ImageRequest.Builder(context).data(pictureUrl).build()
val result = ImageLoader(context).execute(request)
(result.image?.asDrawable(context.resources) as? android.graphics.drawable.BitmapDrawable)?.bitmap
} catch (_: Exception) {
null
}
}
}
NotificationUtils.sendCallNotification(
callerName = callerName,
callerBitmap = null,
callerBitmap = callerBitmap,
uri = uri,
applicationContext = context,
)
@@ -22,7 +22,11 @@ package com.vitorpamplona.amethyst.service.notifications
import android.app.NotificationManager
import android.content.Context
import android.graphics.drawable.BitmapDrawable
import androidx.core.content.ContextCompat
import coil3.ImageLoader
import coil3.asDrawable
import coil3.request.ImageRequest
import com.vitorpamplona.amethyst.Amethyst
import com.vitorpamplona.amethyst.LocalPreferences
import com.vitorpamplona.amethyst.R
@@ -625,7 +629,7 @@ class EventNotificationConsumer(
}
}
private fun notifyIncomingCall(
private suspend fun notifyIncomingCall(
event: CallOfferEvent,
account: Account,
) {
@@ -636,10 +640,23 @@ class EventNotificationConsumer(
val callerUser = LocalCache.getUserIfExists(event.pubKey)
val callerName = callerUser?.toBestDisplayName() ?: event.pubKey.take(8) + "..."
val callerBitmap =
callerUser?.profilePicture()?.let { pictureUrl ->
kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) {
try {
val request = ImageRequest.Builder(applicationContext).data(pictureUrl).build()
val result = ImageLoader(applicationContext).execute(request)
(result.image?.asDrawable(applicationContext.resources) as? BitmapDrawable)?.bitmap
} catch (_: Exception) {
null
}
}
}
NotificationUtils
.sendCallNotification(
callerName = callerName,
callerBitmap = null,
callerBitmap = callerBitmap,
uri = "nostr:${event.pubKey.hexToByteArray().toNpub()}",
applicationContext = applicationContext,
)