From dd416711e273ad61dcf60a42b4856ad96fb97f11 Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Sat, 27 Jun 2026 03:26:07 +0000 Subject: [PATCH] fix: app crash when message id is null (#28) Reviewed-on: https://git.reya.su/reya/coop-mobile/pulls/28 --- .../androidMain/kotlin/su/reya/coop/screens/ChatScreen.kt | 7 ++++--- .../androidMain/kotlin/su/reya/coop/shared/RoomHelper.kt | 4 ++-- shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/composeApp/src/androidMain/kotlin/su/reya/coop/screens/ChatScreen.kt b/composeApp/src/androidMain/kotlin/su/reya/coop/screens/ChatScreen.kt index 2907e2d..0e7db46 100644 --- a/composeApp/src/androidMain/kotlin/su/reya/coop/screens/ChatScreen.kt +++ b/composeApp/src/androidMain/kotlin/su/reya/coop/screens/ChatScreen.kt @@ -234,9 +234,10 @@ fun ChatScreen(id: Long, screening: Boolean = false) { ) { groupedMessages.forEach { (dateHeader, messagesInGroup) -> items( - messagesInGroup, - key = { it.id()?.toBech32()!! }) { event -> - ChatMessage(event) + items = messagesInGroup, + key = { it.id()?.toBech32() ?: it.hashCode() } + ) { + ChatMessage(it) } item { DateSeparator(dateHeader) diff --git a/composeApp/src/androidMain/kotlin/su/reya/coop/shared/RoomHelper.kt b/composeApp/src/androidMain/kotlin/su/reya/coop/shared/RoomHelper.kt index a7c0cbd..bbb861a 100644 --- a/composeApp/src/androidMain/kotlin/su/reya/coop/shared/RoomHelper.kt +++ b/composeApp/src/androidMain/kotlin/su/reya/coop/shared/RoomHelper.kt @@ -18,8 +18,8 @@ fun Room.nameFlow(viewModel: NostrViewModel): Flow { return combine(displayMembers.map { viewModel.getMetadata(it) }) { metadataArray -> val names = metadataArray.mapIndexed { i, metadata -> val profile = metadata?.asRecord() - profile?.name?.takeIf { it.isNotBlank() } - ?: profile?.displayName?.takeIf { it.isNotBlank() } + profile?.displayName?.takeIf { it.isNotBlank() } + ?: profile?.name?.takeIf { it.isNotBlank() } ?: displayMembers[i].short() } diff --git a/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt b/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt index ba0fcce..d5427a0 100644 --- a/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt +++ b/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt @@ -473,7 +473,7 @@ class Nostr { // Decrypt the rumor val rumor = signer.nip44DecryptAsync(sealEvent.author(), sealEvent.content()) - val unsignedEvent = UnsignedEvent.fromJson(rumor) + val unsignedEvent = UnsignedEvent.fromJson(rumor).ensureId() // Ensure the rumor author matches the seal if (unsignedEvent.author() != sealEvent.author()) { @@ -813,7 +813,7 @@ class Nostr { // Merge the events return events ?.toVec() - ?.map { UnsignedEvent.fromJson(it.content()) } + ?.map { UnsignedEvent.fromJson(it.content()).ensureId() } // Filter out events without public keys (receivers) ?.filter { it.tags().publicKeys().isNotEmpty() } ?.sortedByDescending { it.createdAt().asSecs() } ?: emptyList()