From a0d4b7fbdd5510227599dfe3ffe0e6fe8d0f4ee1 Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Thu, 30 Apr 2026 23:39:49 +0200 Subject: [PATCH] Showing mentioned profiles --- .../compose/database/dao/MentionDao.kt | 5 ++++- .../auxiliary/compose/database/dao/NostrDao.kt | 14 ++++++++++++++ .../database/model/intermdiate/LocalMention.kt | 17 +++++++++++++++++ .../model/intermdiate/LocalNostrEvent.kt | 13 ++----------- .../ui/composable/widgets/feed/EventListView.kt | 9 ++++----- 5 files changed, 41 insertions(+), 17 deletions(-) create mode 100644 composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalMention.kt diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/dao/MentionDao.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/dao/MentionDao.kt index e5bbca1f..1c7168e5 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/dao/MentionDao.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/dao/MentionDao.kt @@ -5,13 +5,16 @@ import ac.cord.auxiliary.compose.database.model.Post import ac.cord.auxiliary.compose.database.model.intermdiate.LocalPost import androidx.room.Dao import androidx.room.Insert +import androidx.room.OnConflictStrategy.Companion.IGNORE import androidx.room.Query import androidx.room.Upsert @Dao interface MentionDao { - @Insert + @Insert( + onConflict = IGNORE + ) suspend fun insert(mention: Mention) @Upsert diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/dao/NostrDao.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/dao/NostrDao.kt index 0b2c52ae..04c057b3 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/dao/NostrDao.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/dao/NostrDao.kt @@ -4,6 +4,7 @@ import ac.cord.auxiliary.compose.database.AuxDatabase import ac.cord.auxiliary.compose.database.GENESIS_AT import ac.cord.auxiliary.compose.database.model.BroadcastNostrEventRequest import ac.cord.auxiliary.compose.database.model.Connection +import ac.cord.auxiliary.compose.database.model.Mention import ac.cord.auxiliary.compose.database.model.NostrEvent import ac.cord.auxiliary.compose.database.model.Post import ac.cord.auxiliary.compose.database.model.Profile @@ -148,6 +149,7 @@ abstract class NostrDao( if (profile == null) { val placeHolderProfile = Profile( + displayName = "LOADING PROFILE...", publicKey = nostrEvent.pubKey, createdAt = GENESIS_AT, nostrEventId = nostrEvent.id, // Will get overwriting by sync, @@ -335,6 +337,7 @@ abstract class NostrDao( // Save a placeholder database.profileDao().insertPlaceholderProfile( Profile( + displayName = "LOADING PROFILE...", publicKey = taggedUser.pubKey, createdAt = GENESIS_AT, nostrEventId = nostrEvent.id, // Will get overwriting by sync, @@ -342,6 +345,13 @@ abstract class NostrDao( ) } + database.mentionDao().insert( + Mention( + mentionedPublicKey = taggedUser.pubKey, + nostrEventId = nostrEvent.id, + relayUrl = taggedUser.relayHint?.url + ) + ) val synchronizeNostrEventRequests = if (recommendedRelay != null) { // listOf( // SynchronizeNostrEventRequest( @@ -465,6 +475,7 @@ abstract class NostrDao( if (quotedProfilePublicKey != null && quotedProfile == null) { database.profileDao().insertPlaceholderProfile( Profile( + displayName = "LOADING PROFILE...", publicKey = quotedProfilePublicKey, createdAt = GENESIS_AT, nostrEventId = nostrEvent.id, // Will get overwriting by sync, @@ -509,6 +520,7 @@ abstract class NostrDao( if (repostedProfilePublicKey != null && repostedProfile == null) { database.profileDao().insertPlaceholderProfile( Profile( + displayName = "LOADING PROFILE...", publicKey = repostedProfilePublicKey, createdAt = GENESIS_AT, nostrEventId = nostrEvent.id, // Will get overwriting by sync, @@ -562,6 +574,7 @@ abstract class NostrDao( if (inReplyToRootProfilePublicKey != null && inReplyToProfile == null) { database.profileDao().insertPlaceholderProfile( Profile( + displayName = "LOADING PROFILE...", publicKey = inReplyToRootProfilePublicKey, createdAt = GENESIS_AT, nostrEventId = nostrEvent.id, // Will get overwriting by sync, @@ -633,6 +646,7 @@ abstract class NostrDao( if (profile == null) { val placeHolderProfile = Profile( + displayName = "LOADING PROFILE...", publicKey = followedHexKEys, createdAt = GENESIS_AT, nostrEventId = nostrEvent.id, // Will get overwriting by sync, 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 new file mode 100644 index 00000000..a114e3b3 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/model/intermdiate/LocalMention.kt @@ -0,0 +1,17 @@ +package ac.cord.auxiliary.compose.database.model.intermdiate + +import ac.cord.auxiliary.compose.database.model.Mention +import ac.cord.auxiliary.compose.database.model.NostrEvent +import ac.cord.auxiliary.compose.database.model.Profile +import androidx.room.Embedded +import androidx.room.Relation + +data class LocalMention( + @Embedded val mention: Mention, + + @Relation( + parentColumn = "mentionedPublicKey", + entityColumn = "publicKey" + ) + val profile: Profile?, +) 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 fae9e72d..0f74a313 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 @@ -75,21 +75,12 @@ data class LocalNostrEvent( ) val inReplyToNostrEvent: InReplyToRelation? = null, -// @Relation( -// parentColumn = "id", -// entityColumn = "nostrEventId", -// associateBy = Junction( -// value = Mention::class, -// parentColumn = "mentionedPublicKey", -// entityColumn = "mentionedPublicKey" -// ) -// ) -// val mentionedProfiles: List = emptyList() @Relation( + entity = Mention::class, parentColumn = "id", entityColumn = "nostrEventId", ) - val mentions: List = emptyList() + val mentionedProfiles: List = emptyList(), ) { @Composable fun RenderNotePreview() { 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 fdfbf2a9..343e7559 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 @@ -209,10 +209,10 @@ private fun TextNoteFeedItem( SuggestionChip( label = { Text( - text = if (localNostrEvent.mentions.isNotEmpty()) { - localNostrEvent.mentions.joinToString(",") { it.mentionedPublicKey } + text = if (localNostrEvent.mentionedProfiles.isNotEmpty()) { + localNostrEvent.mentionedProfiles.joinToString(",") { it.profile?.humanReadableNameOrPubkey() ?: "Find user information" } } else { - ":-|" + ":-(" } ) }, @@ -220,9 +220,8 @@ private fun TextNoteFeedItem( } ) - - } + items( items = nostrEvent.tags, ) { tag ->