From e175c601d71fcf5671594e2131532a07b0ffcc07 Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Sat, 4 Jul 2026 01:33:06 +0200 Subject: [PATCH] Bug fixes --- .../1.json | 217 +++++++++++++++++- .../compose/database/dao/MarmotOutboundDao.kt | 2 +- .../compose/database/model/ChatMessage.kt | 19 +- .../repository/DatabaseChatRepository.kt | 4 +- .../ui/composable/navigation/TorchNavHost.kt | 1 + 5 files changed, 225 insertions(+), 18 deletions(-) diff --git a/composeApp/schemas/at.torch.compose.database.TorchDatabase/1.json b/composeApp/schemas/at.torch.compose.database.TorchDatabase/1.json index fa302c81..e0cb0b45 100644 --- a/composeApp/schemas/at.torch.compose.database.TorchDatabase/1.json +++ b/composeApp/schemas/at.torch.compose.database.TorchDatabase/1.json @@ -2,7 +2,7 @@ "formatVersion": 1, "database": { "version": 1, - "identityHash": "5c51783559255bdfff3112051ee22d05", + "identityHash": "d2e739e05b7ba033c4f8b240af7e386b", "entities": [ { "tableName": "BroadcastNostrEventReceipt", @@ -282,7 +282,7 @@ }, { "tableName": "ChatMessage", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `senderPublicKey` TEXT NOT NULL, `isUserMessage` INTEGER NOT NULL, `giftWrapPayloadId` TEXT, `groupEventId` TEXT, `chatRoomId` TEXT NOT NULL, `replyToMessageId` INTEGER, `quotedMessageId` INTEGER, `content` TEXT NOT NULL, `messageType` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`giftWrapPayloadId`) REFERENCES `GiftWrapPayload`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `senderPublicKey` TEXT NOT NULL, `isUserMessage` INTEGER NOT NULL, `giftWrapPayloadId` TEXT, `marmotGroupEventId` TEXT, `marmotInnerEventId` TEXT, `chatRoomId` TEXT NOT NULL, `replyToMessageId` INTEGER, `quotedMessageId` INTEGER, `content` TEXT NOT NULL, `messageType` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`giftWrapPayloadId`) REFERENCES `GiftWrapPayload`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`marmotGroupEventId`) REFERENCES `MarmotGroupEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`marmotInnerEventId`) REFERENCES `MarmotInnerEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )", "fields": [ { "fieldPath": "id", @@ -308,8 +308,13 @@ "affinity": "TEXT" }, { - "fieldPath": "groupEventId", - "columnName": "groupEventId", + "fieldPath": "marmotGroupEventId", + "columnName": "marmotGroupEventId", + "affinity": "TEXT" + }, + { + "fieldPath": "marmotInnerEventId", + "columnName": "marmotInnerEventId", "affinity": "TEXT" }, { @@ -397,6 +402,28 @@ "referencedColumns": [ "id" ] + }, + { + "table": "MarmotGroupEvent", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "marmotGroupEventId" + ], + "referencedColumns": [ + "id" + ] + }, + { + "table": "MarmotInnerEvent", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "marmotInnerEventId" + ], + "referencedColumns": [ + "id" + ] } ] }, @@ -1125,6 +1152,186 @@ } ] }, + { + "tableName": "MarmotGroupEvent", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `encryptedContent` TEXT NOT NULL, `expiresAt` INTEGER, `nostrEventId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "userPublicKey", + "columnName": "userPublicKey", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "publicKey", + "columnName": "publicKey", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "chatRoomId", + "columnName": "chatRoomId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "encryptedContent", + "columnName": "encryptedContent", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "expiresAt", + "columnName": "expiresAt", + "affinity": "INTEGER" + }, + { + "fieldPath": "nostrEventId", + "columnName": "nostrEventId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "createdAt", + "columnName": "createdAt", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "updatedAt", + "columnName": "updatedAt", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "savedAt", + "columnName": "savedAt", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "deletedAt", + "columnName": "deletedAt", + "affinity": "INTEGER" + }, + { + "fieldPath": "broadcastedAt", + "columnName": "broadcastedAt", + "affinity": "INTEGER" + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "id" + ] + } + }, + { + "tableName": "MarmotInnerEvent", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `kind` INTEGER NOT NULL, `tags` TEXT NOT NULL, `content` TEXT NOT NULL, `quotedEventId` TEXT, `marmotGroupEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`marmotGroupEventId`) REFERENCES `MarmotGroupEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "publicKey", + "columnName": "publicKey", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "chatRoomId", + "columnName": "chatRoomId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "kind", + "columnName": "kind", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "tags", + "columnName": "tags", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "content", + "columnName": "content", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "quotedEventId", + "columnName": "quotedEventId", + "affinity": "TEXT" + }, + { + "fieldPath": "marmotGroupEventId", + "columnName": "marmotGroupEventId", + "affinity": "TEXT" + }, + { + "fieldPath": "createdAt", + "columnName": "createdAt", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "updatedAt", + "columnName": "updatedAt", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "savedAt", + "columnName": "savedAt", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "viewedAt", + "columnName": "viewedAt", + "affinity": "INTEGER" + }, + { + "fieldPath": "deletedAt", + "columnName": "deletedAt", + "affinity": "INTEGER" + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "id" + ] + }, + "foreignKeys": [ + { + "table": "MarmotGroupEvent", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "marmotGroupEventId" + ], + "referencedColumns": [ + "id" + ] + } + ] + }, { "tableName": "MarmotKeyPackage", "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `tlsEncodedMarmotKeyPackage` BLOB NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`publicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE )", @@ -3054,7 +3261,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, '5c51783559255bdfff3112051ee22d05')" + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'd2e739e05b7ba033c4f8b240af7e386b')" ] } } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/at/torch/compose/database/dao/MarmotOutboundDao.kt b/composeApp/src/commonMain/kotlin/at/torch/compose/database/dao/MarmotOutboundDao.kt index f13ac732..c1d7a02a 100644 --- a/composeApp/src/commonMain/kotlin/at/torch/compose/database/dao/MarmotOutboundDao.kt +++ b/composeApp/src/commonMain/kotlin/at/torch/compose/database/dao/MarmotOutboundDao.kt @@ -29,7 +29,7 @@ abstract class MarmotOutboundDao( val logger = Logger.withTag(TAG) @Transaction - suspend fun encryptAndSendMarmotInnerEvent( + open suspend fun encryptAndSendMarmotInnerEvent( localChatRoom: LocalChatRoom, mlsGroup: MlsGroup, innerEvent: Event, diff --git a/composeApp/src/commonMain/kotlin/at/torch/compose/database/model/ChatMessage.kt b/composeApp/src/commonMain/kotlin/at/torch/compose/database/model/ChatMessage.kt index c99ec57f..62bf9201 100644 --- a/composeApp/src/commonMain/kotlin/at/torch/compose/database/model/ChatMessage.kt +++ b/composeApp/src/commonMain/kotlin/at/torch/compose/database/model/ChatMessage.kt @@ -15,7 +15,6 @@ import com.vitorpamplona.quartz.marmot.mip03GroupMessages.GroupEvent import com.vitorpamplona.quartz.nip01Core.core.Event import com.vitorpamplona.quartz.nip01Core.core.HexKey import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair -import com.vitorpamplona.quartz.nip17Dm.messages.ChatMessageEvent import com.vitorpamplona.quartz.nipC7Chats.ChatEvent import kotlin.time.Clock import kotlin.time.Instant @@ -35,9 +34,9 @@ import kotlin.time.Instant onDelete = ForeignKey.CASCADE, ), ForeignKey( - entity = GroupEvent::class, + entity = MarmotGroupEvent::class, parentColumns = ["id"], - childColumns = ["groupEventId"], + childColumns = ["marmotGroupEventId"], onDelete = ForeignKey.CASCADE, ), ForeignKey( @@ -56,7 +55,7 @@ data class ChatMessage( val isUserMessage: Boolean, val giftWrapPayloadId: HexKey?, - val groupEventId: HexKey?, + val marmotGroupEventId: HexKey?, val marmotInnerEventId: HexKey?, val chatRoomId: String, @@ -105,7 +104,7 @@ data class ChatMessage( ChatMessage( giftWrapPayloadId = null, messageType = "message", - groupEventId = groupEvent.id, + marmotGroupEventId = groupEvent.id, marmotInnerEventId = event.id, senderPublicKey = event.pubKey, isUserMessage = activeKeyPair.pubKey.toHex() == groupEvent.pubKey, @@ -118,7 +117,7 @@ data class ChatMessage( ChatMessage( giftWrapPayloadId = null, messageType = "unsupported", - groupEventId = groupEvent.id, + marmotGroupEventId = groupEvent.id, marmotInnerEventId = event.id, senderPublicKey = groupEvent.pubKey, isUserMessage = activeKeyPair.pubKey.toHex() == groupEvent.pubKey, @@ -132,7 +131,7 @@ data class ChatMessage( is GroupEventResult.CommitPending -> { ChatMessage( giftWrapPayloadId = null, - groupEventId = groupEvent.id, + marmotGroupEventId = groupEvent.id, marmotInnerEventId = null, messageType = "pendingCommit", senderPublicKey = groupEvent.pubKey, @@ -145,7 +144,7 @@ data class ChatMessage( is GroupEventResult.CommitProcessed -> { ChatMessage( giftWrapPayloadId = null, - groupEventId = groupEvent.id, + marmotGroupEventId = groupEvent.id, marmotInnerEventId = null, messageType = "processedCommit", senderPublicKey = groupEvent.pubKey, @@ -185,7 +184,7 @@ data class ChatMessage( is GroupEventResult.ProposalStaged -> { ChatMessage( giftWrapPayloadId = null, - groupEventId = groupEvent.id, + marmotGroupEventId = groupEvent.id, marmotInnerEventId = null, messageType = "proposalStaged", senderPublicKey = groupEvent.pubKey, @@ -198,7 +197,7 @@ data class ChatMessage( is GroupEventResult.UndecryptableOuterLayer -> { ChatMessage( giftWrapPayloadId = null, - groupEventId = groupEvent.id, + marmotGroupEventId = groupEvent.id, marmotInnerEventId = null, messageType = "undecryptableOuterLayer", senderPublicKey = groupEvent.pubKey, diff --git a/composeApp/src/commonMain/kotlin/at/torch/compose/database/repository/DatabaseChatRepository.kt b/composeApp/src/commonMain/kotlin/at/torch/compose/database/repository/DatabaseChatRepository.kt index 6f480060..c9fa721e 100644 --- a/composeApp/src/commonMain/kotlin/at/torch/compose/database/repository/DatabaseChatRepository.kt +++ b/composeApp/src/commonMain/kotlin/at/torch/compose/database/repository/DatabaseChatRepository.kt @@ -147,7 +147,7 @@ class DatabaseChatRepository( senderPublicKey = localChatRoom.chatRoom.userPublicKey, isUserMessage = true, giftWrapPayloadId = null, - groupEventId = null, + marmotGroupEventId = null, marmotInnerEventId = marmotInnerEventId, ) ) @@ -190,7 +190,7 @@ class DatabaseChatRepository( senderPublicKey = localChatRoom.chatRoom.userPublicKey, isUserMessage = true, giftWrapPayloadId = giftWrapPayloadId, - groupEventId = null, + marmotGroupEventId = null, marmotInnerEventId = null ) ) diff --git a/composeApp/src/commonMain/kotlin/at/torch/compose/ui/composable/navigation/TorchNavHost.kt b/composeApp/src/commonMain/kotlin/at/torch/compose/ui/composable/navigation/TorchNavHost.kt index 0a5b4fc9..09f92592 100644 --- a/composeApp/src/commonMain/kotlin/at/torch/compose/ui/composable/navigation/TorchNavHost.kt +++ b/composeApp/src/commonMain/kotlin/at/torch/compose/ui/composable/navigation/TorchNavHost.kt @@ -101,6 +101,7 @@ fun TorchNavHost( activeWalletStateFlow = sovereignWalletViewModel.activeWalletInUI, nostrRepository = databaseNostrRepository, chatRepository = databaseChatRepository, + marmotRepository = databaseMarmotRepository, scope = applicationIOScope ) )