feat: optimistic status update for instant feedback

Add setUserStatus() to EventRepository for direct cache updates.
Call it in publishUserStatus() before the relay round-trip so the
status change appears immediately in the drawer and on posts.
This commit is contained in:
The Daniel
2026-04-05 09:21:27 -04:00
parent 5c647f673f
commit 1c59ebf54a
2 changed files with 10 additions and 0 deletions
@@ -50,6 +50,13 @@ class EventRepository(val profileRepo: ProfileRepository? = null, val muteRepo:
fun getUserStatus(pubkey: String): String? = userStatusCache[pubkey]
/** Optimistically update status in local cache before relay confirmation. */
fun setUserStatus(pubkey: String, status: String?) {
if (status.isNullOrBlank()) userStatusCache.remove(pubkey)
else userStatusCache[pubkey] = status
_statusVersion.value++
}
/** NIP-38: process a kind 30315 user status event. Only caches "general" statuses. */
private fun processUserStatus(event: NostrEvent) {
val dTag = event.tags.firstOrNull { it.size >= 2 && it[0] == "d" }?.get(1)
@@ -515,6 +515,9 @@ class FeedViewModel(app: Application) : AndroidViewModel(app) {
/** Publish a NIP-38 user status (kind 30315). Empty string clears the status. */
fun publishUserStatus(status: String) {
val s = signer ?: return
val pubkey = pubkeyHex ?: return
// Optimistic local update so UI feels instant
eventRepo.setUserStatus(pubkey, status.ifBlank { null })
viewModelScope.launch {
val tags = mutableListOf(listOf("d", "general"))
val event = s.signEvent(kind = 30315, content = status, tags = tags)