Set receipt for synced messages

This commit is contained in:
Kgothatso Ngako
2026-06-06 04:35:43 +02:00
parent f3c7e21fa3
commit b8ca6b3419
4 changed files with 30 additions and 5 deletions

View File

@@ -2,11 +2,11 @@
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "630d9cf4853f9f393e7e043f4cd03a6d",
"identityHash": "6f2020861ae05ebf5290388d73772039",
"entities": [
{
"tableName": "BroadcastNostrEventReceipt",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `nostrEventId` TEXT NOT NULL, `unsignedNostrEventId` INTEGER, `isAccepted` INTEGER NOT NULL, `relayURL` TEXT NOT NULL, `messages` TEXT, FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`unsignedNostrEventId`) REFERENCES `UnsignedNostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `nostrEventId` TEXT NOT NULL, `unsignedNostrEventId` INTEGER, `isAccepted` INTEGER NOT NULL, `isSync` INTEGER NOT NULL, `relayURL` TEXT NOT NULL, `messages` TEXT, FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`unsignedNostrEventId`) REFERENCES `UnsignedNostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "id",
@@ -31,6 +31,12 @@
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isSync",
"columnName": "isSync",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "relayURL",
"columnName": "relayURL",
@@ -2863,7 +2869,7 @@
],
"setupQueries": [
"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, '630d9cf4853f9f393e7e043f4cd03a6d')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '6f2020861ae05ebf5290388d73772039')"
]
}
}

View File

@@ -23,5 +23,5 @@ interface ChatMessageDao {
fun getChatMessagesByGiftWrapPayloadId(giftWrapPayloadId: Long): ChatMessage?
@Upsert
suspend fun upsert(chatMessage: ChatMessage)
suspend fun upsert(chatMessage: ChatMessage): Long
}

View File

@@ -2,8 +2,10 @@ package ac.cord.auxiliary.compose.database.dao
import ac.cord.auxiliary.compose.database.AuxDatabase
import ac.cord.auxiliary.compose.database.GENESIS_AT
import ac.cord.auxiliary.compose.database.model.BroadcastNostrEventReceipt
import ac.cord.auxiliary.compose.database.model.BroadcastNostrEventRequest
import ac.cord.auxiliary.compose.database.model.ChatMessage
import ac.cord.auxiliary.compose.database.model.ChatMessageBroadcastNostrEventReceiptRelation
import ac.cord.auxiliary.compose.database.model.ChatRoom
import ac.cord.auxiliary.compose.database.model.Connection
import ac.cord.auxiliary.compose.database.model.Mention
@@ -722,7 +724,7 @@ abstract class NostrDao(
}
}
database.chatMessageDao().upsert(
val chatMessageId = database.chatMessageDao().upsert(
ChatMessage(
giftWrapPayloadId = giftWrapPayload.id,
senderPublicKey = giftWrapPayload.publicKey,
@@ -732,6 +734,22 @@ abstract class NostrDao(
content = giftWrapPayload.content,
)
)
val broadcastNostrEventReceiptId = database.broadcastNostrEventReceiptDao().upsert(
BroadcastNostrEventReceipt(
nostrEventId = nostrEvent.id,
isAccepted = true,
isSync = true,
relayURL = relayURL
)
)
database.chatMessageBroadcastNostrEventReceiptRelationDao().upsert(
ChatMessageBroadcastNostrEventReceiptRelation(
broadcastNostrEventReceiptId = broadcastNostrEventReceiptId,
chatMessageId = chatMessageId
)
)
} else {
logger.w("Failed to setup chatRoom for message")
}

View File

@@ -34,6 +34,7 @@ data class BroadcastNostrEventReceipt(
override val nostrEventId: HexKey,
override val unsignedNostrEventId: Long? = null,
val isAccepted: Boolean,
val isSync: Boolean = false,
val relayURL: String,
val messages: String? = null
): NostrEventEntity, UnsignedNostrEventEntity