From 54b212ea7da215ccabd75c507c43049fc5226f82 Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Sat, 2 May 2026 01:48:33 +0200 Subject: [PATCH] Get rid of the crash --- .../compose/database/dao/NostrEventDao.kt | 12 ++++++------ .../intermdiate/LocalInReplyToNostrEvent.kt | 6 ------ .../database/model/intermdiate/LocalMention.kt | 2 +- .../model/intermdiate/LocalNostrEvent.kt | 11 +++++------ .../model/intermdiate/LocalQuotedNostrEvent.kt | 8 -------- .../intermdiate/LocalRepostedNostrEvent.kt | 2 +- .../repository/DatabaseNostrRepository.kt | 4 ++-- .../compose/repository/NostrRepository.kt | 8 ++++---- .../composable/widgets/content/RichContent.kt | 18 +++++++++--------- .../widgets/detail/TextNoteEventDetail.kt | 1 - .../composable/widgets/feed/EventListView.kt | 2 -- .../widgets/feed/TextNoteFeedItem.kt | 2 -- 12 files changed, 28 insertions(+), 48 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/dao/NostrEventDao.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/dao/NostrEventDao.kt index 2c8459fb..69d855a2 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/dao/NostrEventDao.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/dao/NostrEventDao.kt @@ -17,36 +17,36 @@ import kotlinx.coroutines.flow.Flow @Dao interface NostrEventDao { @Query("SELECT * FROM NostrEvent WHERE kind in (:kinds) ORDER BY createdAt DESC") - fun observeNostrEvents(kinds: Array): Flow?> + fun observeNostrEvents(kinds: Array): Flow?> @Query("SELECT * FROM NostrEvent WHERE content LIKE '%' || :search || '%' AND kind in (:kinds) ORDER BY createdAt DESC") fun observeFilteredNostrEvents( kinds: Array, search: String - ): Flow?> + ): Flow?> @Query("SELECT * FROM NostrEvent WHERE kind in (:kinds) AND id in (:ids) ORDER BY createdAt DESC") fun observeFilteredNostrEvents( kinds: Array, ids: Array, - ): Flow?> + ): Flow?> @Query("SELECT * FROM NostrEvent WHERE kind in (:kinds) AND pubKey in (:authors) ORDER BY createdAt DESC LIMIT 50") fun observeAuthoredNostrEvents( kinds: Array, authors: Array, - ): Flow?> + ): Flow?> @Query("SELECT * FROM NostrEvent WHERE tags LIKE '%' || :publicKey || '%' AND kind in (:kinds) ORDER BY createdAt DESC") fun observePublicKeyMentionedNostrEvents( kinds: Array, publicKey: HexKey - ): Flow?> + ): Flow?> @RawQuery fun observePublicKeyFollowingNostrEvents( query: RoomRawQuery - ): Flow?> + ): Flow?> @Query("SELECT * FROM NostrEvent WHERE kind in (:kinds) ORDER BY savedAt DESC") fun getAllNostrEvents(kinds: Array): List diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalInReplyToNostrEvent.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalInReplyToNostrEvent.kt index 0694b1e6..e11d89c0 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalInReplyToNostrEvent.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalInReplyToNostrEvent.kt @@ -38,12 +38,6 @@ data class LocalInReplyToNostrEvent( ) val profile: Profile?, - @Relation( - entity = Mention::class, - parentColumn = "inReplyToNostrEventId", - entityColumn = "mentioningNostrEventId", - ) - val mentionedProfiles: List = emptyList(), ) { @Composable fun RenderNotePreview() { diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalMention.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalMention.kt index 1247d7c0..acdca3d2 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalMention.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalMention.kt @@ -6,7 +6,7 @@ import androidx.room3.Embedded import androidx.room3.Relation data class LocalMention( - @Embedded val mention: Mention?, + @Embedded val mention: Mention, @Relation( parentColumn = "mentionedPublicKey", diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalNostrEvent.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalNostrEvent.kt index 765b2fe4..624b3176 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalNostrEvent.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalNostrEvent.kt @@ -56,12 +56,11 @@ data class LocalNostrEvent( ) val localInReplyToNostrEvent: LocalInReplyToNostrEvent? = null, - @Relation( - entity = Mention::class, - parentColumn = "id", - entityColumn = "mentioningNostrEventId", - ) - val mentionedProfiles: List? = emptyList(), +// @Relation( +// parentColumn = "id", +// entityColumn = "mentioningNostrEventId", +// ) +// val mentionedProfiles: List? = emptyList(), ) { @Composable fun RenderNotePreview() { diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalQuotedNostrEvent.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalQuotedNostrEvent.kt index ed54711a..f3fc8fdd 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalQuotedNostrEvent.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalQuotedNostrEvent.kt @@ -37,13 +37,6 @@ data class LocalQuotedNostrEvent( entityColumn = "publicKey" ) val profile: Profile?, - - @Relation( - entity = Mention::class, - parentColumn = "quotedNostrEventId", - entityColumn = "mentioningNostrEventId", - ) - val mentionedProfiles: List = emptyList(), ) { @Composable fun RenderNotePreview() { @@ -85,7 +78,6 @@ data class LocalQuotedNostrEvent( RichContent( nostrEvent = nostrEvent, localQuotedNostrEvent = null, - mentionedProfiles = mentionedProfiles, ) } diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalRepostedNostrEvent.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalRepostedNostrEvent.kt index 31f3ca0b..6d27e281 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalRepostedNostrEvent.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalRepostedNostrEvent.kt @@ -43,7 +43,7 @@ data class LocalRepostedNostrEvent( parentColumn = "repostedNostrEventId", entityColumn = "mentioningNostrEventId", ) - val mentionedProfiles: List = emptyList(), + val mentionedProfiles: List? = emptyList(), ) { @Composable fun RenderNotePreview() { diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/repository/DatabaseNostrRepository.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/repository/DatabaseNostrRepository.kt index f064c365..e3f0328b 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/repository/DatabaseNostrRepository.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/repository/DatabaseNostrRepository.kt @@ -441,7 +441,7 @@ class DatabaseNostrRepository( ) } - override suspend fun observeNostrFeed(): Flow?> { + override suspend fun observeNostrFeed(): Flow?> { return database.nostrEventDao().observeNostrEvents( kinds = arrayOf( TextNoteEvent.KIND, @@ -452,7 +452,7 @@ class DatabaseNostrRepository( ) } - override suspend fun observeNostrFeed(synchronizationFilter: SynchronizationFilter): Flow?> { + override suspend fun observeNostrFeed(synchronizationFilter: SynchronizationFilter): Flow?> { return when { synchronizationFilter.kinds != null && synchronizationFilter.search != null -> { diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/repository/NostrRepository.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/repository/NostrRepository.kt index 49d7ab07..6a6dc7b2 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/repository/NostrRepository.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/repository/NostrRepository.kt @@ -84,9 +84,9 @@ interface NostrRepository { suspend fun getNostrEvent(publicKey: HexKey, kind: Kind): NostrEvent? - suspend fun observeNostrFeed(): Flow?> + suspend fun observeNostrFeed(): Flow?> - suspend fun observeNostrFeed(synchronizationFilter: SynchronizationFilter): Flow?> + suspend fun observeNostrFeed(synchronizationFilter: SynchronizationFilter): Flow?> suspend fun observeLocalNostrEventById(nostrEventId: String): Flow @@ -207,11 +207,11 @@ interface NostrRepository { TODO("Not yet implemented") } - override suspend fun observeNostrFeed(): Flow?> { + override suspend fun observeNostrFeed(): Flow?> { TODO("Not yet implemented") } - override suspend fun observeNostrFeed(synchronizationFilter: SynchronizationFilter): Flow?> { + override suspend fun observeNostrFeed(synchronizationFilter: SynchronizationFilter): Flow?> { TODO("Not yet implemented") } diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/content/RichContent.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/content/RichContent.kt index fb2a7616..a8f4ff56 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/content/RichContent.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/content/RichContent.kt @@ -35,7 +35,6 @@ import coil3.compose.AsyncImage fun RichContent( nostrEvent: NostrEvent, localQuotedNostrEvent: LocalQuotedNostrEvent?, - mentionedProfiles: List?, style: TextStyle = MaterialTheme.typography.bodyLarge, color: Color = MaterialTheme.colorScheme.onSurface, linkColor: Color = Color.Unspecified, @@ -110,14 +109,15 @@ fun RichContent( val profileNames = remember(profilePubkeys) { val names = mutableMapOf() - if (mentionedProfiles?.isNotEmpty() == true) { - Logger.withTag("RichContent").d("mentionedProfiles: ${mentionedProfiles}") - for (pubkey in profilePubkeys) { - val mentionedProfile = mentionedProfiles.find { mentionedProfile -> mentionedProfile?.profile?.publicKey == pubkey } - names[pubkey] = mentionedProfile?.profile?.humanReadableNameOrPubkey() - ?: "${pubkey.take(8)}...${pubkey.takeLast(4)}" - } - } + // TODO: Get profiles from profilePubkeys +// if (mentionedProfiles?.isNotEmpty() == true) { +// Logger.withTag("RichContent").d("mentionedProfiles: ${mentionedProfiles}") +// for (pubkey in profilePubkeys) { +// val mentionedProfile = mentionedProfiles.find { mentionedProfile -> mentionedProfile?.profile?.publicKey == pubkey } +// names[pubkey] = mentionedProfile?.profile?.humanReadableNameOrPubkey() +// ?: "${pubkey.take(8)}...${pubkey.takeLast(4)}" +// } +// } names } diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/detail/TextNoteEventDetail.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/detail/TextNoteEventDetail.kt index 1872eff5..7e483c6d 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/detail/TextNoteEventDetail.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/detail/TextNoteEventDetail.kt @@ -143,7 +143,6 @@ fun TextNoteEventDetail( ), nostrEvent = localNostrEvent.nostrEvent, localQuotedNostrEvent = localNostrEvent.localQuotedNostrEvent, - mentionedProfiles = localNostrEvent.mentionedProfiles ) Row( diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/feed/EventListView.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/feed/EventListView.kt index 21358061..e5038ba5 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/feed/EventListView.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/feed/EventListView.kt @@ -68,7 +68,6 @@ fun LocalNostrEvent.ListView( profile = localRepostedNostrEvent.profile, localQuotedNostrEvent = null, localInReplyToNostrEvent = null, - mentionedProfiles = localRepostedNostrEvent.mentionedProfiles, onNavigateToEvent = onNavigateToEvent ) } else { @@ -104,7 +103,6 @@ fun LocalNostrEvent.ListView( profile = profile, localQuotedNostrEvent = localQuotedNostrEvent, localInReplyToNostrEvent = localInReplyToNostrEvent, - mentionedProfiles = mentionedProfiles, onNavigateToEvent = onNavigateToEvent ) } diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/feed/TextNoteFeedItem.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/feed/TextNoteFeedItem.kt index b1e1bc28..9c2ac6e9 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/feed/TextNoteFeedItem.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/feed/TextNoteFeedItem.kt @@ -36,7 +36,6 @@ internal fun TextNoteFeedItem( profile: Profile?, localInReplyToNostrEvent: LocalInReplyToNostrEvent?, localQuotedNostrEvent: LocalQuotedNostrEvent?, - mentionedProfiles: List?, onNavigateToEvent: (HexKey) -> Unit ) { if (localInReplyToNostrEvent != null) { @@ -108,7 +107,6 @@ internal fun TextNoteFeedItem( modifier = Modifier.fillMaxWidth(), nostrEvent = nostrEvent, localQuotedNostrEvent = localQuotedNostrEvent, - mentionedProfiles = mentionedProfiles ) LazyRow(