fix(marmot): a group's preview shows the edited text of its last message

The Marmot list row and the Messages-tab row read the last message's original content,
so after an edit the bubble showed the new text and the rows kept the old one. The preview
now observes the message's edits, the same overlay the bubble draws. Checked on the
tablet: editing the newest message updates the Messages row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Vitor Pamplona
2026-09-28 10:47:48 -04:00
co-authored by Claude Opus 5.5
parent 3615caabcc
commit 8d3565c124
@@ -35,6 +35,7 @@ import com.vitorpamplona.amethyst.commons.resources.marmot_preview_with_sender
import com.vitorpamplona.amethyst.commons.ui.stringRes
import com.vitorpamplona.amethyst.service.relayClient.reqCommand.user.observeUserInfo
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.feed.observeChatEdit
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.feed.types.hasEncryptedMediaV2
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.feed.types.hasMip04Media
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.feed.types.observeUserNameByHex
@@ -58,6 +59,10 @@ fun marmotGroupPreviewText(
// to render as a blank second line under the group name.
val myPubKey = accountViewModel.account.signer.pubKey
val previewEvent = newestMessage?.event
// An edited last message previews its new text, as its bubble does. Observed rather than
// read once so an edit arriving while the list is open updates the row.
val editedContent = newestMessage?.let { observeChatEdit(it) }?.event?.content
val shownText = editedContent ?: previewEvent?.content.orEmpty()
val previewBody =
when {
newestMessage == null -> stringRes(Res.string.marmot_no_messages_yet)
@@ -66,7 +71,7 @@ fun marmotGroupPreviewText(
// Text first: an attachment usually carries a caption, and showing
// "Attachment" over the words the sender actually wrote would be a
// step back from the raw `content` this replaced.
previewEvent.content.isNotBlank() -> previewEvent.content
shownText.isNotBlank() -> shownText
hasMip04Media(previewEvent) || hasEncryptedMediaV2(previewEvent) -> stringRes(Res.string.marmot_preview_media)
else -> stringRes(Res.string.marmot_preview_no_text)
}