Showing mentioned profiles

This commit is contained in:
Kgothatso Ngako committed 2026-04-30 23:39:49 +02:00
1 parent 54db024b6a
commit a0d4b7fbdd
5 files changed
+41 -17

No files matched your search

@@ -5,13 +5,16 @@ import ac.cord.auxiliary.compose.database.model.Post
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalPost import ac.cord.auxiliary.compose.database.model.intermdiate.LocalPost
import androidx.room.Dao import androidx.room.Dao
import androidx.room.Insert import androidx.room.Insert
import androidx.room.OnConflictStrategy.Companion.IGNORE
import androidx.room.Query import androidx.room.Query
import androidx.room.Upsert import androidx.room.Upsert
@Dao @Dao
interface MentionDao { interface MentionDao {
@Insert @Insert(
onConflict = IGNORE
)
suspend fun insert(mention: Mention) suspend fun insert(mention: Mention)
@Upsert @Upsert
@@ -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.GENESIS_AT
import ac.cord.auxiliary.compose.database.model.BroadcastNostrEventRequest import ac.cord.auxiliary.compose.database.model.BroadcastNostrEventRequest
import ac.cord.auxiliary.compose.database.model.Connection 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.NostrEvent
import ac.cord.auxiliary.compose.database.model.Post import ac.cord.auxiliary.compose.database.model.Post
import ac.cord.auxiliary.compose.database.model.Profile import ac.cord.auxiliary.compose.database.model.Profile
@@ -148,6 +149,7 @@ abstract class NostrDao(
if (profile == null) { if (profile == null) {
val placeHolderProfile = Profile( val placeHolderProfile = Profile(
displayName = "LOADING PROFILE...",
publicKey = nostrEvent.pubKey, publicKey = nostrEvent.pubKey,
createdAt = GENESIS_AT, createdAt = GENESIS_AT,
nostrEventId = nostrEvent.id, // Will get overwriting by sync, nostrEventId = nostrEvent.id, // Will get overwriting by sync,
@@ -335,6 +337,7 @@ abstract class NostrDao(
// Save a placeholder // Save a placeholder
database.profileDao().insertPlaceholderProfile( database.profileDao().insertPlaceholderProfile(
Profile( Profile(
displayName = "LOADING PROFILE...",
publicKey = taggedUser.pubKey, publicKey = taggedUser.pubKey,
createdAt = GENESIS_AT, createdAt = GENESIS_AT,
nostrEventId = nostrEvent.id, // Will get overwriting by sync, 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) { val synchronizeNostrEventRequests = if (recommendedRelay != null) {
// listOf( // listOf(
// SynchronizeNostrEventRequest( // SynchronizeNostrEventRequest(
@@ -465,6 +475,7 @@ abstract class NostrDao(
if (quotedProfilePublicKey != null && quotedProfile == null) { if (quotedProfilePublicKey != null && quotedProfile == null) {
database.profileDao().insertPlaceholderProfile( database.profileDao().insertPlaceholderProfile(
Profile( Profile(
displayName = "LOADING PROFILE...",
publicKey = quotedProfilePublicKey, publicKey = quotedProfilePublicKey,
createdAt = GENESIS_AT, createdAt = GENESIS_AT,
nostrEventId = nostrEvent.id, // Will get overwriting by sync, nostrEventId = nostrEvent.id, // Will get overwriting by sync,
@@ -509,6 +520,7 @@ abstract class NostrDao(
if (repostedProfilePublicKey != null && repostedProfile == null) { if (repostedProfilePublicKey != null && repostedProfile == null) {
database.profileDao().insertPlaceholderProfile( database.profileDao().insertPlaceholderProfile(
Profile( Profile(
displayName = "LOADING PROFILE...",
publicKey = repostedProfilePublicKey, publicKey = repostedProfilePublicKey,
createdAt = GENESIS_AT, createdAt = GENESIS_AT,
nostrEventId = nostrEvent.id, // Will get overwriting by sync, nostrEventId = nostrEvent.id, // Will get overwriting by sync,
@@ -562,6 +574,7 @@ abstract class NostrDao(
if (inReplyToRootProfilePublicKey != null && inReplyToProfile == null) { if (inReplyToRootProfilePublicKey != null && inReplyToProfile == null) {
database.profileDao().insertPlaceholderProfile( database.profileDao().insertPlaceholderProfile(
Profile( Profile(
displayName = "LOADING PROFILE...",
publicKey = inReplyToRootProfilePublicKey, publicKey = inReplyToRootProfilePublicKey,
createdAt = GENESIS_AT, createdAt = GENESIS_AT,
nostrEventId = nostrEvent.id, // Will get overwriting by sync, nostrEventId = nostrEvent.id, // Will get overwriting by sync,
@@ -633,6 +646,7 @@ abstract class NostrDao(
if (profile == null) { if (profile == null) {
val placeHolderProfile = Profile( val placeHolderProfile = Profile(
displayName = "LOADING PROFILE...",
publicKey = followedHexKEys, publicKey = followedHexKEys,
createdAt = GENESIS_AT, createdAt = GENESIS_AT,
nostrEventId = nostrEvent.id, // Will get overwriting by sync, nostrEventId = nostrEvent.id, // Will get overwriting by sync,
@@ -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?,
)
@@ -75,21 +75,12 @@ data class LocalNostrEvent(
) )
val inReplyToNostrEvent: InReplyToRelation? = null, val inReplyToNostrEvent: InReplyToRelation? = null,
// @Relation(
// parentColumn = "id",
// entityColumn = "nostrEventId",
// associateBy = Junction(
// value = Mention::class,
// parentColumn = "mentionedPublicKey",
// entityColumn = "mentionedPublicKey"
// )
// )
// val mentionedProfiles: List<Profile> = emptyList()
@Relation( @Relation(
entity = Mention::class,
parentColumn = "id", parentColumn = "id",
entityColumn = "nostrEventId", entityColumn = "nostrEventId",
) )
val mentions: List<Mention> = emptyList() val mentionedProfiles: List<LocalMention> = emptyList(),
) { ) {
@Composable @Composable
fun RenderNotePreview() { fun RenderNotePreview() {
@@ -209,10 +209,10 @@ private fun TextNoteFeedItem(
SuggestionChip( SuggestionChip(
label = { label = {
Text( Text(
text = if (localNostrEvent.mentions.isNotEmpty()) { text = if (localNostrEvent.mentionedProfiles.isNotEmpty()) {
localNostrEvent.mentions.joinToString(",") { it.mentionedPublicKey } localNostrEvent.mentionedProfiles.joinToString(",") { it.profile?.humanReadableNameOrPubkey() ?: "Find user information" }
} else { } else {
":-|" ":-("
} }
) )
}, },
@@ -220,9 +220,8 @@ private fun TextNoteFeedItem(
} }
) )
} }
items( items(
items = nostrEvent.tags, items = nostrEvent.tags,
) { tag -> ) { tag ->