Change how mentions are handled

This commit is contained in:
Kgothatso Ngako committed 2026-05-02 01:19:28 +02:00
1 parent bfc540812d
commit b9cece869e
7 files changed
+30 -24

No files matched your search

@@ -2,7 +2,7 @@
"formatVersion": 1, "formatVersion": 1,
"database": { "database": {
"version": 1, "version": 1,
"identityHash": "296c3251f1f835c144c94c7ff1598939", "identityHash": "2e56a98cfa2734b3c9f8945e5384f7e7",
"entities": [ "entities": [
{ {
"tableName": "BroadcastNostrEventReceipt", "tableName": "BroadcastNostrEventReceipt",
@@ -389,8 +389,14 @@
}, },
{ {
"tableName": "Mention", "tableName": "Mention",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`mentionedPublicKey` TEXT NOT NULL, `relayUrl` TEXT, `nostrEventId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`nostrEventId`, `mentionedPublicKey`), FOREIGN KEY(`mentionedPublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )", "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `mentionedPublicKey` TEXT NOT NULL, `mentioningNostrEventId` TEXT, `relayUrl` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, FOREIGN KEY(`mentionedPublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`mentioningNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [ "fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{ {
"fieldPath": "mentionedPublicKey", "fieldPath": "mentionedPublicKey",
"columnName": "mentionedPublicKey", "columnName": "mentionedPublicKey",
@@ -398,15 +404,14 @@
"notNull": true "notNull": true
}, },
{ {
"fieldPath": "relayUrl", "fieldPath": "mentioningNostrEventId",
"columnName": "relayUrl", "columnName": "mentioningNostrEventId",
"affinity": "TEXT" "affinity": "TEXT"
}, },
{ {
"fieldPath": "nostrEventId", "fieldPath": "relayUrl",
"columnName": "nostrEventId", "columnName": "relayUrl",
"affinity": "TEXT", "affinity": "TEXT"
"notNull": true
}, },
{ {
"fieldPath": "createdAt", "fieldPath": "createdAt",
@@ -438,10 +443,9 @@
} }
], ],
"primaryKey": { "primaryKey": {
"autoGenerate": false, "autoGenerate": true,
"columnNames": [ "columnNames": [
"nostrEventId", "id"
"mentionedPublicKey"
] ]
}, },
"foreignKeys": [ "foreignKeys": [
@@ -461,7 +465,7 @@
"onDelete": "CASCADE", "onDelete": "CASCADE",
"onUpdate": "NO ACTION", "onUpdate": "NO ACTION",
"columns": [ "columns": [
"nostrEventId" "mentioningNostrEventId"
], ],
"referencedColumns": [ "referencedColumns": [
"id" "id"
@@ -1818,7 +1822,7 @@
], ],
"setupQueries": [ "setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '296c3251f1f835c144c94c7ff1598939')" "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '2e56a98cfa2734b3c9f8945e5384f7e7')"
] ]
} }
} }
@@ -362,7 +362,7 @@ abstract class NostrDao(
database.mentionDao().insert( database.mentionDao().insert(
Mention( Mention(
mentionedPublicKey = taggedUser.pubKey, mentionedPublicKey = taggedUser.pubKey,
nostrEventId = nostrEvent.id, mentioningNostrEventId = nostrEvent.id,
relayUrl = taggedUser.relayHint?.url relayUrl = taggedUser.relayHint?.url
) )
) )
@@ -7,6 +7,7 @@ import ac.cord.auxiliary.compose.database.model.traits.SoftDeletableEntity
import ac.cord.auxiliary.compose.database.model.traits.TimestampedEntity import ac.cord.auxiliary.compose.database.model.traits.TimestampedEntity
import androidx.room3.Entity import androidx.room3.Entity
import androidx.room3.ForeignKey import androidx.room3.ForeignKey
import androidx.room3.PrimaryKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey import com.vitorpamplona.quartz.nip01Core.core.HexKey
import kotlin.time.Clock import kotlin.time.Clock
import kotlin.time.Instant import kotlin.time.Instant
@@ -22,22 +23,23 @@ import kotlin.time.Instant
ForeignKey( ForeignKey(
entity = NostrEvent::class, entity = NostrEvent::class,
parentColumns = ["id"], parentColumns = ["id"],
childColumns = ["nostrEventId"], childColumns = ["mentioningNostrEventId"],
onDelete = ForeignKey.CASCADE, onDelete = ForeignKey.CASCADE,
), ),
], ]
primaryKeys = ["nostrEventId", "mentionedPublicKey"]
) )
data class Mention( data class Mention(
@PrimaryKey(autoGenerate = true)
val id: Long = 0,
val mentionedPublicKey: HexKey, val mentionedPublicKey: HexKey,
val mentioningNostrEventId: HexKey? = null,
val relayUrl: String? = null, val relayUrl: String? = null,
override val nostrEventId: HexKey, // This is the contactListEvent with this following...
override val createdAt: Instant = Clock.System.now(), override val createdAt: Instant = Clock.System.now(),
override val updatedAt: Instant = Clock.System.now(), override val updatedAt: Instant = Clock.System.now(),
override val savedAt: Instant = Clock.System.now(), override val savedAt: Instant = Clock.System.now(),
override val deletedAt: Instant? = null, override val deletedAt: Instant? = null,
override val broadcastedAt: Instant? = null, override val broadcastedAt: Instant? = null,
): NostrEventEntity, TimestampedEntity, LocalStoreEntity, BroadcastableEntity, SoftDeletableEntity ): TimestampedEntity, LocalStoreEntity, BroadcastableEntity, SoftDeletableEntity
@@ -41,7 +41,7 @@ data class LocalInReplyToNostrEvent(
@Relation( @Relation(
entity = Mention::class, entity = Mention::class,
parentColumn = "inReplyToNostrEventId", parentColumn = "inReplyToNostrEventId",
entityColumn = "nostrEventId", entityColumn = "mentioningNostrEventId",
) )
val mentionedProfiles: List<LocalMention?> = emptyList(), val mentionedProfiles: List<LocalMention?> = emptyList(),
) { ) {
@@ -59,7 +59,7 @@ data class LocalNostrEvent(
@Relation( @Relation(
entity = Mention::class, entity = Mention::class,
parentColumn = "id", parentColumn = "id",
entityColumn = "nostrEventId", entityColumn = "mentioningNostrEventId",
) )
val mentionedProfiles: List<LocalMention?>? = emptyList(), val mentionedProfiles: List<LocalMention?>? = emptyList(),
) { ) {
@@ -41,7 +41,7 @@ data class LocalQuotedNostrEvent(
@Relation( @Relation(
entity = Mention::class, entity = Mention::class,
parentColumn = "quotedNostrEventId", parentColumn = "quotedNostrEventId",
entityColumn = "nostrEventId", entityColumn = "mentioningNostrEventId",
) )
val mentionedProfiles: List<LocalMention?> = emptyList(), val mentionedProfiles: List<LocalMention?> = emptyList(),
) { ) {
@@ -41,7 +41,7 @@ data class LocalRepostedNostrEvent(
@Relation( @Relation(
entity = Mention::class, entity = Mention::class,
parentColumn = "repostedNostrEventId", parentColumn = "repostedNostrEventId",
entityColumn = "nostrEventId", entityColumn = "mentioningNostrEventId",
) )
val mentionedProfiles: List<LocalMention?> = emptyList(), val mentionedProfiles: List<LocalMention?> = emptyList(),
) { ) {