Adjusts the roudabout way of making the chat screen

This commit is contained in:
Vitor Pamplona
2026-04-28 15:11:17 -04:00
parent 2a7683a7c2
commit ee860b92a1
4 changed files with 40 additions and 35 deletions
@@ -24,6 +24,8 @@ import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.vitorpamplona.amethyst.commons.model.Channel.Companion.DefaultFeedOrder
import com.vitorpamplona.amethyst.commons.model.Note
import com.vitorpamplona.nestsclient.BroadcastHandle
import com.vitorpamplona.nestsclient.NestsClient
import com.vitorpamplona.nestsclient.NestsListener
@@ -41,6 +43,7 @@ import com.vitorpamplona.nestsclient.connectReconnectingNestsSpeaker
import com.vitorpamplona.nestsclient.moq.SubscribeHandle
import com.vitorpamplona.nestsclient.transport.WebTransportFactory
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
import com.vitorpamplona.quartz.nip53LiveActivities.chat.LiveActivitiesChatMessageEvent
import kotlinx.collections.immutable.ImmutableSet
import kotlinx.collections.immutable.persistentSetOf
import kotlinx.collections.immutable.toPersistentSet
@@ -136,7 +139,7 @@ class NestViewModel(
/**
* Chat ledger for the live-activities chat panel (#1) — every
* kind-1311 ([com.vitorpamplona.quartz.nip53LiveActivities.chat.LiveActivitiesChatMessageEvent])
* kind-1311 ([LiveActivitiesChatMessageEvent])
* tagged with this room's `a`-pointer, ordered by `created_at`
* ascending so the newest message is at the end (the panel
* auto-scrolls to it).
@@ -144,10 +147,10 @@ class NestViewModel(
* Dedupes by event id — a relay re-emit on reconnect can't
* produce a duplicate row.
*/
private val chatById = LinkedHashMap<String, com.vitorpamplona.quartz.nip53LiveActivities.chat.LiveActivitiesChatMessageEvent>()
private val chatById = LinkedHashMap<String, Note>()
private val _chat =
MutableStateFlow<List<com.vitorpamplona.quartz.nip53LiveActivities.chat.LiveActivitiesChatMessageEvent>>(emptyList())
val chat: StateFlow<List<com.vitorpamplona.quartz.nip53LiveActivities.chat.LiveActivitiesChatMessageEvent>> = _chat.asStateFlow()
MutableStateFlow<List<Note>>(emptyList())
val chat: StateFlow<List<Note>> = _chat.asStateFlow()
/**
* Recent kind-7 reactions for the floating speaker-avatar overlay
@@ -388,11 +391,11 @@ class NestViewModel(
* room before invoking this. Same-id re-emits are deduped; the
* resulting list is sorted by `created_at` ascending.
*/
fun onChatEvent(event: com.vitorpamplona.quartz.nip53LiveActivities.chat.LiveActivitiesChatMessageEvent) {
fun onChatEvent(chatNote: Note) {
if (closed) return
if (chatById.containsKey(event.id)) return
chatById[event.id] = event
_chat.value = chatById.values.sortedBy { it.createdAt }
if (chatById.containsKey(chatNote.idHex)) return
chatById[chatNote.idHex] = chatNote
_chat.value = chatById.values.sortedWith(DefaultFeedOrder)
}
/**