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 69d855a2..20b7b3b2 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 @@ -8,6 +8,7 @@ import androidx.room3.OnConflictStrategy.Companion.IGNORE import androidx.room3.Query import androidx.room3.RawQuery import androidx.room3.RoomRawQuery +import androidx.room3.Transaction import androidx.room3.Upsert import com.vitorpamplona.quartz.nip01Core.core.HexKey import com.vitorpamplona.quartz.nip01Core.core.Kind @@ -16,33 +17,39 @@ import kotlinx.coroutines.flow.Flow @Dao interface NostrEventDao { + @Transaction @Query("SELECT * FROM NostrEvent WHERE kind in (:kinds) ORDER BY createdAt DESC") fun observeNostrEvents(kinds: Array): Flow?> + @Transaction @Query("SELECT * FROM NostrEvent WHERE content LIKE '%' || :search || '%' AND kind in (:kinds) ORDER BY createdAt DESC") fun observeFilteredNostrEvents( kinds: Array, search: String ): Flow?> + @Transaction @Query("SELECT * FROM NostrEvent WHERE kind in (:kinds) AND id in (:ids) ORDER BY createdAt DESC") fun observeFilteredNostrEvents( kinds: Array, ids: Array, ): Flow?> + @Transaction @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?> + @Transaction @Query("SELECT * FROM NostrEvent WHERE tags LIKE '%' || :publicKey || '%' AND kind in (:kinds) ORDER BY createdAt DESC") fun observePublicKeyMentionedNostrEvents( kinds: Array, publicKey: HexKey ): Flow?> + @Transaction @RawQuery fun observePublicKeyFollowingNostrEvents( query: RoomRawQuery @@ -51,6 +58,7 @@ interface NostrEventDao { @Query("SELECT * FROM NostrEvent WHERE kind in (:kinds) ORDER BY savedAt DESC") fun getAllNostrEvents(kinds: Array): List + @Transaction @Query("SELECT * FROM NostrEvent WHERE id = :id") fun observeNostrEventById(id: String): Flow 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 624b3176..07534449 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,11 +56,12 @@ data class LocalNostrEvent( ) val localInReplyToNostrEvent: LocalInReplyToNostrEvent? = null, -// @Relation( -// parentColumn = "id", -// entityColumn = "mentioningNostrEventId", -// ) -// val mentionedProfiles: List? = emptyList(), + @Relation( + entity = Mention::class, + 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 f3fc8fdd..6c655e43 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,6 +37,13 @@ data class LocalQuotedNostrEvent( entityColumn = "publicKey" ) val profile: Profile?, + + @Relation( + entity = Mention::class, + parentColumn = "quotedNostrEventId", + entityColumn = "mentioningNostrEventId", + ) + val mentionedProfiles: List? = emptyList(), ) { @Composable fun RenderNotePreview() { @@ -78,6 +85,7 @@ data class LocalQuotedNostrEvent( RichContent( nostrEvent = nostrEvent, localQuotedNostrEvent = null, + mentionedProfiles = mentionedProfiles, ) } 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 a8f4ff56..b75caf20 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,6 +35,7 @@ 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, @@ -109,15 +110,14 @@ fun RichContent( val profileNames = remember(profilePubkeys) { val names = mutableMapOf() - // 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)}" -// } -// } + 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 7e483c6d..1872eff5 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,6 +143,7 @@ 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 e5038ba5..21358061 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,6 +68,7 @@ fun LocalNostrEvent.ListView( profile = localRepostedNostrEvent.profile, localQuotedNostrEvent = null, localInReplyToNostrEvent = null, + mentionedProfiles = localRepostedNostrEvent.mentionedProfiles, onNavigateToEvent = onNavigateToEvent ) } else { @@ -103,6 +104,7 @@ 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 9c2ac6e9..b1e1bc28 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,6 +36,7 @@ internal fun TextNoteFeedItem( profile: Profile?, localInReplyToNostrEvent: LocalInReplyToNostrEvent?, localQuotedNostrEvent: LocalQuotedNostrEvent?, + mentionedProfiles: List?, onNavigateToEvent: (HexKey) -> Unit ) { if (localInReplyToNostrEvent != null) { @@ -107,6 +108,7 @@ internal fun TextNoteFeedItem( modifier = Modifier.fillMaxWidth(), nostrEvent = nostrEvent, localQuotedNostrEvent = localQuotedNostrEvent, + mentionedProfiles = mentionedProfiles ) LazyRow(