diff --git a/CLAUDE.md b/CLAUDE.md
index de57265a..42ef01c7 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -81,7 +81,7 @@ say — marks itself once at the top:
```
**Budget: 0 title-case strings.** Literals in composables are reported without a budget —
-39 remain, all of them terms of a `+` concatenation.
+19 remain, all of them terms of a `+` concatenation.
## Every target is 48dp, and every icon has a decided description
diff --git a/composeApp/schemas/com.machankura.bennu.compose.database.BennuDatabase/27.json b/composeApp/schemas/com.machankura.bennu.compose.database.BennuDatabase/27.json
index 1cda00e0..21f24e7b 100644
--- a/composeApp/schemas/com.machankura.bennu.compose.database.BennuDatabase/27.json
+++ b/composeApp/schemas/com.machankura.bennu.compose.database.BennuDatabase/27.json
@@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 27,
- "identityHash": "2fe774344e85e188dd6793623347bf91",
+ "identityHash": "b3d7bf2b5f251ad1f39aeb01c7ab316d",
"entities": [
{
"tableName": "BroadcastNostrEventReceipt",
@@ -1865,7 +1865,7 @@
},
{
"tableName": "GroupTransaction",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`frostSigningSessionId` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `chain` TEXT NOT NULL, `account` INTEGER NOT NULL, `guardedChatRoomId` TEXT, `psbt` TEXT NOT NULL, `txid` TEXT NOT NULL, `signedTransaction` TEXT, `broadcastAt` INTEGER, `seenAt` INTEGER, `confirmedAt` INTEGER, `replacedByTxid` TEXT, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`frostSigningSessionId`), FOREIGN KEY(`frostSigningSessionId`) REFERENCES `FrostSigningSession`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`frostSigningSessionId` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `chain` TEXT NOT NULL, `account` INTEGER NOT NULL, `psbt` TEXT NOT NULL, `txid` TEXT NOT NULL, `signedTransaction` TEXT, `broadcastAt` INTEGER, `seenAt` INTEGER, `confirmedAt` INTEGER, `replacedByTxid` TEXT, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`frostSigningSessionId`), FOREIGN KEY(`frostSigningSessionId`) REFERENCES `FrostSigningSession`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "frostSigningSessionId",
@@ -1891,11 +1891,6 @@
"affinity": "INTEGER",
"notNull": true
},
- {
- "fieldPath": "guardedChatRoomId",
- "columnName": "guardedChatRoomId",
- "affinity": "TEXT"
- },
{
"fieldPath": "psbt",
"columnName": "psbt",
@@ -2116,1407 +2111,6 @@
}
]
},
- {
- "tableName": "MantraArtifact",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `name` TEXT NOT NULL, `url` TEXT NOT NULL, `visibility` TEXT NOT NULL, `dialectId` TEXT NOT NULL, `license` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `signature` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`dialectId`) REFERENCES `MantraDialect`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`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": "name",
- "columnName": "name",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "url",
- "columnName": "url",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "visibility",
- "columnName": "visibility",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "dialectId",
- "columnName": "dialectId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "license",
- "columnName": "license",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "chatRoomId",
- "columnName": "chatRoomId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "signature",
- "columnName": "signature",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "relayHint",
- "columnName": "relayHint",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "marmotGroupEventId",
- "columnName": "marmotGroupEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "groupSignedEventId",
- "columnName": "groupSignedEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "nostrEventId",
- "columnName": "nostrEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "createdAt",
- "columnName": "createdAt",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "updatedAt",
- "columnName": "updatedAt",
- "affinity": "INTEGER",
- "notNull": true
- }
- ],
- "primaryKey": {
- "autoGenerate": false,
- "columnNames": [
- "id"
- ]
- },
- "foreignKeys": [
- {
- "table": "MantraDialect",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "dialectId"
- ],
- "referencedColumns": [
- "id"
- ]
- },
- {
- "table": "ChatRoom",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "chatRoomId"
- ],
- "referencedColumns": [
- "id"
- ]
- }
- ]
- },
- {
- "tableName": "MantraArtifactVersion",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `artifactId` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `versionLabel` TEXT NOT NULL, `signature` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`artifactId`) REFERENCES `MantraArtifact`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
- "fields": [
- {
- "fieldPath": "id",
- "columnName": "id",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "artifactId",
- "columnName": "artifactId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "publicKey",
- "columnName": "publicKey",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "versionLabel",
- "columnName": "versionLabel",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "signature",
- "columnName": "signature",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "chatRoomId",
- "columnName": "chatRoomId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "relayHint",
- "columnName": "relayHint",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "marmotGroupEventId",
- "columnName": "marmotGroupEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "groupSignedEventId",
- "columnName": "groupSignedEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "nostrEventId",
- "columnName": "nostrEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "createdAt",
- "columnName": "createdAt",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "updatedAt",
- "columnName": "updatedAt",
- "affinity": "INTEGER",
- "notNull": true
- }
- ],
- "primaryKey": {
- "autoGenerate": false,
- "columnNames": [
- "id"
- ]
- },
- "foreignKeys": [
- {
- "table": "MantraArtifact",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "artifactId"
- ],
- "referencedColumns": [
- "id"
- ]
- },
- {
- "table": "ChatRoom",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "chatRoomId"
- ],
- "referencedColumns": [
- "id"
- ]
- }
- ]
- },
- {
- "tableName": "MantraChapter",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `artifactVersionId` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `name` TEXT NOT NULL, `originalText` TEXT NOT NULL, `index` INTEGER NOT NULL, `wordCount` INTEGER NOT NULL, `characterCount` INTEGER NOT NULL, `signature` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`artifactVersionId`) REFERENCES `MantraArtifactVersion`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
- "fields": [
- {
- "fieldPath": "id",
- "columnName": "id",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "artifactVersionId",
- "columnName": "artifactVersionId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "publicKey",
- "columnName": "publicKey",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "name",
- "columnName": "name",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "originalText",
- "columnName": "originalText",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "index",
- "columnName": "index",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "wordCount",
- "columnName": "wordCount",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "characterCount",
- "columnName": "characterCount",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "signature",
- "columnName": "signature",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "chatRoomId",
- "columnName": "chatRoomId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "relayHint",
- "columnName": "relayHint",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "marmotGroupEventId",
- "columnName": "marmotGroupEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "groupSignedEventId",
- "columnName": "groupSignedEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "nostrEventId",
- "columnName": "nostrEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "createdAt",
- "columnName": "createdAt",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "updatedAt",
- "columnName": "updatedAt",
- "affinity": "INTEGER",
- "notNull": true
- }
- ],
- "primaryKey": {
- "autoGenerate": false,
- "columnNames": [
- "id"
- ]
- },
- "foreignKeys": [
- {
- "table": "MantraArtifactVersion",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "artifactVersionId"
- ],
- "referencedColumns": [
- "id"
- ]
- },
- {
- "table": "ChatRoom",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "chatRoomId"
- ],
- "referencedColumns": [
- "id"
- ]
- }
- ]
- },
- {
- "tableName": "MantraChunk",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chapterId` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `text` TEXT NOT NULL, `index` INTEGER NOT NULL, `wordCount` INTEGER NOT NULL, `characterCount` INTEGER NOT NULL, `signature` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chapterId`) REFERENCES `MantraChapter`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
- "fields": [
- {
- "fieldPath": "id",
- "columnName": "id",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "chapterId",
- "columnName": "chapterId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "publicKey",
- "columnName": "publicKey",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "text",
- "columnName": "text",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "index",
- "columnName": "index",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "wordCount",
- "columnName": "wordCount",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "characterCount",
- "columnName": "characterCount",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "signature",
- "columnName": "signature",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "chatRoomId",
- "columnName": "chatRoomId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "relayHint",
- "columnName": "relayHint",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "marmotGroupEventId",
- "columnName": "marmotGroupEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "groupSignedEventId",
- "columnName": "groupSignedEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "nostrEventId",
- "columnName": "nostrEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "createdAt",
- "columnName": "createdAt",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "updatedAt",
- "columnName": "updatedAt",
- "affinity": "INTEGER",
- "notNull": true
- }
- ],
- "primaryKey": {
- "autoGenerate": false,
- "columnNames": [
- "id"
- ]
- },
- "foreignKeys": [
- {
- "table": "MantraChapter",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "chapterId"
- ],
- "referencedColumns": [
- "id"
- ]
- },
- {
- "table": "ChatRoom",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "chatRoomId"
- ],
- "referencedColumns": [
- "id"
- ]
- }
- ]
- },
- {
- "tableName": "MantraDialect",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `name` TEXT NOT NULL, `country` TEXT NOT NULL, `language` TEXT NOT NULL, `signature` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`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": "name",
- "columnName": "name",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "country",
- "columnName": "country",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "language",
- "columnName": "language",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "signature",
- "columnName": "signature",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "chatRoomId",
- "columnName": "chatRoomId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "relayHint",
- "columnName": "relayHint",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "marmotGroupEventId",
- "columnName": "marmotGroupEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "groupSignedEventId",
- "columnName": "groupSignedEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "nostrEventId",
- "columnName": "nostrEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "createdAt",
- "columnName": "createdAt",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "updatedAt",
- "columnName": "updatedAt",
- "affinity": "INTEGER",
- "notNull": true
- }
- ],
- "primaryKey": {
- "autoGenerate": false,
- "columnNames": [
- "id"
- ]
- },
- "foreignKeys": [
- {
- "table": "ChatRoom",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "chatRoomId"
- ],
- "referencedColumns": [
- "id"
- ]
- }
- ]
- },
- {
- "tableName": "MantraTranslation",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `translationChunkId` TEXT NOT NULL, `translationArtifactVersionId` TEXT NOT NULL, `text` TEXT NOT NULL, `signature` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`translationChunkId`) REFERENCES `MantraTranslationChunk`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`translationArtifactVersionId`) REFERENCES `MantraTranslationArtifactVersion`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`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": "translationChunkId",
- "columnName": "translationChunkId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "translationArtifactVersionId",
- "columnName": "translationArtifactVersionId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "text",
- "columnName": "text",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "signature",
- "columnName": "signature",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "chatRoomId",
- "columnName": "chatRoomId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "relayHint",
- "columnName": "relayHint",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "marmotGroupEventId",
- "columnName": "marmotGroupEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "groupSignedEventId",
- "columnName": "groupSignedEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "nostrEventId",
- "columnName": "nostrEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "createdAt",
- "columnName": "createdAt",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "updatedAt",
- "columnName": "updatedAt",
- "affinity": "INTEGER",
- "notNull": true
- }
- ],
- "primaryKey": {
- "autoGenerate": false,
- "columnNames": [
- "id"
- ]
- },
- "foreignKeys": [
- {
- "table": "MantraTranslationChunk",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "translationChunkId"
- ],
- "referencedColumns": [
- "id"
- ]
- },
- {
- "table": "MantraTranslationArtifactVersion",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "translationArtifactVersionId"
- ],
- "referencedColumns": [
- "id"
- ]
- },
- {
- "table": "ChatRoom",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "chatRoomId"
- ],
- "referencedColumns": [
- "id"
- ]
- }
- ]
- },
- {
- "tableName": "MantraTranslationArtifactVersion",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `artifactVersionId` TEXT NOT NULL, `dialectId` TEXT NOT NULL, `name` TEXT NOT NULL, `visibility` TEXT NOT NULL, `license` TEXT NOT NULL, `signature` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`artifactVersionId`) REFERENCES `MantraArtifactVersion`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`dialectId`) REFERENCES `MantraDialect`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`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": "artifactVersionId",
- "columnName": "artifactVersionId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "dialectId",
- "columnName": "dialectId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "name",
- "columnName": "name",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "visibility",
- "columnName": "visibility",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "license",
- "columnName": "license",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "signature",
- "columnName": "signature",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "chatRoomId",
- "columnName": "chatRoomId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "relayHint",
- "columnName": "relayHint",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "marmotGroupEventId",
- "columnName": "marmotGroupEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "groupSignedEventId",
- "columnName": "groupSignedEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "nostrEventId",
- "columnName": "nostrEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "createdAt",
- "columnName": "createdAt",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "updatedAt",
- "columnName": "updatedAt",
- "affinity": "INTEGER",
- "notNull": true
- }
- ],
- "primaryKey": {
- "autoGenerate": false,
- "columnNames": [
- "id"
- ]
- },
- "foreignKeys": [
- {
- "table": "MantraArtifactVersion",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "artifactVersionId"
- ],
- "referencedColumns": [
- "id"
- ]
- },
- {
- "table": "MantraDialect",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "dialectId"
- ],
- "referencedColumns": [
- "id"
- ]
- },
- {
- "table": "ChatRoom",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "chatRoomId"
- ],
- "referencedColumns": [
- "id"
- ]
- }
- ]
- },
- {
- "tableName": "MantraTranslationArtifactVersionContributor",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `translationArtifactVersionId` TEXT NOT NULL, `editorPublicKey` TEXT NOT NULL, `signature` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`translationArtifactVersionId`) REFERENCES `MantraTranslationArtifactVersionContributor`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`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": "translationArtifactVersionId",
- "columnName": "translationArtifactVersionId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "editorPublicKey",
- "columnName": "editorPublicKey",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "signature",
- "columnName": "signature",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "chatRoomId",
- "columnName": "chatRoomId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "relayHint",
- "columnName": "relayHint",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "marmotGroupEventId",
- "columnName": "marmotGroupEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "groupSignedEventId",
- "columnName": "groupSignedEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "nostrEventId",
- "columnName": "nostrEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "createdAt",
- "columnName": "createdAt",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "updatedAt",
- "columnName": "updatedAt",
- "affinity": "INTEGER",
- "notNull": true
- }
- ],
- "primaryKey": {
- "autoGenerate": false,
- "columnNames": [
- "id"
- ]
- },
- "foreignKeys": [
- {
- "table": "MantraTranslationArtifactVersionContributor",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "translationArtifactVersionId"
- ],
- "referencedColumns": [
- "id"
- ]
- },
- {
- "table": "ChatRoom",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "chatRoomId"
- ],
- "referencedColumns": [
- "id"
- ]
- }
- ]
- },
- {
- "tableName": "MantraTranslationChapter",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `chapterId` TEXT NOT NULL, `translationArtifactVersionId` TEXT NOT NULL, `index` INTEGER NOT NULL, `signature` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`translationArtifactVersionId`) REFERENCES `MantraTranslationArtifactVersion`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`chapterId`) REFERENCES `MantraChapter`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`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": "chapterId",
- "columnName": "chapterId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "translationArtifactVersionId",
- "columnName": "translationArtifactVersionId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "index",
- "columnName": "index",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "signature",
- "columnName": "signature",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "chatRoomId",
- "columnName": "chatRoomId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "relayHint",
- "columnName": "relayHint",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "marmotGroupEventId",
- "columnName": "marmotGroupEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "groupSignedEventId",
- "columnName": "groupSignedEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "nostrEventId",
- "columnName": "nostrEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "createdAt",
- "columnName": "createdAt",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "updatedAt",
- "columnName": "updatedAt",
- "affinity": "INTEGER",
- "notNull": true
- }
- ],
- "primaryKey": {
- "autoGenerate": false,
- "columnNames": [
- "id"
- ]
- },
- "foreignKeys": [
- {
- "table": "MantraTranslationArtifactVersion",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "translationArtifactVersionId"
- ],
- "referencedColumns": [
- "id"
- ]
- },
- {
- "table": "MantraChapter",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "chapterId"
- ],
- "referencedColumns": [
- "id"
- ]
- },
- {
- "table": "ChatRoom",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "chatRoomId"
- ],
- "referencedColumns": [
- "id"
- ]
- }
- ]
- },
- {
- "tableName": "MantraTranslationChapterContributor",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `translationChapterId` TEXT NOT NULL, `translatorPublicKey` TEXT NOT NULL, `role` TEXT NOT NULL, `signature` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`translationChapterId`) REFERENCES `MantraTranslationChapter`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`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": "translationChapterId",
- "columnName": "translationChapterId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "translatorPublicKey",
- "columnName": "translatorPublicKey",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "role",
- "columnName": "role",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "signature",
- "columnName": "signature",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "chatRoomId",
- "columnName": "chatRoomId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "relayHint",
- "columnName": "relayHint",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "marmotGroupEventId",
- "columnName": "marmotGroupEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "groupSignedEventId",
- "columnName": "groupSignedEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "nostrEventId",
- "columnName": "nostrEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "createdAt",
- "columnName": "createdAt",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "updatedAt",
- "columnName": "updatedAt",
- "affinity": "INTEGER",
- "notNull": true
- }
- ],
- "primaryKey": {
- "autoGenerate": false,
- "columnNames": [
- "id"
- ]
- },
- "foreignKeys": [
- {
- "table": "MantraTranslationChapter",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "translationChapterId"
- ],
- "referencedColumns": [
- "id"
- ]
- },
- {
- "table": "ChatRoom",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "chatRoomId"
- ],
- "referencedColumns": [
- "id"
- ]
- }
- ]
- },
- {
- "tableName": "MantraTranslationChunk",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `chunkId` TEXT NOT NULL, `translationChapterId` TEXT NOT NULL, `text` TEXT NOT NULL, `index` INTEGER NOT NULL, `signature` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chunkId`) REFERENCES `MantraChunk`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`translationChapterId`) REFERENCES `MantraTranslationChapter`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`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": "chunkId",
- "columnName": "chunkId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "translationChapterId",
- "columnName": "translationChapterId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "text",
- "columnName": "text",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "index",
- "columnName": "index",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "signature",
- "columnName": "signature",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "chatRoomId",
- "columnName": "chatRoomId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "relayHint",
- "columnName": "relayHint",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "marmotGroupEventId",
- "columnName": "marmotGroupEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "groupSignedEventId",
- "columnName": "groupSignedEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "nostrEventId",
- "columnName": "nostrEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "createdAt",
- "columnName": "createdAt",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "updatedAt",
- "columnName": "updatedAt",
- "affinity": "INTEGER",
- "notNull": true
- }
- ],
- "primaryKey": {
- "autoGenerate": false,
- "columnNames": [
- "id"
- ]
- },
- "foreignKeys": [
- {
- "table": "MantraChunk",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "chunkId"
- ],
- "referencedColumns": [
- "id"
- ]
- },
- {
- "table": "MantraTranslationChapter",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "translationChapterId"
- ],
- "referencedColumns": [
- "id"
- ]
- },
- {
- "table": "ChatRoom",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "chatRoomId"
- ],
- "referencedColumns": [
- "id"
- ]
- }
- ]
- },
- {
- "tableName": "MantraTranslationContributor",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `dTag` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `translationId` TEXT NOT NULL, `translatorPublicKey` TEXT NOT NULL, `signature` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `marmotGroupEventId` TEXT, `groupSignedEventId` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`translationId`) REFERENCES `MantraTranslation`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
- "fields": [
- {
- "fieldPath": "id",
- "columnName": "id",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "dTag",
- "columnName": "dTag",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "publicKey",
- "columnName": "publicKey",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "translationId",
- "columnName": "translationId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "translatorPublicKey",
- "columnName": "translatorPublicKey",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "signature",
- "columnName": "signature",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "chatRoomId",
- "columnName": "chatRoomId",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "relayHint",
- "columnName": "relayHint",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "marmotGroupEventId",
- "columnName": "marmotGroupEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "groupSignedEventId",
- "columnName": "groupSignedEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "nostrEventId",
- "columnName": "nostrEventId",
- "affinity": "TEXT"
- },
- {
- "fieldPath": "createdAt",
- "columnName": "createdAt",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "updatedAt",
- "columnName": "updatedAt",
- "affinity": "INTEGER",
- "notNull": true
- }
- ],
- "primaryKey": {
- "autoGenerate": false,
- "columnNames": [
- "id"
- ]
- },
- "foreignKeys": [
- {
- "table": "MantraTranslation",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "translationId"
- ],
- "referencedColumns": [
- "id"
- ]
- },
- {
- "table": "ChatRoom",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "chatRoomId"
- ],
- "referencedColumns": [
- "id"
- ]
- }
- ]
- },
{
"tableName": "MarmotCommitResult",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `peerKeyPackageEventId` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `isOneMemberInitialGroupCreation` INTEGER NOT NULL, `commitBytes` BLOB NOT NULL, `welcomeBytes` BLOB, `groupInfoBytes` BLOB, `framedCommitBytes` BLOB NOT NULL, `preCommitExporterSecret` BLOB NOT NULL, `obligationId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, PRIMARY KEY(`id`))",
@@ -3716,7 +2310,7 @@
},
{
"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, `payloadEventId` TEXT, `marmotGroupEventId` TEXT, `directMessageRecipientPublicKey` 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 )",
+ "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, `directMessageRecipientPublicKey` 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",
@@ -3759,11 +2353,6 @@
"columnName": "quotedEventId",
"affinity": "TEXT"
},
- {
- "fieldPath": "payloadEventId",
- "columnName": "payloadEventId",
- "affinity": "TEXT"
- },
{
"fieldPath": "marmotGroupEventId",
"columnName": "marmotGroupEventId",
@@ -5969,7 +4558,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, '2fe774344e85e188dd6793623347bf91')"
+ "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'b3d7bf2b5f251ad1f39aeb01c7ab316d')"
]
}
}
\ No newline at end of file
diff --git a/composeApp/schemas/com.machankura.bennu.compose.database.BennuDatabase/28.json b/composeApp/schemas/com.machankura.bennu.compose.database.BennuDatabase/28.json
new file mode 100644
index 00000000..cd7b208f
--- /dev/null
+++ b/composeApp/schemas/com.machankura.bennu.compose.database.BennuDatabase/28.json
@@ -0,0 +1,4569 @@
+{
+ "formatVersion": 1,
+ "database": {
+ "version": 28,
+ "identityHash": "b81b7b97c63fabcda1c21865b7b8c0e7",
+ "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, `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",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "unsignedNostrEventId",
+ "columnName": "unsignedNostrEventId",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "isAccepted",
+ "columnName": "isAccepted",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "isSync",
+ "columnName": "isSync",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayURL",
+ "columnName": "relayURL",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "messages",
+ "columnName": "messages",
+ "affinity": "TEXT"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_BroadcastNostrEventReceipt_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_BroadcastNostrEventReceipt_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ },
+ {
+ "name": "index_BroadcastNostrEventReceipt_isAccepted",
+ "unique": false,
+ "columnNames": [
+ "isAccepted"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_BroadcastNostrEventReceipt_isAccepted` ON `${TABLE_NAME}` (`isAccepted`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "UnsignedNostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "unsignedNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "BroadcastNostrEventRequest",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `nostrEventId` TEXT NOT NULL, `unsignedNostrEventId` INTEGER, `status` TEXT NOT NULL, `relayURL` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, 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",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "unsignedNostrEventId",
+ "columnName": "unsignedNostrEventId",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "status",
+ "columnName": "status",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayURL",
+ "columnName": "relayURL",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_BroadcastNostrEventRequest_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_BroadcastNostrEventRequest_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ },
+ {
+ "name": "index_BroadcastNostrEventRequest_status",
+ "unique": false,
+ "columnNames": [
+ "status"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_BroadcastNostrEventRequest_status` ON `${TABLE_NAME}` (`status`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "UnsignedNostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "unsignedNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "Connection",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sourcePublicKey` TEXT NOT NULL, `destinationPublicKey` TEXT NOT NULL, `nostrEventId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`sourcePublicKey`, `destinationPublicKey`), FOREIGN KEY(`sourcePublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`destinationPublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sourcePublicKey",
+ "columnName": "sourcePublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "destinationPublicKey",
+ "columnName": "destinationPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "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": [
+ "sourcePublicKey",
+ "destinationPublicKey"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "sourcePublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "destinationPublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ }
+ ]
+ },
+ {
+ "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, `marmotGroupEventId` TEXT, `marmotInnerEventId` TEXT, `chatRoomId` TEXT NOT NULL, `replyToMessageId` INTEGER, `quotedMessageId` INTEGER, `content` TEXT NOT NULL, `messageType` TEXT NOT NULL, `directMessageRecipientPublicKey` TEXT, `frostSigningSessionId` TEXT, `dkgSessionId` TEXT, `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",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "senderPublicKey",
+ "columnName": "senderPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "isUserMessage",
+ "columnName": "isUserMessage",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "giftWrapPayloadId",
+ "columnName": "giftWrapPayloadId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "marmotGroupEventId",
+ "columnName": "marmotGroupEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "marmotInnerEventId",
+ "columnName": "marmotInnerEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "replyToMessageId",
+ "columnName": "replyToMessageId",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "quotedMessageId",
+ "columnName": "quotedMessageId",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "messageType",
+ "columnName": "messageType",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "directMessageRecipientPublicKey",
+ "columnName": "directMessageRecipientPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "frostSigningSessionId",
+ "columnName": "frostSigningSessionId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "dkgSessionId",
+ "columnName": "dkgSessionId",
+ "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": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_ChatMessage_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_ChatMessage_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "GiftWrapPayload",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "giftWrapPayloadId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "MarmotGroupEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "marmotGroupEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "MarmotInnerEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "marmotInnerEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ChatMessageBroadcastNostrEventRequestRelation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `chatMessageId` INTEGER NOT NULL, `broadcastNostrEventRequestId` INTEGER NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, FOREIGN KEY(`chatMessageId`) REFERENCES `ChatMessage`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`broadcastNostrEventRequestId`) REFERENCES `BroadcastNostrEventRequest`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatMessageId",
+ "columnName": "chatMessageId",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "broadcastNostrEventRequestId",
+ "columnName": "broadcastNostrEventRequestId",
+ "affinity": "INTEGER",
+ "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
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ChatMessage",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatMessageId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "BroadcastNostrEventRequest",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "broadcastNostrEventRequestId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ChatMessageBroadcastNostrEventReceiptRelation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `chatMessageId` INTEGER NOT NULL, `broadcastNostrEventReceiptId` INTEGER NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, FOREIGN KEY(`chatMessageId`) REFERENCES `ChatMessage`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`broadcastNostrEventReceiptId`) REFERENCES `BroadcastNostrEventReceipt`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatMessageId",
+ "columnName": "chatMessageId",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "broadcastNostrEventReceiptId",
+ "columnName": "broadcastNostrEventReceiptId",
+ "affinity": "INTEGER",
+ "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
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ChatMessage",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatMessageId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "BroadcastNostrEventReceipt",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "broadcastNostrEventReceiptId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ChatMessageNostrEventRelation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `chatMessageId` INTEGER NOT NULL, `nostrEventId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, FOREIGN KEY(`chatMessageId`) REFERENCES `ChatMessage`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatMessageId",
+ "columnName": "chatMessageId",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "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
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ChatMessage",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatMessageId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "ChatRoom",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `subject` TEXT, `description` TEXT, `mlsGroupState` TEXT, `initialGiftWrapPayloadId` TEXT, `leftGroupAt` INTEGER, `joinedGroupAt` INTEGER, `chronicleRequestedAt` INTEGER, `parentChatRoomId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`userPublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`initialGiftWrapPayloadId`) REFERENCES `GiftWrapPayload`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "subject",
+ "columnName": "subject",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "description",
+ "columnName": "description",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "mlsGroupState",
+ "columnName": "mlsGroupState",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "initialGiftWrapPayloadId",
+ "columnName": "initialGiftWrapPayloadId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "leftGroupAt",
+ "columnName": "leftGroupAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "joinedGroupAt",
+ "columnName": "joinedGroupAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "chronicleRequestedAt",
+ "columnName": "chronicleRequestedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "parentChatRoomId",
+ "columnName": "parentChatRoomId",
+ "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": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "userPublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "GiftWrapPayload",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "initialGiftWrapPayloadId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "DkgParticipantMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sessionId` TEXT NOT NULL, `participantPublicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `payload` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`sessionId`, `participantPublicKey`, `kind`), FOREIGN KEY(`sessionId`) REFERENCES `DkgSession`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sessionId",
+ "columnName": "sessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participantPublicKey",
+ "columnName": "participantPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "payload",
+ "columnName": "payload",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sessionId",
+ "participantPublicKey",
+ "kind"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_DkgParticipantMessage_sessionId",
+ "unique": false,
+ "columnNames": [
+ "sessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_DkgParticipantMessage_sessionId` ON `${TABLE_NAME}` (`sessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "DkgSession",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "sessionId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "DkgSession",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `coordinatorPublicKey` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `threshold` INTEGER NOT NULL, `participantCount` INTEGER NOT NULL, `participantPublicKeys` TEXT, `subject` TEXT, `stage` TEXT NOT NULL, `hostPublicKey` TEXT NOT NULL, `round1Random` TEXT NOT NULL, `round2AuxRandom` TEXT NOT NULL, `coordinatorRound1` TEXT, `certificate` TEXT, `thresholdPublicKey` TEXT, `secretShare` TEXT, `publicShares` TEXT, `recoveryData` TEXT, `failureReason` TEXT, `hostKeyApprovedAt` INTEGER, `round1ApprovedAt` INTEGER, `round2ApprovedAt` INTEGER, `approvalRequestedThrough` TEXT, `parentChatRoomId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "coordinatorPublicKey",
+ "columnName": "coordinatorPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "threshold",
+ "columnName": "threshold",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participantCount",
+ "columnName": "participantCount",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participantPublicKeys",
+ "columnName": "participantPublicKeys",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "subject",
+ "columnName": "subject",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "stage",
+ "columnName": "stage",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "hostPublicKey",
+ "columnName": "hostPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "round1Random",
+ "columnName": "round1Random",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "round2AuxRandom",
+ "columnName": "round2AuxRandom",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "coordinatorRound1",
+ "columnName": "coordinatorRound1",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "certificate",
+ "columnName": "certificate",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "thresholdPublicKey",
+ "columnName": "thresholdPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "secretShare",
+ "columnName": "secretShare",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "publicShares",
+ "columnName": "publicShares",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "recoveryData",
+ "columnName": "recoveryData",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "failureReason",
+ "columnName": "failureReason",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "hostKeyApprovedAt",
+ "columnName": "hostKeyApprovedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "round1ApprovedAt",
+ "columnName": "round1ApprovedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "round2ApprovedAt",
+ "columnName": "round2ApprovedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "approvalRequestedThrough",
+ "columnName": "approvalRequestedThrough",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "parentChatRoomId",
+ "columnName": "parentChatRoomId",
+ "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
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_DkgSession_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_DkgSession_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "FrostSignerMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sessionId` TEXT NOT NULL, `signerPublicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `payload` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`sessionId`, `signerPublicKey`, `kind`), FOREIGN KEY(`sessionId`) REFERENCES `FrostSigningSession`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sessionId",
+ "columnName": "sessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signerPublicKey",
+ "columnName": "signerPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "payload",
+ "columnName": "payload",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sessionId",
+ "signerPublicKey",
+ "kind"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_FrostSignerMessage_sessionId",
+ "unique": false,
+ "columnNames": [
+ "sessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_FrostSignerMessage_sessionId` ON `${TABLE_NAME}` (`sessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "FrostSigningSession",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "sessionId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "FrostSigningItem",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sessionId` TEXT NOT NULL, `itemIndex` INTEGER NOT NULL, `unsignedEventJson` TEXT NOT NULL, `eventId` TEXT NOT NULL, `nonceRandom` TEXT NOT NULL, `aggregatedNonce` TEXT, `signature` TEXT, `inputIndex` INTEGER, PRIMARY KEY(`sessionId`, `itemIndex`), FOREIGN KEY(`sessionId`) REFERENCES `FrostSigningSession`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "sessionId",
+ "columnName": "sessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "itemIndex",
+ "columnName": "itemIndex",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "unsignedEventJson",
+ "columnName": "unsignedEventJson",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "eventId",
+ "columnName": "eventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nonceRandom",
+ "columnName": "nonceRandom",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "aggregatedNonce",
+ "columnName": "aggregatedNonce",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "signature",
+ "columnName": "signature",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "inputIndex",
+ "columnName": "inputIndex",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "sessionId",
+ "itemIndex"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_FrostSigningItem_sessionId",
+ "unique": false,
+ "columnNames": [
+ "sessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_FrostSigningItem_sessionId` ON `${TABLE_NAME}` (`sessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "FrostSigningSession",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "sessionId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "FrostSigningSession",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `coordinatorPublicKey` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `dkgSessionId` TEXT NOT NULL, `threshold` INTEGER NOT NULL, `participantCount` INTEGER NOT NULL, `signerId` INTEGER NOT NULL, `derivationPath` TEXT, `stage` TEXT NOT NULL, `signerIds` TEXT, `failureReason` TEXT, `signApprovedAt` INTEGER, `signDeclinedAt` INTEGER, `approvalRequestedAt` INTEGER, `resentAt` INTEGER, `subject` TEXT NOT NULL DEFAULT 'EVENTS', `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "coordinatorPublicKey",
+ "columnName": "coordinatorPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "dkgSessionId",
+ "columnName": "dkgSessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "threshold",
+ "columnName": "threshold",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participantCount",
+ "columnName": "participantCount",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signerId",
+ "columnName": "signerId",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "derivationPath",
+ "columnName": "derivationPath",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "stage",
+ "columnName": "stage",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signerIds",
+ "columnName": "signerIds",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "failureReason",
+ "columnName": "failureReason",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "signApprovedAt",
+ "columnName": "signApprovedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "signDeclinedAt",
+ "columnName": "signDeclinedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "approvalRequestedAt",
+ "columnName": "approvalRequestedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "resentAt",
+ "columnName": "resentAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "subject",
+ "columnName": "subject",
+ "affinity": "TEXT",
+ "notNull": true,
+ "defaultValue": "'EVENTS'"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "savedAt",
+ "columnName": "savedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_FrostSigningSession_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_FrostSigningSession_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ },
+ {
+ "name": "index_FrostSigningSession_dkgSessionId",
+ "unique": false,
+ "columnNames": [
+ "dkgSessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_FrostSigningSession_dkgSessionId` ON `${TABLE_NAME}` (`dkgSessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GiftWrapMessage",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `receiverPublicKey` TEXT NOT NULL, `receiverRelayHit` TEXT, `content` TEXT NOT NULL, `signature` TEXT NOT NULL, `nostrEventId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`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": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "receiverPublicKey",
+ "columnName": "receiverPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "receiverRelayHit",
+ "columnName": "receiverRelayHit",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signature",
+ "columnName": "signature",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "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": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GiftWrapSeal",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `tags` TEXT NOT NULL, `content` TEXT NOT NULL, `signature` TEXT NOT NULL, `giftWrapMessageId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`giftWrapMessageId`) REFERENCES `GiftWrapMessage`(`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": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "tags",
+ "columnName": "tags",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signature",
+ "columnName": "signature",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "giftWrapMessageId",
+ "columnName": "giftWrapMessageId",
+ "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": "GiftWrapMessage",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "giftWrapMessageId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GiftWrapPayload",
+ "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, `giftWrapSealId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`giftWrapSealId`) REFERENCES `GiftWrapSeal`(`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": "giftWrapSealId",
+ "columnName": "giftWrapSealId",
+ "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": "GiftWrapSeal",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "giftWrapSealId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GroupKeyState",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`chatRoomId` TEXT NOT NULL, `dkgSessionId` TEXT NOT NULL, `thresholdPublicKey` TEXT NOT NULL, `derivationPath` TEXT NOT NULL, `announcedBy` TEXT NOT NULL, `announcedAt` INTEGER NOT NULL, `parentChatRoomId` TEXT, `birthCertificateJson` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`chatRoomId`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "dkgSessionId",
+ "columnName": "dkgSessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "thresholdPublicKey",
+ "columnName": "thresholdPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "derivationPath",
+ "columnName": "derivationPath",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "announcedBy",
+ "columnName": "announcedBy",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "announcedAt",
+ "columnName": "announcedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "parentChatRoomId",
+ "columnName": "parentChatRoomId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "birthCertificateJson",
+ "columnName": "birthCertificateJson",
+ "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
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "chatRoomId"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_GroupKeyState_dkgSessionId",
+ "unique": false,
+ "columnNames": [
+ "dkgSessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupKeyState_dkgSessionId` ON `${TABLE_NAME}` (`dkgSessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GroupSignedEvent",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `tags` TEXT NOT NULL, `content` TEXT NOT NULL, `signature` TEXT NOT NULL, `derivationPath` TEXT, `frostSigningSessionId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "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": "signature",
+ "columnName": "signature",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "derivationPath",
+ "columnName": "derivationPath",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "frostSigningSessionId",
+ "columnName": "frostSigningSessionId",
+ "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
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_GroupSignedEvent_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupSignedEvent_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ },
+ {
+ "name": "index_GroupSignedEvent_kind",
+ "unique": false,
+ "columnNames": [
+ "kind"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupSignedEvent_kind` ON `${TABLE_NAME}` (`kind`)"
+ },
+ {
+ "name": "index_GroupSignedEvent_frostSigningSessionId",
+ "unique": false,
+ "columnNames": [
+ "frostSigningSessionId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupSignedEvent_frostSigningSessionId` ON `${TABLE_NAME}` (`frostSigningSessionId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "GroupTransaction",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`frostSigningSessionId` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `chain` TEXT NOT NULL, `account` INTEGER NOT NULL, `guardedChatRoomId` TEXT, `psbt` TEXT NOT NULL, `txid` TEXT NOT NULL, `signedTransaction` TEXT, `broadcastAt` INTEGER, `seenAt` INTEGER, `confirmedAt` INTEGER, `replacedByTxid` TEXT, `createdAt` INTEGER NOT NULL, PRIMARY KEY(`frostSigningSessionId`), FOREIGN KEY(`frostSigningSessionId`) REFERENCES `FrostSigningSession`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "frostSigningSessionId",
+ "columnName": "frostSigningSessionId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chain",
+ "columnName": "chain",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "account",
+ "columnName": "account",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "guardedChatRoomId",
+ "columnName": "guardedChatRoomId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "psbt",
+ "columnName": "psbt",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "txid",
+ "columnName": "txid",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signedTransaction",
+ "columnName": "signedTransaction",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "broadcastAt",
+ "columnName": "broadcastAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "seenAt",
+ "columnName": "seenAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "confirmedAt",
+ "columnName": "confirmedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "replacedByTxid",
+ "columnName": "replacedByTxid",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "frostSigningSessionId"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_GroupTransaction_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupTransaction_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ },
+ {
+ "name": "index_GroupTransaction_txid",
+ "unique": false,
+ "columnNames": [
+ "txid"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_GroupTransaction_txid` ON `${TABLE_NAME}` (`txid`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "FrostSigningSession",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "frostSigningSessionId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "InReplyToRelation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`replyingNostrEventId` TEXT NOT NULL, `inReplyToNostrEventId` TEXT NOT NULL, `inReplyToProfilePublicKey` TEXT, `inReplyToRootNostrEventId` TEXT, `inReplyToRootProfilePublicKey` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, PRIMARY KEY(`replyingNostrEventId`, `inReplyToNostrEventId`), FOREIGN KEY(`inReplyToProfilePublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`inReplyToRootProfilePublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`replyingNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`inReplyToNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`inReplyToRootNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "replyingNostrEventId",
+ "columnName": "replyingNostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "inReplyToNostrEventId",
+ "columnName": "inReplyToNostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "inReplyToProfilePublicKey",
+ "columnName": "inReplyToProfilePublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "inReplyToRootNostrEventId",
+ "columnName": "inReplyToRootNostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "inReplyToRootProfilePublicKey",
+ "columnName": "inReplyToRootProfilePublicKey",
+ "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": [
+ "replyingNostrEventId",
+ "inReplyToNostrEventId"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "inReplyToProfilePublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "inReplyToRootProfilePublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "replyingNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "inReplyToNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "inReplyToRootNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "MarmotCommitResult",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `peerKeyPackageEventId` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `isOneMemberInitialGroupCreation` INTEGER NOT NULL, `commitBytes` BLOB NOT NULL, `welcomeBytes` BLOB, `groupInfoBytes` BLOB, `framedCommitBytes` BLOB NOT NULL, `preCommitExporterSecret` BLOB NOT NULL, `obligationId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, PRIMARY KEY(`id`))",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userPublicKey",
+ "columnName": "userPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "peerKeyPackageEventId",
+ "columnName": "peerKeyPackageEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "isOneMemberInitialGroupCreation",
+ "columnName": "isOneMemberInitialGroupCreation",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "commitBytes",
+ "columnName": "commitBytes",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "welcomeBytes",
+ "columnName": "welcomeBytes",
+ "affinity": "BLOB"
+ },
+ {
+ "fieldPath": "groupInfoBytes",
+ "columnName": "groupInfoBytes",
+ "affinity": "BLOB"
+ },
+ {
+ "fieldPath": "framedCommitBytes",
+ "columnName": "framedCommitBytes",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "preCommitExporterSecret",
+ "columnName": "preCommitExporterSecret",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "obligationId",
+ "columnName": "obligationId",
+ "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"
+ ]
+ }
+ },
+ {
+ "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, `signature` TEXT NOT NULL, `encryptedContent` TEXT NOT NULL, `expiresAt` INTEGER, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`id`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "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": "signature",
+ "columnName": "signature",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "encryptedContent",
+ "columnName": "encryptedContent",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "expiresAt",
+ "columnName": "expiresAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "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"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "id"
+ ],
+ "referencedColumns": [
+ "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, `directMessageRecipientPublicKey` 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": "directMessageRecipientPublicKey",
+ "columnName": "directMessageRecipientPublicKey",
+ "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, `profile` TEXT, `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 )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "tlsEncodedMarmotKeyPackage",
+ "columnName": "tlsEncodedMarmotKeyPackage",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "profile",
+ "columnName": "profile",
+ "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": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "publicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "MarmotKeyPackageBundle",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `publicKey` TEXT NOT NULL, `tlsEncodedMarmotKeyPackage` BLOB NOT NULL, `ncryptsecInitPrivateKey` TEXT NOT NULL, `ncryptsecEncryptionPrivateKey` TEXT NOT NULL, `ncryptsecSignaturePrivateKey` TEXT NOT NULL, `consumed` INTEGER NOT NULL, `rotated` INTEGER NOT NULL, `profile` TEXT, `dTag` TEXT, `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": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "tlsEncodedMarmotKeyPackage",
+ "columnName": "tlsEncodedMarmotKeyPackage",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "ncryptsecInitPrivateKey",
+ "columnName": "ncryptsecInitPrivateKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "ncryptsecEncryptionPrivateKey",
+ "columnName": "ncryptsecEncryptionPrivateKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "ncryptsecSignaturePrivateKey",
+ "columnName": "ncryptsecSignaturePrivateKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "consumed",
+ "columnName": "consumed",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "rotated",
+ "columnName": "rotated",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "profile",
+ "columnName": "profile",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "dTag",
+ "columnName": "dTag",
+ "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": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_MarmotKeyPackageBundle_publicKey",
+ "unique": false,
+ "columnNames": [
+ "publicKey"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_MarmotKeyPackageBundle_publicKey` ON `${TABLE_NAME}` (`publicKey`)"
+ }
+ ]
+ },
+ {
+ "tableName": "MarmotRouting",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`routingId` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `activeFromEpoch` INTEGER NOT NULL, `retiredAtEpoch` INTEGER, PRIMARY KEY(`routingId`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "routingId",
+ "columnName": "routingId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "activeFromEpoch",
+ "columnName": "activeFromEpoch",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "retiredAtEpoch",
+ "columnName": "retiredAtEpoch",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "routingId"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_MarmotRouting_chatRoomId",
+ "unique": false,
+ "columnNames": [
+ "chatRoomId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_MarmotRouting_chatRoomId` ON `${TABLE_NAME}` (`chatRoomId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "MarmotPublishObligation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`obligationId` TEXT NOT NULL, `bytes` BLOB NOT NULL, PRIMARY KEY(`obligationId`))",
+ "fields": [
+ {
+ "fieldPath": "obligationId",
+ "columnName": "obligationId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "bytes",
+ "columnName": "bytes",
+ "affinity": "BLOB",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "obligationId"
+ ]
+ }
+ },
+ {
+ "tableName": "MarmotOutboundGate",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`groupId` TEXT NOT NULL, `gate` TEXT NOT NULL, PRIMARY KEY(`groupId`))",
+ "fields": [
+ {
+ "fieldPath": "groupId",
+ "columnName": "groupId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "gate",
+ "columnName": "gate",
+ "affinity": "TEXT",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "groupId"
+ ]
+ }
+ },
+ {
+ "tableName": "MarmotRetainedEpochSecret",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`chatRoomId` TEXT NOT NULL, `epoch` INTEGER NOT NULL, `senderDataSecret` BLOB NOT NULL, `encryptionSecret` BLOB NOT NULL, `leafCount` INTEGER NOT NULL, `exporterSecret` BLOB NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, PRIMARY KEY(`chatRoomId`, `epoch`), FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "epoch",
+ "columnName": "epoch",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "senderDataSecret",
+ "columnName": "senderDataSecret",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "encryptionSecret",
+ "columnName": "encryptionSecret",
+ "affinity": "BLOB",
+ "notNull": true
+ },
+ {
+ "fieldPath": "leafCount",
+ "columnName": "leafCount",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "exporterSecret",
+ "columnName": "exporterSecret",
+ "affinity": "BLOB",
+ "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
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "chatRoomId",
+ "epoch"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "Mention",
+ "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": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "mentionedPublicKey",
+ "columnName": "mentionedPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "mentioningNostrEventId",
+ "columnName": "mentioningNostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "relayUrl",
+ "columnName": "relayUrl",
+ "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": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "mentionedPublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "mentioningNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "NegentropySynchronizeRequest",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `uuid` TEXT NOT NULL, `purpose` TEXT NOT NULL, `status` TEXT NOT NULL, `relayURL` TEXT NOT NULL, `isRecommendedRelay` INTEGER NOT NULL, `level` INTEGER NOT NULL, `synchronizationFilter` TEXT NOT NULL, `ownerPublicKey` TEXT, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "uuid",
+ "columnName": "uuid",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "purpose",
+ "columnName": "purpose",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "status",
+ "columnName": "status",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayURL",
+ "columnName": "relayURL",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "isRecommendedRelay",
+ "columnName": "isRecommendedRelay",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "level",
+ "columnName": "level",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "synchronizationFilter",
+ "columnName": "synchronizationFilter",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "ownerPublicKey",
+ "columnName": "ownerPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_NegentropySynchronizeRequest_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NegentropySynchronizeRequest_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ },
+ {
+ "name": "index_NegentropySynchronizeRequest_status",
+ "unique": false,
+ "columnNames": [
+ "status"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NegentropySynchronizeRequest_status` ON `${TABLE_NAME}` (`status`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "NegentropySynchronizeResult",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `relayURL` TEXT NOT NULL, `status` TEXT NOT NULL, `negentropySynchronizeRequestId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`negentropySynchronizeRequestId`) REFERENCES `SynchronizeNostrEventResult`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayURL",
+ "columnName": "relayURL",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "status",
+ "columnName": "status",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "negentropySynchronizeRequestId",
+ "columnName": "negentropySynchronizeRequestId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "SynchronizeNostrEventResult",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "negentropySynchronizeRequestId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "NostrEvent",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `pubKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `tags` TEXT NOT NULL, `content` TEXT NOT NULL, `sig` TEXT NOT NULL, `relayUrl` TEXT, `quotedNostrEventId` TEXT, `quotedAuthorPublicKey` TEXT, `inReplyToNostrEventId` TEXT, `inReplyToAuthorPublicKey` TEXT, `inReplyToRootNostrEventId` TEXT, `inReplyToRootAuthorPublicKey` TEXT, `repostedNostrEventId` TEXT, `repostedAuthorPublicKey` TEXT, `unsignedNostrEventId` INTEGER, `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": "pubKey",
+ "columnName": "pubKey",
+ "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": "sig",
+ "columnName": "sig",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayUrl",
+ "columnName": "relayUrl",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "quotedNostrEventId",
+ "columnName": "quotedNostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "quotedAuthorPublicKey",
+ "columnName": "quotedAuthorPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "inReplyToNostrEventId",
+ "columnName": "inReplyToNostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "inReplyToAuthorPublicKey",
+ "columnName": "inReplyToAuthorPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "inReplyToRootNostrEventId",
+ "columnName": "inReplyToRootNostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "inReplyToRootAuthorPublicKey",
+ "columnName": "inReplyToRootAuthorPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "repostedNostrEventId",
+ "columnName": "repostedNostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "repostedAuthorPublicKey",
+ "columnName": "repostedAuthorPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "unsignedNostrEventId",
+ "columnName": "unsignedNostrEventId",
+ "affinity": "INTEGER"
+ },
+ {
+ "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"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_NostrEvent_kind",
+ "unique": false,
+ "columnNames": [
+ "kind"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NostrEvent_kind` ON `${TABLE_NAME}` (`kind`)"
+ },
+ {
+ "name": "index_NostrEvent_pubKey",
+ "unique": false,
+ "columnNames": [
+ "pubKey"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NostrEvent_pubKey` ON `${TABLE_NAME}` (`pubKey`)"
+ },
+ {
+ "name": "index_NostrEvent_quotedNostrEventId",
+ "unique": false,
+ "columnNames": [
+ "quotedNostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NostrEvent_quotedNostrEventId` ON `${TABLE_NAME}` (`quotedNostrEventId`)"
+ },
+ {
+ "name": "index_NostrEvent_inReplyToNostrEventId",
+ "unique": false,
+ "columnNames": [
+ "inReplyToNostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NostrEvent_inReplyToNostrEventId` ON `${TABLE_NAME}` (`inReplyToNostrEventId`)"
+ },
+ {
+ "name": "index_NostrEvent_inReplyToRootNostrEventId",
+ "unique": false,
+ "columnNames": [
+ "inReplyToRootNostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NostrEvent_inReplyToRootNostrEventId` ON `${TABLE_NAME}` (`inReplyToRootNostrEventId`)"
+ }
+ ]
+ },
+ {
+ "tableName": "NostrEventRelay",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`relayURL` TEXT NOT NULL, `nostrEventId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`nostrEventId`, `relayURL`), FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "relayURL",
+ "columnName": "relayURL",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "nostrEventId",
+ "relayURL"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_NostrEventRelay_relayURL",
+ "unique": false,
+ "columnNames": [
+ "relayURL"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_NostrEventRelay_relayURL` ON `${TABLE_NAME}` (`relayURL`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "Participant",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `participantPublicKey` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `relayHint` TEXT, `adminAt` INTEGER, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, FOREIGN KEY(`participantPublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`chatRoomId`) REFERENCES `ChatRoom`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "participantPublicKey",
+ "columnName": "participantPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chatRoomId",
+ "columnName": "chatRoomId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayHint",
+ "columnName": "relayHint",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "adminAt",
+ "columnName": "adminAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "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": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "participantPublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "ChatRoom",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "chatRoomId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "Post",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `repostId` TEXT, `quote` TEXT, `content` TEXT NOT NULL, `nostrEventId` TEXT NOT NULL, `replyToId` TEXT, `profilePublicKey` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`profilePublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`replyToId`) REFERENCES `Post`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`repostId`) REFERENCES `Post`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "repostId",
+ "columnName": "repostId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "quote",
+ "columnName": "quote",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "replyToId",
+ "columnName": "replyToId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "profilePublicKey",
+ "columnName": "profilePublicKey",
+ "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": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_Post_profilePublicKey",
+ "unique": false,
+ "columnNames": [
+ "profilePublicKey"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Post_profilePublicKey` ON `${TABLE_NAME}` (`profilePublicKey`)"
+ },
+ {
+ "name": "index_Post_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Post_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ },
+ {
+ "name": "index_Post_replyToId",
+ "unique": false,
+ "columnNames": [
+ "replyToId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Post_replyToId` ON `${TABLE_NAME}` (`replyToId`)"
+ },
+ {
+ "name": "index_Post_repostId",
+ "unique": false,
+ "columnNames": [
+ "repostId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Post_repostId` ON `${TABLE_NAME}` (`repostId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "profilePublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "Post",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "replyToId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "Post",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "repostId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "Profile",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`publicKey` TEXT NOT NULL, `userName` TEXT, `displayName` TEXT, `picture` TEXT, `banner` TEXT, `website` TEXT, `about` TEXT, `bot` INTEGER, `pronouns` TEXT, `nip05` TEXT, `domain` TEXT, `lud06` TEXT, `lud16` TEXT, `twitter` TEXT, `nostrEventId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`publicKey`), FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userName",
+ "columnName": "userName",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "displayName",
+ "columnName": "displayName",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "picture",
+ "columnName": "picture",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "banner",
+ "columnName": "banner",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "website",
+ "columnName": "website",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "about",
+ "columnName": "about",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "bot",
+ "columnName": "bot",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "pronouns",
+ "columnName": "pronouns",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "nip05",
+ "columnName": "nip05",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "domain",
+ "columnName": "domain",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "lud06",
+ "columnName": "lud06",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "lud16",
+ "columnName": "lud16",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "twitter",
+ "columnName": "twitter",
+ "affinity": "TEXT"
+ },
+ {
+ "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": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "publicKey"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_Profile_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Profile_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "QuotedRelation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`quotingNostrEventId` TEXT NOT NULL, `quotedNostrEventId` TEXT NOT NULL, `quotedProfilePublicKey` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`quotingNostrEventId`, `quotedNostrEventId`), FOREIGN KEY(`quotedProfilePublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`quotingNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`quotedNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "quotingNostrEventId",
+ "columnName": "quotingNostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "quotedNostrEventId",
+ "columnName": "quotedNostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "quotedProfilePublicKey",
+ "columnName": "quotedProfilePublicKey",
+ "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"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "quotingNostrEventId",
+ "quotedNostrEventId"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "quotedProfilePublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "quotingNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "quotedNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "Reaction",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `content` TEXT NOT NULL, `nostrEventId` TEXT NOT NULL, `replyToId` TEXT NOT NULL, `profilePublicKey` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`profilePublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`replyToId`) REFERENCES `Post`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "replyToId",
+ "columnName": "replyToId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "profilePublicKey",
+ "columnName": "profilePublicKey",
+ "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": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_Reaction_profilePublicKey",
+ "unique": false,
+ "columnNames": [
+ "profilePublicKey"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Reaction_profilePublicKey` ON `${TABLE_NAME}` (`profilePublicKey`)"
+ },
+ {
+ "name": "index_Reaction_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Reaction_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ },
+ {
+ "name": "index_Reaction_replyToId",
+ "unique": false,
+ "columnNames": [
+ "replyToId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Reaction_replyToId` ON `${TABLE_NAME}` (`replyToId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "profilePublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "Post",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "replyToId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "RecentSearch",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`query` TEXT NOT NULL, `synchronizationFilters` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`query`))",
+ "fields": [
+ {
+ "fieldPath": "query",
+ "columnName": "query",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "synchronizationFilters",
+ "columnName": "synchronizationFilters",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "query"
+ ]
+ }
+ },
+ {
+ "tableName": "Relay",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`publicKey` TEXT NOT NULL, `type` TEXT NOT NULL, `url` TEXT NOT NULL, `read` INTEGER NOT NULL, `write` INTEGER NOT NULL, PRIMARY KEY(`publicKey`, `type`, `url`))",
+ "fields": [
+ {
+ "fieldPath": "publicKey",
+ "columnName": "publicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "type",
+ "columnName": "type",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "url",
+ "columnName": "url",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "read",
+ "columnName": "read",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "write",
+ "columnName": "write",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "publicKey",
+ "type",
+ "url"
+ ]
+ }
+ },
+ {
+ "tableName": "RepostedRelation",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`repostingNostrEventId` TEXT NOT NULL, `repostedNostrEventId` TEXT NOT NULL, `repostedProfilePublicKey` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`repostingNostrEventId`, `repostedNostrEventId`), FOREIGN KEY(`repostedProfilePublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`repostedNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`repostingNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "repostingNostrEventId",
+ "columnName": "repostingNostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "repostedNostrEventId",
+ "columnName": "repostedNostrEventId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "repostedProfilePublicKey",
+ "columnName": "repostedProfilePublicKey",
+ "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"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "repostingNostrEventId",
+ "repostedNostrEventId"
+ ]
+ },
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "repostedProfilePublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "repostedNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "repostingNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "SynchronizeNostrEventRequest",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `purpose` TEXT NOT NULL, `status` TEXT NOT NULL, `relayURL` TEXT NOT NULL, `isRecommendedRelay` INTEGER NOT NULL, `level` INTEGER NOT NULL, `synchronizationFilters` TEXT NOT NULL, `ownerPublicKey` TEXT, `nostrEventId` TEXT, `unsignedNostrEventId` INTEGER, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), 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",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "purpose",
+ "columnName": "purpose",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "status",
+ "columnName": "status",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayURL",
+ "columnName": "relayURL",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "isRecommendedRelay",
+ "columnName": "isRecommendedRelay",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "level",
+ "columnName": "level",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "synchronizationFilters",
+ "columnName": "synchronizationFilters",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "ownerPublicKey",
+ "columnName": "ownerPublicKey",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "unsignedNostrEventId",
+ "columnName": "unsignedNostrEventId",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_SynchronizeNostrEventRequest_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_SynchronizeNostrEventRequest_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ },
+ {
+ "name": "index_SynchronizeNostrEventRequest_status",
+ "unique": false,
+ "columnNames": [
+ "status"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_SynchronizeNostrEventRequest_status` ON `${TABLE_NAME}` (`status`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "UnsignedNostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "unsignedNostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "SynchronizeNostrEventResult",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `relayURL` TEXT NOT NULL, `nostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "relayURL",
+ "columnName": "relayURL",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "nostrEventId",
+ "columnName": "nostrEventId",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "createdAt",
+ "columnName": "createdAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "updatedAt",
+ "columnName": "updatedAt",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_SynchronizeNostrEventResult_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_SynchronizeNostrEventResult_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "UnsignedNostrEvent",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `pubKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `tags` TEXT NOT NULL, `privateTags` TEXT, `content` TEXT NOT NULL, `signedAt` INTEGER, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER)",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "pubKey",
+ "columnName": "pubKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "kind",
+ "columnName": "kind",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "tags",
+ "columnName": "tags",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "privateTags",
+ "columnName": "privateTags",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "content",
+ "columnName": "content",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "signedAt",
+ "columnName": "signedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "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": true,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_UnsignedNostrEvent_pubKey",
+ "unique": false,
+ "columnNames": [
+ "pubKey"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_UnsignedNostrEvent_pubKey` ON `${TABLE_NAME}` (`pubKey`)"
+ },
+ {
+ "name": "index_UnsignedNostrEvent_kind",
+ "unique": false,
+ "columnNames": [
+ "kind"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_UnsignedNostrEvent_kind` ON `${TABLE_NAME}` (`kind`)"
+ }
+ ]
+ },
+ {
+ "tableName": "Zap",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `postId` TEXT NOT NULL, `senderPublicKey` TEXT NOT NULL, `receiverPublicKey` TEXT NOT NULL, `message` TEXT, `invoice` TEXT, `amountInMillisatoshis` INTEGER, `nostrEventId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, `broadcastedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`senderPublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`receiverPublicKey`) REFERENCES `Profile`(`publicKey`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`nostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`postId`) REFERENCES `Post`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "postId",
+ "columnName": "postId",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "senderPublicKey",
+ "columnName": "senderPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "receiverPublicKey",
+ "columnName": "receiverPublicKey",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "message",
+ "columnName": "message",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "invoice",
+ "columnName": "invoice",
+ "affinity": "TEXT"
+ },
+ {
+ "fieldPath": "amountInMillisatoshis",
+ "columnName": "amountInMillisatoshis",
+ "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": "viewedAt",
+ "columnName": "viewedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "deletedAt",
+ "columnName": "deletedAt",
+ "affinity": "INTEGER"
+ },
+ {
+ "fieldPath": "broadcastedAt",
+ "columnName": "broadcastedAt",
+ "affinity": "INTEGER"
+ }
+ ],
+ "primaryKey": {
+ "autoGenerate": false,
+ "columnNames": [
+ "id"
+ ]
+ },
+ "indices": [
+ {
+ "name": "index_Zap_senderPublicKey",
+ "unique": false,
+ "columnNames": [
+ "senderPublicKey"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Zap_senderPublicKey` ON `${TABLE_NAME}` (`senderPublicKey`)"
+ },
+ {
+ "name": "index_Zap_nostrEventId",
+ "unique": false,
+ "columnNames": [
+ "nostrEventId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Zap_nostrEventId` ON `${TABLE_NAME}` (`nostrEventId`)"
+ },
+ {
+ "name": "index_Zap_postId",
+ "unique": false,
+ "columnNames": [
+ "postId"
+ ],
+ "orders": [],
+ "createSql": "CREATE INDEX IF NOT EXISTS `index_Zap_postId` ON `${TABLE_NAME}` (`postId`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "senderPublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "Profile",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "receiverPublicKey"
+ ],
+ "referencedColumns": [
+ "publicKey"
+ ]
+ },
+ {
+ "table": "NostrEvent",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "nostrEventId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ },
+ {
+ "table": "Post",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "postId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ }
+ ],
+ "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, 'b81b7b97c63fabcda1c21865b7b8c0e7')"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/composeResources/drawable/compose-multiplatform.xml b/composeApp/src/commonMain/composeResources/drawable/compose-multiplatform.xml
index 1ffc948c..601df181 100644
--- a/composeApp/src/commonMain/composeResources/drawable/compose-multiplatform.xml
+++ b/composeApp/src/commonMain/composeResources/drawable/compose-multiplatform.xml
@@ -1,44 +1,13 @@
-
+
+
+ android:fillColor="#FF3A1A"
+ android:pathData="M0,0 L512,0 L512,512 L0,512 Z"/>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
+ android:fillColor="#000000"
+ android:pathData="M246.31,26.00 C244.88,25.74 243.39,26.79 241.55,28.54 C239.71,30.29 236.15,33.14 235.20,36.48 C234.24,39.82 237.67,41.82 235.83,48.55 C233.99,55.29 227.25,68.63 224.08,76.83 C220.90,85.02 218.77,91.18 216.77,97.79 C214.77,104.40 213.21,110.56 212.00,116.54 C210.80,122.51 209.94,131.37 209.46,133.69 C208.99,136.01 209.62,131.47 209.15,130.51 C208.67,129.56 207.02,130.04 206.60,127.97 C206.19,125.91 206.38,121.30 206.60,118.12 C206.83,114.95 206.99,113.20 207.87,108.91 C208.76,104.62 209.37,99.95 212.00,92.39 C214.64,84.83 221.63,69.74 223.76,63.48 C225.89,57.22 224.97,57.29 224.71,54.91 C224.46,52.52 223.06,50.52 222.17,49.19 C221.28,47.85 220.36,47.50 219.31,46.96 C218.26,46.42 217.31,45.95 215.82,46.01 C214.32,46.07 211.91,46.33 210.42,47.28 C208.92,48.23 207.49,50.24 206.92,51.73 C206.35,53.22 206.70,55.16 206.92,56.18 C207.14,57.19 207.49,57.76 208.19,57.76 C208.89,57.76 210.42,55.86 211.05,56.18 C211.69,56.49 213.59,55.92 212.00,59.67 C210.42,63.42 204.63,72.54 201.52,78.73 C198.41,84.93 195.23,92.07 193.26,96.84 C191.29,101.60 191.04,102.33 189.77,107.32 C188.50,112.31 186.18,123.30 185.64,126.70 C185.10,130.10 184.11,127.43 186.59,127.65 C189.07,127.88 197.71,127.65 200.57,127.97 C203.43,128.29 202.57,128.67 203.74,129.56 C204.92,130.45 206.60,132.10 207.56,133.37 C208.51,134.64 209.78,136.14 209.46,137.18 C209.15,138.23 207.08,138.30 205.65,139.73 C204.22,141.16 213.12,143.70 200.89,145.76 C188.66,147.83 147.13,150.46 132.27,152.12 C117.40,153.77 99.16,154.43 111.62,155.61 C124.07,156.79 190.50,158.21 206.92,159.10 C223.35,159.99 208.29,160.37 210.10,161.01 C211.91,161.65 212.39,162.54 217.72,162.92 C223.06,163.30 237.26,162.82 242.18,163.23 C247.11,163.65 245.84,164.25 247.27,165.46 C248.70,166.67 250.28,168.89 250.76,170.54 C251.24,172.19 251.17,173.72 250.13,175.31 C249.08,176.89 246.16,179.05 244.41,180.07 C242.66,181.09 244.63,181.09 239.64,181.34 C234.66,181.60 219.79,181.28 214.55,181.66 C209.30,182.04 210.42,182.61 208.19,183.57 C205.97,184.52 203.49,185.69 201.20,187.38 C198.92,189.06 196.34,191.44 194.53,193.73 C192.72,196.02 191.36,198.88 190.40,201.04 C189.45,203.20 189.13,204.53 188.81,206.76 C188.50,208.98 188.27,211.84 188.50,214.38 C188.72,216.92 189.07,219.30 190.08,222.00 C191.10,224.71 190.50,225.56 194.53,230.58 C198.57,235.60 208.29,244.56 214.23,252.18 C220.17,259.81 224.97,269.50 230.11,276.33 C235.26,283.16 240.98,287.70 245.04,293.17 C249.11,298.63 249.87,302.38 254.57,309.05 C259.28,315.72 270.14,328.59 273.32,333.19 C276.49,337.80 273.86,334.40 273.63,336.69 C273.41,338.97 275.64,334.08 272.05,346.85 C268.46,359.62 257.05,397.14 252.03,413.25 C247.01,429.35 244.63,436.06 241.87,443.43 C239.10,450.80 237.20,454.45 235.51,457.41 C233.83,460.36 233.51,460.11 231.70,461.22 C229.89,462.33 227.09,463.54 224.71,464.08 C222.33,464.62 219.47,464.55 217.41,464.39 C215.34,464.24 214.13,463.35 212.32,463.12 C210.51,462.90 208.03,462.87 206.60,463.12 C205.17,463.38 204.48,464.08 203.74,464.71 C203.01,465.35 203.81,466.36 202.16,466.94 C200.50,467.51 196.03,467.19 193.90,468.21 C191.77,469.22 189.35,472.59 189.45,472.97 C189.54,473.35 193.10,470.84 194.53,470.43 C195.96,470.02 197.55,470.05 198.03,470.43 C198.50,470.81 197.33,472.11 197.39,472.65 C197.45,473.19 197.71,473.45 198.34,473.61 C198.98,473.77 200.41,473.83 201.20,473.61 C202.00,473.39 200.73,472.65 203.11,472.34 C205.49,472.02 213.97,471.07 215.50,471.70 C217.02,472.34 212.96,474.66 212.32,476.15 C211.69,477.64 210.99,480.69 211.69,480.60 C212.39,480.50 214.93,476.21 216.45,475.51 C217.98,474.81 219.79,476.63 220.90,476.47 C222.01,476.31 220.17,475.58 223.12,474.56 C226.08,473.54 233.45,470.91 238.69,470.43 C243.93,469.95 251.56,471.29 254.57,471.70 C257.59,472.11 256.00,472.75 256.80,472.97 C257.59,473.19 258.64,473.19 259.34,472.97 C260.04,472.75 260.67,472.18 260.93,471.70 C261.18,471.22 260.45,470.37 260.93,470.11 C261.40,469.86 262.67,469.64 263.79,470.11 C264.90,470.59 267.22,473.23 267.60,472.97 C267.98,472.72 266.71,469.64 266.01,468.52 C265.31,467.41 264.64,466.71 263.47,466.30 C262.29,465.89 259.97,466.24 259.02,465.98 C258.07,465.73 258.39,464.78 257.75,464.71 C257.12,464.65 256.54,465.67 255.21,465.67 C253.87,465.67 251.30,465.19 249.81,464.71 C248.32,464.24 247.20,463.60 246.31,462.81 C245.42,462.01 244.57,461.76 244.41,459.95 C244.25,458.14 243.84,457.88 245.36,452.01 C246.89,446.13 248.12,441.59 253.62,424.68 C259.12,407.78 273.54,364.71 278.40,350.67 C283.26,336.62 282.15,343.20 282.85,340.50 C283.55,337.80 283.07,336.31 282.53,334.46 C281.99,332.62 280.94,332.88 279.67,329.38 C278.40,325.89 276.72,317.56 274.91,313.50 C273.09,309.43 270.24,307.24 268.87,304.92 C267.50,302.60 264.10,297.04 266.65,299.52 C269.19,302.00 278.34,313.66 284.12,319.85 C289.90,326.05 298.35,332.81 301.27,336.69 C304.20,340.56 301.18,341.07 301.59,343.04 C302.00,345.01 302.64,342.79 303.81,348.44 C304.99,354.10 306.13,359.81 308.58,377.03 C311.03,394.25 317.06,437.77 318.43,451.69 C319.79,465.60 317.70,458.52 316.84,460.58 C315.98,462.65 315.00,463.22 313.34,464.08 C311.69,464.93 309.53,465.57 306.99,465.67 C304.45,465.76 300.26,464.65 298.10,464.71 C295.94,464.78 295.01,465.41 293.97,465.98 C292.92,466.55 293.39,467.79 291.74,468.21 C290.09,468.62 286.12,467.95 284.12,468.52 C282.12,469.10 280.72,470.49 279.67,471.70 C278.62,472.91 277.54,475.67 277.76,475.83 C277.99,475.99 279.61,473.39 280.94,472.65 C282.28,471.92 284.85,471.29 285.71,471.38 C286.56,471.48 285.61,472.88 286.02,473.29 C286.44,473.70 288.41,473.13 288.25,473.93 C288.09,474.72 285.64,476.69 285.07,478.05 C284.50,479.42 284.50,482.12 284.75,482.18 C285.01,482.25 285.77,479.39 286.66,478.37 C287.55,477.36 289.20,476.24 290.15,476.15 C291.11,476.05 291.65,477.48 292.38,477.74 C293.11,477.99 292.38,478.44 294.60,477.74 C296.83,477.04 302.23,474.56 305.72,473.61 C309.21,472.65 313.92,472.11 315.57,472.02 C317.22,471.92 315.95,472.65 315.57,472.97 C315.19,473.29 314.08,473.04 313.34,473.93 C312.61,474.81 311.53,476.40 311.12,478.37 C310.71,480.34 310.42,485.30 310.80,485.68 C311.18,486.06 312.45,481.39 313.34,480.60 C314.23,479.80 314.62,481.61 316.20,480.91 C317.79,480.22 321.13,477.17 322.87,476.47 C324.62,475.77 325.51,476.15 326.69,476.78 C327.86,477.42 328.97,479.64 329.86,480.28 C330.75,480.91 331.45,479.80 332.09,480.60 C332.72,481.39 333.29,485.04 333.68,485.04 C334.06,485.04 334.37,482.41 334.31,480.60 C334.25,478.79 334.06,475.77 333.36,474.24 C332.66,472.72 329.48,471.70 330.18,471.38 C330.88,471.07 335.96,472.27 337.49,472.34 C339.01,472.40 338.85,472.24 339.39,471.70 C339.93,471.16 340.03,469.41 340.66,469.16 C341.30,468.91 342.41,469.54 343.21,470.11 C344.00,470.68 345.21,472.91 345.43,472.65 C345.65,472.40 345.27,469.73 344.48,468.52 C343.68,467.32 341.68,465.89 340.66,465.35 C339.65,464.81 339.01,465.57 338.44,465.35 C337.87,465.13 337.96,464.14 337.17,464.08 C336.38,464.01 334.79,465.09 333.68,465.03 C332.56,464.97 331.52,464.55 330.50,463.76 C329.48,462.97 328.50,462.01 327.64,460.26 C326.78,458.52 327.58,467.03 325.42,453.28 C323.26,439.52 316.93,394.98 314.62,377.67 C312.30,360.35 312.01,355.97 311.44,349.39 C310.87,342.82 311.37,340.82 311.12,338.28 C310.87,335.73 310.58,335.48 309.85,334.15 C309.12,332.81 308.01,332.46 306.67,330.33 C305.34,328.21 298.32,321.50 301.91,321.44 C305.50,321.38 319.22,327.95 328.28,330.02 C337.33,332.08 351.21,333.03 356.23,333.83 C361.25,334.62 356.80,333.35 358.45,334.78 C360.11,336.21 363.95,340.56 366.08,342.41 C368.21,344.25 370.37,345.74 371.16,345.90 C371.96,346.06 370.05,343.10 370.84,343.36 C371.64,343.61 375.13,347.11 375.93,347.49 C376.72,347.87 375.04,345.42 375.61,345.58 C376.18,345.74 378.88,348.35 379.42,348.44 C379.96,348.54 378.25,346.15 378.79,346.22 C379.33,346.28 382.12,348.51 382.60,348.76 C383.08,349.01 381.71,348.03 381.65,347.81 C381.58,347.58 381.11,347.08 382.28,347.49 C383.46,347.90 388.00,350.35 388.63,350.35 C389.27,350.35 385.78,347.65 386.09,347.49 C386.41,347.33 389.81,349.33 390.54,349.39 C391.27,349.46 389.81,347.49 390.54,347.81 C391.27,348.12 394.45,351.21 394.99,351.30 C395.53,351.40 393.50,348.70 393.72,348.44 C393.94,348.19 395.78,349.62 396.26,349.71 C396.74,349.81 396.26,348.92 396.58,349.08 C396.89,349.24 398.23,351.84 398.16,350.67 C398.10,349.49 395.94,342.88 396.26,342.09 C396.58,341.29 399.91,346.00 400.07,345.90 C400.23,345.80 397.59,342.31 397.21,341.45 C396.83,340.59 397.43,340.56 397.85,340.82 C398.26,341.07 400.01,344.15 399.75,343.04 C399.50,341.93 396.80,335.73 396.26,334.15 C395.72,332.56 396.10,333.26 396.58,333.51 C397.05,333.76 399.50,336.69 399.12,335.73 C398.74,334.78 395.08,329.22 394.35,327.79 C393.62,326.36 394.42,327.09 394.67,327.16 C394.92,327.22 397.78,331.06 395.94,328.11 C394.10,325.16 391.40,319.91 383.55,309.37 C375.70,298.82 359.09,276.96 348.92,264.89 C338.76,252.82 330.88,244.78 322.56,236.94 C314.23,229.09 306.61,223.18 299.05,217.88 C291.49,212.57 282.75,208.03 277.13,205.17 C271.51,202.31 268.87,201.77 265.37,200.72 C261.88,199.67 259.08,199.20 256.16,198.81 C253.24,198.43 250.86,198.18 247.90,198.50 C244.95,198.81 240.85,199.86 238.37,200.72 C235.89,201.58 235.29,201.93 232.97,203.58 C230.65,205.23 226.68,209.04 224.39,210.57 C222.11,212.09 220.74,212.41 219.31,212.79 C217.88,213.17 216.93,213.01 215.82,212.79 C214.70,212.57 213.66,212.38 212.64,211.52 C211.62,210.66 210.26,209.04 209.78,207.71 C209.30,206.38 209.53,204.85 209.78,203.58 C210.03,202.31 210.57,201.20 211.37,200.08 C212.16,198.97 213.34,197.80 214.55,196.91 C215.75,196.02 216.93,195.32 218.68,194.68 C220.42,194.05 221.28,193.41 225.03,193.10 C228.78,192.78 237.10,193.10 241.23,192.78 C245.36,192.46 246.89,192.14 249.81,191.19 C252.73,190.24 256.23,188.81 258.70,187.06 C261.18,185.31 263.31,183.09 264.74,180.71 C266.17,178.32 267.06,175.56 267.28,172.76 C267.50,169.97 267.03,166.82 266.01,163.87 C264.99,160.92 263.72,158.31 261.24,154.97 C258.77,151.64 249.08,145.51 251.08,143.86 C253.08,142.20 265.44,144.33 273.32,145.13 C281.20,145.92 290.85,147.25 298.41,148.62 C305.97,149.99 311.60,151.32 318.74,153.39 C325.89,155.45 341.36,161.11 341.30,161.01 C341.24,160.92 325.48,154.97 318.43,152.75 C311.37,150.53 307.09,149.26 299.05,147.67 C291.01,146.08 278.40,144.24 270.14,143.22 C261.88,142.20 253.30,142.04 249.49,141.63 C245.68,141.22 244.73,140.90 247.27,140.68 C249.81,140.46 254.41,139.82 264.74,140.36 C275.06,140.90 297.78,142.68 309.21,143.86 C320.65,145.03 326.85,146.17 333.36,147.35 C339.87,148.53 348.99,151.07 348.29,150.84 C347.59,150.62 335.36,147.41 329.23,146.08 C323.10,144.75 319.79,144.01 311.44,142.90 C303.08,141.79 290.63,140.30 279.03,139.41 C267.44,138.52 248.54,138.07 241.87,137.50 C235.20,136.93 238.59,136.87 239.01,135.91 C239.42,134.96 242.41,132.96 244.41,131.78 C246.41,130.61 247.33,129.78 251.08,128.92 C254.83,128.07 264.52,135.34 266.96,126.70 C269.41,118.06 265.79,87.69 265.69,77.14 C265.60,66.60 265.79,66.28 266.33,63.48 C266.87,60.69 268.23,60.85 268.87,60.31 C269.50,59.77 269.76,59.99 270.14,60.31 C270.52,60.62 270.52,62.05 271.09,62.21 C271.66,62.37 272.78,62.28 273.63,61.26 C274.49,60.24 275.86,57.67 276.18,56.18 C276.49,54.68 276.02,53.48 275.54,52.36 C275.06,51.25 274.27,50.24 273.32,49.50 C272.36,48.77 271.16,48.17 269.82,47.92 C268.49,47.66 267.28,47.28 265.37,47.92 C263.47,48.55 260.36,49.89 258.39,51.73 C256.42,53.57 254.80,56.33 253.62,59.04 C252.45,61.74 252.10,61.58 251.40,67.93 C250.70,74.28 250.22,88.83 249.49,97.16 C248.76,105.48 247.81,112.66 246.95,117.81 C246.09,122.95 245.46,126.00 244.41,127.97 C243.36,129.94 240.60,133.75 240.60,129.56 C240.60,125.37 243.23,115.96 244.41,102.87 C245.58,89.79 246.85,60.46 247.58,51.09 C248.32,41.72 248.06,48.33 248.86,46.65 C249.65,44.96 252.13,43.69 252.35,40.93 C252.57,38.16 251.14,32.60 250.13,30.13 C249.11,27.65 247.74,26.25 246.31,26.00 Z"/>
+
diff --git a/composeApp/src/commonMain/composeResources/values/strings.xml b/composeApp/src/commonMain/composeResources/values/strings.xml
index 31cca5d0..e146d902 100644
--- a/composeApp/src/commonMain/composeResources/values/strings.xml
+++ b/composeApp/src/commonMain/composeResources/values/strings.xml
@@ -21,21 +21,18 @@
"XML file ... is not valid. Check the file content."
-->
Abandoned
+ Abandon
+ Abandon ceremony
+ Abandon this key ceremony?
+ It ends for everyone in it. No key is created, and the ceremony can be started again.
Abandoned. Nothing was signed.
All
Bennu
- Add a dialect the group can translate into
- Add artifact to library
- Add artifact to the group library
- Add chapter
- Add dialect
Add to group
- Add translation
After this there is no turning back.
All broadcasts are queued so that we can manage data usage on metered connections.
Any amount
ARTICLE
- Artifact detail
As long as you control your keys there can be no dispute about who YOU actually is.
Back
Backup confirmation
@@ -46,16 +43,11 @@
BIP39 seed with the standard BIP84 derivation path. The profile\'s nostr key comes off the same seed, so these 12 words restore both.
Block user
Cancel
- Chapter detail
- Chapter name
- Chapter translation
- Chapters
Choose who to chat with
Close
Cloud backup
Copy URL
Could not unlock your phrase. Please try again.
- Country
Create chat
Create new chat
Create profile
@@ -71,9 +63,6 @@
Currently no messages have been shared.\nBreak the ice.
Declined to sign
Delete group
- Details
- Dialect name
- Dialects
Direct message detail
Direct message functionality will be here.
Direct message via npub
@@ -82,20 +71,12 @@
Download
Download and securely store everything needed to recover this profile and the coins it holds.
Edit profile
- eg. Chapter 1 — The Beginning
- eg. First Edition
- eg. https://harper.com/2-kill-Bird
- eg. Lesotho
- eg. Sesotho
- eg. st
- eg. To Kill a Mocking Bird
Emergency kit
ENDED
Encrypt and back your recovery information up to your Google Drive or iCloud.
Enough members took part without you.
Enter the name you want to use for your group
Enter the name you want to use for your profile
- Enter the translation for this chunk
Events are indexed so that we can deliver a premium local first experience.
Everything else
Everything is cryptographical sound. Just announcing your profile to the world.
@@ -113,7 +94,6 @@
I have saved my recovery phrase somewhere safe.
I understand that if I lose this phone and my recovery phrase, I lose this profile and the funds in its wallet.
If you are new to Bennu or just want to create a fresh profile
- Initial version label
Input npub... or nip05
Introduce yourself
Invite
@@ -126,7 +106,6 @@
Key
Key package management
Key recovery
- Language
Learn more
Leave group
Remove from group
@@ -155,7 +134,6 @@
Name
Name (eg. Alan Turing)
Name (eg. Group Discussions)
- Name of artifact
Needs you
Needs your review.
Network relays
@@ -165,29 +143,17 @@
Not backed up yet
New chat
Next
- No artifacts exists in this groups library.
- No chapters.
- No chapters yet.
No chat message relays were found for this user.
- No chunks.
- No dialects have been defined in this group yet. Add one from the group's detail screen first.
- No dialects have been defined in this group.
No messages. Go to a profile and send them a message.
No one selected yet
No one to add yet.
No projects exists in this group.
No proposal has been abandoned.
- No translations yet.
- No versions.
Not now
Nothing is waiting for your signature.
Nothing was created and no key exists. It is safe to run it again.
Open chat
- Original
- Original text
- Original text (markdown)
✓ Paid
- Paste the chapter's markdown. Blank lines separate paragraphs into chunks.
Pay
Pay now
Post
@@ -200,11 +166,6 @@
Profiles
Projects
Proposals
- Propose
- Propose artifact
- Propose chapter
- Propose dialect
- Propose translation
Publish new key package
Re-broadcast
Asked the members who have not answered to take another look
@@ -260,11 +221,15 @@
Something went wrong and we were unable to sign in to your provided profile. Please try again later.
Something went wrong and we were unable to sign you up. Please try again later.
Something went wrong and we were unable to write a new note. Please try again later.
- Source dialect
Start
Start a group chat
Start chat via npub or nip05
Start key ceremony
+ This room was made from a key the group already holds, so it can't run a key ceremony of its own. A subgroup's ceremony is started from the group's details.
+ A shared key needs at least %1$s members to split it between.
+ Couldn't load this group.
+ Couldn't read your keys.
+ Couldn't start the key ceremony.
Startup error
Taking part with these members
Tap to load
@@ -276,12 +241,8 @@
The group has a shared key.
The recovery phrase (sometimes called a seed) is a list of 12 English words. It is the only way back to this profile: the key that signs as you, and the wallet that holds your coins, are both derived from it.\n\nOnly you have this phrase. Keep it private — nobody from Bennu will ever ask you for it.\n\nDo not lose it. Write it down and keep it somewhere safe that is not this phone. If you lose both the phone and the phrase, this profile and its funds are gone for good.
These are your keys. Keep them safe so they can keep unlocking this profile and its coins, even when you lose or change your phone.
- This artifact has no version for a translation to be of.
- This artifact has no version for a chapter to attach to.
- This chapter has no chunks.
This device holds no phrase for the profile that is signed in.
This decides who can change the group later. You can't switch afterwards.
- This group has no shared key, so it cannot sign them in.
This group has not been asked to sign anything yet.
This group has not signed anything yet.
This is fixed once the ceremony runs. Changing it later means generating a new key.
@@ -299,12 +260,6 @@
Could not sign out. Please try again.
This will give you write access to the profile.
Bennu broadcasts what you publish to a distributed set of relays, so it stays decentralised.
- Translate chunk
- Translate into which dialect?
- Translated text
- Translation
- Translation detail
- Translations
Transmit note
Trending notes functionality coming soon. In the meantime search for what you are looking for.
Try again
@@ -313,9 +268,6 @@
Unlocking your phrase…
Unsupported event kind
Untitled article
- Url
- Version
- Versions
View and accept invites you may have received to stay connected with others.
View invites
Waiting for you
@@ -347,15 +299,9 @@
Your profile is almost ready... just getting it's first cryptographic signature together.
Your share of it is on this device only. Your wallet backup restores it — nobody else's share can.
- Add chapter to %1$s
Add people to %1$s
Ask all %1$s again
Asked again about all %1$s proposals
- Chapter %1$s
- Chapter %1$s · %2$s words · %3$s characters
- Chunk %1$s
- Chunks (%1$s)
- %1$s/%2$s chunks translated
%1$s event(s) still unreadable%2$s
%1$s events, signed together
Everyone has to be online at the same time — the ceremony can only finish once all %1$s of you have taken part.
@@ -384,11 +330,9 @@
%1$s sent a private message to %2$s
Shared key for %1$s
to join the %1$s chat room.
- Translate %1$s
Unsupported event kind: %1$s
%1$s was created, but %2$s couldn't be added yet. Invite them again from the chat once they're on Bennu.
%1$s was created, but its shared key ceremony couldn't be started. Open the chat and start it from the group's details — until then the group has no key of its own.
- %1$s words · %2$s characters
#%1$s
You and %1$s others
You aren't following anyone yet.
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/BennuDatabase.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/BennuDatabase.kt
index bb51dac4..11fb183b 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/BennuDatabase.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/BennuDatabase.kt
@@ -26,19 +26,6 @@ import com.machankura.bennu.compose.database.dao.GiftWrapSealDao
import com.machankura.bennu.compose.database.dao.GroupKeyStateDao
import com.machankura.bennu.compose.database.dao.GroupSignedEventDao
import com.machankura.bennu.compose.database.dao.InReplyToRelationDao
-import com.machankura.bennu.compose.database.dao.MantraArtifactDao
-import com.machankura.bennu.compose.database.dao.MantraArtifactVersionDao
-import com.machankura.bennu.compose.database.dao.MantraChapterDao
-import com.machankura.bennu.compose.database.dao.MantraChunkDao
-import com.machankura.bennu.compose.database.dao.MantraDao
-import com.machankura.bennu.compose.database.dao.MantraDialectDao
-import com.machankura.bennu.compose.database.dao.MantraTranslationArtifactVersionDao
-import com.machankura.bennu.compose.database.dao.MantraTranslationArtifactVersionContributorDao
-import com.machankura.bennu.compose.database.dao.MantraTranslationChapterDao
-import com.machankura.bennu.compose.database.dao.MantraTranslationChapterContributorDao
-import com.machankura.bennu.compose.database.dao.MantraTranslationChunkDao
-import com.machankura.bennu.compose.database.dao.MantraTranslationDao
-import com.machankura.bennu.compose.database.dao.MantraTranslationContributorDao
import com.machankura.bennu.compose.database.dao.MarmotCommitResultDao
import com.machankura.bennu.compose.database.dao.MarmotOutboundDao
import com.machankura.bennu.compose.database.dao.MarmotGroupEventDao
@@ -81,18 +68,6 @@ import com.machankura.bennu.compose.database.model.GiftWrapSeal
import com.machankura.bennu.compose.database.model.GroupKeyState
import com.machankura.bennu.compose.database.model.GroupSignedEvent
import com.machankura.bennu.compose.database.model.InReplyToRelation
-import com.machankura.bennu.compose.database.model.MantraArtifact
-import com.machankura.bennu.compose.database.model.MantraArtifactVersion
-import com.machankura.bennu.compose.database.model.MantraChapter
-import com.machankura.bennu.compose.database.model.MantraChunk
-import com.machankura.bennu.compose.database.model.MantraDialect
-import com.machankura.bennu.compose.database.model.MantraTranslation
-import com.machankura.bennu.compose.database.model.MantraTranslationArtifactVersion
-import com.machankura.bennu.compose.database.model.MantraTranslationArtifactVersionContributor
-import com.machankura.bennu.compose.database.model.MantraTranslationChapter
-import com.machankura.bennu.compose.database.model.MantraTranslationChapterContributor
-import com.machankura.bennu.compose.database.model.MantraTranslationChunk
-import com.machankura.bennu.compose.database.model.MantraTranslationContributor
import com.machankura.bennu.compose.database.model.MarmotCommitResult
import com.machankura.bennu.compose.database.model.MarmotGroupEvent
import com.machankura.bennu.compose.database.model.MarmotInnerEvent
@@ -151,18 +126,6 @@ val GENESIS_AT = Instant.fromEpochMilliseconds(1231006505000L)
GroupSignedEvent::class,
GroupTransaction::class,
InReplyToRelation::class,
- MantraArtifact::class,
- MantraArtifactVersion::class,
- MantraChapter::class,
- MantraChunk::class,
- MantraDialect::class,
- MantraTranslation::class,
- MantraTranslationArtifactVersion::class,
- MantraTranslationArtifactVersionContributor::class,
- MantraTranslationChapter::class,
- MantraTranslationChapterContributor::class,
- MantraTranslationChunk::class,
- MantraTranslationContributor::class,
MarmotCommitResult::class,
MarmotGroupEvent::class,
MarmotInnerEvent::class,
@@ -190,7 +153,7 @@ val GENESIS_AT = Instant.fromEpochMilliseconds(1231006505000L)
UnsignedNostrEvent::class,
Zap::class
],
- version = 27,
+ version = 28,
autoMigrations = [
// v2 only adds the DkgSession/DkgParticipantMessage tables, so Room can
// generate the migration itself — nothing existing changes shape.
@@ -378,11 +341,16 @@ val GENESIS_AT = Instant.fromEpochMilliseconds(1231006505000L)
// nothing is rebuilt; a rebuild of either signing table would fire the
// cascades from FrostSigningSession, see docs/frost-batch-signing.md.
AutoMigration(from = 25, to = 26),
- // v27 adds the nullable GroupTransaction.guardedChatRoomId: the descendant
+ // v27 drops the nip30303 document tables and MarmotInnerEvent's
+ // payloadEventId, and deletes the chat lines nothing renders any more
+ // (docs/ceremony-creation.md, Phase 8). Manual -- it deletes rows --
+ // so it is MIGRATION_26_27 in `getRoomDatabase`, not an entry here.
+ //
+ // v28 adds the nullable GroupTransaction.guardedChatRoomId: the descendant
// whose guarded wallet a guardian's spend draws from
// (docs/group-wallet-guardians.md, Phase 7). Every spend before it was the
// room's own, which is what null means.
- AutoMigration(from = 26, to = 27),
+ AutoMigration(from = 27, to = 28),
]
)
@ConstructedBy(BennuDatabaseConstructor::class)
@@ -429,32 +397,6 @@ abstract class BennuDatabase: RoomDatabase() {
abstract fun inReplyToRelationDao(): InReplyToRelationDao
- abstract fun mantraDao(): MantraDao
-
- abstract fun mantraArtifactDao(): MantraArtifactDao
-
- abstract fun mantraArtifactVersionDao(): MantraArtifactVersionDao
-
- abstract fun mantraChapterDao(): MantraChapterDao
-
- abstract fun mantraChunkDao(): MantraChunkDao
-
- abstract fun mantraDialectDao(): MantraDialectDao
-
- abstract fun mantraTranslationArtifactVersionDao(): MantraTranslationArtifactVersionDao
-
- abstract fun mantraTranslationArtifactVersionContributorDao(): MantraTranslationArtifactVersionContributorDao
-
- abstract fun mantraTranslationChapterDao(): MantraTranslationChapterDao
-
- abstract fun mantraTranslationChapterContributorDao(): MantraTranslationChapterContributorDao
-
- abstract fun mantraTranslationChunkDao(): MantraTranslationChunkDao
-
- abstract fun mantraTranslationDao(): MantraTranslationDao
-
- abstract fun mantraTranslationContributorDao(): MantraTranslationContributorDao
-
abstract fun marmotCommitResultDao(): MarmotCommitResultDao
abstract fun marmotGroupEventDao(): MarmotGroupEventDao
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/builder/PlatformDatabaseBuilder.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/builder/PlatformDatabaseBuilder.kt
index 13e5f002..6c4ae40e 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/builder/PlatformDatabaseBuilder.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/builder/PlatformDatabaseBuilder.kt
@@ -6,6 +6,7 @@ import com.machankura.bennu.compose.database.migrations.MIGRATION_3_4
import com.machankura.bennu.compose.database.migrations.MIGRATION_9_10
import com.machankura.bennu.compose.database.migrations.MIGRATION_13_14
import com.machankura.bennu.compose.database.migrations.MIGRATION_14_15
+import com.machankura.bennu.compose.database.migrations.MIGRATION_26_27
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
@@ -19,13 +20,15 @@ fun getRoomDatabase(
builder: RoomDatabase.Builder
): com.machankura.bennu.compose.database.BennuDatabase {
return builder
- // Everything else Room generates itself. These four move data rather than
+ // Everything else Room generates itself. These five move data rather than
// only changing shape, which an AutoMigration cannot express: 3->4 rewrites
// chat rows, 9->10 copies a session's per-event columns onto the items
// table before dropping them, 13->14 renames a column and rewrites the
- // chat rows that named it the old way, and 14->15 adds a column and deletes
- // the chat rows written for messages from before this device joined.
- .addMigrations(MIGRATION_3_4, MIGRATION_9_10, MIGRATION_13_14, MIGRATION_14_15)
+ // chat rows that named it the old way, 14->15 adds a column and deletes
+ // the chat rows written for messages from before this device joined, and
+ // 26->27 drops the document tables and deletes the chat rows nothing
+ // renders any more.
+ .addMigrations(MIGRATION_3_4, MIGRATION_9_10, MIGRATION_13_14, MIGRATION_14_15, MIGRATION_26_27)
.setDriver(BundledSQLiteDriver())
.setQueryCoroutineContext(Dispatchers.IO)
.build()
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraArtifactDao.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraArtifactDao.kt
deleted file mode 100644
index 9fb30e42..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraArtifactDao.kt
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.machankura.bennu.compose.database.dao
-
-import androidx.room3.Dao
-import androidx.room3.Query
-import androidx.room3.Upsert
-import com.machankura.bennu.compose.database.model.MantraArtifact
-
-@Dao
-interface MantraArtifactDao {
- @Upsert
- suspend fun upsert(mantraArtifact: MantraArtifact)
-
- @Query("SELECT * FROM MantraArtifact WHERE chatRoomId = :chatRoomId ORDER BY createdAt DESC")
- suspend fun getArtifactsByChatRoomId(chatRoomId: String): List
-
- @Query("SELECT * FROM MantraArtifact WHERE id = :id")
- suspend fun getArtifactById(id: String): MantraArtifact?
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraArtifactVersionDao.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraArtifactVersionDao.kt
deleted file mode 100644
index 845c191d..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraArtifactVersionDao.kt
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.machankura.bennu.compose.database.dao
-
-import androidx.room3.Dao
-import androidx.room3.Insert
-import androidx.room3.OnConflictStrategy.Companion.IGNORE
-import androidx.room3.Query
-import androidx.room3.Upsert
-import com.machankura.bennu.compose.database.model.MantraArtifactVersion
-
-@Dao
-interface MantraArtifactVersionDao {
- @Upsert
- suspend fun upsert(mantraArtifactVersion: MantraArtifactVersion)
-
- @Query("SELECT * FROM MantraArtifactVersion WHERE artifactId = :artifactId ORDER BY createdAt DESC")
- suspend fun getArtifactVersionsByArtifactId(artifactId: String): List
-
- @Query("SELECT * FROM MantraArtifactVersion WHERE id = :id")
- suspend fun getArtifactVersionById(id: String): MantraArtifactVersion?
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraChapterDao.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraChapterDao.kt
deleted file mode 100644
index c25108e6..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraChapterDao.kt
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.machankura.bennu.compose.database.dao
-
-import androidx.room3.Dao
-import androidx.room3.Insert
-import androidx.room3.OnConflictStrategy.Companion.IGNORE
-import androidx.room3.Query
-import androidx.room3.Upsert
-import com.machankura.bennu.compose.database.model.MantraChapter
-
-@Dao
-interface MantraChapterDao {
- @Upsert
- suspend fun upsert(mantraChapter: MantraChapter)
-
- /** Chapters across all versions of an artifact, ordered by their in-book index. */
- @Query(
- """
- SELECT MantraChapter.* FROM MantraChapter
- INNER JOIN MantraArtifactVersion
- ON MantraChapter.artifactVersionId = MantraArtifactVersion.id
- WHERE MantraArtifactVersion.artifactId = :artifactId
- ORDER BY MantraChapter.`index` ASC
- """
- )
- suspend fun getChaptersByArtifactId(artifactId: String): List
-
- @Query("SELECT * FROM MantraChapter WHERE artifactVersionId = :artifactVersionId ORDER BY `index` ASC")
- suspend fun getChaptersByArtifactVersionId(artifactVersionId: String): List
-
- @Query("SELECT * FROM MantraChapter WHERE id = :id")
- suspend fun getChapterById(id: String): MantraChapter?
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraChunkDao.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraChunkDao.kt
deleted file mode 100644
index e0913038..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraChunkDao.kt
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.machankura.bennu.compose.database.dao
-
-import androidx.room3.Dao
-import androidx.room3.Insert
-import androidx.room3.OnConflictStrategy.Companion.IGNORE
-import androidx.room3.Query
-import androidx.room3.Upsert
-import com.machankura.bennu.compose.database.model.MantraChunk
-
-@Dao
-interface MantraChunkDao {
- @Upsert
- suspend fun upsert(mantraChunk: MantraChunk)
-
- @Query("SELECT * FROM MantraChunk WHERE chapterId = :chapterId ORDER BY `index` ASC")
- suspend fun getChunksByChapterId(chapterId: String): List
-
- @Query("SELECT * FROM MantraChunk WHERE id = :id")
- suspend fun getChunkById(id: String): MantraChunk?
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraDao.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraDao.kt
deleted file mode 100644
index 5cf51b92..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraDao.kt
+++ /dev/null
@@ -1,216 +0,0 @@
-package com.machankura.bennu.compose.database.dao
-
-import androidx.room3.Dao
-import androidx.room3.Transaction
-import co.touchlab.kermit.Logger
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
-import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
-import com.machankura.bennu.compose.database.BennuDatabase
-import com.machankura.bennu.compose.database.model.ChatMessage
-import com.machankura.bennu.compose.database.model.MantraArtifactVersion
-import com.machankura.bennu.compose.database.model.MantraDialect
-import com.machankura.bennu.compose.database.model.MarmotInnerEvent
-import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
-import com.machankura.bennu.compose.nostr.nip30303.ArtifactVersionEvent
-import com.machankura.bennu.compose.nostr.nip30303.DialectEvent
-import com.machankura.bennu.compose.nostr.nip30303.SubmissionEvent
-import com.machankura.bennu.compose.nostr.nip30303.tags.ArtifactIdTag
-import com.machankura.bennu.compose.repository.MantraRepository.Companion.DEFAULT_LICENSE
-import com.machankura.bennu.compose.repository.MantraRepository.Companion.DEFAULT_VISIBILITY
-import kotlin.time.Instant
-
-@Dao
-abstract class MantraDao(
- private val database: BennuDatabase,
-) {
- val logger = Logger.withTag("NostrDao")
-
- /**
- * The unsigned nip30303 event [template] describes, authored by [publicKey].
- *
- * Its id is computed the same way the matching Mantra* entity computes
- * its own, so the row on disk and the payload on the wire are the same
- * event rather than two copies of one.
- */
- private fun rumorOf(
- template: EventTemplate,
- publicKey: HexKey,
- ): Event = Event(
- id = EventHasher.hashId(
- pubKey = publicKey,
- createdAt = template.createdAt,
- kind = template.kind,
- tags = template.tags,
- content = template.content,
- ),
- pubKey = publicKey,
- createdAt = template.createdAt,
- kind = template.kind,
- tags = template.tags,
- content = template.content,
- // A rumor. What signs for this reaching the group is the kind:445 the
- // outbound pipeline wraps it in, not the payload itself.
- sig = "",
- )
-
- /**
- * Queue [payload] for the group inside a [SubmissionEvent] that
- * [submitterPublicKey] authors.
- *
- * nip30303 events are never sent on their own. Wrapping them means the
- * payload keeps whoever wrote it as its author while the group still knows
- * which member put it there -- see [SubmissionEvent] for why the two are
- * worth telling apart.
- *
- * The submission is stored as an unprocessed rumor (null marmotGroupEventId),
- * which is what the outbound pipeline picks up and encrypts into a kind:445
- * group event for the chat room.
- */
- private suspend fun submitToGroup(
- chatRoomId: String,
- submitterPublicKey: HexKey,
- payload: Event,
- text: String,
- ): MarmotInnerEvent {
- val submissionTemplate = SubmissionEvent.build(payload = payload)
-
- val submissionInnerEvent = MarmotInnerEvent(
- id = EventHasher.hashId(
- pubKey = submitterPublicKey,
- createdAt = submissionTemplate.createdAt,
- kind = submissionTemplate.kind,
- tags = submissionTemplate.tags,
- content = submissionTemplate.content,
- ),
- publicKey = submitterPublicKey,
- kind = SubmissionEvent.KIND,
- createdAt = Instant.fromEpochSeconds(submissionTemplate.createdAt),
- tags = submissionTemplate.tags,
- content = submissionTemplate.content,
- payloadEventId = payload.id,
- chatRoomId = chatRoomId,
- )
-
- sendMarmotInnerEvent(
- chatRoomId = chatRoomId,
- userPublicKey = submitterPublicKey,
- text = text,
- marmotInnerEvent = submissionInnerEvent,
- )
-
- return submissionInnerEvent
- }
-
- @Transaction
- open suspend fun addDialect(
- localChatRoom: LocalChatRoom,
- name: String,
- country: String,
- language: String,
- userPublicKey: HexKey,
- ): MantraDialect? {
- logger.d("addDialect: $name")
-
- val dialectEventTemplate = DialectEvent.build(
- name = name,
- country = country,
- language = language,
- )
-
- val mantraDialect = MantraDialect.fromDialectEventTemplate(
- dialectEventTemplate = dialectEventTemplate,
- chatRoomId = localChatRoom.chatRoom.id,
- userPublicKey = userPublicKey,
- ) ?: return null
-
- return try {
- database.mantraDialectDao().upsert(mantraDialect)
-
- submitToGroup(
- chatRoomId = mantraDialect.chatRoomId,
- submitterPublicKey = userPublicKey,
- payload = rumorOf(dialectEventTemplate, userPublicKey),
- text = "Added $name as a dialect",
- )
-
- mantraDialect
- } catch (error: Throwable) {
- logger.e("Failed to add dialect \"$name\" to chat room ${localChatRoom.chatRoom.id}", error)
- null
- }
-
- }
-
- @Transaction
- open suspend fun addArtifactVersion(
- localChatRoom: LocalChatRoom,
- artifactId: HexKey,
- versionLabel: String,
- userPublicKey: HexKey,
- ): MantraArtifactVersion? {
- return addArtifactVersionInternal(
- localChatRoom = localChatRoom,
- artifactId = artifactId,
- versionLabel = versionLabel,
- userPublicKey = userPublicKey
- )
- }
-
- private suspend fun addArtifactVersionInternal(
- localChatRoom: LocalChatRoom,
- artifactId: HexKey,
- versionLabel: String,
- userPublicKey: HexKey,
- ): MantraArtifactVersion? {
- // The version label is carried in the event content (see
- // MantraArtifactVersion.fromArtifactVersionEvent).
- val artifactVersionEventTemplate = ArtifactVersionEvent.build(
- content = versionLabel,
- ) {
- addUnique(ArtifactIdTag.assemble(artifactId))
- }
-
- val mantraArtifactVersion = MantraArtifactVersion.fromArtifactVersionEventTemplate(
- artifactVersionEventTemplate = artifactVersionEventTemplate,
- chatRoomId = localChatRoom.chatRoom.id,
- userPublicKey = userPublicKey,
- ) ?: return null
-
- database.mantraArtifactVersionDao().upsert(mantraArtifactVersion)
-
- submitToGroup(
- chatRoomId = mantraArtifactVersion.chatRoomId,
- submitterPublicKey = userPublicKey,
- payload = rumorOf(artifactVersionEventTemplate, userPublicKey),
- text = "Add the ${artifactVersionEventTemplate.content} version",
- )
-
- return mantraArtifactVersion
- }
-
- private suspend fun sendMarmotInnerEvent(
- chatRoomId: String,
- userPublicKey: HexKey,
- text: String,
- marmotInnerEvent: MarmotInnerEvent
- ) {
- database.marmotInnerEventDao().upsert(
- marmotInnerEvent
- )
-
- database.chatMessageDao().upsert(
- ChatMessage(
- content = text,
- chatRoomId = chatRoomId,
- senderPublicKey = userPublicKey,
- isUserMessage = true,
- giftWrapPayloadId = null,
- marmotGroupEventId = null,
- marmotInnerEventId = marmotInnerEvent.id,
- )
- )
- // TODO: Depending on visibility (if signature is non-empty) might want to queue this event for broadcasting...
- }
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraDialectDao.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraDialectDao.kt
deleted file mode 100644
index 1d4b7f40..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraDialectDao.kt
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.machankura.bennu.compose.database.dao
-
-import androidx.room3.Dao
-import androidx.room3.Insert
-import androidx.room3.OnConflictStrategy.Companion.IGNORE
-import androidx.room3.Query
-import androidx.room3.Upsert
-import com.machankura.bennu.compose.database.model.MantraDialect
-
-@Dao
-interface MantraDialectDao {
- @Upsert
- suspend fun upsert(mantraDialect: MantraDialect)
-
- @Query("SELECT * FROM MantraDialect WHERE chatRoomId = :chatRoomId ORDER BY name")
- suspend fun getDialectsByChatRoomId(chatRoomId: String): List
-
- @Query("SELECT * FROM MantraDialect WHERE id = :id")
- suspend fun getDialectById(id: String): MantraDialect?
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraTranslationArtifactVersionContributorDao.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraTranslationArtifactVersionContributorDao.kt
deleted file mode 100644
index b15910d7..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraTranslationArtifactVersionContributorDao.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.machankura.bennu.compose.database.dao
-
-import androidx.room3.Dao
-import androidx.room3.Upsert
-import com.machankura.bennu.compose.database.model.MantraTranslationArtifactVersionContributor
-
-@Dao
-interface MantraTranslationArtifactVersionContributorDao {
- @Upsert
- suspend fun upsert(mantraTranslationArtifactVersionContributor: MantraTranslationArtifactVersionContributor)
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraTranslationArtifactVersionDao.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraTranslationArtifactVersionDao.kt
deleted file mode 100644
index ca26aca6..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraTranslationArtifactVersionDao.kt
+++ /dev/null
@@ -1,44 +0,0 @@
-package com.machankura.bennu.compose.database.dao
-
-import androidx.room3.Dao
-import androidx.room3.Insert
-import androidx.room3.OnConflictStrategy.Companion.IGNORE
-import androidx.room3.Query
-import androidx.room3.Upsert
-import com.machankura.bennu.compose.database.model.MantraTranslationArtifactVersion
-
-@Dao
-interface MantraTranslationArtifactVersionDao {
- @Upsert
- suspend fun upsert(mantraTranslationArtifactVersion: MantraTranslationArtifactVersion)
-
- /** Translations targeting any version of an artifact. */
- @Query(
- """
- SELECT MantraTranslationArtifactVersion.* FROM MantraTranslationArtifactVersion
- INNER JOIN MantraArtifactVersion
- ON MantraTranslationArtifactVersion.artifactVersionId = MantraArtifactVersion.id
- WHERE MantraArtifactVersion.artifactId = :artifactId
- ORDER BY MantraTranslationArtifactVersion.createdAt DESC
- """
- )
- suspend fun getTranslationsByArtifactId(artifactId: String): List
-
- /**
- * Translations of one version, which is what a chapter of that version has
- * to be scaffolded into. Narrower than [getTranslationsByArtifactId]: a
- * chapter belongs to a version, and a translation of an older version is
- * not a translation the chapter is in.
- */
- @Query(
- """
- SELECT * FROM MantraTranslationArtifactVersion
- WHERE artifactVersionId = :artifactVersionId
- ORDER BY createdAt DESC
- """
- )
- suspend fun getTranslationsByArtifactVersionId(artifactVersionId: String): List
-
- @Query("SELECT * FROM MantraTranslationArtifactVersion WHERE id = :id")
- suspend fun getTranslationById(id: String): MantraTranslationArtifactVersion?
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraTranslationChapterContributorDao.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraTranslationChapterContributorDao.kt
deleted file mode 100644
index f5826cb7..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraTranslationChapterContributorDao.kt
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.machankura.bennu.compose.database.dao
-
-import androidx.room3.Dao
-import androidx.room3.Upsert
-import com.machankura.bennu.compose.database.model.MantraTranslationChapter
-import com.machankura.bennu.compose.database.model.MantraTranslationChapterContributor
-
-@Dao
-interface MantraTranslationChapterContributorDao {
- @Upsert
- suspend fun upsert(mantraTranslationChapterContributor: MantraTranslationChapterContributor)
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraTranslationChapterDao.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraTranslationChapterDao.kt
deleted file mode 100644
index 9cb71940..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraTranslationChapterDao.kt
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.machankura.bennu.compose.database.dao
-
-import androidx.room3.Dao
-import androidx.room3.Insert
-import androidx.room3.OnConflictStrategy.Companion.IGNORE
-import androidx.room3.Query
-import androidx.room3.Upsert
-import com.machankura.bennu.compose.database.model.MantraTranslationChapter
-
-@Dao
-interface MantraTranslationChapterDao {
- @Upsert
- suspend fun upsert(mantraTranslationChapter: MantraTranslationChapter)
-
- @Query("SELECT * FROM MantraTranslationChapter WHERE translationArtifactVersionId = :translationArtifactVersionId ORDER BY `index` ASC")
- suspend fun getTranslationChaptersByTranslationArtifactVersionId(translationArtifactVersionId: String): List
-
- @Query("SELECT * FROM MantraTranslationChapter WHERE id = :id")
- suspend fun getTranslationChapterById(id: String): MantraTranslationChapter?
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraTranslationChunkDao.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraTranslationChunkDao.kt
deleted file mode 100644
index a80eca2d..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraTranslationChunkDao.kt
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.machankura.bennu.compose.database.dao
-
-import androidx.room3.Dao
-import androidx.room3.Insert
-import androidx.room3.OnConflictStrategy.Companion.IGNORE
-import androidx.room3.Query
-import androidx.room3.Upsert
-import com.machankura.bennu.compose.database.model.MantraTranslationChunk
-
-@Dao
-interface MantraTranslationChunkDao {
- @Upsert
- suspend fun upsert(mantraTranslationChunk: MantraTranslationChunk)
-
- @Query("SELECT * FROM MantraTranslationChunk WHERE translationChapterId = :translationChapterId ORDER BY `index` ASC")
- suspend fun getTranslationChunksByTranslationChapterId(translationChapterId: String): List
-
- /**
- * Every translation this chapter holds of one source chunk.
- *
- * There should only ever be one, and this is how that is kept true: a
- * retranslation is a new event with a new id rather than an edit, so the
- * row it replaces has to be found and dropped.
- */
- @Query("SELECT * FROM MantraTranslationChunk WHERE translationChapterId = :translationChapterId AND chunkId = :chunkId")
- suspend fun getTranslationChunksByChunkId(
- translationChapterId: String,
- chunkId: String
- ): List
-
- @Query("DELETE FROM MantraTranslationChunk WHERE id = :id")
- suspend fun deleteById(id: String)
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraTranslationContributorDao.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraTranslationContributorDao.kt
deleted file mode 100644
index da5ce79e..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraTranslationContributorDao.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.machankura.bennu.compose.database.dao
-
-import androidx.room3.Dao
-import androidx.room3.Upsert
-import com.machankura.bennu.compose.database.model.MantraTranslationContributor
-
-@Dao
-interface MantraTranslationContributorDao {
- @Upsert
- suspend fun upsert(mantraTranslationContributor: MantraTranslationContributor)
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraTranslationDao.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraTranslationDao.kt
deleted file mode 100644
index 0c13bb3f..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MantraTranslationDao.kt
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.machankura.bennu.compose.database.dao
-
-import androidx.room3.Dao
-import androidx.room3.Insert
-import androidx.room3.OnConflictStrategy.Companion.IGNORE
-import androidx.room3.Upsert
-import com.machankura.bennu.compose.database.model.MantraTranslation
-
-@Dao
-interface MantraTranslationDao {
- @Upsert
- suspend fun upsert(mantraTranslation: MantraTranslation)
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MarmotInnerEventDao.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MarmotInnerEventDao.kt
index 8867b41c..55e790a6 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MarmotInnerEventDao.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/MarmotInnerEventDao.kt
@@ -65,12 +65,4 @@ interface MarmotInnerEventDao {
@Query("DELETE FROM MarmotInnerEvent WHERE id = :id")
suspend fun deleteById(id: String)
- /**
- * Drop the submissions carrying [payloadEventId].
- *
- * A submission's id is the envelope's, not the payload's, so a superseded
- * nip30303 event cannot be un-queued by its own id.
- */
- @Query("DELETE FROM MarmotInnerEvent WHERE payloadEventId = :payloadEventId")
- suspend fun deleteByPayloadEventId(payloadEventId: String)
}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/NostrDao.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/NostrDao.kt
index ac1381d7..2b5bd3ac 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/NostrDao.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/dao/NostrDao.kt
@@ -1531,8 +1531,12 @@ abstract class NostrDao(
is GroupEventResult.ProposalStaged -> {
database.marmotOutboundDao().commitStagedProposals(localChatRoom)
}
+ // Every application message lands here -- chat, documents, and the
+ // ceremony and signing messages handled just below. Debug, because at
+ // info it read like a failure on each of them and sent at least one
+ // investigation the wrong way.
else -> {
- logger.i("No app logic to handle: $groupEventResult")
+ logger.d("No membership change to file for: $groupEventResult")
}
}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/migrations/RemoveDocumentsMigration.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/migrations/RemoveDocumentsMigration.kt
new file mode 100644
index 00000000..c936df0b
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/migrations/RemoveDocumentsMigration.kt
@@ -0,0 +1,80 @@
+package com.machankura.bennu.compose.database.migrations
+
+import androidx.room3.migration.Migration
+import androidx.sqlite.SQLiteConnection
+import androidx.sqlite.execSQL
+
+/**
+ * Drops the nip30303 document tables, and the chat lines nothing can show any more.
+ *
+ * The artifact, chapter, dialect and translation screens were unreachable, and
+ * their kinds shared numbers with the key ceremony's: a subgroup's round 1 (30312)
+ * was read as a document submission and landed in the parent's chat as raw hex.
+ * See docs/ceremony-creation.md, Phases 7 and 8.
+ *
+ * Manual rather than an `AutoMigration`, because it deletes chat rows as well as
+ * changing shape:
+ *
+ * - the lines the removed document arms wrote (`artifact`, `chapter`, `dialect`,
+ * `translationArtifactVersion`, `translation`), which nothing renders now;
+ * - the `unsupported` lines written for a ceremony's own messages. They are the
+ * raw-hex bubbles above, found by the kind of the inner event behind them, and
+ * only those: an `unsupported` line over any other kind is still the only trace
+ * an unrecognised payload leaves, and stays.
+ *
+ * Then the twelve tables, children before parents. No kept table has a foreign key
+ * into any of them, so nothing outside them cascades; the order is so the drops
+ * hold if foreign keys are ever enforced during a migration. And
+ * `MarmotInnerEvent.payloadEventId`, which only a submission ever set.
+ *
+ * `DROP COLUMN` is safe for the reason `ChronicleRenameMigration` gives for
+ * `RENAME COLUMN`: `getRoomDatabase` pins `BundledSQLiteDriver` on every platform,
+ * so the SQLite underneath is one this app chose. The column has no index and is
+ * in no foreign key, either of which SQLite would refuse to drop it from.
+ *
+ * `GroupSignedEvent` keeps any rows of the document kinds. The table is generic
+ * and keyed by kind, nothing reads those kinds any more, and deleting what a group
+ * signed is not this migration's call. The chronicle's column and its lines stay
+ * too: the chronicle is kept, carrying nothing.
+ */
+val MIGRATION_26_27 = object : Migration(26, 27) {
+ override suspend fun migrate(connection: SQLiteConnection) {
+ connection.execSQL(
+ "DELETE FROM `ChatMessage` WHERE `messageType` IN " +
+ "('artifact', 'chapter', 'dialect', 'translationArtifactVersion', 'translation')"
+ )
+ connection.execSQL(
+ "DELETE FROM `ChatMessage` WHERE `messageType` = 'unsupported' " +
+ "AND `marmotInnerEventId` IN (" +
+ "SELECT `id` FROM `MarmotInnerEvent` WHERE `kind` BETWEEN $FIRST_CEREMONY_KIND AND $LAST_CEREMONY_KIND)"
+ )
+
+ DOCUMENT_TABLES.forEach { table -> connection.execSQL("DROP TABLE IF EXISTS `$table`") }
+
+ connection.execSQL("ALTER TABLE `MarmotInnerEvent` DROP COLUMN `payloadEventId`")
+ }
+}
+
+/**
+ * The ceremony's kinds, written out rather than read from `DkgRitualEvents`: a
+ * migration has to keep meaning what it meant when it shipped, whatever the
+ * constants later say.
+ */
+private const val FIRST_CEREMONY_KIND = 30310
+private const val LAST_CEREMONY_KIND = 30316
+
+/** Children before parents. */
+internal val DOCUMENT_TABLES = listOf(
+ "MantraTranslationContributor",
+ "MantraTranslation",
+ "MantraTranslationArtifactVersionContributor",
+ "MantraTranslationChapterContributor",
+ "MantraTranslationChunk",
+ "MantraTranslationChapter",
+ "MantraTranslationArtifactVersion",
+ "MantraChunk",
+ "MantraChapter",
+ "MantraArtifactVersion",
+ "MantraArtifact",
+ "MantraDialect",
+)
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/ChatMessage.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/ChatMessage.kt
index 8d442022..0ad56b00 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/ChatMessage.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/ChatMessage.kt
@@ -35,20 +35,8 @@ import com.machankura.bennu.compose.nostr.subgroup.SubgroupBirthCertificateEvent
import com.machankura.bennu.compose.nostr.wallet.GroupWallet
import com.machankura.bennu.compose.nostr.wallet.GroupWalletStatementEvent
import com.machankura.bennu.compose.nostr.wallet.GuardedWalletNoticeEvent
-import com.machankura.bennu.compose.nostr.nip30303.ArtifactEvent
-import com.machankura.bennu.compose.nostr.nip30303.ArtifactVersionEvent
-import com.machankura.bennu.compose.nostr.nip30303.ChapterEvent
-import com.machankura.bennu.compose.nostr.nip30303.ChunkEvent
-import com.machankura.bennu.compose.nostr.nip30303.DialectEvent
import com.machankura.bennu.compose.nostr.chronicle.ChronicleEvent
import com.machankura.bennu.compose.nostr.chronicle.ChronicleRequestEvent
-import com.machankura.bennu.compose.nostr.nip30303.SubmissionEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationArtifactVersionContributorListEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationArtifactVersionEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationChapterEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationChunkEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationContributorListEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationEvent
import co.touchlab.kermit.Logger
import com.vitorpamplona.quartz.nip01Core.core.firstTagValue
import com.vitorpamplona.quartz.nip59Giftwrap.wraps.GiftWrapEvent
@@ -891,24 +879,17 @@ data class ChatMessage(
val event = Event.fromJsonOrNull(groupEventResult.innerEventJson)
?: throw MarmotUnprocessableInnerEventException("Can't process ${groupEventResult.innerEventJson}")
- // A submission is an envelope: the nip30303 event it delivers
- // is in its content, written by whoever wrote it. Everything
- // else on the wire is the nip30303 event itself. Either way the
- // row on disk is the outer event -- that is what the group sent
- // and what the chat line is attributed to.
- val submission = if (event.kind == SubmissionEvent.KIND) {
- SubmissionEvent(
- id = event.id,
- pubKey = event.pubKey,
- createdAt = event.createdAt,
- tags = event.tags,
- content = event.content,
- sig = event.sig,
- )
- } else {
- null
- }
- val payload = submission?.payload()
+ // A key ceremony's or a signing session's own message. Decided
+ // first: 30310-30312 were nip30303 document kinds too, and round
+ // 1 of a subgroup's ceremony (30312) was read as a document
+ // submission, failed to parse, and landed in the parent's chat
+ // as raw hex -- see docs/ceremony-creation.md, finding F11. Stored like
+ // every inner event, so a ceremony can replay what arrived
+ // before its proposal; acted on by the managers
+ // `NostrDao.fileGroupEventResult` dispatches to, which write
+ // their own transcript lines.
+ val isProtocolMessage = event.kind in DkgRitualEvents.ALL ||
+ event.kind in FrostSigningEvents.ALL
database.marmotInnerEventDao().upsert(
MarmotInnerEvent(
@@ -919,12 +900,13 @@ data class ChatMessage(
content = event.content,
chatRoomId = groupEventResult.groupId,
kind = event.kind,
- payloadEventId = payload?.id,
createdAt = Instant.fromEpochSeconds(event.createdAt)
)
)
- // A direct message is not a nip30303 payload to apply. It is
+ if (isProtocolMessage) return null
+
+ // A direct message is not a payload to apply. It is
// gift wrapped for one member, and what this device does with it
// depends only on whether its key opens it. A legacy room carries
// the wrap itself; a current-profile room carries it inside an
@@ -1022,33 +1004,16 @@ data class ChatMessage(
return null
}
- // A submission whose payload will not parse, or which carries
- // another submission, is kept but not applied: there is nothing
- // here we can turn into a row.
- if (submission != null && (payload == null || payload.kind == SubmissionEvent.KIND)) {
- ChatMessage(
- giftWrapPayloadId = null,
- messageType = "unsupported",
- marmotGroupEventId = groupEvent.id,
- marmotInnerEventId = event.id,
- senderPublicKey = event.pubKey,
- isUserMessage = senderIdentity == activeKeyPair.pubKey.toHex(),
- chatRoomId = groupEventResult.groupId,
- createdAt = Instant.fromEpochSeconds(event.createdAt),
- content = event.content,
- )
- } else {
- applyInnerEvent(
- database = database,
- groupId = groupEventResult.groupId,
- event = payload ?: event,
- marmotGroupEventId = groupEvent.id,
- marmotInnerEventId = event.id,
- senderPublicKey = event.pubKey,
- isUserMessage = senderIdentity == activeKeyPair.pubKey.toHex(),
- createdAt = Instant.fromEpochSeconds(event.createdAt),
- )
- }
+ applyInnerEvent(
+ database = database,
+ groupId = groupEventResult.groupId,
+ event = event,
+ marmotGroupEventId = groupEvent.id,
+ marmotInnerEventId = event.id,
+ senderPublicKey = event.pubKey,
+ isUserMessage = senderIdentity == activeKeyPair.pubKey.toHex(),
+ createdAt = Instant.fromEpochSeconds(event.createdAt),
+ )
}
is GroupEventResult.CommitPending -> {
ChatMessage(
@@ -1142,16 +1107,12 @@ data class ChatMessage(
}
/**
- * Apply one nip30303 [event] the group delivered, and describe it for
- * the transcript.
+ * Apply one [event] the group delivered, and describe it for the
+ * transcript.
*
* [event] is what is being applied; the other parameters are how it
- * arrived. They come apart for submissions: the payload is written by
- * whoever wrote it -- possibly nobody in this group -- while
- * [marmotInnerEventId], [senderPublicKey] and [createdAt] all belong to
- * the envelope a member actually sent. Entity rows take their author
- * from [event], so the chat line says who added it and the row says who
- * wrote it.
+ * arrived -- [marmotInnerEventId], [senderPublicKey] and [createdAt]
+ * belong to the message a member actually sent.
*
* [groupSignedEventId] is the third way in, and the one with no
* envelope at all: a `GroupSignedEvent` the group put its own signature
@@ -1189,327 +1150,11 @@ data class ChatMessage(
)
return when (event.kind) {
- ChatEvent.KIND -> {
- ChatMessage(
- giftWrapPayloadId = null,
- messageType = "message",
- marmotGroupEventId = marmotGroupEventId,
- marmotInnerEventId = marmotInnerEventId,
- senderPublicKey = senderPublicKey,
- isUserMessage = isUserMessage,
- chatRoomId = groupId,
- createdAt = createdAt,
- content = event.content, // TODO: Figure out what to do here...
- )
- }
- ArtifactEvent.KIND -> {
- val artifactEvent = ArtifactEvent(
- id = event.id,
- pubKey = event.pubKey,
- createdAt = event.createdAt,
- tags = event.tags,
- content = event.content,
- sig = event.sig,
- )
-
- MantraArtifact.fromArtifactEvent(
- artifactEvent = artifactEvent,
- chatRoomId = groupId,
- )?.let { mantraArtifact ->
- database.mantraArtifactDao().upsert(
- mantraArtifact.copy(
- marmotGroupEventId = marmotGroupEventId,
- groupSignedEventId = groupSignedEventId,
- )
- )
-
- // The version the artifact starts life with is its own
- // event, signed in the same batch and applied after this
- // one -- see AddArtifactViewModel.addArtifact. It used to
- // be derived here instead; deriving it now as well would
- // stand a second, unsigned version row against the same
- // artifact, since the two hash differently.
-
- ChatMessage(
- giftWrapPayloadId = null,
- messageType = "artifact",
- marmotGroupEventId = marmotGroupEventId,
- marmotInnerEventId = marmotInnerEventId,
- senderPublicKey = senderPublicKey,
- isUserMessage = isUserMessage,
- chatRoomId = groupId,
- createdAt = createdAt,
- content = "Added ${mantraArtifact.name} to artifacts"
- )
- }
- }
- ArtifactVersionEvent.KIND -> {
- MantraArtifactVersion.fromArtifactVersionEvent(
- artifactVersionEvent = ArtifactVersionEvent(
- id = event.id,
- pubKey = event.pubKey,
- createdAt = event.createdAt,
- tags = event.tags,
- content = event.content,
- sig = event.sig
- ),
- chatRoomId = groupId,
- )?.let { mantraArtifactVersion ->
- database.mantraArtifactVersionDao().upsert(
- mantraArtifactVersion.copy(
- marmotGroupEventId = marmotGroupEventId,
- groupSignedEventId = groupSignedEventId,
- )
- )
-
- // No line of its own. A version arrives as the second
- // item of the batch that carries its artifact, and the
- // artifact has already said so -- the same reason a
- // chunk writes no line beside its chapter. While the
- // version was derived here rather than signed it wrote
- // none either, so this is the transcript standing still
- // rather than losing something.
- }
- null
- }
- ChapterEvent.KIND -> {
- // The chunks the chapter splits into are their own events,
- // signed in the same session and applied after it -- see
- // AddChapterViewModel.addChapter. Nothing to do here but the
- // chapter itself.
- MantraChapter.fromChapterEvent(
- chapterEvent = ChapterEvent(
- id = event.id,
- pubKey = event.pubKey,
- createdAt = event.createdAt,
- tags = event.tags,
- content = event.content,
- sig = event.sig
- ),
- chatRoomId = groupId,
- )?.let { mantraChapter ->
- database.mantraChapterDao().upsert(
- mantraChapter.copy(
- marmotGroupEventId = marmotGroupEventId,
- groupSignedEventId = groupSignedEventId,
- )
- )
-
- ChatMessage(
- giftWrapPayloadId = null,
- messageType = "chapter",
- marmotGroupEventId = marmotGroupEventId,
- marmotInnerEventId = marmotInnerEventId,
- senderPublicKey = senderPublicKey,
- isUserMessage = isUserMessage,
- chatRoomId = groupId,
- createdAt = createdAt,
- content = "Added ${mantraChapter.name} to chapters" // TODO: Use artifact name...
- )
- }
- }
-
- ChunkEvent.KIND -> {
- MantraChunk.fromChunkEvent(
- chunkEvent = ChunkEvent(
- id = event.id,
- pubKey = event.pubKey,
- createdAt = event.createdAt,
- tags = event.tags,
- content = event.content,
- sig = event.sig
- ),
- chatRoomId = groupId,
- )?.let { mantraChunk ->
- database.mantraChunkDao().upsert(
- mantraChunk.copy(
- marmotGroupEventId = marmotGroupEventId,
- groupSignedEventId = groupSignedEventId,
- )
- )
-
- // TODO: Chunks might be too noisy to show in chat...
- }
- null
- }
- DialectEvent.KIND -> {
- MantraDialect.fromDialectEvent(
- dialectEvent = DialectEvent(
- id = event.id,
- pubKey = event.pubKey,
- createdAt = event.createdAt,
- tags = event.tags,
- content = event.content,
- sig = event.sig
- ),
- chatRoomId = groupId,
- )?.let { mantraDialect ->
- database.mantraDialectDao().upsert(
- mantraDialect.copy(
- marmotGroupEventId = marmotGroupEventId,
- groupSignedEventId = groupSignedEventId,
- )
- )
-
-
- ChatMessage(
- giftWrapPayloadId = null,
- messageType = "dialect",
- marmotGroupEventId = marmotGroupEventId,
- marmotInnerEventId = marmotInnerEventId,
- senderPublicKey = senderPublicKey,
- isUserMessage = isUserMessage,
- chatRoomId = groupId,
- createdAt = createdAt,
- content = "Added ${mantraDialect.name} to dialects" // TODO: Use artifact name...
- )
- }
- }
- TranslationArtifactVersionEvent.KIND -> {
- MantraTranslationArtifactVersion.fromTranslationArtifactVersionEvent(
- translationArtifactVersionEvent = TranslationArtifactVersionEvent(
- id = event.id,
- pubKey = event.pubKey,
- createdAt = event.createdAt,
- tags = event.tags,
- content = event.content,
- sig = event.sig
- ),
- chatRoomId = groupId,
- )?.let { mantraTranslationArtifactVersion ->
- database.mantraTranslationArtifactVersionDao().upsert(
- mantraTranslationArtifactVersion.copy(
- marmotGroupEventId = marmotGroupEventId,
- groupSignedEventId = groupSignedEventId,
- )
- )
-
- ChatMessage(
- giftWrapPayloadId = null,
- messageType = "translationArtifactVersion",
- marmotGroupEventId = marmotGroupEventId,
- marmotInnerEventId = marmotInnerEventId,
- senderPublicKey = senderPublicKey,
- isUserMessage = isUserMessage,
- chatRoomId = groupId,
- createdAt = createdAt,
- content = "Added ${mantraTranslationArtifactVersion.name} to translation artifact versions" // TODO: Use artifact name...
- )
- }
- }
- TranslationArtifactVersionContributorListEvent.KIND -> {
- // TODO: Consume contributors...
- null
- }
- TranslationChapterEvent.KIND -> {
- MantraTranslationChapter.fromTranslationChapterEvent(
- translationChapterEvent = TranslationChapterEvent(
- id = event.id,
- pubKey = event.pubKey,
- createdAt = event.createdAt,
- tags = event.tags,
- content = event.content,
- sig = event.sig
- ),
- chatRoomId = groupId,
- )?.let { mantraTranslationChapter ->
- database.mantraTranslationChapterDao().upsert(
- mantraTranslationChapter.copy(
- marmotGroupEventId = marmotGroupEventId,
- groupSignedEventId = groupSignedEventId,
- )
- )
- // TODO: translation chapter might be too noisy for chat updates
- }
- null
- }
- TranslationChunkEvent.KIND -> {
- MantraTranslationChunk.fromTranslationChunkEvent(
- translationChunkEvent = TranslationChunkEvent(
- id = event.id,
- pubKey = event.pubKey,
- createdAt = event.createdAt,
- tags = event.tags,
- content = event.content,
- sig = event.sig
- ),
- chatRoomId = groupId,
- )?.let { mantraTranslationChunk ->
- // One translation per source chunk. Retranslating changes
- // the text and so the event's id, which makes it a new
- // event rather than an edit of the old one -- so the one
- // it supersedes is dropped here, or a passage would have
- // two answers to what it says and the reader would be
- // shown whichever the query happened to reach first.
- //
- // Newest wins by the timestamp the group signed at, not by
- // when it arrived, with the id breaking a tie. Two devices
- // catching up read the same events in whatever order the
- // relay hands them over, and they have to end up holding
- // the same translation either way.
- val existing = database.mantraTranslationChunkDao()
- .getTranslationChunksByChunkId(
- translationChapterId = mantraTranslationChunk.translationChapterId,
- chunkId = mantraTranslationChunk.chunkId,
- )
- .filterNot { it.id == mantraTranslationChunk.id }
-
- val isNewest = existing.none {
- it.createdAt > mantraTranslationChunk.createdAt ||
- (it.createdAt == mantraTranslationChunk.createdAt &&
- it.id > mantraTranslationChunk.id)
- }
-
- if (isNewest) {
- existing.forEach {
- database.mantraTranslationChunkDao().deleteById(it.id)
- }
-
- database.mantraTranslationChunkDao().upsert(
- mantraTranslationChunk.copy(
- marmotGroupEventId = marmotGroupEventId,
- groupSignedEventId = groupSignedEventId,
- )
- )
- }
- }
- null
- }
- TranslationContributorListEvent.KIND -> {
- // TODO: Consume contributors...
- null
- }
- TranslationEvent.KIND -> {
- MantraTranslation.fromTranslationEvent(
- translationEvent = TranslationEvent(
- id = event.id,
- pubKey = event.pubKey,
- createdAt = event.createdAt,
- tags = event.tags,
- content = event.content,
- sig = event.sig
- ),
- chatRoomId = groupId,
- )?.let { mantraTranslation ->
- database.mantraTranslationDao().upsert(
- mantraTranslation.copy(
- marmotGroupEventId = marmotGroupEventId,
- groupSignedEventId = groupSignedEventId,
- )
- )
- ChatMessage(
- giftWrapPayloadId = null,
- messageType = "translation",
- marmotGroupEventId = marmotGroupEventId,
- marmotInnerEventId = marmotInnerEventId,
- senderPublicKey = senderPublicKey,
- isUserMessage = isUserMessage,
- chatRoomId = groupId,
- createdAt = createdAt,
- content = "Added ${mantraTranslation.text} to translations" // TODO: Reference original text
- )
- }
- }
+ // First, above every content kind: protocol kinds are never
+ // content, whatever else might share their number, and a `when`
+ // takes the first arm that matches. The ceremony's 30310 and 30311
+ // once reached document arms that sat above this one.
+ //
// A signing session's own protocol messages. FrostSigningManager
// applies them and writes its own transcript lines naming who did
// what, so an "unsupported" row here would be a second, worse
@@ -1531,6 +1176,19 @@ data class ChatMessage(
// none of their business.
in DkgRitualEvents.ALL -> null
+ ChatEvent.KIND -> {
+ ChatMessage(
+ giftWrapPayloadId = null,
+ messageType = "message",
+ marmotGroupEventId = marmotGroupEventId,
+ marmotInnerEventId = marmotInnerEventId,
+ senderPublicKey = senderPublicKey,
+ isUserMessage = isUserMessage,
+ chatRoomId = groupId,
+ createdAt = createdAt,
+ content = event.content, // TODO: Figure out what to do here...
+ )
+ }
// The group saying what key one of its rooms signs with, arriving
// here the way every group-signed event does: applied by
// `FrostSigningManager` once a quorum has signed the proposal it
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraArtifact.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraArtifact.kt
deleted file mode 100644
index db1cdfb4..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraArtifact.kt
+++ /dev/null
@@ -1,163 +0,0 @@
-package com.machankura.bennu.compose.database.model
-
-import androidx.room3.Entity
-import androidx.room3.ForeignKey
-import androidx.room3.PrimaryKey
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
-import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
-import com.vitorpamplona.quartz.nip31Alts.AltTag
-import com.machankura.bennu.compose.database.model.traits.OptionalNostrEventEntity
-import com.machankura.bennu.compose.database.model.traits.TimestampedEntity
-import com.machankura.bennu.compose.nostr.nip30303.ArtifactEvent
-import com.machankura.bennu.compose.nostr.nip30303.tags.ArtifactVersionMetadataTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.DialectIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.LicenseTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.UrlTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.VisibilityTag
-import kotlin.time.Clock
-import kotlin.time.Instant
-
-/**
- * 30300
- */
-@Entity(
- foreignKeys = [
- ForeignKey(
- entity = MantraDialect::class,
- parentColumns = ["id"],
- childColumns = ["dialectId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ForeignKey(
- entity = ChatRoom::class,
- parentColumns = ["id"],
- childColumns = ["chatRoomId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ]
-)
-data class MantraArtifact(
- @PrimaryKey
- val id: HexKey,
- val publicKey: String,
- val name: String,
- val url: String, // Hash this to get the dTag...
- val visibility: String, // public, private, permissioned (public, but only members can contribute)
- val dialectId: String,
- val license: String,
-// val artifactApprovalId: String,
-
- val chatRoomId: String,
-
- /**
- * Signature will be an empty string if this is a rumor
- */
- val signature: String,
-
- val relayHint: String? = null,
-
- val marmotGroupEventId: HexKey? = null,
-
- /** The [GroupSignedEvent] this row was made from, when the group signed it. */
- val groupSignedEventId: HexKey? = null,
- /**
- * Related nostrEventId if this is not a rumor...
- */
- override val nostrEventId: HexKey? = null,
- override val createdAt: Instant = Clock.System.now(),
- override val updatedAt: Instant = createdAt
-): OptionalNostrEventEntity, TimestampedEntity {
- /**
- * The event the group signed, rebuilt from this row.
- *
- * [versionLabel] is a parameter because it is not on this row and cannot be.
- * `fromArtifactEvent` reads the artifact's own fields and drops the version
- * metadata, which `ChatMessage.applyInnerEvent` has by then turned into the
- * artifact's first `MantraArtifactVersion`. It was still part of what the
- * group put its signature to, so a rebuild without it hashes to a different
- * id and produces an event the signature does not cover -- which a receiver
- * reads as a forgery, silently. Recover it from the initial version: the one
- * whose `createdAt` is this artifact's, since `initialVersionOf` derives it
- * from the same event.
- *
- * Tag order matches [ArtifactEvent.build] exactly -- alt first -- for the
- * same reason, and `ChronicleRoundTripTest` is what says so. Both of those were
- * wrong here until a chronicle needed to rebuild an artifact and nothing had
- * ever called this.
- */
- @Deprecated(
- "Chronicle fallback for work signed before the GroupSignedEvent table. Read the " +
- "event off that table instead; this rebuild goes when the last pre-v13 install " +
- "does -- see the removal checklist in docs/member-chronicle.md."
- )
- fun toArtifactEvent(versionLabel: String): ArtifactEvent {
- return ArtifactEvent(
- id = id,
- pubKey = publicKey,
- createdAt = createdAt.epochSeconds,
- // Tag order matches ArtifactEvent.build so the event id round-trips.
- tags = TagArrayBuilder()
- .addUnique(
- AltTag.assemble(ArtifactEvent.ALT_DESCRIPTION)
- )
- .addUnique(UrlTag.assemble(url))
- .addUnique(VisibilityTag.assemble(visibility))
- .addUnique(LicenseTag.assemble(license))
- .addUnique(
- DialectIdTag.assemble(dialectId)
- )
- .addUnique(
- ArtifactVersionMetadataTag.assemble(versionLabel)
- )
- .build(),
- content = name,
- sig = signature
- )
- }
-
- companion object {
- fun fromArtifactEventTemplate(artifactEventTemplate: EventTemplate, chatRoomId: HexKey, userPublicKey: HexKey): MantraArtifact? {
- return fromArtifactEvent(
- ArtifactEvent(
- id = EventHasher.hashId(
- pubKey = userPublicKey, // TODO: get pub key...
- tags = artifactEventTemplate.tags,
- content = artifactEventTemplate.content,
- createdAt = artifactEventTemplate.createdAt,
- kind = artifactEventTemplate.kind
- ),
- content = artifactEventTemplate.content,
- tags = artifactEventTemplate.tags,
- createdAt = artifactEventTemplate.createdAt,
- pubKey = userPublicKey,
- sig = "" // Unsigned....
- ),
- chatRoomId = chatRoomId
- )
- }
- fun fromArtifactEvent(artifactEvent: ArtifactEvent, chatRoomId: HexKey, ): MantraArtifact? {
- return artifactEvent.url()?.let { url ->
- artifactEvent.visibility()?.let { visibility ->
- artifactEvent.license()?.let { license ->
- artifactEvent.dialectId()?.let { dialectId ->
- MantraArtifact(
- id = artifactEvent.id,
- publicKey = artifactEvent.pubKey,
- dialectId = dialectId,
- createdAt = Instant.fromEpochSeconds(artifactEvent.createdAt),
- url = url,
- license = license,
- visibility = visibility,
- name = artifactEvent.content,
- signature = artifactEvent.sig,
- chatRoomId = chatRoomId
- )
- }
- }
- }
- }
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraArtifactVersion.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraArtifactVersion.kt
deleted file mode 100644
index b73ccb1e..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraArtifactVersion.kt
+++ /dev/null
@@ -1,135 +0,0 @@
-package com.machankura.bennu.compose.database.model
-
-import androidx.room3.Entity
-import androidx.room3.ForeignKey
-import androidx.room3.PrimaryKey
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
-import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
-import com.vitorpamplona.quartz.nip31Alts.AltTag
-import com.machankura.bennu.compose.database.model.traits.OptionalNostrEventEntity
-import com.machankura.bennu.compose.database.model.traits.TimestampedEntity
-import com.machankura.bennu.compose.nostr.nip30303.ArtifactVersionEvent
-import com.machankura.bennu.compose.nostr.nip30303.tags.ArtifactIdTag
-import kotlin.time.Clock
-import kotlin.time.Instant
-
-/**
- * 30301
- */
-@Entity(
- foreignKeys = [
- ForeignKey(
- entity = MantraArtifact::class,
- parentColumns = ["id"],
- childColumns = ["artifactId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ForeignKey(
- entity = ChatRoom::class,
- parentColumns = ["id"],
- childColumns = ["chatRoomId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ],
-)
-data class MantraArtifactVersion(
- @PrimaryKey
- val id: HexKey,
- val artifactId: HexKey,
- val publicKey: HexKey,
-
- /**
- * Version Tag...
- */
- val versionLabel: String,
-
- /**
- * Signature will be an empty string if this is a rumor
- */
- val signature: String,
-
- val chatRoomId: String,
-
- val relayHint: String? = null,
- val marmotGroupEventId: HexKey? = null,
-
- /** The [GroupSignedEvent] this row was made from, when the group signed it. */
- val groupSignedEventId: HexKey? = null,
-
- /**
- * Related nostrEventId if this is not a rumor...
- */
- override val nostrEventId: HexKey? = null,
-
- override val createdAt: Instant = Clock.System.now(),
- override val updatedAt: Instant = createdAt
-): OptionalNostrEventEntity, TimestampedEntity {
- @Deprecated(
- "Chronicle fallback for work signed before the GroupSignedEvent table. Read the " +
- "event off that table instead; this rebuild goes when the last pre-v13 install " +
- "does -- see the removal checklist in docs/member-chronicle.md."
- )
- fun toArtifactVersionEvent(): ArtifactVersionEvent {
- return ArtifactVersionEvent(
- id = id,
- pubKey = publicKey,
- createdAt = createdAt.epochSeconds,
- // Tag order matches ArtifactVersionEvent.initialVersionOf, which puts
- // the alt first because `build` does, or the event id does not
- // round-trip. It was the other way round here for as long as nothing
- // called this -- see ChronicleRoundTripTest, which is what calls it now.
- tags = TagArrayBuilder()
- .addUnique(
- AltTag.assemble(ArtifactVersionEvent.ALT_DESCRIPTION)
- )
- .addUnique(
- ArtifactIdTag.assemble(artifactId)
- )
- .build(),
- content = versionLabel,
- sig = signature
- )
- }
-
- companion object {
- fun fromArtifactVersionEventTemplate(
- artifactVersionEventTemplate: EventTemplate,
- chatRoomId: HexKey,
- userPublicKey: HexKey,
- ): MantraArtifactVersion? {
- return fromArtifactVersionEvent(
- ArtifactVersionEvent(
- id = EventHasher.hashId(
- pubKey = userPublicKey,
- tags = artifactVersionEventTemplate.tags,
- content = artifactVersionEventTemplate.content,
- createdAt = artifactVersionEventTemplate.createdAt,
- kind = artifactVersionEventTemplate.kind,
- ),
- content = artifactVersionEventTemplate.content,
- tags = artifactVersionEventTemplate.tags,
- createdAt = artifactVersionEventTemplate.createdAt,
- pubKey = userPublicKey,
- sig = "", // Unsigned rumor
- ),
- chatRoomId = chatRoomId,
- )
- }
-
- fun fromArtifactVersionEvent(artifactVersionEvent: ArtifactVersionEvent, chatRoomId: HexKey, ): MantraArtifactVersion? {
- return artifactVersionEvent.artifactId()?.let { artifactId ->
- MantraArtifactVersion(
- id = artifactVersionEvent.id,
- publicKey = artifactVersionEvent.pubKey,
- createdAt = Instant.fromEpochSeconds(artifactVersionEvent.createdAt),
- artifactId = artifactId,
- versionLabel = artifactVersionEvent.content,
- signature = artifactVersionEvent.sig,
- chatRoomId = chatRoomId
- )
- }
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraChapter.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraChapter.kt
deleted file mode 100644
index 4d86b31c..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraChapter.kt
+++ /dev/null
@@ -1,157 +0,0 @@
-package com.machankura.bennu.compose.database.model
-
-import androidx.room3.Entity
-import androidx.room3.ForeignKey
-import androidx.room3.PrimaryKey
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
-import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
-import com.vitorpamplona.quartz.nip31Alts.AltTag
-import com.machankura.bennu.compose.database.model.traits.OptionalNostrEventEntity
-import com.machankura.bennu.compose.database.model.traits.TimestampedEntity
-import com.machankura.bennu.compose.nostr.nip30303.ChapterEvent
-import com.machankura.bennu.compose.nostr.nip30303.tags.ArtifactVersionIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.IndexTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.NameTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.OriginalTextTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.WordStatisticsTag
-import kotlin.time.Clock
-import kotlin.time.Instant
-
-/**
- * 30302
- */
-@Entity(
- foreignKeys = [
- ForeignKey(
- entity = MantraArtifactVersion::class,
- parentColumns = ["id"],
- childColumns = ["artifactVersionId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ForeignKey(
- entity = ChatRoom::class,
- parentColumns = ["id"],
- childColumns = ["chatRoomId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ],
-)
-data class MantraChapter(
- @PrimaryKey
- val id: HexKey,
- val artifactVersionId: HexKey,
- val publicKey: HexKey,
- val name: String,
- val originalText: String,
- val index: Int,
- val wordCount: Int,
- val characterCount: Int,
-
- /**
- * Signature will be an empty string if this is a rumor
- */
- val signature: String,
-
- val chatRoomId: String,
-
- val relayHint: String? = null,
- val marmotGroupEventId: HexKey? = null,
-
- /** The [GroupSignedEvent] this row was made from, when the group signed it. */
- val groupSignedEventId: HexKey? = null,
-
- /**
- * Related nostrEventId if this is not a rumor...
- */
- override val nostrEventId: HexKey? = null,
-
- override val createdAt: Instant = Clock.System.now(),
- override val updatedAt: Instant = createdAt
-): OptionalNostrEventEntity, TimestampedEntity {
-
- @Deprecated(
- "Chronicle fallback for work signed before the GroupSignedEvent table. Read the " +
- "event off that table instead; this rebuild goes when the last pre-v13 install " +
- "does -- see the removal checklist in docs/member-chronicle.md."
- )
- fun toChapterEvent(): ChapterEvent {
- return ChapterEvent(
- id = id,
- pubKey = publicKey,
- createdAt = createdAt.epochSeconds,
- // Tag order matches ChapterEvent.build so the event id round-trips.
- tags = TagArrayBuilder()
- .addUnique(AltTag.assemble(ChapterEvent.ALT_DESCRIPTION))
- .addUnique(
- ArtifactVersionIdTag.assemble(artifactVersionId)
- )
- .addUnique(NameTag.assemble(name))
- .addUnique(OriginalTextTag.assemble(originalText))
- .addUnique(
- IndexTag.assemble(
- index
- )
- )
- .addUnique(
- WordStatisticsTag.assemble(wordCount, characterCount)
- )
- .build(),
- content = "",
- sig = signature
- )
- }
-
- companion object {
- fun fromChapterEventTemplate(
- chapterEventTemplate: EventTemplate,
- chatRoomId: HexKey,
- userPublicKey: HexKey,
- ): MantraChapter? {
- return fromChapterEvent(
- ChapterEvent(
- id = EventHasher.hashId(
- pubKey = userPublicKey,
- tags = chapterEventTemplate.tags,
- content = chapterEventTemplate.content,
- createdAt = chapterEventTemplate.createdAt,
- kind = chapterEventTemplate.kind,
- ),
- content = chapterEventTemplate.content,
- tags = chapterEventTemplate.tags,
- createdAt = chapterEventTemplate.createdAt,
- pubKey = userPublicKey,
- sig = "", // Unsigned rumor
- ),
- chatRoomId = chatRoomId,
- )
- }
-
- fun fromChapterEvent(chapterEvent: ChapterEvent, chatRoomId: HexKey): MantraChapter? {
- return chapterEvent.name()?.let { name ->
- chapterEvent.originalText()?.let { originalText ->
- chapterEvent.wordStatisticsTag?.let { wordStatisticsTag ->
- chapterEvent.artifactVersionId()?.let { artifactId ->
- chapterEvent.index()?.let { index ->
- MantraChapter(
- id = chapterEvent.id,
- publicKey = chapterEvent.pubKey,
- createdAt = Instant.fromEpochSeconds(chapterEvent.createdAt),
- artifactVersionId = artifactId,
- name = name,
- originalText = originalText,
- index = index,
- wordCount = wordStatisticsTag.wordCount,
- characterCount = wordStatisticsTag.characterCount,
- signature = chapterEvent.sig,
- chatRoomId = chatRoomId
- )
- }
- }
- }
- }
- }
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraChunk.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraChunk.kt
deleted file mode 100644
index f71f451d..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraChunk.kt
+++ /dev/null
@@ -1,147 +0,0 @@
-package com.machankura.bennu.compose.database.model
-
-import androidx.room3.Entity
-import androidx.room3.ForeignKey
-import androidx.room3.PrimaryKey
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
-import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
-import com.vitorpamplona.quartz.nip31Alts.AltTag
-import com.machankura.bennu.compose.database.model.traits.OptionalNostrEventEntity
-import com.machankura.bennu.compose.database.model.traits.TimestampedEntity
-import com.machankura.bennu.compose.nostr.nip30303.ChunkEvent
-import com.machankura.bennu.compose.nostr.nip30303.tags.ChapterIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.IndexTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.WordStatisticsTag
-import kotlin.time.Clock
-import kotlin.time.Instant
-
-/**
- * 30303
- */
-@Entity(
- foreignKeys = [
- ForeignKey(
- entity = MantraChapter::class,
- parentColumns = ["id"],
- childColumns = ["chapterId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ForeignKey(
- entity = ChatRoom::class,
- parentColumns = ["id"],
- childColumns = ["chatRoomId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ],
-)
-data class MantraChunk(
- @PrimaryKey
- val id: HexKey,
- val chapterId: HexKey,
- val publicKey: HexKey,
- val text: String,
- val index: Int,
- val wordCount: Int,
- val characterCount: Int,
-
- /**
- * Signature will be an empty string if this is a rumor
- */
- val signature: String,
-
- val chatRoomId: String,
-
- val relayHint: String? = null,
- val marmotGroupEventId: HexKey? = null,
-
- /** The [GroupSignedEvent] this row was made from, when the group signed it. */
- val groupSignedEventId: HexKey? = null,
-
- /**
- * Related nostrEventId if this is not a rumor...
- */
- override val nostrEventId: HexKey? = null,
- override val createdAt: Instant = Clock.System.now(),
- override val updatedAt: Instant = createdAt
-): OptionalNostrEventEntity, TimestampedEntity {
-
- @Deprecated(
- "Chronicle fallback for work signed before the GroupSignedEvent table. Read the " +
- "event off that table instead; this rebuild goes when the last pre-v13 install " +
- "does -- see the removal checklist in docs/member-chronicle.md."
- )
- fun toChunkEvent(): ChunkEvent {
- return ChunkEvent(
- id = id,
- pubKey = publicKey,
- createdAt = createdAt.epochSeconds,
- // Tag order matches ChunkEvent.build so the event id round-trips.
- tags = TagArrayBuilder()
- .addUnique(AltTag.assemble(ChunkEvent.ALT_DESCRIPTION))
- .addUnique(
- ChapterIdTag.assemble(chapterId)
- )
- .addUnique(
- IndexTag.assemble(
- index
- )
- )
- .addUnique(
- WordStatisticsTag.assemble(wordCount, characterCount)
- )
- .build(),
- content = text,
- sig = signature
- )
- }
-
- companion object {
- fun fromChunkEventTemplate(
- chunkEventTemplate: EventTemplate,
- chatRoomId: HexKey,
- userPublicKey: HexKey,
- ): MantraChunk? {
- return fromChunkEvent(
- ChunkEvent(
- id = EventHasher.hashId(
- pubKey = userPublicKey,
- tags = chunkEventTemplate.tags,
- content = chunkEventTemplate.content,
- createdAt = chunkEventTemplate.createdAt,
- kind = chunkEventTemplate.kind,
- ),
- content = chunkEventTemplate.content,
- tags = chunkEventTemplate.tags,
- createdAt = chunkEventTemplate.createdAt,
- pubKey = userPublicKey,
- sig = "", // Unsigned rumor
- ),
- chatRoomId = chatRoomId,
- )
- }
-
- fun fromChunkEvent(chunkEvent: ChunkEvent, chatRoomId: HexKey): MantraChunk? {
- return chunkEvent.wordStatisticsTag?.let { wordStatisticsTag ->
- chunkEvent.index()?.let { index ->
- chunkEvent.chapterId()?.let { chapterId ->
- MantraChunk(
- id = chunkEvent.id,
- publicKey = chunkEvent.pubKey,
- createdAt = Instant.fromEpochSeconds(chunkEvent.createdAt),
- index = index,
- wordCount = wordStatisticsTag.wordCount,
- characterCount = wordStatisticsTag.characterCount,
- chapterId = chapterId,
- text = chunkEvent.content,
- signature = chunkEvent.sig,
- chatRoomId = chatRoomId
- )
- }
-
- }
- }
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraDialect.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraDialect.kt
deleted file mode 100644
index 113b4b99..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraDialect.kt
+++ /dev/null
@@ -1,126 +0,0 @@
-package com.machankura.bennu.compose.database.model
-
-import androidx.room3.Entity
-import androidx.room3.ForeignKey
-import androidx.room3.PrimaryKey
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
-import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
-import com.vitorpamplona.quartz.nip31Alts.AltTag
-import com.machankura.bennu.compose.database.model.traits.OptionalNostrEventEntity
-import com.machankura.bennu.compose.database.model.traits.TimestampedEntity
-import com.machankura.bennu.compose.nostr.nip30303.DialectEvent
-import com.machankura.bennu.compose.nostr.nip30303.tags.CountryTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.LanguageTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.NameTag
-import kotlin.time.Clock
-import kotlin.time.Instant
-
-/**
- * 30304
- */
-@Entity(
- foreignKeys = [
- ForeignKey(
- entity = ChatRoom::class,
- parentColumns = ["id"],
- childColumns = ["chatRoomId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ]
-)
-data class MantraDialect(
- @PrimaryKey
- val id: HexKey,
- val publicKey: HexKey,
- val name: String,
- val country: String,
- val language: String,
-
- val signature: String,
-
- val chatRoomId: String,
-
- val relayHint: String? = null,
- val marmotGroupEventId: HexKey? = null,
-
- /** The [GroupSignedEvent] this row was made from, when the group signed it. */
- val groupSignedEventId: HexKey? = null,
-
- /**
- * Related nostrEventId if this is not a rumor...
- */
- override val nostrEventId: HexKey? = null,
- override val createdAt: Instant = Clock.System.now(),
- override val updatedAt: Instant = createdAt
-): OptionalNostrEventEntity, TimestampedEntity {
-
- @Deprecated(
- "Chronicle fallback for work signed before the GroupSignedEvent table. Read the " +
- "event off that table instead; this rebuild goes when the last pre-v13 install " +
- "does -- see the removal checklist in docs/member-chronicle.md."
- )
- fun toDialectEvent(): DialectEvent {
- return DialectEvent(
- id = id,
- pubKey = publicKey,
- createdAt = createdAt.epochSeconds,
- // Tag order matches DialectEvent.build so the event id round-trips.
- tags = TagArrayBuilder()
- .addUnique(AltTag.assemble(DialectEvent.ALT_DESCRIPTION))
- .addUnique(NameTag.assemble(name))
- .addUnique(CountryTag.assemble(country))
- .addUnique(LanguageTag.assemble(language))
- .build(),
- content = language, // TODO: Consider using the isoCode... as content?
- sig = signature
- )
- }
-
- companion object {
- fun fromDialectEventTemplate(
- dialectEventTemplate: EventTemplate,
- chatRoomId: HexKey,
- userPublicKey: HexKey,
- ): MantraDialect? {
- return fromDialectEvent(
- DialectEvent(
- id = EventHasher.hashId(
- pubKey = userPublicKey,
- tags = dialectEventTemplate.tags,
- content = dialectEventTemplate.content,
- createdAt = dialectEventTemplate.createdAt,
- kind = dialectEventTemplate.kind,
- ),
- content = dialectEventTemplate.content,
- tags = dialectEventTemplate.tags,
- createdAt = dialectEventTemplate.createdAt,
- pubKey = userPublicKey,
- sig = "", // Unsigned rumor
- ),
- chatRoomId = chatRoomId,
- )
- }
-
- fun fromDialectEvent(dialectEvent: DialectEvent, chatRoomId: HexKey): MantraDialect? {
- return dialectEvent.name()?.let { name ->
- dialectEvent.language()?.let { language ->
- dialectEvent.country()?.let { country ->
-
- MantraDialect(
- id = dialectEvent.id,
- publicKey = dialectEvent.pubKey,
- createdAt = Instant.fromEpochSeconds(dialectEvent.createdAt),
- name = name,
- language = language,
- country = country,
- signature = dialectEvent.sig,
- chatRoomId = chatRoomId
- )
- }
- }
- }
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslation.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslation.kt
deleted file mode 100644
index 31983b4f..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslation.kt
+++ /dev/null
@@ -1,107 +0,0 @@
-package com.machankura.bennu.compose.database.model
-
-import androidx.room3.Entity
-import androidx.room3.ForeignKey
-import androidx.room3.PrimaryKey
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.utils.ensure
-import com.machankura.bennu.compose.database.model.traits.OptionalNostrEventEntity
-import com.machankura.bennu.compose.database.model.traits.TimestampedEntity
-import com.machankura.bennu.compose.nostr.nip30303.TranslationEvent
-import com.machankura.bennu.compose.nostr.nip30303.tags.TranslationArtifactVersionIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.TranslationChunkIdTag
-import kotlin.time.Clock
-import kotlin.time.Instant
-
-/**
- * 30305
- */
-@Entity(
- foreignKeys = [
- ForeignKey(
- entity = MantraTranslationChunk::class,
- parentColumns = ["id"],
- childColumns = ["translationChunkId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ForeignKey(
- entity = MantraTranslationArtifactVersion::class,
- parentColumns = ["id"],
- childColumns = ["translationArtifactVersionId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ForeignKey(
- entity = ChatRoom::class,
- parentColumns = ["id"],
- childColumns = ["chatRoomId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ],
-)
-data class MantraTranslation(
- @PrimaryKey
- val id: HexKey,
- val publicKey: HexKey,
- val translationChunkId: HexKey,
- val translationArtifactVersionId: HexKey,
- val text: String,
-
- val signature: String,
-
- val chatRoomId: String,
-
- val relayHint: String? = null,
- val marmotGroupEventId: HexKey? = null,
-
- /** The [GroupSignedEvent] this row was made from, when the group signed it. */
- val groupSignedEventId: HexKey? = null,
-
- /**
- * Related nostrEventId if this is not a rumor...
- */
- override val nostrEventId: HexKey? = null,
- override val createdAt: Instant = Clock.System.now(),
- override val updatedAt: Instant = createdAt
-): OptionalNostrEventEntity, TimestampedEntity {
-
- fun toTranslationEvent(): TranslationEvent {
- return TranslationEvent(
- id = id,
- pubKey = publicKey,
- createdAt = createdAt.epochSeconds,
- tags = TagArrayBuilder()
- .addUnique(
- TranslationArtifactVersionIdTag.assemble(translationArtifactVersionId)
- )
- .addUnique(
- TranslationChunkIdTag.assemble(translationChunkId)
- )
- .build(),
- content = text,
- sig = signature
- )
- }
-
- companion object {
- fun fromTranslationEvent(translationEvent: TranslationEvent, chatRoomId: HexKey): MantraTranslation? {
- ensure(translationEvent.translationChunkId() != null) { return null}
- ensure(translationEvent.translationArtifactVersionId() != null) { return null}
-
- return translationEvent.translationChunkId()?.let { translationChunkId ->
- translationEvent.translationArtifactVersionId()?.let { translationArtifactVersionId ->
- MantraTranslation(
- id = translationEvent.id,
- publicKey = translationEvent.pubKey,
- createdAt = Instant.fromEpochSeconds(translationEvent.createdAt),
- text = translationEvent.content,
- translationChunkId = translationChunkId,
- translationArtifactVersionId = translationArtifactVersionId,
- signature = translationEvent.sig,
- chatRoomId = chatRoomId
- )
- }
- }
- }
- }
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslationArtifactVersion.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslationArtifactVersion.kt
deleted file mode 100644
index 8f7c45e5..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslationArtifactVersion.kt
+++ /dev/null
@@ -1,158 +0,0 @@
-package com.machankura.bennu.compose.database.model
-
-import androidx.room3.Entity
-import androidx.room3.ForeignKey
-import androidx.room3.PrimaryKey
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
-import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
-import com.vitorpamplona.quartz.nip31Alts.AltTag
-import com.machankura.bennu.compose.database.model.traits.OptionalNostrEventEntity
-import com.machankura.bennu.compose.database.model.traits.TimestampedEntity
-import com.machankura.bennu.compose.nostr.nip30303.TranslationArtifactVersionEvent
-import com.machankura.bennu.compose.nostr.nip30303.tags.ArtifactVersionIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.DialectIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.LicenseTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.NameTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.VisibilityTag
-import kotlin.time.Clock
-import kotlin.time.Instant
-
-/**
- * 30306
- */
-@Entity(
- foreignKeys = [
- ForeignKey(
- entity = MantraArtifactVersion::class,
- parentColumns = ["id"],
- childColumns = ["artifactVersionId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ForeignKey(
- entity = MantraDialect::class,
- parentColumns = ["id"],
- childColumns = ["dialectId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ForeignKey(
- entity = ChatRoom::class,
- parentColumns = ["id"],
- childColumns = ["chatRoomId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ],
-)
-data class MantraTranslationArtifactVersion(
- @PrimaryKey
- val id: HexKey,
- val publicKey: HexKey,
- val artifactVersionId: HexKey,
- val dialectId: HexKey,
- val name: String,
- val visibility: String,
- val license: String,
-
- /**
- * Signature will be an empty string if this is a rumor
- */
- val signature: String,
-
- val chatRoomId: String,
-
- val relayHint: String? = null,
- val marmotGroupEventId: HexKey? = null,
-
- /** The [GroupSignedEvent] this row was made from, when the group signed it. */
- val groupSignedEventId: HexKey? = null,
-
- /**
- * Related nostrEventId if this is not a rumor...
- */
- override val nostrEventId: HexKey? = null,
- override val createdAt: Instant = Clock.System.now(),
- override val updatedAt: Instant = createdAt
-): OptionalNostrEventEntity, TimestampedEntity {
-
- @Deprecated(
- "Chronicle fallback for work signed before the GroupSignedEvent table. Read the " +
- "event off that table instead; this rebuild goes when the last pre-v13 install " +
- "does -- see the removal checklist in docs/member-chronicle.md."
- )
- fun toTranslationArtifactVersionEvent(): TranslationArtifactVersionEvent {
- return TranslationArtifactVersionEvent(
- id = id,
- pubKey = publicKey,
- createdAt = createdAt.epochSeconds,
- // Tag order matches TranslationArtifactVersionEvent.build so the id round-trips.
- tags = TagArrayBuilder()
- .addUnique(AltTag.assemble(TranslationArtifactVersionEvent.ALT_DESCRIPTION))
- .addUnique(
- ArtifactVersionIdTag.assemble(artifactVersionId)
- )
- .addUnique(
- DialectIdTag.assemble(dialectId)
- )
- .addUnique(NameTag.assemble(name))
- .addUnique(VisibilityTag.assemble(visibility))
- .addUnique(LicenseTag.assemble(license))
- .build(),
- content = "",
- sig = signature
- )
- }
-
- companion object {
- fun fromTranslationArtifactVersionEventTemplate(
- translationArtifactVersionEventTemplate: EventTemplate,
- chatRoomId: HexKey,
- userPublicKey: HexKey,
- ): MantraTranslationArtifactVersion? {
- return fromTranslationArtifactVersionEvent(
- TranslationArtifactVersionEvent(
- id = EventHasher.hashId(
- pubKey = userPublicKey,
- tags = translationArtifactVersionEventTemplate.tags,
- content = translationArtifactVersionEventTemplate.content,
- createdAt = translationArtifactVersionEventTemplate.createdAt,
- kind = translationArtifactVersionEventTemplate.kind,
- ),
- content = translationArtifactVersionEventTemplate.content,
- tags = translationArtifactVersionEventTemplate.tags,
- createdAt = translationArtifactVersionEventTemplate.createdAt,
- pubKey = userPublicKey,
- sig = "", // Unsigned rumor
- ),
- chatRoomId = chatRoomId,
- )
- }
-
- fun fromTranslationArtifactVersionEvent(translationArtifactVersionEvent: TranslationArtifactVersionEvent, chatRoomId: HexKey): MantraTranslationArtifactVersion? {
-
- return translationArtifactVersionEvent.artifactVersionId()?.let { artifactVersionId ->
- translationArtifactVersionEvent.dialectId()?.let { dialectId ->
- translationArtifactVersionEvent.name()?.let { name ->
- translationArtifactVersionEvent.visibility()?.let { visibility ->
- translationArtifactVersionEvent.license()?.let { license ->
- MantraTranslationArtifactVersion(
- id = translationArtifactVersionEvent.id,
- publicKey = translationArtifactVersionEvent.pubKey,
- createdAt = Instant.fromEpochSeconds(translationArtifactVersionEvent.createdAt),
- artifactVersionId = artifactVersionId,
- dialectId = dialectId,
- name = name,
- visibility = visibility,
- license = license,
- signature = translationArtifactVersionEvent.sig,
- chatRoomId = chatRoomId
- )
- }
- }
- }
- }
- }
- }
- }
-}
-
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslationArtifactVersionContributor.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslationArtifactVersionContributor.kt
deleted file mode 100644
index ae958bed..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslationArtifactVersionContributor.kt
+++ /dev/null
@@ -1,90 +0,0 @@
-package com.machankura.bennu.compose.database.model
-
-import androidx.room3.Entity
-import androidx.room3.ForeignKey
-import androidx.room3.PrimaryKey
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.utils.TimeUtils
-import com.machankura.bennu.compose.database.model.traits.OptionalNostrEventEntity
-import com.machankura.bennu.compose.database.model.traits.TimestampedEntity
-import com.machankura.bennu.compose.nostr.nip30303.TranslationArtifactVersionContributorListEvent
-import com.machankura.bennu.compose.nostr.nip30303.tags.ContributorTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.TranslationArtifactVersionIdTag
-import kotlin.time.Clock
-import kotlin.time.Instant
-
-/**
- * 30307
- */
-@Entity(
- foreignKeys = [
- ForeignKey(
- entity = MantraTranslationArtifactVersionContributor::class,
- parentColumns = ["id"],
- childColumns = ["translationArtifactVersionId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ForeignKey(
- entity = ChatRoom::class,
- parentColumns = ["id"],
- childColumns = ["chatRoomId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ],
-)
-data class MantraTranslationArtifactVersionContributor(
- @PrimaryKey
- val id: HexKey,
- val publicKey: HexKey,
- val translationArtifactVersionId: HexKey,
- val editorPublicKey: HexKey,
-
- /**
- * Signature will be an empty string if this is a rumor
- */
- val signature: String,
-
- val chatRoomId: String,
-
- val relayHint: String? = null,
- val marmotGroupEventId: HexKey? = null,
-
- /** The [GroupSignedEvent] this row was made from, when the group signed it. */
- val groupSignedEventId: HexKey? = null,
-
- /**
- * Related nostrEventId if this is not a rumor...
- */
- override val nostrEventId: HexKey? = null,
- override val createdAt: Instant = Clock.System.now(),
- override val updatedAt: Instant = createdAt
-): OptionalNostrEventEntity, TimestampedEntity {
-
- companion object {
- fun toTranslationChapterProofReaderListEvent(chatRoomId: HexKey, mantraTranslationChapterProofReaders: List): TranslationArtifactVersionContributorListEvent {
- // TODO: create TranslationChapterProofReaderListEvent from mantraTranslationChapterProofReaders
- return TranslationArtifactVersionContributorListEvent(
- id = "",
- pubKey = "",
- createdAt = TimeUtils.now(),
- tags = TagArrayBuilder()
-
- .addUnique(
- TranslationArtifactVersionIdTag.assemble("") // TODO: use actual value..
- )
- // TODO: Add tag for editorPublicKey
- .addUnique(
- ContributorTag.assemble(
- "",
- ContributorTag.ROLE_EDITOR
- )
- )
- .build(),
- content = "",
- sig = ""
- )
- }
- }
-}
-
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslationChapter.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslationChapter.kt
deleted file mode 100644
index 5aa9475e..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslationChapter.kt
+++ /dev/null
@@ -1,146 +0,0 @@
-package com.machankura.bennu.compose.database.model
-
-import androidx.room3.Entity
-import androidx.room3.ForeignKey
-import androidx.room3.PrimaryKey
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
-import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
-import com.vitorpamplona.quartz.nip31Alts.AltTag
-import com.machankura.bennu.compose.database.model.traits.OptionalNostrEventEntity
-import com.machankura.bennu.compose.database.model.traits.TimestampedEntity
-import com.machankura.bennu.compose.nostr.nip30303.TranslationChapterEvent
-import com.machankura.bennu.compose.nostr.nip30303.tags.ChapterIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.IndexTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.TranslationArtifactVersionIdTag
-import kotlin.time.Clock
-import kotlin.time.Instant
-
-/**
- * 30308
- */
-@Entity(
- foreignKeys = [
- ForeignKey(
- entity = MantraTranslationArtifactVersion::class,
- parentColumns = ["id"],
- childColumns = ["translationArtifactVersionId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ForeignKey(
- entity = MantraChapter::class,
- parentColumns = ["id"],
- childColumns = ["chapterId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ForeignKey(
- entity = ChatRoom::class,
- parentColumns = ["id"],
- childColumns = ["chatRoomId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ],
-)
-data class MantraTranslationChapter(
- @PrimaryKey
- val id: HexKey,
- val publicKey: HexKey,
- val chapterId: HexKey,
- val translationArtifactVersionId: HexKey,
- val index: Int,
-
- /**
- * Signature will be an empty string if this is a rumor
- */
- val signature: String,
-
- val chatRoomId: String,
-
- val relayHint: String? = null,
- val marmotGroupEventId: HexKey? = null,
-
- /** The [GroupSignedEvent] this row was made from, when the group signed it. */
- val groupSignedEventId: HexKey? = null,
-
- /**
- * Related nostrEventId if this is not a rumor...
- */
- override val nostrEventId: HexKey? = null,
- override val createdAt: Instant = Clock.System.now(),
- override val updatedAt: Instant = createdAt
-): OptionalNostrEventEntity, TimestampedEntity {
- @Deprecated(
- "Chronicle fallback for work signed before the GroupSignedEvent table. Read the " +
- "event off that table instead; this rebuild goes when the last pre-v13 install " +
- "does -- see the removal checklist in docs/member-chronicle.md."
- )
- fun toTranslationChapterEvent(): TranslationChapterEvent {
- return TranslationChapterEvent(
- id = id,
- pubKey = publicKey,
- createdAt = createdAt.epochSeconds,
- // Tag order matches TranslationChapterEvent.build so the id round-trips.
- tags = TagArrayBuilder()
- .addUnique(AltTag.assemble(TranslationChapterEvent.ALT_DESCRIPTION))
- .addUnique(
- TranslationArtifactVersionIdTag.assemble(translationArtifactVersionId)
- )
- .addUnique(
- ChapterIdTag.assemble(chapterId)
- )
- .addUnique(
- IndexTag.assemble(index)
- )
- .build(),
- content = "",
- sig = signature
- )
- }
-
- companion object {
- fun fromTranslationChapterEventTemplate(
- translationChapterEventTemplate: EventTemplate,
- chatRoomId: HexKey,
- userPublicKey: HexKey,
- ): MantraTranslationChapter? {
- return fromTranslationChapterEvent(
- TranslationChapterEvent(
- id = EventHasher.hashId(
- pubKey = userPublicKey,
- tags = translationChapterEventTemplate.tags,
- content = translationChapterEventTemplate.content,
- createdAt = translationChapterEventTemplate.createdAt,
- kind = translationChapterEventTemplate.kind,
- ),
- content = translationChapterEventTemplate.content,
- tags = translationChapterEventTemplate.tags,
- createdAt = translationChapterEventTemplate.createdAt,
- pubKey = userPublicKey,
- sig = "", // Unsigned rumor
- ),
- chatRoomId = chatRoomId,
- )
- }
-
- fun fromTranslationChapterEvent(translationChapterEvent: TranslationChapterEvent, chatRoomId: HexKey): MantraTranslationChapter? {
- return translationChapterEvent.chapterId()?.let { chapterId ->
- translationChapterEvent.translationArtifactVersionId()?.let { translationArtifactVersionId ->
- translationChapterEvent.index()?.let { index ->
- MantraTranslationChapter(
- id = translationChapterEvent.id,
- publicKey = translationChapterEvent.pubKey,
- createdAt = Instant.fromEpochSeconds(translationChapterEvent.createdAt),
- chapterId = chapterId,
- translationArtifactVersionId = translationArtifactVersionId,
- index = index,
- signature = translationChapterEvent.sig,
- chatRoomId = chatRoomId
- )
- }
- }
- }
- }
- }
-}
-
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslationChapterContributor.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslationChapterContributor.kt
deleted file mode 100644
index 8a776a53..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslationChapterContributor.kt
+++ /dev/null
@@ -1,87 +0,0 @@
-package com.machankura.bennu.compose.database.model
-
-import androidx.room3.Entity
-import androidx.room3.ForeignKey
-import androidx.room3.PrimaryKey
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nipF4Podcasts.metadata.tags.AuthorTag
-import com.vitorpamplona.quartz.utils.TimeUtils
-import com.machankura.bennu.compose.database.model.traits.OptionalNostrEventEntity
-import com.machankura.bennu.compose.database.model.traits.TimestampedEntity
-import com.machankura.bennu.compose.nostr.nip30303.TranslationChapterContributorListEvent
-import com.machankura.bennu.compose.nostr.nip30303.tags.ContributorTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.TranslationChapterIdTag
-import kotlin.time.Clock
-import kotlin.time.Instant
-
-/**
- * 30310
- */
-@Entity(
- foreignKeys = [
- ForeignKey(
- entity = MantraTranslationChapter::class,
- parentColumns = ["id"],
- childColumns = ["translationChapterId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ForeignKey(
- entity = ChatRoom::class,
- parentColumns = ["id"],
- childColumns = ["chatRoomId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ],
-)
-data class MantraTranslationChapterContributor(
- @PrimaryKey
- val id: HexKey,
- val publicKey: HexKey,
- val translationChapterId: HexKey,
- val translatorPublicKey: HexKey,
-
- val role: String,
- /**
- * Signature will be an empty string if this is a rumor
- */
- val signature: String,
-
- val chatRoomId: String,
-
- val relayHint: String? = null,
- val marmotGroupEventId: HexKey? = null,
-
- /** The [GroupSignedEvent] this row was made from, when the group signed it. */
- val groupSignedEventId: HexKey? = null,
-
- /**
- * Related nostrEventId if this is not a rumor...
- */
- override val nostrEventId: HexKey? = null,
- override val createdAt: Instant = Clock.System.now(),
- override val updatedAt: Instant = createdAt
-): OptionalNostrEventEntity, TimestampedEntity {
-
- companion object {
- fun toTranslationChapterTranslatorListEvent(mantraTranslationChapterTranslators: List): TranslationChapterContributorListEvent {
- // TODO: create TranslationChapterProofReaderListEvent from mantraTranslationChapterProofReaders
- return TranslationChapterContributorListEvent(
- id = "",
- pubKey = "",
- createdAt = TimeUtils.now(),
- tags = TagArrayBuilder()
- .addUnique(
- TranslationChapterIdTag.assemble("")
- )
- .addUnique(
- ContributorTag.assemble("", ContributorTag.ROLE_TRANSLATOR)
- )
- .build(),
- content = "",
- sig = ""
- )
- }
- }
-}
-
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslationChunk.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslationChunk.kt
deleted file mode 100644
index ac090b51..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslationChunk.kt
+++ /dev/null
@@ -1,148 +0,0 @@
-package com.machankura.bennu.compose.database.model
-
-import androidx.room3.Entity
-import androidx.room3.ForeignKey
-import androidx.room3.PrimaryKey
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
-import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
-import com.vitorpamplona.quartz.nip31Alts.AltTag
-import com.machankura.bennu.compose.database.model.traits.OptionalNostrEventEntity
-import com.machankura.bennu.compose.database.model.traits.TimestampedEntity
-import com.machankura.bennu.compose.nostr.nip30303.TranslationChunkEvent
-import com.machankura.bennu.compose.nostr.nip30303.tags.ChunkIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.IndexTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.TranslationChapterIdTag
-import kotlin.time.Clock
-import kotlin.time.Instant
-
-/**
- * 30311
- */
-@Entity(
- foreignKeys = [
- ForeignKey(
- entity = MantraChunk::class,
- parentColumns = ["id"],
- childColumns = ["chunkId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ForeignKey(
- entity = MantraTranslationChapter::class,
- parentColumns = ["id"],
- childColumns = ["translationChapterId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ForeignKey(
- entity = ChatRoom::class,
- parentColumns = ["id"],
- childColumns = ["chatRoomId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ],
-)
-data class MantraTranslationChunk(
- @PrimaryKey
- val id: HexKey,
- val publicKey: HexKey,
- val chunkId: HexKey,
- val translationChapterId: HexKey,
- val text: String,
- val index: Int,
-
- /**
- * Signature will be an empty string if this is a rumor
- */
- val signature: String,
-
- val chatRoomId: String,
-
- val relayHint: String? = null,
- val marmotGroupEventId: HexKey? = null,
-
- /** The [GroupSignedEvent] this row was made from, when the group signed it. */
- val groupSignedEventId: HexKey? = null,
-
- /**
- * Related nostrEventId if this is not a rumor...
- */
- override val nostrEventId: HexKey? = null,
- override val createdAt: Instant = Clock.System.now(),
- override val updatedAt: Instant = createdAt
-): OptionalNostrEventEntity, TimestampedEntity {
-
- @Deprecated(
- "Chronicle fallback for work signed before the GroupSignedEvent table. Read the " +
- "event off that table instead; this rebuild goes when the last pre-v13 install " +
- "does -- see the removal checklist in docs/member-chronicle.md."
- )
- fun toTranslationChunkEvent(): TranslationChunkEvent {
- return TranslationChunkEvent(
- id = id,
- pubKey = publicKey,
- createdAt = createdAt.epochSeconds,
- // Tag order matches TranslationChunkEvent.build so the id round-trips.
- tags = TagArrayBuilder()
- .addUnique(AltTag.assemble(TranslationChunkEvent.ALT_DESCRIPTION))
- .addUnique(
- TranslationChapterIdTag.assemble(translationChapterId)
- )
- .addUnique(
- ChunkIdTag.assemble(chunkId)
- )
- .addUnique(
- IndexTag.assemble(index)
- )
- .build(),
- content = text,
- sig = signature
- )
- }
-
- companion object {
- fun fromTranslationChunkEventTemplate(
- translationChunkEventTemplate: EventTemplate,
- chatRoomId: HexKey,
- userPublicKey: HexKey,
- ): MantraTranslationChunk? {
- return fromTranslationChunkEvent(
- TranslationChunkEvent(
- id = EventHasher.hashId(
- pubKey = userPublicKey,
- tags = translationChunkEventTemplate.tags,
- content = translationChunkEventTemplate.content,
- createdAt = translationChunkEventTemplate.createdAt,
- kind = translationChunkEventTemplate.kind,
- ),
- content = translationChunkEventTemplate.content,
- tags = translationChunkEventTemplate.tags,
- createdAt = translationChunkEventTemplate.createdAt,
- pubKey = userPublicKey,
- sig = "", // Unsigned rumor
- ),
- chatRoomId = chatRoomId,
- )
- }
-
- fun fromTranslationChunkEvent(translationChunkEvent: TranslationChunkEvent, chatRoomId: HexKey): MantraTranslationChunk? {
- return translationChunkEvent.translationChapterId()?.let { translationChapterId ->
- translationChunkEvent.chunkId()?.let { chunkId ->
- translationChunkEvent.index()?.let { index ->
- MantraTranslationChunk(
- id = translationChunkEvent.id,
- publicKey = translationChunkEvent.pubKey,
- createdAt = Instant.fromEpochSeconds(translationChunkEvent.createdAt),
- translationChapterId = translationChapterId,
- chunkId = chunkId,
- index = index,
- text = translationChunkEvent.content,
- signature = translationChunkEvent.sig,
- chatRoomId = chatRoomId
- )
- }
- }
- }
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslationChunkProposal.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslationChunkProposal.kt
deleted file mode 100644
index 68c63b74..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslationChunkProposal.kt
+++ /dev/null
@@ -1,140 +0,0 @@
-package com.machankura.bennu.compose.database.model
-
-import androidx.room3.Entity
-import androidx.room3.ForeignKey
-import androidx.room3.PrimaryKey
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
-import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
-import com.vitorpamplona.quartz.nip31Alts.AltTag
-import com.machankura.bennu.compose.database.model.traits.OptionalNostrEventEntity
-import com.machankura.bennu.compose.database.model.traits.TimestampedEntity
-import com.machankura.bennu.compose.nostr.nip30303.TranslationChunkEvent
-import com.machankura.bennu.compose.nostr.nip30303.tags.ChunkIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.IndexTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.TranslationChapterIdTag
-import kotlin.time.Clock
-import kotlin.time.Instant
-
-/**
- * 30311
- */
-@Entity(
- foreignKeys = [
- ForeignKey(
- entity = MantraChunk::class,
- parentColumns = ["id"],
- childColumns = ["chunkId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ForeignKey(
- entity = MantraTranslationChapter::class,
- parentColumns = ["id"],
- childColumns = ["translationChapterId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ForeignKey(
- entity = ChatRoom::class,
- parentColumns = ["id"],
- childColumns = ["chatRoomId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ],
-)
-data class MantraTranslationChunkProposal(
- @PrimaryKey
- val id: HexKey,
- val publicKey: HexKey,
- val chunkId: HexKey,
- val translationChapterId: HexKey,
- val text: String,
- val index: Int,
-
- /**
- * Signature will be an empty string if this is a rumor
- */
- val signature: String,
-
- val chatRoomId: String,
-
- val relayHint: String? = null,
- val marmotGroupEventId: HexKey? = null,
-
- /**
- * Related nostrEventId if this is not a rumor...
- */
- override val nostrEventId: HexKey? = null,
- override val createdAt: Instant = Clock.System.now(),
- override val updatedAt: Instant = createdAt
-): OptionalNostrEventEntity, TimestampedEntity {
-
- fun toTranslationChunkEvent(): TranslationChunkEvent {
- return TranslationChunkEvent(
- id = id,
- pubKey = publicKey,
- createdAt = createdAt.epochSeconds,
- // Tag order matches TranslationChunkEvent.build so the id round-trips.
- tags = TagArrayBuilder()
- .addUnique(AltTag.assemble(TranslationChunkEvent.ALT_DESCRIPTION))
- .addUnique(
- TranslationChapterIdTag.assemble(translationChapterId)
- )
- .addUnique(
- ChunkIdTag.assemble(chunkId)
- )
- .addUnique(
- IndexTag.assemble(index)
- )
- .build(),
- content = text,
- sig = signature
- )
- }
-
- companion object {
- fun fromTranslationChunkEventTemplate(
- translationChunkEventTemplate: EventTemplate,
- chatRoomId: HexKey,
- userPublicKey: HexKey,
- ): MantraTranslationChunkProposal? {
- return fromTranslationChunkEvent(
- TranslationChunkEvent(
- id = EventHasher.hashId(
- pubKey = userPublicKey,
- tags = translationChunkEventTemplate.tags,
- content = translationChunkEventTemplate.content,
- createdAt = translationChunkEventTemplate.createdAt,
- kind = translationChunkEventTemplate.kind,
- ),
- content = translationChunkEventTemplate.content,
- tags = translationChunkEventTemplate.tags,
- createdAt = translationChunkEventTemplate.createdAt,
- pubKey = userPublicKey,
- sig = "", // Unsigned rumor
- ),
- chatRoomId = chatRoomId,
- )
- }
-
- fun fromTranslationChunkEvent(translationChunkEvent: TranslationChunkEvent, chatRoomId: HexKey): MantraTranslationChunkProposal? {
- return translationChunkEvent.translationChapterId()?.let { translationChapterId ->
- translationChunkEvent.chunkId()?.let { chunkId ->
- translationChunkEvent.index()?.let { index ->
- MantraTranslationChunkProposal(
- id = translationChunkEvent.id,
- publicKey = translationChunkEvent.pubKey,
- createdAt = Instant.fromEpochSeconds(translationChunkEvent.createdAt),
- translationChapterId = translationChapterId,
- chunkId = chunkId,
- index = index,
- text = translationChunkEvent.content,
- signature = translationChunkEvent.sig,
- chatRoomId = chatRoomId
- )
- }
- }
- }
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslationContributor.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslationContributor.kt
deleted file mode 100644
index 56ef346f..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MantraTranslationContributor.kt
+++ /dev/null
@@ -1,116 +0,0 @@
-package com.machankura.bennu.compose.database.model
-
-import androidx.room3.Entity
-import androidx.room3.ForeignKey
-import androidx.room3.PrimaryKey
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
-import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
-import com.vitorpamplona.quartz.nip01Core.tags.dTag.DTag
-import com.vitorpamplona.quartz.nip31Alts.alt
-import com.machankura.bennu.compose.database.model.traits.OptionalNostrEventEntity
-import com.machankura.bennu.compose.database.model.traits.TimestampedEntity
-import com.machankura.bennu.compose.nostr.nip30303.TranslationContributorListEvent
-import com.machankura.bennu.compose.nostr.nip30303.tags.ContributorTag
-import kotlin.time.Clock
-import kotlin.time.Instant
-
-/**
- * 30312
- */
-@Entity(
- foreignKeys = [
- ForeignKey(
- entity = MantraTranslation::class,
- parentColumns = ["id"],
- childColumns = ["translationId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ForeignKey(
- entity = ChatRoom::class,
- parentColumns = ["id"],
- childColumns = ["chatRoomId"],
- onDelete = ForeignKey.CASCADE,
- ),
- ],
-)
-data class MantraTranslationContributor(
- @PrimaryKey
- val id: HexKey,
- val dTag: String,
- val publicKey: HexKey,
- val translationId: HexKey,
- val translatorPublicKey: HexKey,
-
- /**
- * Signature will be an empty string if this is a rumor
- */
- val signature: String,
-
- val chatRoomId: String,
-
- val relayHint: String? = null,
- val marmotGroupEventId: HexKey? = null,
-
- /** The [GroupSignedEvent] this row was made from, when the group signed it. */
- val groupSignedEventId: HexKey? = null,
- /**
- * Related nostrEventId if this is not a rumor...
- */
- override val nostrEventId: HexKey? = null,
- override val createdAt: Instant = Clock.System.now(),
- override val updatedAt: Instant = createdAt
-): OptionalNostrEventEntity, TimestampedEntity {
-
- companion object {
- fun toTranslationChapterProofReaderListEvent(mantraTranslationContributors: List): TranslationContributorListEvent? {
- mantraTranslationContributors.firstOrNull()?.let { firstMantraTranslationTranslator ->
- val allFromSameEvent = mantraTranslationContributors.all {
- it.publicKey == firstMantraTranslationTranslator.publicKey
- && it.createdAt == firstMantraTranslationTranslator.createdAt
- && it.dTag == firstMantraTranslationTranslator.dTag
- }
-
- if (allFromSameEvent) {
- val translatorPublicKeys = mantraTranslationContributors.map {
- ContributorTag.assemble(
- pubKey = it.publicKey,
- role = ContributorTag.ROLE_TRANSLATOR
- )
- }
- val template = eventTemplate(
- kind = TranslationContributorListEvent.KIND,
- description = "",
- createdAt = firstMantraTranslationTranslator.createdAt.epochSeconds
- ) {
- addUnique(
- DTag.assemble(
- firstMantraTranslationTranslator.dTag
- )
- )
- alt(TranslationContributorListEvent.ALT_DESCRIPTION)
-
- }
-
-
- return TranslationContributorListEvent(
- id = EventHasher.hashId(
- pubKey = firstMantraTranslationTranslator.publicKey,
- tags = template.tags,
- createdAt = template.createdAt,
- content = template.content,
- kind = template.kind
- ),
- pubKey = firstMantraTranslationTranslator.publicKey,
- createdAt = firstMantraTranslationTranslator.createdAt.epochSeconds,
- tags = translatorPublicKeys.toTypedArray(),
- content = template.content,
- sig = firstMantraTranslationTranslator.signature
- )
- }
- }
- return null
- }
- }
-}
-
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MarmotInnerEvent.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MarmotInnerEvent.kt
index 00ead353..568724a9 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MarmotInnerEvent.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/model/MarmotInnerEvent.kt
@@ -64,14 +64,6 @@ data class MarmotInnerEvent( // TODO: Rename this to GiftWrapPayload...
val content: String,
val quotedEventId: String? = null,
- /**
- * For a SubmissionEvent rumor, the id of the nip30303 event it carries.
- *
- * The submission's own id is derived from the envelope, so it is the only
- * handle the queue has on what is actually being submitted. Null for every
- * other kind, where the row *is* the event.
- */
- val payloadEventId: HexKey? = null,
/**
* Associated MarmotGroupEvent
@@ -140,7 +132,6 @@ data class MarmotInnerEvent( // TODO: Rename this to GiftWrapPayload...
if (!tags.contentDeepEquals(other.tags)) return false
if (content != other.content) return false
if (quotedEventId != other.quotedEventId) return false
- if (payloadEventId != other.payloadEventId) return false
if (marmotGroupEventId != other.marmotGroupEventId) return false
if (directMessageRecipientPublicKey != other.directMessageRecipientPublicKey) return false
if (createdAt != other.createdAt) return false
@@ -161,7 +152,6 @@ data class MarmotInnerEvent( // TODO: Rename this to GiftWrapPayload...
result = 31 * result + tags.contentDeepHashCode()
result = 31 * result + content.hashCode()
result = 31 * result + (quotedEventId?.hashCode() ?: 0)
- result = 31 * result + (payloadEventId?.hashCode() ?: 0)
result = 31 * result + (marmotGroupEventId?.hashCode() ?: 0)
result = 31 * result + (directMessageRecipientPublicKey?.hashCode() ?: 0)
result = 31 * result + createdAt.hashCode()
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/repository/DatabaseDkgRepository.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/repository/DatabaseDkgRepository.kt
index 16015f4b..4f6a73aa 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/repository/DatabaseDkgRepository.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/repository/DatabaseDkgRepository.kt
@@ -214,6 +214,17 @@ class DatabaseDkgRepository(
null
}
+ override suspend fun abandon(localChatRoom: LocalChatRoom, sessionId: String): Boolean = try {
+ ChillDkgRitualManager.abandon(
+ database = database,
+ localChatRoom = localChatRoom,
+ sessionId = sessionId,
+ )
+ } catch (e: Throwable) {
+ logger.e("Error abandoning DKG ritual $sessionId", e)
+ false
+ }
+
override suspend fun approve(
localChatRoom: LocalChatRoom,
sessionId: String,
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/repository/DatabaseMantraRepository.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/repository/DatabaseMantraRepository.kt
deleted file mode 100644
index 28bd0e10..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/database/repository/DatabaseMantraRepository.kt
+++ /dev/null
@@ -1,94 +0,0 @@
-package com.machankura.bennu.compose.database.repository
-
-import co.touchlab.kermit.Logger
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import kotlinx.coroutines.CoroutineScope
-import com.machankura.bennu.compose.database.BennuDatabase
-import com.machankura.bennu.compose.database.model.MantraArtifact
-import com.machankura.bennu.compose.database.model.MantraArtifactVersion
-import com.machankura.bennu.compose.database.model.MantraChapter
-import com.machankura.bennu.compose.database.model.MantraChunk
-import com.machankura.bennu.compose.database.model.MantraDialect
-import com.machankura.bennu.compose.database.model.MantraTranslationArtifactVersion
-import com.machankura.bennu.compose.database.model.MantraTranslationChapter
-import com.machankura.bennu.compose.database.model.MantraTranslationChunk
-import com.machankura.bennu.compose.database.model.MarmotInnerEvent
-import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
-import com.machankura.bennu.compose.repository.MantraRepository
-
-class DatabaseMantraRepository(
- val database: BennuDatabase,
- val scope: CoroutineScope
-): MantraRepository {
-
- private val logger = Logger.withTag(TAG)
-
- override suspend fun getArtifacts(chatRoomId: String): List =
- database.mantraArtifactDao().getArtifactsByChatRoomId(chatRoomId)
-
- override suspend fun getArtifact(id: String): MantraArtifact? =
- database.mantraArtifactDao().getArtifactById(id)
-
- override suspend fun getArtifactVersions(artifactId: String): List =
- database.mantraArtifactVersionDao().getArtifactVersionsByArtifactId(artifactId)
-
- override suspend fun getArtifactVersion(id: String): MantraArtifactVersion? =
- database.mantraArtifactVersionDao().getArtifactVersionById(id)
-
- override suspend fun getChaptersForArtifact(artifactId: String): List =
- database.mantraChapterDao().getChaptersByArtifactId(artifactId)
-
- override suspend fun getChaptersForArtifactVersion(artifactVersionId: String): List =
- database.mantraChapterDao().getChaptersByArtifactVersionId(artifactVersionId)
-
- override suspend fun getChapter(id: String): MantraChapter? =
- database.mantraChapterDao().getChapterById(id)
-
- override suspend fun getChunksForChapter(chapterId: String): List =
- database.mantraChunkDao().getChunksByChapterId(chapterId)
-
- override suspend fun getChunk(id: String): MantraChunk? =
- database.mantraChunkDao().getChunkById(id)
-
- override suspend fun getTranslationsForArtifact(artifactId: String): List =
- database.mantraTranslationArtifactVersionDao().getTranslationsByArtifactId(artifactId)
-
- override suspend fun getTranslation(id: String): MantraTranslationArtifactVersion? =
- database.mantraTranslationArtifactVersionDao().getTranslationById(id)
-
- override suspend fun getTranslationsForArtifactVersion(artifactVersionId: String): List =
- database.mantraTranslationArtifactVersionDao().getTranslationsByArtifactVersionId(artifactVersionId)
-
- override suspend fun getTranslationChapter(id: String): MantraTranslationChapter? =
- database.mantraTranslationChapterDao().getTranslationChapterById(id)
-
- override suspend fun getTranslationChapters(translationArtifactVersionId: String): List =
- database.mantraTranslationChapterDao().getTranslationChaptersByTranslationArtifactVersionId(translationArtifactVersionId)
-
- override suspend fun getTranslationChunks(translationChapterId: String): List =
- database.mantraTranslationChunkDao().getTranslationChunksByTranslationChapterId(translationChapterId)
-
- override suspend fun getDialects(chatRoomId: String): List =
- database.mantraDialectDao().getDialectsByChatRoomId(chatRoomId)
-
- override suspend fun getDialect(id: String): MantraDialect? =
- database.mantraDialectDao().getDialectById(id)
-
- override suspend fun addArtifactVersion(
- localChatRoom: LocalChatRoom,
- artifactId: HexKey,
- versionLabel: String,
- userPublicKey: HexKey,
- ): MantraArtifactVersion? {
- return database.mantraDao().addArtifactVersion(
- localChatRoom = localChatRoom,
- artifactId = artifactId,
- versionLabel = versionLabel,
- userPublicKey = userPublicKey
- )
- }
-
- companion object {
- private const val TAG = "DatabaseMantraRepository"
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/ChillDkgRitualManager.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/ChillDkgRitualManager.kt
index 28cd7985..d3113ba5 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/ChillDkgRitualManager.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/ChillDkgRitualManager.kt
@@ -106,6 +106,9 @@ object ChillDkgRitualManager {
*/
const val MINIMUM_PARTICIPANTS = 2
+ /** Why a ceremony a participant walked away from ended, as every device records it. */
+ private const val ABANDONED = "Abandoned by a participant"
+
/**
* This device's long-term ChillDKG host secret key.
*
@@ -138,6 +141,14 @@ object ChillDkgRitualManager {
fun canRunRitual(localChatRoom: LocalChatRoom): Boolean =
memberPublicKeys(localChatRoom).size >= MINIMUM_PARTICIPANTS
+ /**
+ * Whether [localChatRoom] is a Marmot room, and so can host a subgroup's
+ * ceremony but never one of its own. The same reading [broadcast] makes to
+ * pick a transport.
+ */
+ fun isMarmotRoom(localChatRoom: LocalChatRoom): Boolean =
+ localChatRoom.chatRoom.mlsGroupState != null
+
/**
* Everyone a ceremony is being run with — which is not the same question as
* who is in the room it runs in.
@@ -245,6 +256,15 @@ object ChillDkgRitualManager {
"${(members - room).joinToString { it.take(8) }}, who are not in it"
}
+ // A Marmot room's id is derived from the key it already has, so a ceremony
+ // of its own would make a key the room could never answer to. It hosts its
+ // subgroups' ceremonies and nothing else. The screens stopped offering one
+ // here, and this is what makes that a rule rather than a screen not drawing
+ // a button -- see docs/ceremony-creation.md.
+ require(parentChatRoomId != null || !isMarmotRoom(localChatRoom)) {
+ "${localChatRoom.chatRoom.id} is a Marmot room; it can only host a subgroup's ceremony"
+ }
+
require(members.size >= MINIMUM_PARTICIPANTS) {
"A shared key needs at least $MINIMUM_PARTICIPANTS members, this ceremony has ${members.size}"
}
@@ -375,7 +395,7 @@ object ChillDkgRitualManager {
return
}
- if (!record(database, session, innerEvent)) return
+ if (!record(database, localChatRoom, session, innerEvent)) return
advance(
database = database,
@@ -399,6 +419,20 @@ object ChillDkgRitualManager {
): DkgSession? {
database.dkgSessionDao().getSessionById(sessionId)?.let { return it }
+ // The receiving half of `proposeRitual`'s refusal. A build from before it
+ // can still put a group's own ceremony on the wire in a Marmot room, and
+ // recording it would show every member a ceremony whose key the room can
+ // never use -- which is how a second ceremony ended up beside a subgroup's.
+ if (isMarmotRoom(localChatRoom) &&
+ DkgRitualEvents.parseParentChatRoomId(innerEvent.tags) == null
+ ) {
+ logger.w(
+ "DKG proposal $sessionId names no parent in Marmot room " +
+ "${localChatRoom.chatRoom.id}; dropping"
+ )
+ return null
+ }
+
// The participant set is the proposal's own p-tags plus its sender, NOT
// this device's view of the room. `n` is hashed into the session identity,
// so two devices that disagree on it cannot complete a ritual together —
@@ -550,7 +584,7 @@ object ChillDkgRitualManager {
logger.i("Replaying ${stored.size} stored message(s) for ritual ${session.id}")
stored.forEach { payload ->
- if (!record(database, session, payload)) return
+ if (!record(database, localChatRoom, session, payload)) return
}
}
@@ -564,6 +598,7 @@ object ChillDkgRitualManager {
*/
private suspend fun record(
database: BennuDatabase,
+ localChatRoom: LocalChatRoom,
session: DkgSession,
innerEvent: Event
): Boolean {
@@ -634,6 +669,18 @@ object ChillDkgRitualManager {
}
DkgRitualEvents.FAILURE -> {
+ // Only somebody in the ceremony can end it. In a parent's room every
+ // member can read a subgroup's proposal, and so could name its
+ // session -- but a member who was never in it walking away is not
+ // the ceremony failing.
+ if (innerEvent.pubKey !in participantsOf(session, localChatRoom)) {
+ logger.w(
+ "Ritual ${session.id}: FAILURE from ${innerEvent.pubKey.take(8)}, " +
+ "who is not in it; ignoring"
+ )
+ return true
+ }
+
fail(
database = database,
session = session,
@@ -1088,6 +1135,49 @@ object ChillDkgRitualManager {
return null
}
+ /**
+ * Ends a ceremony this device is in, for everyone in it.
+ *
+ * ChillDKG has no "no" short of this: a participant who never approves stalls
+ * the ceremony for good, and the others are left waiting on a key that will
+ * not come. Saying so lets them stop. It is the same FAILURE message a fault
+ * sends, and every device files it the same way -- no key is created, and the
+ * group can start again.
+ *
+ * Returns whether it was ended. Refuses, rather than throws, a ceremony this
+ * device is not in or one that is already over: a stale screen may ask.
+ */
+ suspend fun abandon(
+ database: BennuDatabase,
+ localChatRoom: LocalChatRoom,
+ sessionId: String,
+ ): Boolean {
+ val session = database.dkgSessionDao().getSessionById(sessionId) ?: return false
+
+ if (session.stage == DkgRitualStage.COMPLETE || session.stage == DkgRitualStage.FAILED) {
+ logger.i("Ritual $sessionId is already over; nothing to abandon")
+ return false
+ }
+
+ if (session.userPublicKey !in participantsOf(session, localChatRoom)) {
+ logger.w("Ritual $sessionId does not include this device; not abandoning it")
+ return false
+ }
+
+ logger.i("Abandoning ritual $sessionId")
+
+ fail(database, session, ABANDONED)
+ broadcast(
+ database = database,
+ localChatRoom = localChatRoom,
+ session = session,
+ kind = DkgRitualEvents.FAILURE,
+ content = ABANDONED
+ )
+
+ return true
+ }
+
/**
* Records that this device's owner agreed to [step], then lets the ritual run as
* far as the next thing it is waiting on.
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/ChronicleManager.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/ChronicleManager.kt
index 3fe5838d..39cf6bfb 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/ChronicleManager.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/ChronicleManager.kt
@@ -18,7 +18,7 @@ import kotlin.time.Instant
import com.machankura.bennu.compose.nostr.chronicle.ChronicleEvent
import com.machankura.bennu.compose.nostr.chronicle.ChronicleRequestEvent
import com.machankura.bennu.compose.nostr.frost.GroupKeyStateEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationChunkEvent
+import com.machankura.bennu.compose.nostr.chronicle.ChronicleKinds
/**
* Building the group's signed record into pages a member who lacks it can apply.
@@ -28,49 +28,39 @@ import com.machankura.bennu.compose.nostr.nip30303.TranslationChunkEvent
* locally by each device that took part and never goes on the wire. This is how
* it gets to them.
*
- * ### The events are the chronicle, and the rows are the fallback
+ * ### Carrying nothing, for now
+ *
+ * What a chronicle may carry is [ChronicleEvent.KINDS], and that is empty since
+ * the document kinds it was built for were removed (docs/ceremony-creation.md,
+ * Phase 7). Every entry point here takes the kinds as a parameter defaulting to
+ * that list, and with it empty the chronicle is quiet: [requestIfEmpty] asks for
+ * nothing, [sendTo] sends nothing, and a page from an older build applies
+ * nothing. The machinery is kept, and tested with a list of the tests' own, for
+ * the next kind that should join.
+ *
+ * ### The events are the chronicle
*
* `GroupSignedEvent` holds what the group signed, as it signed it, so
- * [signedEventsOf] reads it first: no rebuild, no round-trip risk, and nothing
- * that depends on a row having kept every field of the event it came from. The
- * artifact's version label is the standing example -- it is not on the artifact
- * row at all, and [rebuiltEventsOf] has to go and find it on the initial version
- * or leave the artifact out.
+ * [signedEventsOf] reads it: no rebuild, no round-trip risk, and nothing that
+ * depends on a row having kept every field of the event it came from.
*
- * A room whose work predates that table has no events on file, so the rebuild
- * stays as the fallback for exactly what the table is missing, keyed by id.
- * Every payload it produces stands or falls on being byte-identical to what was
- * signed; `ChronicleRoundTripTest` is what says it is, per kind, against a real
- * quorum, and it found two faults in the artifact's rebuild the first time it
- * ran -- both of which would have shipped payloads that every receiver drops as
- * forgeries without a word. Both it and everything that exists only to hold it
- * up are marked `@Deprecated`; the fallback can go once no install still holds
- * pre-v13 work, and docs/member-chronicle.md's "Retiring the rebuild" is the list
- * of what goes with it.
- *
- * **The allowlist does real work on the way out now.** The rebuild could only
- * ever produce document kinds; the table holds everything the group has ever
- * signed, `GroupKeyStateEvent` included. So [signedEventsOf] filters on
- * [ChronicleEvent.isChroniclable] before anything else, which is the same rule
- * [applyPage] applies on the way in. Without it `ChronicleEvent.build` would
- * refuse the page and take the whole chronicle down with it.
- *
- * A room's own key state no longer sits in that table under the room -- it is
- * signed in the NIP-17 room the ceremony ran in, before the room exists, and
- * filed under that room; see `GroupKeyStateManager`. That makes the filter a
- * narrower guard than it was and not a redundant one: what it is really stopping
+ * **The allowlist does real work on the way out.** The table holds everything
+ * the group has ever signed, `GroupKeyStateEvent` included. So [signedEventsOf]
+ * filters on the kinds before anything else, which is the same rule [applyPage]
+ * applies on the way in. Without it `ChronicleEvent.build` would refuse the page
+ * and take the whole chronicle down with it. What the filter is really stopping
* is a member replaying any group-signed statement about the record as though it
- * were work, and [applyPage] refuses the same kinds coming the other way. The
- * two are a pair and neither is safe to drop on the strength of the other.
+ * were work, and [applyPage] refuses the same kinds coming the other way. The two
+ * are a pair and neither is safe to drop on the strength of the other.
*
* ### Nothing unverifiable leaves
*
- * Every rebuilt event is checked with [GroupKeyStateEvent.isSignedByRoom] before
- * it is packed, against the same room id the recipient will check it with. That
- * is not politeness towards the receiver, who checks anyway. It is what keeps an
- * chronicle honest about its own size: a row that came from a member's rumor
- * cannot be chronicled, and dropping it here rather than letting the recipient
- * drop it means the page count says what will actually arrive.
+ * Every event is checked with [GroupKeyStateEvent.isSignedByRoom] before it is
+ * packed, against the same room id the recipient will check it with. That is not
+ * politeness towards the receiver, who checks anyway. It is what keeps a
+ * chronicle honest about its own size: dropping a payload here rather than
+ * letting the recipient drop it means the page count says what will actually
+ * arrive.
*/
object ChronicleManager {
private const val TAG = "ChronicleManager"
@@ -93,16 +83,13 @@ object ChronicleManager {
recipient: HexKey,
chronicleId: String = RandomInstance.bytes(32).toHex(),
createdAt: Long = TimeUtils.now(),
+ kinds: ChronicleKinds = ChronicleEvent.KINDS,
): List> {
- val held = signedEventsOf(database, chatRoomId)
+ val held = signedEventsOf(database, chatRoomId, kinds)
- // One rule over both sources: nothing leaves that the recipient could
- // not check for themselves. What a drop means depends on where it came
- // from, and the two are worth telling apart when reading this log --
- // from the rebuild it is the ordinary case of a member's own rumor
- // sitting in the same table as the group's work, and from the record it
- // is a row that has drifted from the event it recorded, which nothing
- // in this app does on purpose.
+ // Nothing leaves that the recipient could not check for themselves. A
+ // drop here is a row that has drifted from the event it recorded, which
+ // nothing in this app does on purpose.
val verified = held.filter { GroupKeyStateEvent.isSignedByRoom(it, chatRoomId) }
if (verified.size != held.size) {
logger.d(
@@ -111,7 +98,7 @@ object ChronicleManager {
)
}
- val pages = paginate(ChronicleEvent.inApplyOrder(verified))
+ val pages = paginate(kinds.inApplyOrder(verified))
if (pages.isEmpty()) {
logger.i("Nothing signed to chronicle for room $chatRoomId")
return emptyList()
@@ -130,6 +117,7 @@ object ChronicleManager {
count = pages.size,
recipient = recipient,
createdAt = createdAt,
+ kinds = kinds,
)
}
}
@@ -139,9 +127,12 @@ object ChronicleManager {
/**
* Ask the group for its signed history, if this device holds none of it.
*
- * Called on entering a room. The condition is deliberately crude -- no
- * dialects and no artifacts -- because the three cases it has to catch look
- * identical from inside the database and should not be told apart:
+ * Called on entering a room. Does nothing while [kinds] is empty, which it
+ * is in this app at the moment -- see the class comment.
+ *
+ * The condition is deliberately crude -- nothing of a chroniclable kind on
+ * file -- because the three cases it has to catch look identical from inside
+ * the database and should not be told apart:
*
* - a member added after the work was done, whose invite may be recent;
* - a reinstall, whose invite is long past;
@@ -162,12 +153,17 @@ object ChronicleManager {
database: BennuDatabase,
chatRoomId: String,
userPublicKey: HexKey,
+ kinds: ChronicleKinds = ChronicleEvent.KINDS,
): Boolean {
+ // Quiet while a chronicle may carry nothing: there is no answer worth
+ // asking for, and asking would put a request on the wire and a line in
+ // the transcript on every room the member opens.
+ if (kinds.isEmpty()) return false
+
val chatRoom = database.chatRoomDao().findChatRoomById(chatRoomId)?.chatRoom ?: return false
if (chatRoom.chronicleRequestedAt != null) return false
- val holdsWork = database.mantraDialectDao().getDialectsByChatRoomId(chatRoomId).isNotEmpty() ||
- database.mantraArtifactDao().getArtifactsByChatRoomId(chatRoomId).isNotEmpty()
+ val holdsWork = signedEventsOf(database, chatRoomId, kinds).isNotEmpty()
if (holdsWork) return false
@@ -217,10 +213,11 @@ object ChronicleManager {
chatRoomId: String,
userPublicKey: HexKey,
recipient: HexKey,
+ kinds: ChronicleKinds = ChronicleEvent.KINDS,
): Int {
if (recipient.equals(userPublicKey, ignoreCase = true)) return 0
- val pages = assemble(database, chatRoomId, recipient)
+ val pages = assemble(database, chatRoomId, recipient, kinds = kinds)
if (pages.isEmpty()) {
logger.i("Nothing signed here to send ${recipient.take(8)} for $chatRoomId")
return 0
@@ -373,6 +370,7 @@ object ChronicleManager {
chatRoomId: String,
userPublicKey: HexKey,
page: Event,
+ kinds: ChronicleKinds = ChronicleEvent.KINDS,
): Outcome {
val recipient = ChronicleEvent(
id = page.id,
@@ -388,7 +386,7 @@ object ChronicleManager {
return Outcome()
}
- return sweep(database, chatRoomId, userPublicKey)
+ return sweep(database, chatRoomId, userPublicKey, kinds)
}
/**
@@ -421,6 +419,7 @@ object ChronicleManager {
database: BennuDatabase,
chatRoomId: String,
userPublicKey: HexKey,
+ kinds: ChronicleKinds = ChronicleEvent.KINDS,
): Outcome {
val pages = database.marmotInnerEventDao()
.getByChatRoomAndKinds(chatRoomId, listOf(ChronicleEvent.KIND))
@@ -433,7 +432,7 @@ object ChronicleManager {
while (true) {
pass = Outcome()
- pages.forEach { pass += applyPage(database, chatRoomId, it) }
+ pages.forEach { pass += applyPage(database, chatRoomId, it, kinds) }
if (pass.failed == 0 || pass.failed >= previousFailures) {
if (pass.failed > 0) {
@@ -513,6 +512,7 @@ object ChronicleManager {
database: BennuDatabase,
chatRoomId: String,
stored: MarmotInnerEvent,
+ kinds: ChronicleKinds,
): Outcome {
val payloads = ChronicleEvent.decodePage(stored.content)
if (payloads == null) {
@@ -530,13 +530,13 @@ object ChronicleManager {
var outcome = Outcome()
- ChronicleEvent.inApplyOrder(payloads).forEach { payload ->
+ kinds.inApplyOrder(payloads).forEach { payload ->
// The allowlist first, and it is not a formality. Verification admits
// an event to the apply path on the strength of the group's
// signature, which makes every kind the group has ever signed
// replayable by any member at any time -- a GroupKeyStateEvent from
// an earlier epoch passes the signature check perfectly.
- if (!ChronicleEvent.isChroniclable(payload.kind)) {
+ if (!kinds.isChroniclable(payload.kind)) {
logger.w(
"Chronicle page ${stored.id.take(8)} carries kind ${payload.kind}, " +
"which a chronicle may not deliver; dropping ${payload.id.take(8)}"
@@ -605,224 +605,31 @@ object ChronicleManager {
}
/**
- * Every chroniclable event this device holds for the room: the ones the group
- * signed here or sent here, plus anything only the rows still remember.
+ * Every chroniclable event this device holds for the room, as the group
+ * signed it.
*
- * The record comes first because it is the event rather than a reconstruction
- * of one, and the rebuild fills the gap behind it -- keyed by id, so an event
- * held both ways travels once. A room that upgraded mid-life has both, and
- * neither half is complete on its own.
- *
- * The two disagree only in one direction worth naming. An id the rebuild
- * produces that the record does not hold is either work from before the
- * table existed, which is the point of the fallback, or a rebuild that has
- * gone wrong -- and a wrong rebuild hashes to an id whose signature does not
- * verify, so the filter in [assemble] drops it either way rather than
- * shipping a payload every receiver reads as a forgery.
- *
- * Order does not matter at this point; [ChronicleEvent.inApplyOrder] settles it
- * afterwards. It is stable within a rank, so a room holding some of its work
- * both ways can order two chapters differently from a member holding one way
- * only. That costs nothing: pages are idempotent and applied payload by
- * payload, and two members already differed by the order their rows were
- * written in.
+ * Order does not matter at this point; [ChronicleKinds.inApplyOrder] settles
+ * it afterwards.
*/
private suspend fun signedEventsOf(
database: BennuDatabase,
chatRoomId: String,
- ): List {
- val recorded = database.groupSignedEventDao()
- .getByChatRoomId(chatRoomId)
- // The allowlist, applied to the source that can actually trip it --
- // see the class comment. A key state on file is the room's own, and
- // sending it would be handing every member a validly signed
- // statement about what the room signs with, replayable forever.
- .filter { ChronicleEvent.isChroniclable(it.kind) }
- .map { it.toEvent() }
-
- val onFile = recorded.mapTo(mutableSetOf()) { it.id }
- val rebuilt = rebuiltEventsOf(database, chatRoomId).filterNot { it.id in onFile }
-
- if (rebuilt.isNotEmpty()) {
- logger.d(
- "Chronicling $chatRoomId: ${recorded.size} event(s) as the group signed them, " +
- "${rebuilt.size} rebuilt from rows that predate the record"
- )
- }
-
- return currentTranslationsOnly(recorded + rebuilt)
- }
-
- /**
- * Drops every translation of a passage but the one that stands.
- *
- * The record keeps every event the group ever signed, deliberately -- a
- * signature is the group's statement and discarding one is not this table's
- * business. The rows do not: `ChatMessage.applyInnerEvent` supersedes a
- * translation chunk, deleting the one it replaces, so a passage translated
- * three times leaves one row and three events.
- *
- * That difference reaches the chronicle the moment it is read from the record
- * rather than rebuilt from rows, and it compounds: every draft a group ever
- * signed would travel in every chronicle it ever sends, for as long as the room
- * exists. A chronicle exists to catch a member up on where the group has got
- * to, not to hand them its drafting history.
- *
- * **The rule is the applying arm's, restated rather than approximated**:
- * newest by the timestamp the group signed at, id breaking a tie. It has to
- * be, or the chronicle would ship one translation as current and the recipient
- * would settle on another -- and since both are validly signed, nothing
- * downstream would notice the disagreement.
- *
- * Dropping the drafts is safe precisely because the recipient applies the
- * same rule: it is not what keeps them correct, only what stops them being
- * sent work they would immediately discard.
- *
- * A translation naming no passage is left alone rather than grouped with
- * others: it is unappliable either way, and letting one stand in for a whole
- * passage would let a malformed event suppress a good one.
- */
- private fun currentTranslationsOnly(events: List): List {
- val translations = events.filter { it.kind == TranslationChunkEvent.KIND }
- if (translations.size < 2) return events
-
- val current = translations
- .groupBy { event ->
- val translation = TranslationChunkEvent(
- id = event.id,
- pubKey = event.pubKey,
- createdAt = event.createdAt,
- tags = event.tags,
- content = event.content,
- sig = event.sig,
- )
-
- val chapterId = translation.translationChapterId()
- val chunkId = translation.chunkId()
-
- if (chapterId == null || chunkId == null) event.id else "$chapterId/$chunkId"
- }
- .values
- .mapNotNull { candidates ->
- candidates.maxWithOrNull(compareBy({ it.createdAt }, { it.id }))
- }
- .mapTo(mutableSetOf()) { it.id }
-
- if (current.size != translations.size) {
- logger.d(
- "Leaving ${translations.size - current.size} superseded translation(s) " +
- "out of the chronicle"
- )
- }
-
- return events.filter { it.kind != TranslationChunkEvent.KIND || it.id in current }
- }
-
- /**
- * The room's rows, rebuilt into the events they came from.
- *
- * Walked down the tree rather than queried per kind, because only dialects
- * and artifacts have a by-room query and the rest hang off a parent. The walk
- * is also what makes an artifact's version label reachable: it is not on the
- * artifact row -- see `MantraArtifact.toArtifactEvent` -- and the version it
- * went into is one step away here.
- *
- * Still walked on every chronicle, and by now it contributes nothing in most
- * rooms: everything signed or applied since `GroupSignedEvent` existed is on
- * file as an event, and [signedEventsOf] discards whatever this rebuilds of
- * it. The walk is a handful of indexed queries against a room's own rows,
- * and it is what makes a half-upgraded room whole, so it runs rather than
- * being skipped when the record looks complete -- there is no way to tell a
- * complete record from a partial one without doing it.
- *
- * It returns everything it can rebuild and lets [signedEventsOf] and the
- * verify filter decide what can travel.
- *
- * Deprecated rather than merely legacy: it is a whole mechanism kept alive
- * for a shrinking set of rows, and it takes eight `toXEvent()` methods and a
- * ten-case round-trip suite with it. **docs/member-chronicle.md, "Retiring the
- * rebuild", is the checklist** -- what goes, what only looks like it goes,
- * and the one thing that has to be true before any of it can.
- */
- @Deprecated(
- "Chronicle fallback for work signed before the GroupSignedEvent table. " +
- "Goes when the last pre-v13 install does -- see the removal checklist " +
- "in docs/member-chronicle.md."
- )
- private suspend fun rebuiltEventsOf(
- database: BennuDatabase,
- chatRoomId: String,
- ): List = buildList {
- database.mantraDialectDao().getDialectsByChatRoomId(chatRoomId).forEach {
- add(it.toDialectEvent())
- }
-
- database.mantraArtifactDao().getArtifactsByChatRoomId(chatRoomId).forEach { artifact ->
- val versions = database.mantraArtifactVersionDao()
- .getArtifactVersionsByArtifactId(artifact.id)
-
- // The version an artifact starts life with carries the label the
- // artifact was signed with, and `ArtifactVersionEvent.initialVersionOf`
- // gives it the artifact's own timestamp. The label is still not on the
- // artifact row -- `fromArtifactEvent` drops it -- so this is where it
- // comes back from. An artifact with no such version is one this device
- // cannot rebuild, which is a gap in the chronicle rather than a reason to
- // abandon it.
- val versionLabel = versions
- .firstOrNull { it.createdAt == artifact.createdAt }
- ?.versionLabel
-
- if (versionLabel == null) {
- logger.w("Artifact ${artifact.id} has no initial version; leaving it out")
- } else {
- add(artifact.toArtifactEvent(versionLabel = versionLabel))
- }
-
- versions.forEach { version ->
- add(version.toArtifactVersionEvent())
-
- database.mantraChapterDao()
- .getChaptersByArtifactVersionId(version.id)
- .forEach { chapter ->
- add(chapter.toChapterEvent())
-
- database.mantraChunkDao()
- .getChunksByChapterId(chapter.id)
- .forEach { add(it.toChunkEvent()) }
- }
-
- database.mantraTranslationArtifactVersionDao()
- .getTranslationsByArtifactVersionId(version.id)
- .forEach { translationVersion ->
- add(translationVersion.toTranslationArtifactVersionEvent())
-
- database.mantraTranslationChapterDao()
- .getTranslationChaptersByTranslationArtifactVersionId(translationVersion.id)
- .forEach { translationChapter ->
- add(translationChapter.toTranslationChapterEvent())
-
- // Only the translation that survived supersession
- // is here to be found: retranslating a passage
- // changes the text and so the event id, and the
- // arm that applies one drops what it replaces. So
- // a chronicle carries a group's current answer to
- // each passage rather than its drafts, which is
- // the same thing every other member holds.
- database.mantraTranslationChunkDao()
- .getTranslationChunksByTranslationChapterId(translationChapter.id)
- .forEach { add(it.toTranslationChunkEvent()) }
- }
- }
- }
- }
- }
+ kinds: ChronicleKinds,
+ ): List = database.groupSignedEventDao()
+ .getByChatRoomId(chatRoomId)
+ // The allowlist, applied to the source that can actually trip it --
+ // see the class comment. A key state on file is the room's own, and
+ // sending it would be handing every member a validly signed
+ // statement about what the room signs with, replayable forever.
+ .filter { kinds.isChroniclable(it.kind) }
+ .map { it.toEvent() }
/**
* [events] cut into pages that fit, keeping the order they arrive in.
*
* Greedy: fill a page until the next event would cross either cap. Both are
- * checked because they bind different chronicles -- a room of one-line dialects
- * hits the count first and a room of chapters hits the bytes.
+ * checked because they bind different chronicles -- a room of one-line events
+ * hits the count first and a room of long ones hits the bytes.
*
* The bytes are the page's *escaped* bytes -- what it will occupy as the
* `content` of the Marmot app event that carries it, which is what a
@@ -832,7 +639,7 @@ object ChronicleManager {
*
* An event too large to share a page with anything is given one of its own.
* One too large for even that is dropped with a log rather than failing the
- * chronicle: a chapter nobody can chronicle is a hole, and a member who gets
+ * chronicle: an event nobody can chronicle is a hole, and a member who gets
* nothing at all is a bigger one.
*/
private fun paginate(events: List): List> {
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/TranslationScaffold.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/TranslationScaffold.kt
deleted file mode 100644
index 83081bf8..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/TranslationScaffold.kt
+++ /dev/null
@@ -1,92 +0,0 @@
-package com.machankura.bennu.compose.managers
-
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
-import com.machankura.bennu.compose.database.model.MantraChapter
-import com.machankura.bennu.compose.database.model.MantraTranslationChapter
-import com.machankura.bennu.compose.nostr.nip30303.TranslationChapterEvent
-
-/**
- * The rows that join a translation to the chapters it is a translation of.
- *
- * A translation chapter carries no words. It is `(translation, chapter,
- * position)` and nothing else, and it exists so that a translated chunk has
- * somewhere to hang: a translation without one for a chapter is a translation
- * that chapter cannot be worked on in.
- *
- * Both ends of that join arrive on their own schedule -- a chapter is signed
- * into an artifact that already has translations, a translation is started on
- * an artifact that already has chapters -- so the same scaffolding is built
- * from either side and, when the two miss each other, afterwards. One function
- * for all three, because three copies of a cross product is three chances to
- * disagree about what a translation covers.
- */
-object TranslationScaffold {
-
- /**
- * A source chapter, reduced to what a translation chapter needs of it:
- * which chapter, and where it sits.
- *
- * Taken as this rather than as a [MantraChapter] because the chapter is not
- * always a row yet. When a chapter is signed into an artifact, the
- * scaffolding goes out in the same breath as the chapter itself, against an
- * id that exists only as the unsigned event a session is about to sign.
- */
- data class SourceChapter(
- val id: HexKey,
- val index: Int,
- ) {
- companion object {
- fun of(chapter: MantraChapter) = SourceChapter(id = chapter.id, index = chapter.index)
- }
- }
-
- /**
- * A translation chapter for every pair of [translationArtifactVersionIds]
- * and [chapters], in that nesting: a translation's chapters stay together
- * and in reading order.
- *
- * The order is the order a session will sign them in and the order they
- * will be applied in, so it is fixed here rather than left to a caller.
- *
- * [createdAt] is stamped on all of them rather than read per event, so that
- * a scaffolding proposed as one act reads as one -- the timestamp of the
- * chapter or the translation that occasioned it, not of whichever moment
- * each template happened to be built in.
- */
- fun chaptersOf(
- translationArtifactVersionIds: List,
- chapters: List,
- createdAt: Long,
- ): List> =
- translationArtifactVersionIds.flatMap { translationArtifactVersionId ->
- chapters.map { chapter ->
- TranslationChapterEvent.build(
- translationArtifactVersionId = translationArtifactVersionId,
- chapterId = chapter.id,
- // The source chapter's own position, never this list's: a
- // catch-up proposes a subset, so counting the list would
- // renumber the chapters it happens to be filling in.
- index = chapter.index,
- createdAt = createdAt,
- )
- }
- }
-
- /**
- * The source chapters a translation has nothing for yet.
- *
- * Matched on the source chapter each translation chapter names rather than
- * on how many there are of each. A translation that is missing its second
- * chapter and has picked up its third is not a translation that is missing
- * its last one, and a count would say it was.
- */
- fun chaptersMissingFrom(
- translationChapters: List,
- sourceChapters: List,
- ): List {
- val covered = translationChapters.mapTo(mutableSetOf()) { it.chapterId }
-
- return sourceChapters.filterNot { it.id in covered }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/GroupEventProposal.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/GroupEventProposal.kt
index 8d65a414..b8b49037 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/GroupEventProposal.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/GroupEventProposal.kt
@@ -48,8 +48,8 @@ object GroupEventProposal {
*
* Not the kinds `ChatMessage.applyInnerEvent` has an arm for. A subgroup
* certificate or a key state event has invariants a paste cannot be trusted
- * to meet and a place in the room's life that a form is not, and the
- * nip30303 kinds have editors of their own. The line is "has a section on the
+ * to meet and a place in the room's life that a form is not. The line is
+ * "has a section on the
* group's screen", because that is where a member goes to see it landed.
*/
val ACCEPTED_KINDS: Set =
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/chronicle/ChronicleEvent.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/chronicle/ChronicleEvent.kt
index c6e7c1ce..db522049 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/chronicle/ChronicleEvent.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/chronicle/ChronicleEvent.kt
@@ -14,14 +14,6 @@ import com.machankura.bennu.compose.network.serialization.CommonJson
import com.machankura.bennu.compose.nostr.chronicle.tags.ChronicleIdTag
import com.machankura.bennu.compose.nostr.chronicle.tags.ChroniclePageTag
import com.machankura.bennu.compose.nostr.chronicle.tags.ChronicleRecipientTag
-import com.machankura.bennu.compose.nostr.nip30303.ArtifactEvent
-import com.machankura.bennu.compose.nostr.nip30303.ArtifactVersionEvent
-import com.machankura.bennu.compose.nostr.nip30303.ChapterEvent
-import com.machankura.bennu.compose.nostr.nip30303.ChunkEvent
-import com.machankura.bennu.compose.nostr.nip30303.DialectEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationArtifactVersionEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationChapterEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationChunkEvent
/**
* 30327
@@ -45,16 +37,7 @@ import com.machankura.bennu.compose.nostr.nip30303.TranslationChunkEvent
* deliberately does not do: it never carries the chat, and it cannot make its
* recipient able to *sign* anything.
*
- * ### Why not a [com.machankura.bennu.compose.nostr.nip30303.SubmissionEvent] each
- *
- * The envelope fits and the meaning does not. A submission is an *act* -- this
- * member is putting this event in front of this group -- and a chronicle asserts
- * nothing; it re-delivers what the group already agreed. On one kind a
- * four-hundred-event backfill is indistinguishable from four hundred new
- * submissions and every device has to guess which it is looking at. It would
- * also be one inner event and one kind:445 per payload, where a page is one, and
- * the submission arm of `ChatMessage.applyInnerEvent` files a chat line per
- * payload, which a chronicle must not.
+ * It carries nothing in this app at the moment -- see [KINDS].
*/
@Immutable
class ChronicleEvent(
@@ -88,18 +71,12 @@ class ChronicleEvent(
companion object {
/**
* Sits past `GroupKeyStateEvent` at 30326, in the Marmot inner-event
- * space it shares with the nip30303 document kinds and the FROST signing
- * family.
+ * space it shares with the FROST signing family.
*
- * 30313 was free next to the document kinds and is not used, on
- * `FrostSigningEvents`' own advice: the DKG's 30310-30316 already overlap
- * that range and are told apart only by living in NIP-17 gift wraps
- * instead, which is "an accident of routing rather than a decision, and
- * the next family added should not rely on it." This is that next family.
- *
- * It is also the right neighbourhood on the merits. A chronicle is not a
- * document kind; it is a statement about the record, which is what a key
- * state is too.
+ * 30313 is not used, on `FrostSigningEvents`' own advice: the DKG's
+ * 30310-30316 sit there, and once collided with document kinds that
+ * shared their numbers. This family took numbers nobody else uses
+ * instead.
*/
const val KIND: Kind = 30327
@@ -109,7 +86,7 @@ class ChronicleEvent(
* The most JSON one page may carry.
*
* A byte cap rather than a count alone, because the payloads vary by two
- * orders of magnitude -- a chunk is a paragraph, an artifact is a URL.
+ * orders of magnitude -- a paragraph of text against a single URL.
* Sized so the finished kind:445 clears the tightest relay limits with
* room for the MLS framing and the NIP-44 expansion that sit outside it;
* measure it against a real one rather than trusting the arithmetic.
@@ -130,8 +107,8 @@ class ChronicleEvent(
* The most payloads one page may carry.
*
* The byte cap bounds the transport; this bounds the receiver's *work*,
- * and they are not the same limit -- 64 KB of one-line dialects is a lot
- * more signature verifies than 64 KB of chapters.
+ * and they are not the same limit -- 64 KB of one-line events is a lot
+ * more signature verifies than 64 KB of long ones.
*
* **Sized under what the byte cap allows, or it would never fire.** An
* event carries a 64-character id, a 64-character pubkey and a
@@ -154,82 +131,30 @@ class ChronicleEvent(
const val MAX_PAGE_EVENTS = 96
/**
- * The kinds a chronicle may carry, in the order they have to be applied.
+ * The kinds a chronicle may carry in this app: **none, at the moment.**
*
- * One list doing both jobs, because a separate allowlist is one more
- * thing that can disagree with the order it is applied in.
+ * It was built to hand a late member the group's signed documents --
+ * dialects, artifacts, chapters and their translations -- and those kinds
+ * were removed with the screens that made them (docs/ceremony-creation.md,
+ * Phase 7). Everything else the group signs is left out on purpose:
*
- * **The order is Room's, not nostr's.** Every one of these has a foreign
- * key on the one before it, so a chronicle applied out of order is a
- * constraint violation rather than a wrong answer. Kind order is not
- * dependency order and never was -- a translation chapter (30308) hangs
- * off a translation artifact version (30306) which hangs off an artifact
- * version (30301) -- so this is a list rather than a `sortedBy { kind }`.
+ * - a `GroupKeyStateEvent` or a subgroup's birth certificate is a validly
+ * signed statement about the group that anyone holding a copy could
+ * replay -- see [ChronicleKinds];
+ * - posts, profiles, relay lists and wallet statements have their own
+ * ways to a member who joins late, or none worth a chronicle.
*
- * **It is an allowlist first.** Verification admits an event to the apply
- * path on the strength of the group's signature, which makes every kind
- * the group has ever signed replayable by any member at any time. A
- * `GroupKeyStateEvent` is group-signed and passes verification perfectly,
- * so a chronicle carrying an old one is a validly signed statement about
- * what the room signs with, replayed by whoever kept a copy. Nothing but
- * this list stops it.
- *
- * ### What is missing from it, and why
- *
- * **Only kinds the group actually signs can be here**, because a chronicle
- * that cannot be verified is one that has to be believed. Six of the
- * thirteen nip30303 kinds reach a signing session; the rest travel as
- * rumors -- empty signature, member author, vouched for by the MLS frame
- * they arrived in and by nothing that survives leaving it.
- *
- * Left out for that reason:
- *
- * - `TranslationEvent` (30311). Nothing builds one; the inbound arm
- * exists and no producer does.
- * - The contributor lists (30305, 30307, 30310). `applyInnerEvent` has
- * no arm that writes a row for any of them, so chronicling them would
- * cost bytes and restore nothing.
- *
- * Two kinds were on that list and are not any more, because the app
- * stopped leaving them unsigned. `ArtifactVersionEvent` (30301) used to be
- * derived from the signed artifact on arrival, and is now the second item
- * of the batch that carries it. `TranslationChunkEvent` (30309) -- the
- * translated text itself -- used to be submitted as its author's rumor,
- * and is now proposed to the group like everything else. Both are
- * therefore checkable, and a chronicle that left them out would hand a new
- * member the whole structure and none of the prose.
+ * So the machinery stays and carries nothing: with an empty list a device
+ * asks for no chronicle, sends none, and applies nothing from one that an
+ * older build sends -- see `ChronicleManager`. Adding a kind back is a
+ * decision that belongs here, with the reason it is safe to replay.
*/
- private val APPLY_ORDER: List = listOf(
- DialectEvent.KIND,
- ArtifactEvent.KIND,
- ArtifactVersionEvent.KIND,
- ChapterEvent.KIND,
- ChunkEvent.KIND,
- TranslationArtifactVersionEvent.KIND,
- TranslationChapterEvent.KIND,
- TranslationChunkEvent.KIND,
- )
+ val KINDS: ChronicleKinds = ChronicleKinds.NONE
- /** Every kind a chronicle may carry. */
- val CHRONICLABLE_KINDS: Set = APPLY_ORDER.toSet()
+ /** Every kind a chronicle may carry in this app. */
+ val CHRONICLABLE_KINDS: Set = KINDS.all
- /**
- * Where [kind] sits in dependency order, or null if a chronicle may not
- * carry it at all.
- */
- fun applyRank(kind: Kind): Int? = APPLY_ORDER.indexOf(kind).takeIf { it >= 0 }
-
- fun isChroniclable(kind: Kind): Boolean = kind in CHRONICLABLE_KINDS
-
- /**
- * [payloads] in dependency order, so a page applies front to back.
- *
- * Stable within a rank: two chapters of one version have no order between
- * them and keeping the caller's is one less thing that varies between two
- * members assembling the same chronicle.
- */
- fun inApplyOrder(payloads: List): List =
- payloads.sortedBy { applyRank(it.kind) ?: Int.MAX_VALUE }
+ fun isChroniclable(kind: Kind): Boolean = KINDS.isChroniclable(kind)
/**
* The bytes [json] occupies once it is the `content` of a Marmot app event --
@@ -315,6 +240,7 @@ class ChronicleEvent(
count: Int,
recipient: HexKey,
createdAt: Long = TimeUtils.now(),
+ kinds: ChronicleKinds = KINDS,
initializer: TagArrayBuilder.() -> Unit = {},
): EventTemplate {
require(payloads.isNotEmpty()) { "A chronicle page carries at least one event" }
@@ -322,7 +248,7 @@ class ChronicleEvent(
"A chronicle page carries at most $MAX_PAGE_EVENTS events, not ${payloads.size}"
}
payloads.forEach {
- require(isChroniclable(it.kind)) { "A chronicle may not carry kind ${it.kind}" }
+ require(kinds.isChroniclable(it.kind)) { "A chronicle may not carry kind ${it.kind}" }
}
val content = encodePage(payloads)
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/chronicle/ChronicleKinds.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/chronicle/ChronicleKinds.kt
new file mode 100644
index 00000000..2de65eb4
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/chronicle/ChronicleKinds.kt
@@ -0,0 +1,51 @@
+package com.machankura.bennu.compose.nostr.chronicle
+
+import com.vitorpamplona.quartz.nip01Core.core.Event
+import com.vitorpamplona.quartz.nip01Core.core.Kind
+
+/**
+ * The kinds a chronicle may carry, in the order they have to be applied.
+ *
+ * One list doing both jobs, because a separate allowlist is one more thing that
+ * can disagree with the order it is applied in. The order is the database's, not
+ * nostr's: where one kind's rows hang off another's, the one they hang off comes
+ * first, so a page applies front to back.
+ *
+ * **It is an allowlist first.** Verification admits an event to the apply path on
+ * the strength of the group's signature, which makes every kind the group has
+ * ever signed replayable by any member at any time. A `GroupKeyStateEvent` is
+ * group-signed and passes verification perfectly, so a chronicle carrying an old
+ * one is a validly signed statement about what the room signs with, replayed by
+ * whoever kept a copy. Nothing but this list stops it.
+ *
+ * A value rather than a constant so the machinery can be exercised without
+ * making anything chroniclable in the app: the app's own list is
+ * [ChronicleEvent.KINDS], and the tests hand in theirs.
+ */
+class ChronicleKinds(private val applyOrder: List) {
+
+ /** Every kind a chronicle may carry. */
+ val all: Set = applyOrder.toSet()
+
+ /** A chronicle that may carry nothing asks for nothing and sends nothing. */
+ fun isEmpty(): Boolean = applyOrder.isEmpty()
+
+ /** Where [kind] sits in apply order, or null if a chronicle may not carry it at all. */
+ fun applyRank(kind: Kind): Int? = applyOrder.indexOf(kind).takeIf { it >= 0 }
+
+ fun isChroniclable(kind: Kind): Boolean = kind in all
+
+ /**
+ * [payloads] in apply order, so a page applies front to back.
+ *
+ * Stable within a rank: two events of one kind have no order between them,
+ * and keeping the caller's is one less thing that varies between two members
+ * assembling the same chronicle.
+ */
+ fun inApplyOrder(payloads: List): List =
+ payloads.sortedBy { applyRank(it.kind) ?: Int.MAX_VALUE }
+
+ companion object {
+ val NONE = ChronicleKinds(emptyList())
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/dkg/DkgRitualEvents.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/dkg/DkgRitualEvents.kt
index 7df3a943..5d30666f 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/dkg/DkgRitualEvents.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/dkg/DkgRitualEvents.kt
@@ -9,11 +9,16 @@ import com.machankura.bennu.compose.nostr.subgroup.tags.SubgroupParentTag
/**
* The nostr kinds a ChillDKG ritual is carried on.
*
- * These are **rumor** kinds: they only ever exist inside a NIP-17 gift wrap
- * addressed to the group, so no relay sees them unencrypted and the replaceable
- * semantics normally implied by the 3xxxx range never apply. They sit next to
- * the app's other private kinds (30300-30309) deliberately — the transport,
- * sealing and broadcast pipeline is the same one chat messages ride.
+ * These are **rumor** kinds: they only ever travel encrypted -- inside a NIP-17
+ * gift wrap for a group's own ceremony, and as a Marmot inner event in the
+ * parent's room for a subgroup's -- so no relay sees them in the clear and the
+ * replaceable semantics normally implied by the 3xxxx range never apply. The
+ * transport, sealing and broadcast pipeline is the one chat messages ride.
+ *
+ * 30310-30312 used to be nip30303 document kinds too, and a round 1 read as a
+ * document submission once reached a parent's chat as raw hex. `ChatMessage`
+ * recognises these before any content kind for that reason, and the document
+ * kinds are gone. See docs/ceremony-creation.md.
*
* Who talks to whom, in order:
*
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/frost/FrostSigningEvents.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/frost/FrostSigningEvents.kt
index 82963ec9..3a5e9ebf 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/frost/FrostSigningEvents.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/frost/FrostSigningEvents.kt
@@ -51,23 +51,17 @@ import com.machankura.bennu.compose.nostr.frost.tags.FrostSilentMembersTag
*
* ### Why 3032x
*
- * These share the inner-event space with the nip30303 document kinds, which run
- * 30300 up to [com.machankura.bennu.compose.nostr.nip30303.SubmissionEvent] at 30312 --
- * the same space, because both are Marmot inner events and both are dispatched
- * on kind by the same inbound path. Starting at 30320 leaves that family room to
- * grow into.
+ * These started past the nip30303 document kinds, which ran 30300 up to 30312
+ * in the same Marmot inner-event space and were dispatched on kind by the same
+ * inbound path. Those kinds are gone (docs/ceremony-creation.md), and 30300-30309
+ * are free.
*
- * The DKG's 30310-30316 look like a clash and are not, but the reason is
- * narrower than it used to be. The nip30303 kinds exist only inside Marmot inner
- * events and the DKG's only inside NIP-17 gift wraps, so the numbers overlap
- * where nothing reads across -- the DKG's proposal and host-key kinds sit on
- * 30310 and 30311 alongside two nip30303 kinds, and its round-1 kind is 30312,
- * alongside SubmissionEvent.
- *
- * These kinds are now the ones that *do* travel on both transports, which is
- * exactly why they must not overlap with either family. They do not. But that
- * separation was an accident of routing rather than a decision, and the next
- * family added should not rely on it.
+ * The DKG's 30310-30316 *did* clash with that family once a subgroup's ceremony
+ * moved into its parent's Marmot room: its round 1 reached the parent's chat as
+ * an unreadable document submission. `ChatMessage` recognises this family's
+ * kinds and the DKG's before any content kind, so a protocol kind is never read
+ * as content whatever shares its number. A new family should still take numbers
+ * nobody else uses.
*/
object FrostSigningEvents {
/**
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/ArtifactEvent.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/ArtifactEvent.kt
deleted file mode 100644
index 77d21318..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/ArtifactEvent.kt
+++ /dev/null
@@ -1,71 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303
-
-import androidx.compose.runtime.Immutable
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
-import com.vitorpamplona.quartz.nip22Comments.RootScope
-import com.vitorpamplona.quartz.nip31Alts.alt
-import com.vitorpamplona.quartz.nip50Search.SearchableEvent
-import com.vitorpamplona.quartz.utils.TimeUtils
-import com.machankura.bennu.compose.nostr.nip30303.tags.ArtifactVersionMetadataTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.DialectIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.LicenseTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.UrlTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.VisibilityTag
-
-
-@Immutable
-class ArtifactEvent(
- id: HexKey,
- pubKey: HexKey,
- createdAt: Long,
- tags: Array>,
- content: String,
- sig: HexKey,
-) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
- fun url() = tags.firstNotNullOfOrNull(UrlTag::parse)?.url
- fun visibility() = tags.firstNotNullOfOrNull(VisibilityTag::parse)?.visibility
- fun license() = tags.firstNotNullOfOrNull(LicenseTag::parse)?.license
-
- fun dialectIdReference() = tags.firstNotNullOfOrNull(DialectIdTag::parse)?.ref
- fun dialectId() = dialectIdReference()?.eventId
-
- /**
- * The label of the version this artifact starts life with.
- *
- * Carried on the artifact rather than in an event of its own because the
- * group signs the artifact and nothing else. A first version proposed
- * separately would need either a second quorum for one form or an id each
- * device invents for itself, and invented ids differ on every device holding
- * the same artifact. Null on artifacts written before this was declared.
- */
- fun versionLabel() = tags.firstNotNullOfOrNull(ArtifactVersionMetadataTag::parse)?.versionLabel
-
- companion object {
- const val KIND = 30300
- const val ALT_DESCRIPTION = "Artifact"
-
- fun build(
- name: String,
- url: String,
- visibility: String,
- license: String,
- dialectId: String,
- versionLabel: String,
- createdAt: Long = TimeUtils.now(),
- initializer: TagArrayBuilder.() -> Unit = {},
- ) = eventTemplate(KIND, name, createdAt) {
- alt(ALT_DESCRIPTION)
- addUnique(UrlTag.assemble(url))
- addUnique(VisibilityTag.assemble(visibility))
- addUnique(LicenseTag.assemble(license))
- addUnique(
- DialectIdTag.assemble(dialectId)
- )
- addUnique(ArtifactVersionMetadataTag.assemble(versionLabel))
- initializer()
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/ArtifactVersionEvent.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/ArtifactVersionEvent.kt
deleted file mode 100644
index 541a1616..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/ArtifactVersionEvent.kt
+++ /dev/null
@@ -1,86 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303
-
-import androidx.compose.runtime.Immutable
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
-import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
-import com.vitorpamplona.quartz.nip22Comments.RootScope
-import com.vitorpamplona.quartz.nip31Alts.alt
-import com.vitorpamplona.quartz.nip50Search.SearchableEvent
-import com.vitorpamplona.quartz.utils.TimeUtils
-import com.machankura.bennu.compose.nostr.nip30303.tags.ArtifactIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.ArtifactVersionMetadataTag
-
-
-@Immutable
-class ArtifactVersionEvent(
- id: HexKey,
- pubKey: HexKey,
- createdAt: Long,
- tags: Array>,
- content: String,
- sig: HexKey,
-) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
-
- fun versionLabel() = tags.firstNotNullOfOrNull(ArtifactVersionMetadataTag::parse)?.versionLabel
-
- fun artifactIdReference() = tags.firstNotNullOfOrNull(ArtifactIdTag::parse)?.ref
- fun artifactId() = artifactIdReference()?.eventId
-
- companion object {
- const val KIND = 30301
- const val ALT_DESCRIPTION = "ArtifactVersion"
-
- /**
- * The first version [artifact] declares, ready to be signed with it.
- *
- * An artifact and the version it starts life with go to the group as one
- * batch, so this is built from the artifact *after* it has been authored
- * under the group's key -- [artifact] is the unsigned event the session
- * will sign, which is where the id this carries comes from. Building it
- * anywhere else would mean naming an artifact id before one exists.
- *
- * It takes the artifact's own timestamp, so the batch reads as one act
- * rather than two events that happen to share a session.
- *
- * This used to be derived on arrival instead, from the label the
- * artifact carries -- the same shape a chapter's chunks were in, and
- * abandoned for the same reason. Deriving cost nothing while the
- * alternative was a second quorum, and nothing is what it bought: a row
- * naming the group as its author with no signature to show for it, which
- * a chapter then hangs off. A batch is one quorum, so the version can
- * carry the group's signature over its own label.
- *
- * Empty when the artifact declares no version -- every artifact written
- * before it did -- which leaves a batch of one and an artifact with no
- * version, exactly as before.
- */
- fun initialVersionOf(artifact: Event): List> {
- val versionLabel = ArtifactEvent(
- id = artifact.id,
- pubKey = artifact.pubKey,
- createdAt = artifact.createdAt,
- tags = artifact.tags,
- content = artifact.content,
- sig = artifact.sig
- ).versionLabel() ?: return emptyList()
-
- return listOf(
- build(content = versionLabel, createdAt = artifact.createdAt) {
- addUnique(ArtifactIdTag.assemble(artifact.id))
- }
- )
- }
-
- fun build(
- content: String,
- createdAt: Long = TimeUtils.now(),
- initializer: TagArrayBuilder.() -> Unit = {},
- ) = eventTemplate(KIND, content, createdAt) {
- alt(ALT_DESCRIPTION)
- initializer()
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/ChapterEvent.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/ChapterEvent.kt
deleted file mode 100644
index 933e1c38..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/ChapterEvent.kt
+++ /dev/null
@@ -1,71 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303
-
-import androidx.compose.runtime.Immutable
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
-import com.vitorpamplona.quartz.nip31Alts.alt
-import com.vitorpamplona.quartz.utils.TimeUtils
-import com.machankura.bennu.compose.nostr.nip30303.tags.ArtifactVersionIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.IndexTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.NameTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.OriginalTextTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.WordStatisticsTag
-
-
-@Immutable
-class ChapterEvent(
- id: HexKey,
- pubKey: HexKey,
- createdAt: Long,
- tags: Array>,
- content: String,
- sig: HexKey,
-) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
- val wordStatisticsTag = tags.firstNotNullOfOrNull(WordStatisticsTag::parse)
-
- fun artifactVersionIdReference() = tags.firstNotNullOfOrNull(ArtifactVersionIdTag::parse)?.ref
- fun artifactVersionId() = artifactVersionIdReference()?.eventId
-
- fun name() = tags.firstNotNullOfOrNull(NameTag::parse)?.name
-
- /**
- * The markdown the chapter is, whole.
- *
- * The chapter carries its text even though the chunks cut from it are
- * signed alongside it and carry the same words between them. It is the
- * chapter as the group signed it: chunk boundaries are a decision about how
- * to divide the work, and a chapter that kept only the pieces could never be
- * divided again differently without losing what was agreed to.
- */
- fun originalText() = tags.firstNotNullOfOrNull(OriginalTextTag::parse)?.originalText
-
- fun index() = tags.firstNotNullOfOrNull(IndexTag::parse)?.index
- fun wordCount() = wordStatisticsTag?.wordCount
- fun characterCount() = wordStatisticsTag?.characterCount
-
- companion object {
- const val KIND = 30302
- const val ALT_DESCRIPTION = "Chapter"
-
- fun build(
- artifactVersionId: String,
- name: String,
- originalText: String,
- index: Int,
- wordCount: Int,
- characterCount: Int,
- createdAt: Long = TimeUtils.now(),
- initializer: TagArrayBuilder.() -> Unit = {},
- ) = eventTemplate(KIND, "", createdAt) {
- alt(ALT_DESCRIPTION)
- addUnique(ArtifactVersionIdTag.assemble(artifactVersionId))
- addUnique(NameTag.assemble(name))
- addUnique(OriginalTextTag.assemble(originalText))
- addUnique(IndexTag.assemble(index))
- addUnique(WordStatisticsTag.assemble(wordCount, characterCount))
- initializer()
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/ChunkEvent.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/ChunkEvent.kt
deleted file mode 100644
index 8a9004be..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/ChunkEvent.kt
+++ /dev/null
@@ -1,94 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303
-
-import androidx.compose.runtime.Immutable
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
-import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
-import com.vitorpamplona.quartz.nip22Comments.RootScope
-import com.vitorpamplona.quartz.nip31Alts.alt
-import com.vitorpamplona.quartz.nip50Search.SearchableEvent
-import com.vitorpamplona.quartz.utils.TimeUtils
-import com.machankura.bennu.compose.nostr.nip30303.tags.ChapterIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.IndexTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.WordStatisticsTag
-import com.machankura.bennu.compose.text.Markdown
-
-
-@Immutable
-class ChunkEvent(
- id: HexKey,
- pubKey: HexKey,
- createdAt: Long,
- tags: Array>,
- content: String,
- sig: HexKey,
-) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
- val wordStatisticsTag = tags.firstNotNullOfOrNull(WordStatisticsTag::parse)
-
- fun index() = tags.firstNotNullOfOrNull(IndexTag::parse)?.index
- fun wordCount() = wordStatisticsTag?.wordCount
- fun characterCount() = wordStatisticsTag?.characterCount
-
- fun chapterIdReference() = tags.firstNotNullOfOrNull(ChapterIdTag::parse)?.ref
- fun chapterId() = chapterIdReference()?.eventId
-
- companion object {
- const val KIND = 30303
- const val ALT_DESCRIPTION = "Chunk"
-
- /**
- * The chunks [chapter]'s text splits into, ready to be signed with it.
- *
- * A chapter and its chunks go to the group as one batch, so these are
- * built from the chapter *after* it has been authored under the group's
- * key -- [chapter] is the unsigned event the session will sign, which is
- * where the id each chunk carries comes from. Splitting anywhere else
- * would mean naming a chapter id before one exists.
- *
- * They take the chapter's own timestamp, so the batch reads as one act
- * rather than as events that happen to share a session.
- *
- * Empty when the chapter has no text to split, which is a chapter with
- * nothing in it to translate.
- */
- fun splitOf(chapter: Event): List> {
- val originalText = ChapterEvent(
- id = chapter.id,
- pubKey = chapter.pubKey,
- createdAt = chapter.createdAt,
- tags = chapter.tags,
- content = chapter.content,
- sig = chapter.sig
- ).originalText() ?: return emptyList()
-
- return Markdown.splitParagraphs(originalText).mapIndexed { index, paragraph ->
- build(
- chapterId = chapter.id,
- text = paragraph,
- index = index,
- wordCount = Markdown.wordCount(paragraph),
- characterCount = Markdown.characterCount(paragraph),
- createdAt = chapter.createdAt,
- )
- }
- }
-
- fun build(
- chapterId: String,
- text: String,
- index: Int,
- wordCount: Int,
- characterCount: Int,
- createdAt: Long = TimeUtils.now(),
- initializer: TagArrayBuilder.() -> Unit = {},
- ) = eventTemplate(KIND, text, createdAt) {
- alt(ALT_DESCRIPTION)
- addUnique(ChapterIdTag.assemble(chapterId))
- addUnique(IndexTag.assemble(index))
- addUnique(WordStatisticsTag.assemble(wordCount, characterCount))
- initializer()
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/DialectEvent.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/DialectEvent.kt
deleted file mode 100644
index e8fcae4c..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/DialectEvent.kt
+++ /dev/null
@@ -1,48 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303
-
-import androidx.compose.runtime.Immutable
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
-import com.vitorpamplona.quartz.nip22Comments.RootScope
-import com.vitorpamplona.quartz.nip31Alts.alt
-import com.vitorpamplona.quartz.nip50Search.SearchableEvent
-import com.vitorpamplona.quartz.utils.TimeUtils
-import com.machankura.bennu.compose.nostr.nip30303.tags.CountryTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.LanguageTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.NameTag
-
-
-@Immutable
-class DialectEvent(
- id: HexKey,
- pubKey: HexKey,
- createdAt: Long,
- tags: Array>,
- content: String,
- sig: HexKey,
-) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
- fun name() = tags.firstNotNullOfOrNull(NameTag::parse)?.name
- fun country() = tags.firstNotNullOfOrNull(CountryTag::parse)?.country
- fun language() = tags.firstNotNullOfOrNull(LanguageTag::parse)?.language
-
- companion object {
- const val KIND = 30304
- const val ALT_DESCRIPTION = "Dialect"
-
- fun build(
- name: String,
- country: String,
- language: String,
- createdAt: Long = TimeUtils.now(),
- initializer: TagArrayBuilder.() -> Unit = {},
- ) = eventTemplate(KIND, language, createdAt) {
- alt(ALT_DESCRIPTION)
- addUnique(NameTag.assemble(name))
- addUnique(CountryTag.assemble(country))
- addUnique(LanguageTag.assemble(language))
- initializer()
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/SubmissionEvent.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/SubmissionEvent.kt
deleted file mode 100644
index 4d458ac4..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/SubmissionEvent.kt
+++ /dev/null
@@ -1,81 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303
-
-import androidx.compose.runtime.Immutable
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
-import com.vitorpamplona.quartz.nip31Alts.alt
-import com.vitorpamplona.quartz.utils.TimeUtils
-import com.machankura.bennu.compose.nostr.nip30303.tags.PayloadIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.PayloadKindTag
-
-/**
- * 30312
- *
- * An envelope that carries one nip30303 event into a group.
- *
- * Every other nip30303 kind describes a thing -- an artifact, a dialect, a
- * chapter, a translated chunk. A submission describes an act: *this member is
- * putting this event in front of this group*. The two are separate on purpose,
- * because they answer different questions and often have different answers.
- *
- * The payload travels whole, in [content], keeping its own id, author and
- * signature. Nothing is rewritten to make it look like the submitter's work.
- * That buys two things:
- *
- * - A group can take in work written by somebody who is not in it. A
- * translation lifted from a public chronicle, a chapter transcribed by an
- * outside contributor, an artifact somebody published years ago -- an admin
- * submits it and the group applies it, with the original author still named
- * on the row.
- * - Authorship stops being a claim the transport makes. Before this, being
- * the sender of a group message *was* being the author of the event inside
- * it, so the only events a group could hold were ones its own members had
- * written under their own keys.
- *
- * A submission is not an endorsement and grants nothing: a payload's author is
- * whoever signed it, and who may submit is the group's business.
- */
-@Immutable
-class SubmissionEvent(
- id: HexKey,
- pubKey: HexKey,
- createdAt: Long,
- tags: Array>,
- content: String,
- sig: HexKey,
-) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
-
- /**
- * The submitted event, parsed out of [content].
- *
- * Null when the content is not an event at all -- treat that as a
- * submission that cannot be applied, not as an empty one.
- */
- fun payload(): Event? = Event.fromJsonOrNull(content)
-
- fun payloadKind() = tags.firstNotNullOfOrNull(PayloadKindTag::parse)?.kind
-
- fun payloadIdReference() = tags.firstNotNullOfOrNull(PayloadIdTag::parse)?.ref
- fun payloadId() = payloadIdReference()?.eventId
-
- /** Who wrote the payload, which is not who sent this submission. */
- fun payloadAuthor() = payloadIdReference()?.author
-
- companion object {
- const val KIND = 30312
- const val ALT_DESCRIPTION = "Submission"
-
- fun build(
- payload: Event,
- createdAt: Long = TimeUtils.now(),
- initializer: TagArrayBuilder.() -> Unit = {},
- ) = eventTemplate(KIND, payload.toJson(), createdAt) {
- alt(ALT_DESCRIPTION)
- addUnique(PayloadKindTag.assemble(payload.kind))
- addUnique(PayloadIdTag.assemble(eventId = payload.id, pubkey = payload.pubKey))
- initializer()
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationArtifactVersionContributorListEvent.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationArtifactVersionContributorListEvent.kt
deleted file mode 100644
index 4c6c049b..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationArtifactVersionContributorListEvent.kt
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303
-
-import androidx.compose.runtime.Immutable
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
-import com.vitorpamplona.quartz.nip22Comments.RootScope
-import com.vitorpamplona.quartz.nip31Alts.alt
-import com.vitorpamplona.quartz.nip50Search.SearchableEvent
-import com.vitorpamplona.quartz.utils.TimeUtils
-
-
-@Immutable
-class TranslationArtifactVersionContributorListEvent(
- id: HexKey,
- pubKey: HexKey,
- createdAt: Long,
- tags: Array>,
- content: String,
- sig: HexKey,
-) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
-
- companion object {
- const val KIND = 30305
- const val ALT_DESCRIPTION = "TranslationArtifactVersionContributorListEvent"
-
- fun build(
- content: String,
- createdAt: Long = TimeUtils.now(),
- initializer: TagArrayBuilder.() -> Unit = {},
- ) = eventTemplate(KIND, content, createdAt) {
- alt(ALT_DESCRIPTION)
- initializer()
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationArtifactVersionEvent.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationArtifactVersionEvent.kt
deleted file mode 100644
index ac851170..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationArtifactVersionEvent.kt
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303
-
-import androidx.compose.runtime.Immutable
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
-import com.vitorpamplona.quartz.nip31Alts.alt
-import com.vitorpamplona.quartz.utils.TimeUtils
-import com.machankura.bennu.compose.nostr.nip30303.tags.ArtifactVersionIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.DialectIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.LicenseTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.NameTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.VisibilityTag
-
-
-@Immutable
-class TranslationArtifactVersionEvent(
- id: HexKey,
- pubKey: HexKey,
- createdAt: Long,
- tags: Array>,
- content: String,
- sig: HexKey,
-) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
-
- fun name() = tags.firstNotNullOfOrNull(NameTag::parse)?.name
- fun visibility() = tags.firstNotNullOfOrNull(VisibilityTag::parse)?.visibility
- fun license() = tags.firstNotNullOfOrNull(LicenseTag::parse)?.license
-
- fun artifactVersionIdReference() = tags.firstNotNullOfOrNull(ArtifactVersionIdTag::parse)?.ref
- fun artifactVersionId() = artifactVersionIdReference()?.eventId
-
- fun dialectIdReference() = tags.firstNotNullOfOrNull(DialectIdTag::parse)?.ref
- fun dialectId() = dialectIdReference()?.eventId
-
- companion object {
- const val KIND = 30306
- const val ALT_DESCRIPTION = "TranslationArtifactVersion"
-
- fun build(
- artifactVersionId: String,
- dialectId: String,
- name: String,
- visibility: String,
- license: String,
- createdAt: Long = TimeUtils.now(),
- initializer: TagArrayBuilder.() -> Unit = {},
- ) = eventTemplate(KIND, "", createdAt) {
- alt(ALT_DESCRIPTION)
- addUnique(ArtifactVersionIdTag.assemble(artifactVersionId))
- addUnique(DialectIdTag.assemble(dialectId))
- addUnique(NameTag.assemble(name))
- addUnique(VisibilityTag.assemble(visibility))
- addUnique(LicenseTag.assemble(license))
- initializer()
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationChapterContributorListEvent.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationChapterContributorListEvent.kt
deleted file mode 100644
index 62ce9b9a..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationChapterContributorListEvent.kt
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303
-
-import androidx.compose.runtime.Immutable
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
-import com.vitorpamplona.quartz.nip22Comments.RootScope
-import com.vitorpamplona.quartz.nip31Alts.alt
-import com.vitorpamplona.quartz.nip50Search.SearchableEvent
-import com.vitorpamplona.quartz.utils.TimeUtils
-
-
-@Immutable
-class TranslationChapterContributorListEvent(
- id: HexKey,
- pubKey: HexKey,
- createdAt: Long,
- tags: Array>,
- content: String,
- sig: HexKey,
-) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
-
- companion object {
- const val KIND = 30307
- const val ALT_DESCRIPTION = "TranslationChapterContributorListEvent"
-
- fun build(
- content: String,
- createdAt: Long = TimeUtils.now(),
- initializer: TagArrayBuilder.() -> Unit = {},
- ) = eventTemplate(KIND, content, createdAt) {
- alt(ALT_DESCRIPTION)
- initializer()
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationChapterEvent.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationChapterEvent.kt
deleted file mode 100644
index d37c9bfc..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationChapterEvent.kt
+++ /dev/null
@@ -1,53 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303
-
-import androidx.compose.runtime.Immutable
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
-import com.vitorpamplona.quartz.nip22Comments.RootScope
-import com.vitorpamplona.quartz.nip31Alts.alt
-import com.vitorpamplona.quartz.nip50Search.SearchableEvent
-import com.vitorpamplona.quartz.utils.TimeUtils
-import com.machankura.bennu.compose.nostr.nip30303.tags.ChapterIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.IndexTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.TranslationArtifactVersionIdTag
-
-
-@Immutable
-class TranslationChapterEvent(
- id: HexKey,
- pubKey: HexKey,
- createdAt: Long,
- tags: Array>,
- content: String,
- sig: HexKey,
-) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
-
- fun translationArtifactVersionIdReference() = tags.firstNotNullOfOrNull(TranslationArtifactVersionIdTag::parse)?.ref
- fun translationArtifactVersionId() = translationArtifactVersionIdReference()?.eventId
-
- fun chapterIdReference() = tags.firstNotNullOfOrNull(ChapterIdTag::parse)?.ref
- fun chapterId() = chapterIdReference()?.eventId
-
- fun index() = tags.firstNotNullOfOrNull(IndexTag::parse)?.index
-
- companion object {
- const val KIND = 30308
- const val ALT_DESCRIPTION = "TranslationChapter"
-
- fun build(
- translationArtifactVersionId: String,
- chapterId: String,
- index: Int,
- createdAt: Long = TimeUtils.now(),
- initializer: TagArrayBuilder.() -> Unit = {},
- ) = eventTemplate(KIND, "", createdAt) {
- alt(ALT_DESCRIPTION)
- addUnique(TranslationArtifactVersionIdTag.assemble(translationArtifactVersionId))
- addUnique(ChapterIdTag.assemble(chapterId))
- addUnique(IndexTag.assemble(index))
- initializer()
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationChunkEvent.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationChunkEvent.kt
deleted file mode 100644
index 725d5421..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationChunkEvent.kt
+++ /dev/null
@@ -1,55 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303
-
-import androidx.compose.runtime.Immutable
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
-import com.vitorpamplona.quartz.nip22Comments.RootScope
-import com.vitorpamplona.quartz.nip31Alts.alt
-import com.vitorpamplona.quartz.nip50Search.SearchableEvent
-import com.vitorpamplona.quartz.utils.TimeUtils
-import com.machankura.bennu.compose.nostr.nip30303.tags.ChunkIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.IndexTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.TranslationArtifactVersionIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.TranslationChapterIdTag
-
-
-@Immutable
-class TranslationChunkEvent(
- id: HexKey,
- pubKey: HexKey,
- createdAt: Long,
- tags: Array>,
- content: String,
- sig: HexKey,
-) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
-
- fun translationChapterIdReference() = tags.firstNotNullOfOrNull(TranslationChapterIdTag::parse)?.ref
- fun translationChapterId() = translationChapterIdReference()?.eventId
-
- fun index() = tags.firstNotNullOfOrNull(IndexTag::parse)?.index
-
- fun chunkIdReference() = tags.firstNotNullOfOrNull(ChunkIdTag::parse)?.ref
- fun chunkId() = chunkIdReference()?.eventId
-
- companion object {
- const val KIND = 30309
- const val ALT_DESCRIPTION = "TranslationChunk"
-
- fun build(
- translationChapterId: String,
- chunkId: String,
- index: Int,
- text: String,
- createdAt: Long = TimeUtils.now(),
- initializer: TagArrayBuilder.() -> Unit = {},
- ) = eventTemplate(KIND, text, createdAt) {
- alt(ALT_DESCRIPTION)
- addUnique(TranslationChapterIdTag.assemble(translationChapterId))
- addUnique(ChunkIdTag.assemble(chunkId))
- addUnique(IndexTag.assemble(index))
- initializer()
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationChunkProposalEvent.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationChunkProposalEvent.kt
deleted file mode 100644
index 2032dbe6..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationChunkProposalEvent.kt
+++ /dev/null
@@ -1,55 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303
-
-import androidx.compose.runtime.Immutable
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
-import com.vitorpamplona.quartz.nip22Comments.RootScope
-import com.vitorpamplona.quartz.nip31Alts.alt
-import com.vitorpamplona.quartz.nip50Search.SearchableEvent
-import com.vitorpamplona.quartz.utils.TimeUtils
-import com.machankura.bennu.compose.nostr.nip30303.tags.ChunkIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.IndexTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.TranslationArtifactVersionIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.TranslationChapterIdTag
-
-
-@Immutable
-class TranslationChunkProposalEvent(
- id: HexKey,
- pubKey: HexKey,
- createdAt: Long,
- tags: Array>,
- content: String,
- sig: HexKey,
-) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
-
- fun translationChapterIdReference() = tags.firstNotNullOfOrNull(TranslationChapterIdTag::parse)?.ref
- fun translationChapterId() = translationChapterIdReference()?.eventId
-
- fun index() = tags.firstNotNullOfOrNull(IndexTag::parse)?.index
-
- fun chunkIdReference() = tags.firstNotNullOfOrNull(ChunkIdTag::parse)?.ref
- fun chunkId() = chunkIdReference()?.eventId
-
- companion object {
- const val KIND = 30309
- const val ALT_DESCRIPTION = "TranslationChunk"
-
- fun build(
- translationChapterId: String,
- chunkId: String,
- index: Int,
- text: String,
- createdAt: Long = TimeUtils.now(),
- initializer: TagArrayBuilder.() -> Unit = {},
- ) = eventTemplate(KIND, text, createdAt) {
- alt(ALT_DESCRIPTION)
- addUnique(TranslationChapterIdTag.assemble(translationChapterId))
- addUnique(ChunkIdTag.assemble(chunkId))
- addUnique(IndexTag.assemble(index))
- initializer()
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationContributorListEvent.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationContributorListEvent.kt
deleted file mode 100644
index ac186cef..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationContributorListEvent.kt
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303
-
-import androidx.compose.runtime.Immutable
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
-import com.vitorpamplona.quartz.nip22Comments.RootScope
-import com.vitorpamplona.quartz.nip31Alts.alt
-import com.vitorpamplona.quartz.nip50Search.SearchableEvent
-import com.vitorpamplona.quartz.utils.TimeUtils
-
-
-@Immutable
-class TranslationContributorListEvent(
- id: HexKey,
- pubKey: HexKey,
- createdAt: Long,
- tags: Array>,
- content: String,
- sig: HexKey,
-) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
-
- companion object {
- const val KIND = 30310
- const val ALT_DESCRIPTION = "TranslationContributorListEvent"
-
- fun build(
- content: String,
- createdAt: Long = TimeUtils.now(),
- initializer: TagArrayBuilder.() -> Unit = {},
- ) = eventTemplate(KIND, content, createdAt) {
- alt(ALT_DESCRIPTION)
- initializer()
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationEvent.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationEvent.kt
deleted file mode 100644
index 978f0eea..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/TranslationEvent.kt
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303
-
-import androidx.compose.runtime.Immutable
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
-import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
-import com.vitorpamplona.quartz.nip22Comments.RootScope
-import com.vitorpamplona.quartz.nip31Alts.alt
-import com.vitorpamplona.quartz.nip50Search.SearchableEvent
-import com.vitorpamplona.quartz.utils.TimeUtils
-import com.machankura.bennu.compose.nostr.nip30303.tags.TranslationArtifactVersionIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.TranslationChunkIdTag
-
-
-@Immutable
-class TranslationEvent(
- id: HexKey,
- pubKey: HexKey,
- createdAt: Long,
- tags: Array>,
- content: String,
- sig: HexKey,
-) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
-
- fun translationChunkIdReference() = tags.firstNotNullOfOrNull(TranslationChunkIdTag::parse)?.ref
- fun translationChunkId() = translationChunkIdReference()?.eventId
-
- fun translationArtifactVersionIdReference() = tags.firstNotNullOfOrNull(TranslationArtifactVersionIdTag::parse)?.ref
- fun translationArtifactVersionId() = translationArtifactVersionIdReference()?.eventId
-
- companion object {
- const val KIND = 30311
- const val ALT_DESCRIPTION = "Translation"
-
- fun build(
- content: String,
- createdAt: Long = TimeUtils.now(),
- initializer: TagArrayBuilder.() -> Unit = {},
- ) = eventTemplate(KIND, content, createdAt) {
- alt(ALT_DESCRIPTION)
- initializer()
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/ArtifactIdTag.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/ArtifactIdTag.kt
deleted file mode 100644
index 05679d22..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/ArtifactIdTag.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303.tags
-
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.has
-import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
-import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
-import com.vitorpamplona.quartz.nip01Core.tags.events.EventReference
-import com.vitorpamplona.quartz.utils.arrayOfNotNull
-import com.vitorpamplona.quartz.utils.ensure
-
-data class ArtifactIdTag(
- val ref: EventReference,
-) {
- constructor(eventId: String, relayHint: NormalizedRelayUrl?, pubkey: String?) : this(
- EventReference(eventId, pubkey, relayHint)
- )
-
- companion object {
- const val TAG_NAME = "artifactId"
-
- fun parse(tag: Array): ArtifactIdTag? {
- ensure(tag.has(1)) { return null }
- ensure(tag[0] == TAG_NAME) { return null }
- ensure(tag[1].length == 64) { return null }
-
- val relayHint = tag.getOrNull(2)?.let { RelayUrlNormalizer.normalizeOrNull(it) }
-
- return ArtifactIdTag(tag[1], relayHint, tag.getOrNull(3))
- }
-
- fun assemble(
- eventId: HexKey,
- relay: NormalizedRelayUrl? = null,
- pubkey: String? = null,
- ) = arrayOfNotNull(TAG_NAME, eventId, relay?.url, pubkey)
-
- fun assemble(ref: EventReference) = assemble(ref.eventId, ref.relayHint, ref.author)
- }
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/ArtifactVersionIdTag.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/ArtifactVersionIdTag.kt
deleted file mode 100644
index ceed58a3..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/ArtifactVersionIdTag.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303.tags
-
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.has
-import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
-import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
-import com.vitorpamplona.quartz.nip01Core.tags.events.EventReference
-import com.vitorpamplona.quartz.utils.arrayOfNotNull
-import com.vitorpamplona.quartz.utils.ensure
-
-class ArtifactVersionIdTag(
- val ref: EventReference,
-) {
- constructor(eventId: String, relayHint: NormalizedRelayUrl?, pubkey: String?) : this(
- EventReference(eventId, pubkey, relayHint)
- )
-
- companion object {
- const val TAG_NAME = "artifactVersionId"
-
- fun parse(tag: Array): ArtifactVersionIdTag? {
- ensure(tag.has(1)) { return null }
- ensure(tag[0] == TAG_NAME) { return null }
- ensure(tag[1].length == 64) { return null }
-
- val relayHint = tag.getOrNull(2)?.let { RelayUrlNormalizer.normalizeOrNull(it) }
-
- return ArtifactVersionIdTag(tag[1], relayHint, tag.getOrNull(3))
- }
-
- fun assemble(
- eventId: HexKey,
- relay: NormalizedRelayUrl? = null,
- pubkey: String? = null,
- ) = arrayOfNotNull(TAG_NAME, eventId, relay?.url, pubkey)
-
- fun assemble(ref: EventReference) = assemble(ref.eventId, ref.relayHint, ref.author)
- }
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/ArtifactVersionMetadataTag.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/ArtifactVersionMetadataTag.kt
deleted file mode 100644
index ebb206d9..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/ArtifactVersionMetadataTag.kt
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303.tags
-
-import com.vitorpamplona.quartz.nip01Core.core.has
-import com.vitorpamplona.quartz.utils.ensure
-
-class ArtifactVersionMetadataTag(
- val versionLabel: String,
-) {
- fun toTagArray() = assemble(
- versionLabel = versionLabel,
- )
-
- companion object {
- const val TAG_NAME = "artifactVersion"
-
- fun parse(tag: Array): ArtifactVersionMetadataTag? {
- ensure(tag.has(1)) { return null }
- ensure(tag[0] == TAG_NAME) { return null }
-
- return ArtifactVersionMetadataTag(
- versionLabel = tag[1],
- )
- }
-
- fun assemble(
- versionLabel: String,
- ): Array = arrayOf(
- TAG_NAME,
- versionLabel
- )
-
- fun assemble(artifactVersionMetadataTag: ArtifactVersionMetadataTag) = assemble(
- versionLabel = artifactVersionMetadataTag.versionLabel,
- )
- }
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/ChapterIdTag.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/ChapterIdTag.kt
deleted file mode 100644
index 898388c2..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/ChapterIdTag.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303.tags
-
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.has
-import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
-import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
-import com.vitorpamplona.quartz.nip01Core.tags.events.EventReference
-import com.vitorpamplona.quartz.utils.arrayOfNotNull
-import com.vitorpamplona.quartz.utils.ensure
-
-class ChapterIdTag(
- val ref: EventReference,
-) {
- constructor(eventId: String, relayHint: NormalizedRelayUrl?, pubkey: String?) : this(
- EventReference(eventId, pubkey, relayHint)
- )
-
- companion object {
- const val TAG_NAME = "chapterIdTag"
-
- fun parse(tag: Array): ChapterIdTag? {
- ensure(tag.has(1)) { return null }
- ensure(tag[0] == TAG_NAME) { return null }
- ensure(tag[1].length == 64) { return null }
-
- val relayHint = tag.getOrNull(2)?.let { RelayUrlNormalizer.normalizeOrNull(it) }
-
- return ChapterIdTag(tag[1], relayHint, tag.getOrNull(3))
- }
-
- fun assemble(
- eventId: HexKey,
- relay: NormalizedRelayUrl? = null,
- pubkey: String? = null,
- ) = arrayOfNotNull(TAG_NAME, eventId, relay?.url, pubkey)
-
- fun assemble(ref: EventReference) = assemble(ref.eventId, ref.relayHint, ref.author)
- }
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/ChunkIdTag.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/ChunkIdTag.kt
deleted file mode 100644
index 0ef01f08..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/ChunkIdTag.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303.tags
-
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.has
-import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
-import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
-import com.vitorpamplona.quartz.nip01Core.tags.events.EventReference
-import com.vitorpamplona.quartz.utils.arrayOfNotNull
-import com.vitorpamplona.quartz.utils.ensure
-
-class ChunkIdTag(
- val ref: EventReference,
-) {
- constructor(eventId: String, relayHint: NormalizedRelayUrl?, pubkey: String?) : this(
- EventReference(eventId, pubkey, relayHint)
- )
-
- companion object {
- const val TAG_NAME = "chunkIdTag"
-
- fun parse(tag: Array): ChunkIdTag? {
- ensure(tag.has(1)) { return null }
- ensure(tag[0] == TAG_NAME) { return null }
- ensure(tag[1].length == 64) { return null }
-
- val relayHint = tag.getOrNull(2)?.let { RelayUrlNormalizer.normalizeOrNull(it) }
-
- return ChunkIdTag(tag[1], relayHint, tag.getOrNull(3))
- }
-
- fun assemble(
- eventId: HexKey,
- relay: NormalizedRelayUrl? = null,
- pubkey: String? = null,
- ) = arrayOfNotNull(TAG_NAME, eventId, relay?.url, pubkey)
-
- fun assemble(ref: EventReference) = assemble(ref.eventId, ref.relayHint, ref.author)
- }
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/ContributorTag.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/ContributorTag.kt
deleted file mode 100644
index 71ebe987..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/ContributorTag.kt
+++ /dev/null
@@ -1,52 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303.tags
-
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.has
-import com.vitorpamplona.quartz.utils.ensure
-
-/**
- * Based on NIP-F4
- */
-class ContributorTag(
- val pubKey: HexKey,
- val role: String? = null,
-) {
- fun toTagArray() = assemble(pubKey, role)
-
- companion object {
- const val TAG_NAME = "p"
-
- const val ROLE_TRANSLATOR = "translator"
- const val ROLE_PROOF_READER = "proofreader"
- const val ROLE_EDITOR = "editor"
-
- private val KNOWN_ROLES = setOf(ROLE_TRANSLATOR, ROLE_PROOF_READER, ROLE_EDITOR)
-
- fun isTagged(tag: Array) = tag.has(1) && tag[0] == TAG_NAME && tag[1].length == 64
-
- fun parse(tag: Array): ContributorTag? {
- ensure(tag.has(1)) { return null }
- ensure(tag[0] == TAG_NAME) { return null }
- ensure(tag[1].length == 64) { return null }
- // NIP-F4 overloads slot 2 as role — but only host/cohost/editor are spec-defined.
- // Anything else (notably a stale relay-hint URL copied from a kind:3 p-tag) gets
- // dropped so it doesn't render as 'Role: wss://relay…' under the author chip.
- val role = tag.getOrNull(2)?.takeIf { it in KNOWN_ROLES }
- return ContributorTag(tag[1], role)
- }
-
- fun assemble(
- pubKey: HexKey,
- role: String? = null,
- ): Array =
- if (role.isNullOrEmpty()) {
- arrayOf(TAG_NAME, pubKey)
- } else {
- arrayOf(TAG_NAME, pubKey, role)
- }
-
- fun assemble(author: ContributorTag) = assemble(author.pubKey, author.role)
-
- fun assemble(authors: List) = authors.map { assemble(it) }
- }
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/CountryTag.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/CountryTag.kt
deleted file mode 100644
index 07b578fd..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/CountryTag.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303.tags
-
-import com.vitorpamplona.quartz.nip01Core.core.has
-import com.vitorpamplona.quartz.utils.ensure
-
-class CountryTag(
- val country: String,
-) {
- fun toTagArray() = assemble(country = country)
-
- companion object {
- const val TAG_NAME = "country"
-
- fun parse(tag: Array): CountryTag? {
- ensure(tag.has(1)) { return null }
- ensure(tag[0] == TAG_NAME) { return null }
-
- return CountryTag(country = tag[1])
- }
-
- fun assemble(country: String): Array = arrayOf(TAG_NAME, country)
-
- fun assemble(countryTag: CountryTag) = assemble(country = countryTag.country)
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/DialectIdTag.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/DialectIdTag.kt
deleted file mode 100644
index 7b544d8e..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/DialectIdTag.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303.tags
-
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.has
-import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
-import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
-import com.vitorpamplona.quartz.nip01Core.tags.events.EventReference
-import com.vitorpamplona.quartz.utils.arrayOfNotNull
-import com.vitorpamplona.quartz.utils.ensure
-
-class DialectIdTag(
- val ref: EventReference,
-) {
- constructor(eventId: String, relayHint: NormalizedRelayUrl?, pubkey: String?) : this(
- EventReference(eventId, pubkey, relayHint)
- )
-
- companion object {
- const val TAG_NAME = "dialectIdTag"
-
- fun parse(tag: Array): DialectIdTag? {
- ensure(tag.has(1)) { return null }
- ensure(tag[0] == TAG_NAME) { return null }
- ensure(tag[1].length == 64) { return null }
-
- val relayHint = tag.getOrNull(2)?.let { RelayUrlNormalizer.normalizeOrNull(it) }
-
- return DialectIdTag(tag[1], relayHint, tag.getOrNull(3))
- }
-
- fun assemble(
- eventId: HexKey,
- relay: NormalizedRelayUrl? = null,
- pubkey: String? = null,
- ) = arrayOfNotNull(TAG_NAME, eventId, relay?.url, pubkey)
-
- fun assemble(ref: EventReference) = assemble(ref.eventId, ref.relayHint, ref.author)
- }
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/IndexTag.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/IndexTag.kt
deleted file mode 100644
index 10833c25..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/IndexTag.kt
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303.tags
-
-import com.vitorpamplona.quartz.nip01Core.core.has
-import com.vitorpamplona.quartz.utils.ensure
-
-class IndexTag(
- val index: Int,
-) {
- fun toTagArray() = assemble(
- index = index,
- )
-
- companion object {
- const val TAG_NAME = "index"
-
- fun parse(tag: Array): IndexTag? {
- ensure(tag.has(1)) { return null }
- ensure(tag[0] == TAG_NAME) { return null }
-
- val index = tag[1].toIntOrNull() ?: return null
- return IndexTag(
- index = index,
- )
- }
-
- fun assemble(
- index: Int,
- ): Array = arrayOf(
- TAG_NAME,
- index.toString()
- )
-
- fun assemble(indexTag: IndexTag) = assemble(
- index = indexTag.index,
- )
- }
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/LanguageTag.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/LanguageTag.kt
deleted file mode 100644
index 3060d6c6..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/LanguageTag.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303.tags
-
-import com.vitorpamplona.quartz.nip01Core.core.has
-import com.vitorpamplona.quartz.utils.ensure
-
-class LanguageTag(
- val language: String,
-) {
- fun toTagArray() = assemble(language = language)
-
- companion object {
- const val TAG_NAME = "language"
-
- fun parse(tag: Array): LanguageTag? {
- ensure(tag.has(1)) { return null }
- ensure(tag[0] == TAG_NAME) { return null }
-
- return LanguageTag(language = tag[1])
- }
-
- fun assemble(language: String): Array = arrayOf(TAG_NAME, language)
-
- fun assemble(languageTag: LanguageTag) = assemble(language = languageTag.language)
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/LicenseTag.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/LicenseTag.kt
deleted file mode 100644
index 3bf5a07b..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/LicenseTag.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303.tags
-
-import com.vitorpamplona.quartz.nip01Core.core.has
-import com.vitorpamplona.quartz.utils.ensure
-
-class LicenseTag(
- val license: String,
-) {
- fun toTagArray() = assemble(license = license)
-
- companion object {
- const val TAG_NAME = "license"
-
- fun parse(tag: Array): LicenseTag? {
- ensure(tag.has(1)) { return null }
- ensure(tag[0] == TAG_NAME) { return null }
-
- return LicenseTag(license = tag[1])
- }
-
- fun assemble(license: String): Array = arrayOf(TAG_NAME, license)
-
- fun assemble(licenseTag: LicenseTag) = assemble(license = licenseTag.license)
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/NameTag.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/NameTag.kt
deleted file mode 100644
index d467590c..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/NameTag.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303.tags
-
-import com.vitorpamplona.quartz.nip01Core.core.has
-import com.vitorpamplona.quartz.utils.ensure
-
-class NameTag(
- val name: String,
-) {
- fun toTagArray() = assemble(name = name)
-
- companion object {
- const val TAG_NAME = "name"
-
- fun parse(tag: Array): NameTag? {
- ensure(tag.has(1)) { return null }
- ensure(tag[0] == TAG_NAME) { return null }
-
- return NameTag(name = tag[1])
- }
-
- fun assemble(name: String): Array = arrayOf(TAG_NAME, name)
-
- fun assemble(nameTag: NameTag) = assemble(name = nameTag.name)
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/OriginalTextTag.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/OriginalTextTag.kt
deleted file mode 100644
index 29c06d83..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/OriginalTextTag.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303.tags
-
-import com.vitorpamplona.quartz.nip01Core.core.has
-import com.vitorpamplona.quartz.utils.ensure
-
-class OriginalTextTag(
- val originalText: String,
-) {
- fun toTagArray() = assemble(originalText = originalText)
-
- companion object {
- const val TAG_NAME = "original_text"
-
- fun parse(tag: Array): OriginalTextTag? {
- ensure(tag.has(1)) { return null }
- ensure(tag[0] == TAG_NAME) { return null }
-
- return OriginalTextTag(originalText = tag[1])
- }
-
- fun assemble(originalText: String): Array = arrayOf(TAG_NAME, originalText)
-
- fun assemble(originalTextTag: OriginalTextTag) = assemble(originalText = originalTextTag.originalText)
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/PayloadIdTag.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/PayloadIdTag.kt
deleted file mode 100644
index b8f9a4a0..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/PayloadIdTag.kt
+++ /dev/null
@@ -1,47 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303.tags
-
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.has
-import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
-import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
-import com.vitorpamplona.quartz.nip01Core.tags.events.EventReference
-import com.vitorpamplona.quartz.utils.arrayOfNotNull
-import com.vitorpamplona.quartz.utils.ensure
-
-/**
- * The event a submission carries, named on the submission itself.
- *
- * The payload is already in the submission's content, so this tag is not how a
- * reader gets at it -- it is how they filter for it. The author slot matters
- * more than usual here: on a submission it names whoever wrote the payload,
- * who is not necessarily the member who submitted it.
- */
-data class PayloadIdTag(
- val ref: EventReference,
-) {
- constructor(eventId: String, relayHint: NormalizedRelayUrl?, pubkey: String?) : this(
- EventReference(eventId, pubkey, relayHint)
- )
-
- companion object {
- const val TAG_NAME = "payloadId"
-
- fun parse(tag: Array): PayloadIdTag? {
- ensure(tag.has(1)) { return null }
- ensure(tag[0] == TAG_NAME) { return null }
- ensure(tag[1].length == 64) { return null }
-
- val relayHint = tag.getOrNull(2)?.let { RelayUrlNormalizer.normalizeOrNull(it) }
-
- return PayloadIdTag(tag[1], relayHint, tag.getOrNull(3))
- }
-
- fun assemble(
- eventId: HexKey,
- relay: NormalizedRelayUrl? = null,
- pubkey: String? = null,
- ) = arrayOfNotNull(TAG_NAME, eventId, relay?.url, pubkey)
-
- fun assemble(ref: EventReference) = assemble(ref.eventId, ref.relayHint, ref.author)
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/PayloadKindTag.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/PayloadKindTag.kt
deleted file mode 100644
index 4ab55914..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/PayloadKindTag.kt
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303.tags
-
-import com.vitorpamplona.quartz.nip01Core.core.has
-import com.vitorpamplona.quartz.utils.ensure
-
-/**
- * The kind of the event a submission carries.
- *
- * Lets a client decide whether it can apply a submission without parsing the
- * payload JSON out of the content first.
- */
-class PayloadKindTag(
- val kind: Int,
-) {
- fun toTagArray() = assemble(
- kind = kind,
- )
-
- companion object {
- const val TAG_NAME = "payloadKind"
-
- fun parse(tag: Array): PayloadKindTag? {
- ensure(tag.has(1)) { return null }
- ensure(tag[0] == TAG_NAME) { return null }
-
- val kind = tag[1].toIntOrNull() ?: return null
- return PayloadKindTag(
- kind = kind,
- )
- }
-
- fun assemble(
- kind: Int,
- ): Array = arrayOf(
- TAG_NAME,
- kind.toString()
- )
-
- fun assemble(payloadKindTag: PayloadKindTag) = assemble(
- kind = payloadKindTag.kind,
- )
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/TranslationArtifactVersionIdTag.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/TranslationArtifactVersionIdTag.kt
deleted file mode 100644
index 2cb6e164..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/TranslationArtifactVersionIdTag.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303.tags
-
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.has
-import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
-import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
-import com.vitorpamplona.quartz.nip01Core.tags.events.EventReference
-import com.vitorpamplona.quartz.utils.arrayOfNotNull
-import com.vitorpamplona.quartz.utils.ensure
-
-class TranslationArtifactVersionIdTag(
- val ref: EventReference,
-) {
- constructor(eventId: String, relayHint: NormalizedRelayUrl?, pubkey: String?) : this(
- EventReference(eventId, pubkey, relayHint)
- )
-
- companion object {
- const val TAG_NAME = "translationArtifactVersionId"
-
- fun parse(tag: Array): DialectIdTag? {
- ensure(tag.has(1)) { return null }
- ensure(tag[0] == TAG_NAME) { return null }
- ensure(tag[1].length == 64) { return null }
-
- val relayHint = tag.getOrNull(2)?.let { RelayUrlNormalizer.normalizeOrNull(it) }
-
- return DialectIdTag(tag[1], relayHint, tag.getOrNull(3))
- }
-
- fun assemble(
- eventId: HexKey,
- relay: NormalizedRelayUrl? = null,
- pubkey: String? = null,
- ) = arrayOfNotNull(TAG_NAME, eventId, relay?.url, pubkey)
-
- fun assemble(ref: EventReference) = assemble(ref.eventId, ref.relayHint, ref.author)
- }
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/TranslationChapterIdTag.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/TranslationChapterIdTag.kt
deleted file mode 100644
index 0bd306ac..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/TranslationChapterIdTag.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303.tags
-
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.has
-import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
-import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
-import com.vitorpamplona.quartz.nip01Core.tags.events.EventReference
-import com.vitorpamplona.quartz.utils.arrayOfNotNull
-import com.vitorpamplona.quartz.utils.ensure
-
-class TranslationChapterIdTag(
- val ref: EventReference,
-) {
- constructor(eventId: String, relayHint: NormalizedRelayUrl?, pubkey: String?) : this(
- EventReference(eventId, pubkey, relayHint)
- )
-
- companion object {
- const val TAG_NAME = "translationChapterIdTag"
-
- fun parse(tag: Array): TranslationChapterIdTag? {
- ensure(tag.has(1)) { return null }
- ensure(tag[0] == TAG_NAME) { return null }
- ensure(tag[1].length == 64) { return null }
-
- val relayHint = tag.getOrNull(2)?.let { RelayUrlNormalizer.normalizeOrNull(it) }
-
- return TranslationChapterIdTag(tag[1], relayHint, tag.getOrNull(3))
- }
-
- fun assemble(
- eventId: HexKey,
- relay: NormalizedRelayUrl? = null,
- pubkey: String? = null,
- ) = arrayOfNotNull(TAG_NAME, eventId, relay?.url, pubkey)
-
- fun assemble(ref: EventReference) = assemble(ref.eventId, ref.relayHint, ref.author)
- }
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/TranslationChunkIdTag.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/TranslationChunkIdTag.kt
deleted file mode 100644
index 7d448c61..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/TranslationChunkIdTag.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303.tags
-
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.has
-import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
-import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
-import com.vitorpamplona.quartz.nip01Core.tags.events.EventReference
-import com.vitorpamplona.quartz.utils.arrayOfNotNull
-import com.vitorpamplona.quartz.utils.ensure
-
-class TranslationChunkIdTag(
- val ref: EventReference,
-) {
- constructor(eventId: String, relayHint: NormalizedRelayUrl?, pubkey: String?) : this(
- EventReference(eventId, pubkey, relayHint)
- )
-
- companion object {
- const val TAG_NAME = "translationChunkIdTag"
-
- fun parse(tag: Array): TranslationChunkIdTag? {
- ensure(tag.has(1)) { return null }
- ensure(tag[0] == TAG_NAME) { return null }
- ensure(tag[1].length == 64) { return null }
-
- val relayHint = tag.getOrNull(2)?.let { RelayUrlNormalizer.normalizeOrNull(it) }
-
- return TranslationChunkIdTag(tag[1], relayHint, tag.getOrNull(3))
- }
-
- fun assemble(
- eventId: HexKey,
- relay: NormalizedRelayUrl? = null,
- pubkey: String? = null,
- ) = arrayOfNotNull(TAG_NAME, eventId, relay?.url, pubkey)
-
- fun assemble(ref: EventReference) = assemble(ref.eventId, ref.relayHint, ref.author)
- }
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/TranslationIdTag.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/TranslationIdTag.kt
deleted file mode 100644
index ba7361d6..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/TranslationIdTag.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303.tags
-
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.nip01Core.core.has
-import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
-import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
-import com.vitorpamplona.quartz.nip01Core.tags.events.EventReference
-import com.vitorpamplona.quartz.utils.arrayOfNotNull
-import com.vitorpamplona.quartz.utils.ensure
-
-class TranslationIdTag(
- val ref: EventReference,
-) {
- constructor(eventId: String, relayHint: NormalizedRelayUrl?, pubkey: String?) : this(
- EventReference(eventId, pubkey, relayHint)
- )
-
- companion object {
- const val TAG_NAME = "translationIdTag"
-
- fun parse(tag: Array): TranslationIdTag? {
- ensure(tag.has(1)) { return null }
- ensure(tag[0] == TAG_NAME) { return null }
- ensure(tag[1].length == 64) { return null }
-
- val relayHint = tag.getOrNull(2)?.let { RelayUrlNormalizer.normalizeOrNull(it) }
-
- return TranslationIdTag(tag[1], relayHint, tag.getOrNull(3))
- }
-
- fun assemble(
- eventId: HexKey,
- relay: NormalizedRelayUrl? = null,
- pubkey: String? = null,
- ) = arrayOfNotNull(TAG_NAME, eventId, relay?.url, pubkey)
-
- fun assemble(ref: EventReference) = assemble(ref.eventId, ref.relayHint, ref.author)
- }
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/UrlTag.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/UrlTag.kt
deleted file mode 100644
index c0f1b10a..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/UrlTag.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303.tags
-
-import com.vitorpamplona.quartz.nip01Core.core.has
-import com.vitorpamplona.quartz.utils.ensure
-
-class UrlTag(
- val url: String,
-) {
- fun toTagArray() = assemble(url = url)
-
- companion object {
- const val TAG_NAME = "url"
-
- fun parse(tag: Array): UrlTag? {
- ensure(tag.has(1)) { return null }
- ensure(tag[0] == TAG_NAME) { return null }
-
- return UrlTag(url = tag[1])
- }
-
- fun assemble(url: String): Array = arrayOf(TAG_NAME, url)
-
- fun assemble(urlTag: UrlTag) = assemble(url = urlTag.url)
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/VisibilityTag.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/VisibilityTag.kt
deleted file mode 100644
index 267551c2..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/VisibilityTag.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303.tags
-
-import com.vitorpamplona.quartz.nip01Core.core.has
-import com.vitorpamplona.quartz.utils.ensure
-
-class VisibilityTag(
- val visibility: String,
-) {
- fun toTagArray() = assemble(visibility = visibility)
-
- companion object {
- const val TAG_NAME = "visibility"
-
- fun parse(tag: Array): VisibilityTag? {
- ensure(tag.has(1)) { return null }
- ensure(tag[0] == TAG_NAME) { return null }
-
- return VisibilityTag(visibility = tag[1])
- }
-
- fun assemble(visibility: String): Array = arrayOf(TAG_NAME, visibility)
-
- fun assemble(visibilityTag: VisibilityTag) = assemble(visibility = visibilityTag.visibility)
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/WordStatisticsTag.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/WordStatisticsTag.kt
deleted file mode 100644
index 9728424e..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/nostr/nip30303/tags/WordStatisticsTag.kt
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303.tags
-
-import com.vitorpamplona.quartz.nip01Core.core.has
-import com.vitorpamplona.quartz.utils.ensure
-
-class WordStatisticsTag(
- val wordCount: Int,
- val characterCount: Int,
-) {
- fun toTagArray() = assemble(
- wordCount = wordCount,
- characterCount = characterCount,
- )
-
- companion object {
- const val TAG_NAME = "word_stats"
-
- fun parse(tag: Array): WordStatisticsTag? {
- ensure(tag.has(2)) { return null }
- ensure(tag[0] == TAG_NAME) { return null }
-
- val wordCount = tag[1].toIntOrNull() ?: return null
- val characterCount = tag[2].toIntOrNull() ?: return null
-
- return WordStatisticsTag(
- wordCount = wordCount,
- characterCount = characterCount,
- )
- }
-
- fun assemble(
- wordCount: Int,
- characterCount: Int,
- ): Array = arrayOf(
- TAG_NAME,
- wordCount.toString(),
- characterCount.toString(),
- )
-
- fun assemble(wordStatisticsTag: WordStatisticsTag) = assemble(
- wordCount = wordStatisticsTag.wordCount,
- characterCount = wordStatisticsTag.characterCount,
- )
- }
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/repository/DkgRepository.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/repository/DkgRepository.kt
index 3857ff5b..60b57863 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/repository/DkgRepository.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/repository/DkgRepository.kt
@@ -110,6 +110,12 @@ interface DkgRepository {
* room has no standing to propose one -- both of which mean there is nothing
* true to propose.
*/
+ /**
+ * Ends a ceremony this device is in, for everyone in it -- see
+ * `ChillDkgRitualManager.abandon`. Returns whether it was ended.
+ */
+ suspend fun abandon(localChatRoom: LocalChatRoom, sessionId: String): Boolean
+
suspend fun proposeGroupKeyState(
localChatRoom: LocalChatRoom,
userPublicKey: HexKey,
@@ -232,6 +238,8 @@ interface DkgRepository {
nostrPrivateKey: ByteArray
) = Unit
+ override suspend fun abandon(localChatRoom: LocalChatRoom, sessionId: String): Boolean = false
+
override suspend fun proposeGroupKeyState(
localChatRoom: LocalChatRoom,
userPublicKey: HexKey,
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/repository/MantraRepository.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/repository/MantraRepository.kt
deleted file mode 100644
index 6c7912ea..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/repository/MantraRepository.kt
+++ /dev/null
@@ -1,113 +0,0 @@
-package com.machankura.bennu.compose.repository
-
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.machankura.bennu.compose.database.model.MantraArtifact
-import com.machankura.bennu.compose.database.model.MantraArtifactVersion
-import com.machankura.bennu.compose.database.model.MantraChapter
-import com.machankura.bennu.compose.database.model.MantraChunk
-import com.machankura.bennu.compose.database.model.MantraDialect
-import com.machankura.bennu.compose.database.model.MantraTranslationArtifactVersion
-import com.machankura.bennu.compose.database.model.MantraTranslationChapter
-import com.machankura.bennu.compose.database.model.MantraTranslationChunk
-import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
-
-interface MantraRepository {
- suspend fun getArtifacts(chatRoomId: String): List
-
- suspend fun getArtifact(id: String): MantraArtifact?
-
- suspend fun getArtifactVersions(artifactId: String): List
-
- suspend fun getArtifactVersion(id: String): MantraArtifactVersion?
-
- suspend fun getChaptersForArtifact(artifactId: String): List
-
- /**
- * The chapters of one version of an artifact, in reading order. A chapter
- * hangs off a version rather than off the artifact, so this is what a new
- * chapter's index counts.
- */
- suspend fun getChaptersForArtifactVersion(artifactVersionId: String): List
-
- suspend fun getChapter(id: String): MantraChapter?
-
- suspend fun getChunksForChapter(chapterId: String): List
-
- suspend fun getChunk(id: String): MantraChunk?
-
- suspend fun getTranslationsForArtifact(artifactId: String): List
-
- suspend fun getTranslation(id: String): MantraTranslationArtifactVersion?
-
- /**
- * The translations of one artifact version: what a chapter signed into that
- * version has to be scaffolded into, and what a translation is caught up
- * against.
- */
- suspend fun getTranslationsForArtifactVersion(artifactVersionId: String): List
-
- suspend fun getTranslationChapter(id: String): MantraTranslationChapter?
-
- suspend fun getTranslationChapters(translationArtifactVersionId: String): List
-
- suspend fun getTranslationChunks(translationChapterId: String): List
-
- suspend fun getDialects(chatRoomId: String): List
-
- suspend fun getDialect(id: String): MantraDialect?
-
- suspend fun addArtifactVersion(
- localChatRoom: LocalChatRoom,
- artifactId: HexKey,
- versionLabel: String,
- userPublicKey: HexKey,
- ): MantraArtifactVersion?
-
- companion object {
- const val DEFAULT_VISIBILITY = "private"
- const val DEFAULT_LICENSE = "cc"
-
- val NO_OP_MANTRA_REPOSITORY = object: MantraRepository{
- override suspend fun getArtifacts(chatRoomId: String): List = emptyList()
-
- override suspend fun getArtifact(id: String): MantraArtifact? = null
-
- override suspend fun getArtifactVersions(artifactId: String): List = emptyList()
-
- override suspend fun getArtifactVersion(id: String): MantraArtifactVersion? = null
-
- override suspend fun getChaptersForArtifact(artifactId: String): List = emptyList()
-
- override suspend fun getChaptersForArtifactVersion(artifactVersionId: String): List = emptyList()
-
- override suspend fun getChapter(id: String): MantraChapter? = null
-
- override suspend fun getChunksForChapter(chapterId: String): List = emptyList()
-
- override suspend fun getChunk(id: String): MantraChunk? = null
-
- override suspend fun getTranslationsForArtifact(artifactId: String): List = emptyList()
-
- override suspend fun getTranslation(id: String): MantraTranslationArtifactVersion? = null
-
- override suspend fun getTranslationsForArtifactVersion(artifactVersionId: String): List = emptyList()
-
- override suspend fun getTranslationChapter(id: String): MantraTranslationChapter? = null
-
- override suspend fun getTranslationChapters(translationArtifactVersionId: String): List = emptyList()
-
- override suspend fun getTranslationChunks(translationChapterId: String): List = emptyList()
-
- override suspend fun getDialects(chatRoomId: String): List = emptyList()
-
- override suspend fun getDialect(id: String): MantraDialect? = null
-
- override suspend fun addArtifactVersion(
- localChatRoom: LocalChatRoom,
- artifactId: HexKey,
- versionLabel: String,
- userPublicKey: HexKey,
- ): MantraArtifactVersion? = null
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/text/Markdown.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/text/Markdown.kt
deleted file mode 100644
index b9f07412..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/text/Markdown.kt
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.machankura.bennu.compose.text
-
-/**
- * Lightweight helpers for the markdown original text of chapters/chunks.
- *
- * Counts are computed on the raw markdown text (no rendering/stripping):
- * words are whitespace-separated tokens and characters are the string length.
- */
-object Markdown {
- private val WHITESPACE = Regex("\\s+")
-
- /** A paragraph break is one or more blank lines. */
- private val PARAGRAPH_BREAK = Regex("(?:\\r?\\n){2,}")
-
- fun wordCount(text: String): Int {
- val trimmed = text.trim()
- return if (trimmed.isEmpty()) 0 else trimmed.split(WHITESPACE).count { it.isNotBlank() }
- }
-
- fun characterCount(text: String): Int = text.length
-
- /**
- * Split markdown into paragraphs (blocks separated by blank lines),
- * trimmed and with empties removed. Each paragraph becomes a chunk.
- */
- fun splitParagraphs(text: String): List =
- text.split(PARAGRAPH_BREAK)
- .map { it.trim() }
- .filter { it.isNotEmpty() }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/text/ProposedEvent.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/text/ProposedEvent.kt
index 68bf3f42..5c773f65 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/text/ProposedEvent.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/text/ProposedEvent.kt
@@ -8,19 +8,12 @@ import com.machankura.bennu.compose.nostr.GroupRelaySet
import com.machankura.bennu.compose.nostr.frost.GroupKeyStateEvent
import com.machankura.bennu.compose.nostr.subgroup.SubgroupBirthCertificateEvent
import com.machankura.bennu.compose.nostr.wallet.GroupWalletStatementEvent
-import com.machankura.bennu.compose.nostr.nip30303.ArtifactEvent
-import com.machankura.bennu.compose.nostr.nip30303.ArtifactVersionEvent
-import com.machankura.bennu.compose.nostr.nip30303.ChapterEvent
-import com.machankura.bennu.compose.nostr.nip30303.DialectEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationArtifactVersionEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationChapterEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationChunkEvent
/**
* An event a group is being asked to sign, said in words.
*
* Shown as the thing rather than as an event: a member deciding whether to sign
- * is deciding about a dialect or an artifact, and "kind 30304" answers a
+ * is deciding about a profile or a relay list, and "kind 10002" answers a
* question nobody asked. The raw kind stays for anything not recognised, since
* refusing to describe an event is better than describing it wrongly.
*
@@ -36,99 +29,6 @@ object ProposedEvent {
data class Summary(val label: String, val detail: String)
fun summarize(event: Event): Summary = when (event.kind) {
- DialectEvent.KIND -> Summary(
- label = "New dialect",
- detail = DialectEvent(
- event.id, event.pubKey, event.createdAt, event.tags, event.content, event.sig
- ).let { dialect ->
- listOfNotNull(dialect.name(), dialect.country(), dialect.language())
- .joinToString(" · ")
- }
- )
-
- ArtifactEvent.KIND -> Summary(
- label = "New artifact",
- detail = ArtifactEvent(
- event.id, event.pubKey, event.createdAt, event.tags, event.content, event.sig
- ).let { artifact ->
- // The url is the substance of an artifact -- signing one is putting
- // the group's name to what it points at -- so it goes next to the
- // name rather than being left for the detail screen afterwards.
- listOfNotNull(event.content, artifact.versionLabel(), artifact.url())
- .joinToString(" · ")
- }
- )
-
- // Signed alongside the artifact it belongs to rather than on its own,
- // so this is almost always read as the second line of a batch of two.
- // Named after the artifact rather than the label, because the label is
- // the whole of the content and would otherwise be said twice.
- ArtifactVersionEvent.KIND -> Summary(
- label = "Version of the artifact",
- detail = event.content.ifBlank { "Unlabelled" }
- )
-
- ChapterEvent.KIND -> Summary(
- label = "New chapter",
- detail = ChapterEvent(
- event.id, event.pubKey, event.createdAt, event.tags, event.content, event.sig
- ).let { chapter ->
- // The text is the substance of a chapter -- signing one is putting
- // the group's name to what everybody will translate from -- but it
- // is a whole chapter, so its size stands in for it here. The chunk
- // count says how many of the batch's other items came out of this
- // text, which is the rest of what is being signed.
- val chunkCount = chapter.originalText()?.let { Markdown.splitParagraphs(it).size }
-
- listOfNotNull(
- chapter.name(),
- chapter.wordCount()?.let { "$it words" },
- chunkCount?.let { "$it ${if (it == 1) "chunk" else "chunks"}" }
- ).joinToString(" · ")
- }
- )
-
- TranslationArtifactVersionEvent.KIND -> Summary(
- label = "New translation",
- detail = TranslationArtifactVersionEvent(
- event.id, event.pubKey, event.createdAt, event.tags, event.content, event.sig
- ).let { translation ->
- // Named after the dialect it is into, which is the whole of what is
- // being decided: everything else in the batch follows from it.
- listOfNotNull(translation.name(), translation.visibility(), translation.license())
- .joinToString(" · ")
- }
- )
-
- TranslationChapterEvent.KIND -> Summary(
- label = "Chapter of the translation",
- detail = TranslationChapterEvent(
- event.id, event.pubKey, event.createdAt, event.tags, event.content, event.sig
- ).let { chapter ->
- // A translation chapter is a place for translated chunks to hang
- // off, so there is nothing in it to read -- only where in the work
- // it sits. Counted from one, the way the chapter list reads.
- chapter.index()?.let { "Chapter ${it + 1}" } ?: "Position unknown"
- }
- )
-
- TranslationChunkEvent.KIND -> Summary(
- label = "Translated passage",
- detail = TranslationChunkEvent(
- event.id, event.pubKey, event.createdAt, event.tags, event.content, event.sig
- ).let { chunk ->
- // The translation itself is the whole of what is being decided --
- // a member signing this is agreeing that these words say what the
- // original said -- so it is the detail rather than a count of it.
- // Where in the chapter it sits comes first, since that is what
- // says which passage to read it against.
- listOfNotNull(
- chunk.index()?.let { "Passage ${it + 1}" },
- event.content
- ).joinToString(" · ")
- }
- )
-
// The one thing a group signs that is about the group rather than about
// its work, and the only one a member sees before the room has done
// anything. Shown as the path and the ceremony rather than as the key:
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/AddArtifactScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/AddArtifactScreen.kt
deleted file mode 100644
index 0e84f739..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/AddArtifactScreen.kt
+++ /dev/null
@@ -1,406 +0,0 @@
-package com.machankura.bennu.compose.ui.composable
-
-import androidx.compose.foundation.background
-import androidx.compose.foundation.layout.Arrangement
-import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.ExperimentalLayoutApi
-import androidx.compose.foundation.layout.FlowRow
-import androidx.compose.foundation.layout.Spacer
-import androidx.compose.foundation.layout.fillMaxSize
-import androidx.compose.foundation.layout.fillMaxWidth
-import androidx.compose.foundation.layout.height
-import androidx.compose.foundation.layout.padding
-import androidx.compose.foundation.layout.imePadding
-import androidx.compose.foundation.text.input.rememberTextFieldState
-import androidx.compose.material.icons.Icons
-import androidx.compose.material.icons.filled.Add
-import androidx.compose.material.icons.filled.DriveFileRenameOutline
-import androidx.compose.material.icons.filled.Label
-import androidx.compose.material.icons.filled.Link
-import androidx.compose.material.icons.filled.LocalOffer
-import androidx.compose.material.icons.filled.MoreVert
-import androidx.compose.material3.BottomAppBar
-import androidx.compose.material3.BottomAppBarDefaults
-import androidx.compose.material3.ExperimentalMaterial3Api
-import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
-import androidx.compose.material3.FilterChip
-import androidx.compose.material3.Icon
-import androidx.compose.material3.IconButton
-import androidx.compose.material3.MaterialTheme
-import androidx.compose.material3.OutlinedTextField
-import androidx.compose.material3.OutlinedTextFieldDefaults
-import androidx.compose.material3.Scaffold
-import androidx.compose.material3.Surface
-import androidx.compose.material3.Text
-import androidx.compose.material3.TopAppBar
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.LaunchedEffect
-import androidx.compose.runtime.getValue
-import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.remember
-import androidx.compose.runtime.setValue
-import androidx.compose.ui.Alignment
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.text.style.TextAlign
-import androidx.compose.ui.unit.dp
-import androidx.lifecycle.viewmodel.compose.viewModel
-import com.machankura.bennu.compose.database.model.ChatRoom
-import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
-import com.machankura.bennu.compose.repository.ChatRepository
-import com.machankura.bennu.compose.repository.FrostSigningRepository
-import com.machankura.bennu.compose.repository.NostrRepository
-import com.machankura.bennu.compose.ui.composable.navigation.routes.ChatRoomDetailRoute
-import com.machankura.bennu.compose.ui.composable.navigation.routes.Route
-import com.machankura.bennu.compose.ui.composable.widgets.LoadingDataIndicator
-import com.machankura.bennu.compose.ui.theme.BennuTheme
-import com.machankura.bennu.compose.ui.view.state.ChatRoomMessagingUIState
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.machankura.bennu.compose.repository.MantraRepository
-import com.machankura.bennu.compose.ui.composable.navigation.routes.FrostSigningRoute
-import com.machankura.bennu.compose.ui.composable.navigation.routes.ImplementationPendingRoute
-import com.machankura.bennu.compose.ui.view.model.AddArtifactViewModel
-import com.machankura.bennu.compose.ui.view.state.AddArtifactUIState
-import com.machankura.bennu.compose.ui.theme.spacing
-import bennu.composeapp.generated.resources.Res
-import org.jetbrains.compose.resources.stringResource
-import bennu.composeapp.generated.resources.add_artifact_to_the_group_library
-import bennu.composeapp.generated.resources.direct_message_detail
-import bennu.composeapp.generated.resources.direct_message_functionality_will_be_here
-import bennu.composeapp.generated.resources.eg_first_edition
-import bennu.composeapp.generated.resources.eg_https_harper_com_2_kill_bird
-import bennu.composeapp.generated.resources.eg_to_kill_a_mocking_bird
-import bennu.composeapp.generated.resources.initial_version_label
-import bennu.composeapp.generated.resources.name_of_artifact
-import bennu.composeapp.generated.resources.no_dialects_have_been_defined_in_this_group
-import bennu.composeapp.generated.resources.propose_artifact
-import bennu.composeapp.generated.resources.source_dialect
-import bennu.composeapp.generated.resources.url
-import androidx.compose.material3.SnackbarHost
-import com.machankura.bennu.compose.ui.composable.widgets.LocalSnackbarHostState
-import com.machankura.bennu.compose.ui.composable.widgets.NavigateBackButton
-import com.machankura.bennu.compose.ui.theme.readableContent
-import com.machankura.bennu.compose.ui.composable.widgets.ScreenStateTransition
-import com.machankura.bennu.compose.ui.composable.widgets.buttons.ExtendedFab
-import com.machankura.bennu.compose.ui.theme.ConformancePreviews
-
-@OptIn(ExperimentalMaterial3ExpressiveApi::class, ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class)
-@Composable
-fun AddArtifactScreen(
- activeUserPublicKey: HexKey,
- chatRoomId: String,
- relayHint: String?,
- initialAddArtifactUIState: AddArtifactUIState = AddArtifactUIState.Loading,
- nostrRepository: NostrRepository,
- chatRepository: ChatRepository,
- mantraRepository: MantraRepository,
- frostSigningRepository: FrostSigningRepository,
- onNavigateToRouteAndPopUpInclusive: (Route) -> Unit,
- onNavigateToRoute: (Route) -> Unit,
- onNavigateBack: () -> Unit,
-) {
- val addArtifactViewModel: AddArtifactViewModel = viewModel(
- factory = AddArtifactViewModel.factory(
- chatRoomId = chatRoomId,
- relayHint = relayHint,
- initialAddArtifactUIState = initialAddArtifactUIState,
- nostrRepository = nostrRepository,
- chatRepository = chatRepository,
- activeUserPublicKey = activeUserPublicKey,
- mantraRepository = mantraRepository,
- frostSigningRepository = frostSigningRepository
- )
- )
-
- ScreenStateTransition(addArtifactViewModel.addArtifactUIState) { uiState ->
- when (val addArtifactUIState = uiState) {
- is AddArtifactUIState.Error -> {
- Column(
- modifier = Modifier.fillMaxWidth(),
- horizontalAlignment = Alignment.CenterHorizontally
- ) {
- Spacer(
- modifier = Modifier.height(MaterialTheme.spacing.space600)
- )
- Text(
- text = addArtifactUIState.message,
- )
- }
- }
- is AddArtifactUIState.Loaded -> {
- val nameFieldState = rememberTextFieldState()
- val urlFieldState = rememberTextFieldState()
- val versionLabelFieldState = rememberTextFieldState("1.0")
-
- // The id of the group dialect this artifact is written in. Null until
- // one is picked; dialects are defined from the group detail screen.
- var selectedDialectId: String? by remember { mutableStateOf(null) }
-
- // The two things the form cannot ask for again. A dialect has to
- // already exist and nothing here can create one; a shared key has to
- // have been ceremonied and this is not where that happens. Either
- // missing is a dead end rather than something to propose and be told
- // about afterwards, and the button says so.
- val canAddArtifact = selectedDialectId != null && addArtifactUIState.canSign
-
- // imePadding: this screen has a text field, and without it the software
- // keyboard covers whatever is being typed into.
- Scaffold(
- snackbarHost = { SnackbarHost(LocalSnackbarHostState.current) },
- modifier = Modifier.imePadding(),
- topBar = {
- TopAppBar(
- title = {
- addArtifactUIState.localChatRoom.RenderChatRoomTitleText()
- },
- navigationIcon = { NavigateBackButton(onNavigateBack) },
- )
- },
- bottomBar = {
- BottomAppBar(
- actions = {},
- floatingActionButton = {
- ExtendedFab(
- label = stringResource(Res.string.propose_artifact),
- icon = { Icon(Icons.Default.Add, contentDescription = "Propose artifact") },
- enabled = canAddArtifact,
- onClick = {
- addArtifactViewModel.addArtifact(
- localChatRoom = addArtifactUIState.localChatRoom,
- nameField = nameFieldState,
- urlField = urlFieldState,
- versionLabelField = versionLabelFieldState,
- dialectId = selectedDialectId,
- onSuccess = { sessionId ->
- // Onto the session rather than to the
- // artifact. Nothing has been created yet
- // -- the artifact appears when enough
- // members sign -- so a detail screen for
- // a row that does not exist would read as
- // a failure.
- onNavigateToRouteAndPopUpInclusive.invoke(
- FrostSigningRoute(
- activeUserPublicKey = activeUserPublicKey,
- chatRoomId = chatRoomId,
- sessionId = sessionId
- )
- )
- },
- onFailure = {
- onNavigateToRoute.invoke(
- ImplementationPendingRoute("Failed artifact")
- )
- }
- )
-
- }
- )
- }
- )
- }
- ) { innerPadding ->
- Column(
- modifier = Modifier.padding(innerPadding).readableContent().fillMaxSize()
- ) {
- // TODO: Check that we have direct message relays for this user...
- Column(
- modifier = Modifier.fillMaxWidth(),
- verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space125),
- horizontalAlignment = Alignment.CenterHorizontally
- ) {
- Text(stringResource(Res.string.add_artifact_to_the_group_library))
-
- if (!addArtifactUIState.canSign) {
- Text(
- text = "This group has no shared key, so it cannot sign an " +
- "artifact into its library. Run a shared key ceremony first.",
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.error
- )
- }
-
- OutlinedTextField(
- modifier = Modifier.fillMaxWidth()
- .background(BottomAppBarDefaults.containerColor),
- state = nameFieldState,
- colors = OutlinedTextFieldDefaults.colors(
- focusedBorderColor = Color.Transparent,
- unfocusedBorderColor = Color.Transparent,
- disabledBorderColor = Color.Transparent
- ),
- leadingIcon = {
- Icon(
- Icons.Default.DriveFileRenameOutline,
- contentDescription = "Name of the artifact"
- )
- },
- label = {
- Text(
- text = stringResource(Res.string.name_of_artifact)
- )
- },
- placeholder = {
- Text(
- text = stringResource(Res.string.eg_to_kill_a_mocking_bird)
- )
- },
- )
-
- OutlinedTextField(
- modifier = Modifier.fillMaxWidth()
- .background(BottomAppBarDefaults.containerColor),
- state = urlFieldState,
- colors = OutlinedTextFieldDefaults.colors(
- focusedBorderColor = Color.Transparent,
- unfocusedBorderColor = Color.Transparent,
- disabledBorderColor = Color.Transparent
- ),
- leadingIcon = {
- Icon(
- Icons.Default.Link,
- contentDescription = "Link to the artifact"
- )
- },
- label = {
- Text(
- text = stringResource(Res.string.url)
- )
- },
- placeholder = {
- Text(
- text = stringResource(Res.string.eg_https_harper_com_2_kill_bird)
- )
- },
- )
-
- OutlinedTextField(
- modifier = Modifier.fillMaxWidth()
- .background(BottomAppBarDefaults.containerColor),
- state = versionLabelFieldState,
- colors = OutlinedTextFieldDefaults.colors(
- focusedBorderColor = Color.Transparent,
- unfocusedBorderColor = Color.Transparent,
- disabledBorderColor = Color.Transparent
- ),
- leadingIcon = {
- Icon(
- Icons.Default.LocalOffer,
- contentDescription = "Verison label"
- )
- },
- label = {
- Text(
- text = stringResource(Res.string.initial_version_label)
- )
- },
- placeholder = {
- Text(
- text = stringResource(Res.string.eg_first_edition)
- )
- },
- )
-
- Text(stringResource(Res.string.source_dialect))
-
- if (addArtifactUIState.dialects.isEmpty()) {
- Text(
- text = stringResource(Res.string.no_dialects_have_been_defined_in_this_group),
- style = MaterialTheme.typography.bodySmall
- )
- } else {
- FlowRow(
- modifier = Modifier.fillMaxWidth(),
- horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.itemGap)
- ) {
- addArtifactUIState.dialects.forEach { dialect ->
- FilterChip(
- selected = selectedDialectId == dialect.id,
- onClick = { selectedDialectId = dialect.id },
- label = { Text(dialect.name) }
- )
- }
- }
- }
-
- // TODO: Add Visibility
- }
- }
- }
- }
- AddArtifactUIState.Loading -> {
- Column(
- modifier = Modifier.fillMaxWidth().padding(
- MaterialTheme.spacing.space250
- ),
- horizontalAlignment = Alignment.CenterHorizontally,
- verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space250)
- ) {
-
- Spacer(
- modifier = Modifier.weight(1f)
- )
- Text(
- text = stringResource(Res.string.direct_message_detail),
- style = MaterialTheme.typography.bodyLarge,
- textAlign = TextAlign.Center
- )
-
- Text(
- text = stringResource(Res.string.direct_message_functionality_will_be_here),
- style = MaterialTheme.typography.bodySmall,
- textAlign = TextAlign.Center
- )
-
- LoadingDataIndicator(
- fillScreen = false
- )
-
- Spacer(
- modifier = Modifier.weight(2f)
- )
- }
- }
- }
- }
-
- LaunchedEffect(true) {
- if (initialAddArtifactUIState == AddArtifactUIState.Loading) {
- addArtifactViewModel.initiateChatRoomDetail()
- }
- }
-}
-
-@ConformancePreviews
-@Composable
-private fun AddArtifactScreenPreview() {
- BennuTheme {
- Surface(
- modifier = Modifier.fillMaxSize()
- ) {
- AddArtifactScreen(
- activeUserPublicKey = "",
- chatRoomId = "publicKey",
- relayHint = null,
- initialAddArtifactUIState = AddArtifactUIState.Loaded(
- localChatRoom = LocalChatRoom(
- chatRoom = ChatRoom(
- id = "",
- userPublicKey = "",
- subject = "Message title",
- description = "See something. Say somethin",
- initialGiftWrapPayloadId = "sdfaer",
- mlsGroupState = null
- ),
- )
- ),
- nostrRepository = NostrRepository.NO_OP_NOSTR_REPOSITORY,
- chatRepository = ChatRepository.NO_OP_CHAT_REPOSITORY,
- mantraRepository = MantraRepository.NO_OP_MANTRA_REPOSITORY,
- frostSigningRepository = FrostSigningRepository.NO_OP_FROST_SIGNING_REPOSITORY,
- onNavigateToRouteAndPopUpInclusive = {},
- onNavigateToRoute = {},
- onNavigateBack = {},
- )
- }
- }
-}
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/AddChapterScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/AddChapterScreen.kt
deleted file mode 100644
index f5fdd087..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/AddChapterScreen.kt
+++ /dev/null
@@ -1,326 +0,0 @@
-package com.machankura.bennu.compose.ui.composable
-
-import androidx.compose.foundation.layout.Arrangement
-import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.Spacer
-import androidx.compose.foundation.layout.fillMaxSize
-import androidx.compose.foundation.layout.fillMaxWidth
-import androidx.compose.foundation.layout.height
-import androidx.compose.foundation.layout.padding
-import androidx.compose.foundation.layout.imePadding
-import androidx.compose.foundation.text.input.rememberTextFieldState
-import androidx.compose.material.icons.Icons
-import androidx.compose.material.icons.filled.Add
-import androidx.compose.material.icons.filled.DriveFileRenameOutline
-import androidx.compose.material3.BottomAppBar
-import androidx.compose.material3.ExperimentalMaterial3Api
-import androidx.compose.material3.Icon
-import androidx.compose.material3.MaterialTheme
-import androidx.compose.material3.OutlinedTextField
-import androidx.compose.material3.Scaffold
-import androidx.compose.material3.Surface
-import androidx.compose.material3.Text
-import androidx.compose.material3.TopAppBar
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.LaunchedEffect
-import androidx.compose.ui.Alignment
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.text.style.TextAlign
-import androidx.compose.ui.unit.dp
-import androidx.lifecycle.viewmodel.compose.viewModel
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.machankura.bennu.compose.database.model.ChatRoom
-import com.machankura.bennu.compose.database.model.MantraArtifact
-import com.machankura.bennu.compose.database.model.MantraArtifactVersion
-import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
-import com.machankura.bennu.compose.repository.ChatRepository
-import com.machankura.bennu.compose.repository.FrostSigningRepository
-import com.machankura.bennu.compose.repository.MantraRepository
-import com.machankura.bennu.compose.text.Markdown
-import com.machankura.bennu.compose.ui.composable.navigation.routes.FrostSigningRoute
-import com.machankura.bennu.compose.ui.composable.navigation.routes.ImplementationPendingRoute
-import com.machankura.bennu.compose.ui.composable.navigation.routes.Route
-import com.machankura.bennu.compose.ui.composable.widgets.LoadingDataIndicator
-import com.machankura.bennu.compose.ui.theme.BennuTheme
-import com.machankura.bennu.compose.ui.view.model.AddChapterViewModel
-import com.machankura.bennu.compose.ui.view.state.AddChapterUIState
-import com.machankura.bennu.compose.ui.theme.spacing
-import bennu.composeapp.generated.resources.Res
-import org.jetbrains.compose.resources.stringResource
-import bennu.composeapp.generated.resources.add_chapter
-import bennu.composeapp.generated.resources.chapter_name
-import bennu.composeapp.generated.resources.eg_chapter_1_the_beginning
-import bennu.composeapp.generated.resources.original_text_markdown
-import bennu.composeapp.generated.resources.paste_the_chapter_s_markdown_blank_lines
-import bennu.composeapp.generated.resources.propose_chapter
-import bennu.composeapp.generated.resources.this_artifact_has_no_version_for_a_chapter
-import bennu.composeapp.generated.resources.add_chapter_to
-import androidx.compose.material3.SnackbarHost
-import com.machankura.bennu.compose.ui.composable.widgets.LocalSnackbarHostState
-import com.machankura.bennu.compose.ui.theme.readableContent
-import com.machankura.bennu.compose.ui.composable.widgets.ScreenStateTransition
-import com.machankura.bennu.compose.ui.composable.widgets.NavigateBackButton
-import com.machankura.bennu.compose.ui.composable.widgets.buttons.ExtendedFab
-import com.machankura.bennu.compose.ui.theme.ConformancePreviews
-
-@OptIn(ExperimentalMaterial3Api::class)
-@Composable
-fun AddChapterScreen(
- activeUserPublicKey: HexKey,
- artifactId: String,
- chatRoomId: String,
- relayHint: String?,
- initialAddChapterUIState: AddChapterUIState = AddChapterUIState.Loading,
- mantraRepository: MantraRepository,
- chatRepository: ChatRepository,
- frostSigningRepository: FrostSigningRepository,
- onNavigateToRouteAndPopUpInclusive: (Route) -> Unit,
- onNavigateToRoute: (Route) -> Unit,
- onNavigateBack: () -> Unit,
-) {
- val addChapterViewModel: AddChapterViewModel = viewModel(
- factory = AddChapterViewModel.factory(
- activeUserPublicKey = activeUserPublicKey,
- artifactId = artifactId,
- chatRoomId = chatRoomId,
- relayHint = relayHint,
- initialAddChapterUIState = initialAddChapterUIState,
- mantraRepository = mantraRepository,
- chatRepository = chatRepository,
- frostSigningRepository = frostSigningRepository,
- )
- )
-
- ScreenStateTransition(addChapterViewModel.addChapterUIState) { uiState ->
- when (val addChapterUIState = uiState) {
- is AddChapterUIState.Error -> {
- Column(
- modifier = Modifier.fillMaxWidth(),
- horizontalAlignment = Alignment.CenterHorizontally
- ) {
- Spacer(modifier = Modifier.height(MaterialTheme.spacing.space600))
- Text(text = addChapterUIState.message)
- }
- }
-
- is AddChapterUIState.Loaded -> {
- val nameFieldState = rememberTextFieldState()
- val originalTextFieldState = rememberTextFieldState()
-
- // Live counts / paragraph (chunk) preview from the markdown text.
- val originalText = originalTextFieldState.text.toString()
- val wordCount = Markdown.wordCount(originalText)
- val characterCount = Markdown.characterCount(originalText)
- val paragraphCount = Markdown.splitParagraphs(originalText).size
-
- // A chapter hangs off a version, and the group has to be able to
- // sign; without both there is nothing this screen can propose.
- val artifactVersion = addChapterUIState.artifactVersion
-
- // The chapter and a chunk per paragraph are signed in one session,
- // and a session signs a bounded number of events. Past that the
- // chapter has to be split in two, which is worth saying while there
- // is still a cursor in the text rather than after a failed propose.
- val tooManyChunks = paragraphCount > AddChapterViewModel.MAX_CHUNKS_PER_CHAPTER
-
- val canProposeChapter = artifactVersion != null &&
- addChapterUIState.canSign &&
- paragraphCount > 0 &&
- !tooManyChunks
-
- // imePadding: this screen has a text field, and without it the software
- // keyboard covers whatever is being typed into.
- Scaffold(
- snackbarHost = { SnackbarHost(LocalSnackbarHostState.current) },
- modifier = Modifier.imePadding(),
- topBar = {
- TopAppBar(
- title = { Text(stringResource(Res.string.add_chapter_to, addChapterUIState.artifact.name)) },
- navigationIcon = { NavigateBackButton(onNavigateBack) },
- )
- },
- bottomBar = {
- BottomAppBar(
- actions = {},
- floatingActionButton = {
- ExtendedFab(
- label = stringResource(Res.string.propose_chapter),
- icon = { Icon(Icons.Default.Add, contentDescription = "Propose chapter") },
- enabled = canProposeChapter,
- onClick = {
- if (artifactVersion == null) return@ExtendedFab
-
- addChapterViewModel.addChapter(
- localChatRoom = addChapterUIState.localChatRoom,
- artifactVersion = artifactVersion,
- nameField = nameFieldState,
- originalTextField = originalTextFieldState,
- onSuccess = { sessionId ->
- // Onto the session rather than back to
- // the artifact. Nothing has been created
- // yet -- the chapter appears when enough
- // members sign -- so landing on the list
- // it is not in would read as a failure.
- onNavigateToRouteAndPopUpInclusive.invoke(
- FrostSigningRoute(
- activeUserPublicKey = activeUserPublicKey,
- chatRoomId = chatRoomId,
- sessionId = sessionId
- )
- )
- },
- onFailure = {
- onNavigateToRoute.invoke(
- ImplementationPendingRoute("Failed chapter")
- )
- }
- )
- }
- )
- }
- )
- }
- ) { innerPadding ->
- Column(
- modifier = Modifier.padding(innerPadding).readableContent().fillMaxSize().padding(MaterialTheme.spacing.space250),
- verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space125)
- ) {
- if (!addChapterUIState.canSign) {
- Text(
- text = "This group has no shared key, so it cannot sign a " +
- "chapter into existence. Run a shared key ceremony first.",
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.error
- )
- } else if (artifactVersion == null) {
- Text(
- text = stringResource(Res.string.this_artifact_has_no_version_for_a_chapter),
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.error
- )
- } else if (tooManyChunks) {
- Text(
- text = "$paragraphCount chunks is more than the group can sign in " +
- "one go. Split the chapter so that no part of it is over " +
- "${AddChapterViewModel.MAX_CHUNKS_PER_CHAPTER} paragraphs.",
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.error
- )
- }
-
- OutlinedTextField(
- modifier = Modifier.fillMaxWidth(),
- state = nameFieldState,
- leadingIcon = {
- Icon(
- Icons.Default.DriveFileRenameOutline,
- contentDescription = "Name of the chapter"
- )
- },
- label = { Text(stringResource(Res.string.chapter_name)) },
- placeholder = { Text(stringResource(Res.string.eg_chapter_1_the_beginning)) },
- )
-
- OutlinedTextField(
- modifier = Modifier.fillMaxWidth().weight(1f),
- state = originalTextFieldState,
- label = { Text(stringResource(Res.string.original_text_markdown)) },
- placeholder = { Text(stringResource(Res.string.paste_the_chapter_s_markdown_blank_lines)) },
- )
-
- Text(
- // The chunk count is what the group is asked to sign
- // alongside the chapter, so it is a count of the work
- // being proposed rather than a curiosity about the text.
- text = "$wordCount words · $characterCount characters · " +
- "$paragraphCount ${if (paragraphCount == 1) "chunk" else "chunks"} " +
- "of ${AddChapterViewModel.MAX_CHUNKS_PER_CHAPTER}",
- style = MaterialTheme.typography.labelMedium,
- color = if (tooManyChunks) {
- MaterialTheme.colorScheme.error
- } else {
- MaterialTheme.typography.labelMedium.color
- }
- )
- }
- }
- }
-
- AddChapterUIState.Loading -> {
- Column(
- modifier = Modifier.fillMaxWidth().padding(MaterialTheme.spacing.space250),
- horizontalAlignment = Alignment.CenterHorizontally,
- verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space250)
- ) {
- Spacer(modifier = Modifier.weight(1f))
- Text(
- text = stringResource(Res.string.add_chapter),
- style = MaterialTheme.typography.bodyLarge,
- textAlign = TextAlign.Center
- )
- LoadingDataIndicator(fillScreen = false)
- Spacer(modifier = Modifier.weight(2f))
- }
- }
- }
- }
-
- LaunchedEffect(true) {
- if (initialAddChapterUIState == AddChapterUIState.Loading) {
- addChapterViewModel.initiateAddChapter()
- }
- }
-}
-
-@ConformancePreviews
-@Composable
-private fun AddChapterScreenPreview() {
- BennuTheme {
- Surface(modifier = Modifier.fillMaxSize()) {
- AddChapterScreen(
- activeUserPublicKey = "",
- artifactId = "artifactId",
- chatRoomId = "chatRoomId",
- relayHint = null,
- initialAddChapterUIState = AddChapterUIState.Loaded(
- localChatRoom = LocalChatRoom(
- chatRoom = ChatRoom(
- id = "chatRoomId",
- userPublicKey = "",
- subject = "Message title",
- description = "See something. Say somethin",
- initialGiftWrapPayloadId = "sdfaer",
- mlsGroupState = null
- ),
- ),
- artifact = MantraArtifact(
- id = "artifactId",
- publicKey = "author",
- name = "To Kill a Mockingbird",
- url = "https://harper.com/2-kill-Bird",
- visibility = "private",
- dialectId = "dialectId",
- license = "cc",
- chatRoomId = "chatRoomId",
- signature = ""
- ),
- artifactVersion = MantraArtifactVersion(
- id = "artifactVersionId",
- artifactId = "artifactId",
- publicKey = "author",
- versionLabel = "1.0",
- chatRoomId = "chatRoomId",
- signature = ""
- ),
- canSign = true,
- ),
- mantraRepository = MantraRepository.NO_OP_MANTRA_REPOSITORY,
- chatRepository = ChatRepository.NO_OP_CHAT_REPOSITORY,
- frostSigningRepository = FrostSigningRepository.NO_OP_FROST_SIGNING_REPOSITORY,
- onNavigateToRouteAndPopUpInclusive = {},
- onNavigateToRoute = {},
- onNavigateBack = {}
- )
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/AddDialectScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/AddDialectScreen.kt
deleted file mode 100644
index 137b9e39..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/AddDialectScreen.kt
+++ /dev/null
@@ -1,342 +0,0 @@
-package com.machankura.bennu.compose.ui.composable
-
-import androidx.compose.foundation.background
-import androidx.compose.foundation.layout.Arrangement
-import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.Spacer
-import androidx.compose.foundation.layout.fillMaxSize
-import androidx.compose.foundation.layout.fillMaxWidth
-import androidx.compose.foundation.layout.height
-import androidx.compose.foundation.layout.padding
-import androidx.compose.foundation.layout.imePadding
-import androidx.compose.foundation.text.input.rememberTextFieldState
-import androidx.compose.material.icons.Icons
-import androidx.compose.material.icons.filled.Add
-import androidx.compose.material.icons.filled.Public
-import androidx.compose.material.icons.filled.Title
-import androidx.compose.material.icons.filled.Translate
-import androidx.compose.material3.BottomAppBar
-import androidx.compose.material3.BottomAppBarDefaults
-import androidx.compose.material3.ExperimentalMaterial3Api
-import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
-import androidx.compose.material3.Icon
-import androidx.compose.material3.MaterialTheme
-import androidx.compose.material3.OutlinedTextField
-import androidx.compose.material3.OutlinedTextFieldDefaults
-import androidx.compose.material3.Scaffold
-import androidx.compose.material3.Surface
-import androidx.compose.material3.Text
-import androidx.compose.material3.TopAppBar
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.LaunchedEffect
-import androidx.compose.ui.Alignment
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.text.style.TextAlign
-import androidx.compose.ui.unit.dp
-import androidx.lifecycle.viewmodel.compose.viewModel
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.machankura.bennu.compose.database.model.ChatRoom
-import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
-import com.machankura.bennu.compose.repository.ChatRepository
-import com.machankura.bennu.compose.repository.FrostSigningRepository
-import com.machankura.bennu.compose.repository.NostrRepository
-import com.machankura.bennu.compose.ui.composable.navigation.routes.FrostSigningRoute
-import com.machankura.bennu.compose.ui.composable.navigation.routes.ImplementationPendingRoute
-import com.machankura.bennu.compose.ui.composable.navigation.routes.Route
-import com.machankura.bennu.compose.ui.composable.widgets.LoadingDataIndicator
-import com.machankura.bennu.compose.ui.theme.BennuTheme
-import com.machankura.bennu.compose.ui.view.model.AddDialectViewModel
-import com.machankura.bennu.compose.ui.view.state.AddDialectUIState
-import com.machankura.bennu.compose.ui.theme.spacing
-import bennu.composeapp.generated.resources.Res
-import org.jetbrains.compose.resources.stringResource
-import bennu.composeapp.generated.resources.add_a_dialect_the_group_can_translate_into
-import bennu.composeapp.generated.resources.add_dialect
-import bennu.composeapp.generated.resources.country
-import bennu.composeapp.generated.resources.dialect_name
-import bennu.composeapp.generated.resources.eg_lesotho
-import bennu.composeapp.generated.resources.eg_sesotho
-import bennu.composeapp.generated.resources.eg_st
-import bennu.composeapp.generated.resources.language
-import bennu.composeapp.generated.resources.propose_dialect
-import androidx.compose.material3.SnackbarHost
-import com.machankura.bennu.compose.ui.composable.widgets.LocalSnackbarHostState
-import com.machankura.bennu.compose.ui.composable.widgets.NavigateBackButton
-import com.machankura.bennu.compose.ui.theme.readableContent
-import com.machankura.bennu.compose.ui.composable.widgets.ScreenStateTransition
-import com.machankura.bennu.compose.ui.composable.widgets.buttons.ExtendedFab
-import com.machankura.bennu.compose.ui.theme.ConformancePreviews
-
-@OptIn(ExperimentalMaterial3ExpressiveApi::class, ExperimentalMaterial3Api::class)
-@Composable
-fun AddDialectScreen(
- activeUserPublicKey: HexKey,
- chatRoomId: String,
- relayHint: String?,
- initialAddDialectUIState: AddDialectUIState = AddDialectUIState.Loading,
- nostrRepository: NostrRepository,
- chatRepository: ChatRepository,
- frostSigningRepository: FrostSigningRepository,
- onNavigateToRouteAndPopUpInclusive: (Route) -> Unit,
- onNavigateToRoute: (Route) -> Unit,
- onNavigateBack: () -> Unit,
-) {
- val addDialectViewModel: AddDialectViewModel = viewModel(
- factory = AddDialectViewModel.factory(
- chatRoomId = chatRoomId,
- relayHint = relayHint,
- initialAddDialectUIState = initialAddDialectUIState,
- nostrRepository = nostrRepository,
- chatRepository = chatRepository,
- activeUserPublicKey = activeUserPublicKey,
- frostSigningRepository = frostSigningRepository
- )
- )
-
- ScreenStateTransition(addDialectViewModel.addDialectUIState) { uiState ->
- when (val addDialectUIState = uiState) {
- is AddDialectUIState.Error -> {
- Column(
- modifier = Modifier.fillMaxWidth(),
- horizontalAlignment = Alignment.CenterHorizontally
- ) {
- Spacer(
- modifier = Modifier.height(MaterialTheme.spacing.space600)
- )
- Text(
- text = addDialectUIState.message,
- )
- }
- }
- is AddDialectUIState.Loaded -> {
- val nameFieldState = rememberTextFieldState()
- val countryFieldState = rememberTextFieldState()
- val languageFieldState = rememberTextFieldState()
-
- // imePadding: this screen has a text field, and without it the software
- // keyboard covers whatever is being typed into.
- Scaffold(
- snackbarHost = { SnackbarHost(LocalSnackbarHostState.current) },
- modifier = Modifier.imePadding(),
- topBar = {
- TopAppBar(
- title = {
- addDialectUIState.localChatRoom.RenderChatRoomTitleText()
- },
- navigationIcon = { NavigateBackButton(onNavigateBack) },
- )
- },
- bottomBar = {
- BottomAppBar(
- actions = {},
- floatingActionButton = {
- ExtendedFab(
- label = stringResource(Res.string.propose_dialect),
- icon = { Icon(Icons.Default.Add, contentDescription = "Propose dialect") },
- enabled = addDialectUIState.canSign,
- onClick = {
- addDialectViewModel.addDialect(
- localChatRoom = addDialectUIState.localChatRoom,
- nameField = nameFieldState,
- countryField = countryFieldState,
- languageField = languageFieldState,
- onSuccess = { sessionId ->
- // Onto the session rather than back to
- // the group. Nothing has been created
- // yet -- the dialect appears when enough
- // members sign -- so landing on the list
- // it is not in would read as a failure.
- onNavigateToRouteAndPopUpInclusive.invoke(
- FrostSigningRoute(
- activeUserPublicKey = activeUserPublicKey,
- chatRoomId = chatRoomId,
- sessionId = sessionId
- )
- )
- },
- onFailure = {
- onNavigateToRoute.invoke(
- ImplementationPendingRoute("Failed dialect")
- )
- }
- )
- }
- )
- }
- )
- }
- ) { innerPadding ->
- Column(
- modifier = Modifier.padding(innerPadding).readableContent().fillMaxSize()
- ) {
- Column(
- modifier = Modifier.fillMaxWidth(),
- verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space125),
- horizontalAlignment = Alignment.CenterHorizontally
- ) {
- Text(stringResource(Res.string.add_a_dialect_the_group_can_translate_into))
-
- if (!addDialectUIState.canSign) {
- Text(
- text = "This group has no shared key, so it cannot sign a " +
- "dialect into existence. Run a shared key ceremony first.",
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.error
- )
- }
-
- OutlinedTextField(
- modifier = Modifier.fillMaxWidth()
- .background(BottomAppBarDefaults.containerColor),
- state = nameFieldState,
- colors = OutlinedTextFieldDefaults.colors(
- focusedBorderColor = Color.Transparent,
- unfocusedBorderColor = Color.Transparent,
- disabledBorderColor = Color.Transparent
- ),
- leadingIcon = {
- Icon(
- Icons.Default.Title,
- contentDescription = "Name of the dialect"
- )
- },
- label = {
- Text(
- text = stringResource(Res.string.dialect_name)
- )
- },
- placeholder = {
- Text(
- text = stringResource(Res.string.eg_sesotho)
- )
- },
- )
-
- OutlinedTextField(
- modifier = Modifier.fillMaxWidth()
- .background(BottomAppBarDefaults.containerColor),
- state = countryFieldState,
- colors = OutlinedTextFieldDefaults.colors(
- focusedBorderColor = Color.Transparent,
- unfocusedBorderColor = Color.Transparent,
- disabledBorderColor = Color.Transparent
- ),
- leadingIcon = {
- Icon(
- Icons.Default.Public,
- contentDescription = "Country of the dialect"
- )
- },
- label = {
- Text(
- text = stringResource(Res.string.country)
- )
- },
- placeholder = {
- Text(
- text = stringResource(Res.string.eg_lesotho)
- )
- },
- )
-
- OutlinedTextField(
- modifier = Modifier.fillMaxWidth()
- .background(BottomAppBarDefaults.containerColor),
- state = languageFieldState,
- colors = OutlinedTextFieldDefaults.colors(
- focusedBorderColor = Color.Transparent,
- unfocusedBorderColor = Color.Transparent,
- disabledBorderColor = Color.Transparent
- ),
- leadingIcon = {
- Icon(
- Icons.Default.Translate,
- contentDescription = "Language of the dialect"
- )
- },
- label = {
- Text(
- text = stringResource(Res.string.language)
- )
- },
- placeholder = {
- Text(
- text = stringResource(Res.string.eg_st)
- )
- },
- )
- }
- }
- }
- }
- AddDialectUIState.Loading -> {
- Column(
- modifier = Modifier.fillMaxWidth().padding(
- MaterialTheme.spacing.space250
- ),
- horizontalAlignment = Alignment.CenterHorizontally,
- verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space250)
- ) {
-
- Spacer(
- modifier = Modifier.weight(1f)
- )
- Text(
- text = stringResource(Res.string.add_dialect),
- style = MaterialTheme.typography.bodyLarge,
- textAlign = TextAlign.Center
- )
-
- LoadingDataIndicator(
- fillScreen = false
- )
-
- Spacer(
- modifier = Modifier.weight(2f)
- )
- }
- }
- }
- }
-
- LaunchedEffect(true) {
- if (initialAddDialectUIState == AddDialectUIState.Loading) {
- addDialectViewModel.initiateAddDialect()
- }
- }
-}
-
-@ConformancePreviews
-@Composable
-private fun AddDialectScreenPreview() {
- BennuTheme {
- Surface(
- modifier = Modifier.fillMaxSize()
- ) {
- AddDialectScreen(
- activeUserPublicKey = "",
- chatRoomId = "publicKey",
- relayHint = null,
- initialAddDialectUIState = AddDialectUIState.Loaded(
- localChatRoom = LocalChatRoom(
- chatRoom = ChatRoom(
- id = "",
- userPublicKey = "",
- subject = "Message title",
- description = "See something. Say somethin",
- initialGiftWrapPayloadId = "sdfaer",
- mlsGroupState = null
- ),
- )
- ),
- nostrRepository = NostrRepository.NO_OP_NOSTR_REPOSITORY,
- chatRepository = ChatRepository.NO_OP_CHAT_REPOSITORY,
- frostSigningRepository = FrostSigningRepository.NO_OP_FROST_SIGNING_REPOSITORY,
- onNavigateToRouteAndPopUpInclusive = {},
- onNavigateToRoute = {},
- onNavigateBack = {},
- )
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/AddTranslationArtifactVersionScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/AddTranslationArtifactVersionScreen.kt
deleted file mode 100644
index b55fac5b..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/AddTranslationArtifactVersionScreen.kt
+++ /dev/null
@@ -1,341 +0,0 @@
-package com.machankura.bennu.compose.ui.composable
-
-import androidx.compose.foundation.layout.Arrangement
-import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.Spacer
-import androidx.compose.foundation.layout.ExperimentalLayoutApi
-import androidx.compose.foundation.layout.FlowRow
-import androidx.compose.foundation.layout.fillMaxSize
-import androidx.compose.foundation.layout.fillMaxWidth
-import androidx.compose.foundation.layout.height
-import androidx.compose.foundation.layout.padding
-import androidx.compose.material.icons.Icons
-import androidx.compose.material.icons.filled.Translate
-import androidx.compose.material3.BottomAppBar
-import androidx.compose.material3.ExperimentalMaterial3Api
-import androidx.compose.material3.FilterChip
-import androidx.compose.material3.Icon
-import androidx.compose.material3.MaterialTheme
-import androidx.compose.material3.Scaffold
-import androidx.compose.material3.Surface
-import androidx.compose.material3.Text
-import androidx.compose.material3.TopAppBar
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.LaunchedEffect
-import androidx.compose.runtime.getValue
-import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.remember
-import androidx.compose.runtime.setValue
-import androidx.compose.ui.Alignment
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.text.style.TextAlign
-import androidx.compose.ui.unit.dp
-import androidx.lifecycle.viewmodel.compose.viewModel
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.machankura.bennu.compose.database.model.ChatRoom
-import com.machankura.bennu.compose.database.model.MantraArtifact
-import com.machankura.bennu.compose.database.model.MantraArtifactVersion
-import com.machankura.bennu.compose.database.model.MantraDialect
-import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
-import com.machankura.bennu.compose.managers.FrostSigningManager
-import com.machankura.bennu.compose.repository.ChatRepository
-import com.machankura.bennu.compose.repository.FrostSigningRepository
-import com.machankura.bennu.compose.repository.MantraRepository
-import com.machankura.bennu.compose.ui.composable.navigation.routes.FrostSigningRoute
-import com.machankura.bennu.compose.ui.composable.navigation.routes.ImplementationPendingRoute
-import com.machankura.bennu.compose.ui.composable.navigation.routes.Route
-import com.machankura.bennu.compose.ui.composable.widgets.LoadingDataIndicator
-import com.machankura.bennu.compose.ui.theme.BennuTheme
-import com.machankura.bennu.compose.ui.view.model.AddTranslationArtifactVersionViewModel
-import com.machankura.bennu.compose.ui.view.state.AddTranslationArtifactVersionUIState
-import com.machankura.bennu.compose.ui.theme.spacing
-import bennu.composeapp.generated.resources.Res
-import org.jetbrains.compose.resources.stringResource
-import bennu.composeapp.generated.resources.add_translation
-import bennu.composeapp.generated.resources.propose_translation
-import bennu.composeapp.generated.resources.this_artifact_has_no_version_for_a
-import bennu.composeapp.generated.resources.translate_into_which_dialect
-import bennu.composeapp.generated.resources.translate
-import androidx.compose.material3.SnackbarHost
-import com.machankura.bennu.compose.ui.composable.widgets.LocalSnackbarHostState
-import com.machankura.bennu.compose.ui.theme.readableContent
-import com.machankura.bennu.compose.ui.composable.widgets.ScreenStateTransition
-import com.machankura.bennu.compose.ui.composable.widgets.NavigateBackButton
-import com.machankura.bennu.compose.ui.composable.widgets.buttons.ExtendedFab
-import com.machankura.bennu.compose.ui.theme.ConformancePreviews
-
-@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class)
-@Composable
-fun AddTranslationArtifactVersionScreen(
- activeUserPublicKey: HexKey,
- artifactId: String,
- chatRoomId: String,
- relayHint: String?,
- initialAddTranslationArtifactVersionUIState: AddTranslationArtifactVersionUIState = AddTranslationArtifactVersionUIState.Loading,
- mantraRepository: MantraRepository,
- chatRepository: ChatRepository,
- frostSigningRepository: FrostSigningRepository,
- onNavigateToRouteAndPopUpInclusive: (Route) -> Unit,
- onNavigateToRoute: (Route) -> Unit,
- onNavigateBack: () -> Unit,
-) {
- val addTranslationArtifactVersionViewModel: AddTranslationArtifactVersionViewModel = viewModel(
- factory = AddTranslationArtifactVersionViewModel.factory(
- activeUserPublicKey = activeUserPublicKey,
- artifactId = artifactId,
- chatRoomId = chatRoomId,
- relayHint = relayHint,
- initialAddTranslationArtifactVersionUIState = initialAddTranslationArtifactVersionUIState,
- mantraRepository = mantraRepository,
- chatRepository = chatRepository,
- frostSigningRepository = frostSigningRepository,
- )
- )
-
- ScreenStateTransition(addTranslationArtifactVersionViewModel.addTranslationArtifactVersionUIState) { uiState ->
- when (val addTranslationUIState = uiState) {
- is AddTranslationArtifactVersionUIState.Error -> {
- Column(
- modifier = Modifier.fillMaxWidth(),
- horizontalAlignment = Alignment.CenterHorizontally
- ) {
- Spacer(modifier = Modifier.height(MaterialTheme.spacing.space600))
- Text(text = addTranslationUIState.message)
- }
- }
-
- is AddTranslationArtifactVersionUIState.Loaded -> {
- // A translation is into a dialect the group already signed into
- // existence. Nothing is chosen to begin with: picking the first one
- // for somebody would be choosing the language of the work.
- var selectedDialectId: String? by remember { mutableStateOf(null) }
- val selectedDialect = addTranslationUIState.dialects
- .firstOrNull { dialect -> dialect.id == selectedDialectId }
-
- // A translation hangs off a version, and the group has to be able to
- // sign; without both there is nothing this screen can propose.
- val artifactVersion = addTranslationUIState.artifactVersion
- val chapterCount = addTranslationUIState.chapters.size
-
- // The translation and a chapter apiece are signed together, and a
- // session signs a bounded number of events -- so a long artifact is
- // proposed in more than one, and the admins answer once per
- // session. That is a number worth seeing before the tap.
- val sessionCount = 1 + (
- (chapterCount - AddTranslationArtifactVersionViewModel.MAX_CHAPTERS_PER_TRANSLATION)
- .coerceAtLeast(0) + FrostSigningManager.MAX_BATCH_SIZE - 1
- ) / FrostSigningManager.MAX_BATCH_SIZE
-
- val canProposeTranslation = artifactVersion != null &&
- selectedDialect != null &&
- addTranslationUIState.canSign
-
- Scaffold(
- snackbarHost = { SnackbarHost(LocalSnackbarHostState.current) },
- topBar = {
- TopAppBar(
- title = { Text(stringResource(Res.string.translate, addTranslationUIState.artifact.name)) },
- navigationIcon = { NavigateBackButton(onNavigateBack) },
- )
- },
- bottomBar = {
- BottomAppBar(
- actions = {},
- floatingActionButton = {
- ExtendedFab(
- label = stringResource(Res.string.propose_translation),
- icon = { Icon(Icons.Default.Translate, contentDescription = "Propose translation") },
- enabled = canProposeTranslation,
- onClick = {
- if (artifactVersion == null || selectedDialect == null) return@ExtendedFab
-
- addTranslationArtifactVersionViewModel.addTranslation(
- localChatRoom = addTranslationUIState.localChatRoom,
- artifact = addTranslationUIState.artifact,
- artifactVersion = artifactVersion,
- dialect = selectedDialect,
- chapters = addTranslationUIState.chapters,
- onSuccess = { sessionId ->
- // Onto the session rather than back to
- // the artifact. Nothing has been created
- // yet -- the translation appears when
- // enough members sign -- so landing on
- // the list it is not in would read as a
- // failure.
- onNavigateToRouteAndPopUpInclusive.invoke(
- FrostSigningRoute(
- activeUserPublicKey = activeUserPublicKey,
- chatRoomId = chatRoomId,
- sessionId = sessionId
- )
- )
- },
- onFailure = {
- onNavigateToRoute.invoke(
- ImplementationPendingRoute("Failed translation")
- )
- }
- )
- }
- )
- }
- )
- }
- ) { innerPadding ->
- Column(
- modifier = Modifier.padding(innerPadding).readableContent().fillMaxSize().padding(MaterialTheme.spacing.space250),
- verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space125)
- ) {
- if (!addTranslationUIState.canSign) {
- Text(
- text = "This group has no shared key, so it cannot sign a " +
- "translation into existence. Run a shared key ceremony first.",
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.error
- )
- } else if (artifactVersion == null) {
- Text(
- text = stringResource(Res.string.this_artifact_has_no_version_for_a),
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.error
- )
- }
-
- Text(stringResource(Res.string.translate_into_which_dialect))
-
- if (addTranslationUIState.dialects.isEmpty()) {
- // The only way out of this screen, and it is not on it:
- // a dialect is the group's too, and asking for one is
- // its own quorum from the room's own detail screen.
- Text(
- text = "This group has no dialects yet. Add one from the group's " +
- "details before translating anything into it.",
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.error
- )
- }
-
- FlowRow(
- modifier = Modifier.fillMaxWidth(),
- horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.itemGap)
- ) {
- addTranslationUIState.dialects.forEach { dialect ->
- FilterChip(
- selected = selectedDialectId == dialect.id,
- onClick = { selectedDialectId = dialect.id },
- label = { Text(dialect.name) }
- )
- }
- }
-
- Text(
- // What the group is being asked to sign, counted before
- // the tap rather than described after it: the chapters
- // are the rest of the batch. The empty case is worth
- // its own sentence, so that a translation of an artifact
- // nobody has written into yet does not read as broken.
- text = if (chapterCount == 0) {
- "The artifact has no chapters yet, so the group would sign the " +
- "translation on its own. Chapters signed afterwards are put " +
- "into it as they are added."
- } else {
- "The group signs the translation and " +
- "$chapterCount ${if (chapterCount == 1) "chapter" else "chapters"}" +
- (if (sessionCount == 1) "" else ", in $sessionCount sessions to sign") +
- ". Chunks are translated one at a time afterwards."
- },
- style = MaterialTheme.typography.labelMedium,
- )
- }
- }
- }
-
- AddTranslationArtifactVersionUIState.Loading -> {
- Column(
- modifier = Modifier.fillMaxWidth().padding(MaterialTheme.spacing.space250),
- horizontalAlignment = Alignment.CenterHorizontally,
- verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space250)
- ) {
- Spacer(modifier = Modifier.weight(1f))
- Text(
- text = stringResource(Res.string.add_translation),
- style = MaterialTheme.typography.bodyLarge,
- textAlign = TextAlign.Center
- )
- LoadingDataIndicator(fillScreen = false)
- Spacer(modifier = Modifier.weight(2f))
- }
- }
- }
- }
-
- LaunchedEffect(true) {
- if (initialAddTranslationArtifactVersionUIState == AddTranslationArtifactVersionUIState.Loading) {
- addTranslationArtifactVersionViewModel.initiateAddTranslation()
- }
- }
-}
-
-@ConformancePreviews
-@Composable
-private fun AddTranslationArtifactVersionScreenPreview() {
- BennuTheme {
- Surface(modifier = Modifier.fillMaxSize()) {
- AddTranslationArtifactVersionScreen(
- activeUserPublicKey = "",
- artifactId = "artifactId",
- chatRoomId = "chatRoomId",
- relayHint = null,
- initialAddTranslationArtifactVersionUIState = AddTranslationArtifactVersionUIState.Loaded(
- localChatRoom = LocalChatRoom(
- chatRoom = ChatRoom(
- id = "",
- userPublicKey = "",
- subject = "Message title",
- description = "See something. Say somethin",
- initialGiftWrapPayloadId = "sdfaer",
- mlsGroupState = null
- ),
- ),
- artifact = MantraArtifact(
- id = "artifactId",
- publicKey = "author",
- name = "To Kill a Mockingbird",
- url = "https://harper.com/2-kill-Bird",
- visibility = "private",
- dialectId = "dialectId",
- license = "cc",
- chatRoomId = "chatRoomId",
- signature = ""
- ),
- dialects = listOf(
- MantraDialect(
- id = "dialectId",
- publicKey = "author",
- name = "Sesotho",
- country = "Lesotho",
- language = "st",
- chatRoomId = "chatRoomId",
- signature = ""
- )
- ),
- artifactVersion = MantraArtifactVersion(
- id = "artifactVersionId",
- artifactId = "artifactId",
- publicKey = "author",
- versionLabel = "1.0",
- chatRoomId = "chatRoomId",
- signature = ""
- ),
- canSign = true,
- ),
- mantraRepository = MantraRepository.NO_OP_MANTRA_REPOSITORY,
- chatRepository = ChatRepository.NO_OP_CHAT_REPOSITORY,
- frostSigningRepository = FrostSigningRepository.NO_OP_FROST_SIGNING_REPOSITORY,
- onNavigateToRouteAndPopUpInclusive = {},
- onNavigateToRoute = {},
- onNavigateBack = {}
- )
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/ArtifactDetailScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/ArtifactDetailScreen.kt
deleted file mode 100644
index ce39a59a..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/ArtifactDetailScreen.kt
+++ /dev/null
@@ -1,354 +0,0 @@
-package com.machankura.bennu.compose.ui.composable
-
-import androidx.compose.foundation.layout.Arrangement
-import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.Spacer
-import androidx.compose.foundation.layout.fillMaxSize
-import androidx.compose.foundation.layout.fillMaxWidth
-import androidx.compose.foundation.layout.height
-import androidx.compose.foundation.layout.padding
-import androidx.compose.foundation.lazy.LazyColumn
-import androidx.compose.foundation.lazy.items
-import androidx.compose.foundation.layout.width
-import androidx.compose.material.icons.Icons
-import androidx.compose.material.icons.filled.Article
-import androidx.compose.material.icons.filled.PostAdd
-import androidx.compose.material.icons.filled.Translate
-import androidx.compose.material3.Card
-import androidx.compose.material3.ExperimentalMaterial3Api
-import androidx.compose.material3.HorizontalDivider
-import androidx.compose.material3.Icon
-import androidx.compose.material3.ListItem
-import androidx.compose.material3.MaterialTheme
-import androidx.compose.material3.Scaffold
-import androidx.compose.material3.Surface
-import androidx.compose.material3.Text
-import androidx.compose.material3.TextButton
-import androidx.compose.material3.TopAppBar
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.LaunchedEffect
-import androidx.compose.ui.Alignment
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.text.style.TextAlign
-import androidx.compose.ui.unit.dp
-import androidx.lifecycle.viewmodel.compose.viewModel
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.machankura.bennu.compose.database.model.MantraArtifact
-import com.machankura.bennu.compose.repository.MantraRepository
-import com.machankura.bennu.compose.ui.composable.widgets.DetailRow
-import com.machankura.bennu.compose.ui.composable.navigation.routes.AddChapterRoute
-import com.machankura.bennu.compose.ui.composable.navigation.routes.AddTranslationRoute
-import com.machankura.bennu.compose.ui.composable.navigation.routes.ChapterDetailRoute
-import com.machankura.bennu.compose.ui.composable.navigation.routes.Route
-import com.machankura.bennu.compose.ui.composable.navigation.routes.TranslationArtifactVersionDetailRoute
-import com.machankura.bennu.compose.ui.composable.widgets.LoadingDataIndicator
-import com.machankura.bennu.compose.ui.theme.BennuTheme
-import com.machankura.bennu.compose.ui.view.model.ArtifactDetailViewModel
-import com.machankura.bennu.compose.ui.view.state.ArtifactDetailUIState
-import com.machankura.bennu.compose.ui.theme.spacing
-import bennu.composeapp.generated.resources.Res
-import org.jetbrains.compose.resources.stringResource
-import bennu.composeapp.generated.resources.add_chapter
-import bennu.composeapp.generated.resources.add_translation
-import bennu.composeapp.generated.resources.artifact_detail
-import bennu.composeapp.generated.resources.chapters
-import bennu.composeapp.generated.resources.details
-import bennu.composeapp.generated.resources.no_chapters_yet
-import bennu.composeapp.generated.resources.no_translations_yet
-import bennu.composeapp.generated.resources.no_versions
-import bennu.composeapp.generated.resources.translations
-import bennu.composeapp.generated.resources.version
-import bennu.composeapp.generated.resources.versions
-import bennu.composeapp.generated.resources.chapter
-import bennu.composeapp.generated.resources.words_characters
-import androidx.compose.material3.SnackbarHost
-import com.machankura.bennu.compose.ui.composable.widgets.LocalSnackbarHostState
-import com.machankura.bennu.compose.ui.theme.readableContent
-import com.machankura.bennu.compose.ui.composable.widgets.ScreenStateTransition
-import com.machankura.bennu.compose.ui.composable.widgets.NavigateBackButton
-import com.machankura.bennu.compose.ui.theme.ConformancePreviews
-
-@OptIn(ExperimentalMaterial3Api::class)
-@Composable
-fun ArtifactDetailScreen(
- activeUserPublicKey: HexKey,
- artifactId: String,
- chatRoomId: String,
- relayHint: String?,
- initialArtifactDetailUIState: ArtifactDetailUIState = ArtifactDetailUIState.Loading,
- mantraRepository: MantraRepository,
- onNavigateToRoute: (Route) -> Unit,
- onNavigateBack: () -> Unit,
-) {
- val artifactDetailViewModel: ArtifactDetailViewModel = viewModel(
- factory = ArtifactDetailViewModel.factory(
- activeUserPublicKey = activeUserPublicKey,
- artifactId = artifactId,
- chatRoomId = chatRoomId,
- relayHint = relayHint,
- initialArtifactDetailUIState = initialArtifactDetailUIState,
- mantraRepository = mantraRepository,
- )
- )
-
- ScreenStateTransition(artifactDetailViewModel.artifactDetailUIState) { uiState ->
- when (val artifactDetailUIState = uiState) {
- is ArtifactDetailUIState.Error -> {
- Column(
- modifier = Modifier.fillMaxWidth(),
- horizontalAlignment = Alignment.CenterHorizontally
- ) {
- Spacer(modifier = Modifier.height(MaterialTheme.spacing.space600))
- Text(text = artifactDetailUIState.message)
- }
- }
-
- is ArtifactDetailUIState.Loaded -> {
- val artifact = artifactDetailUIState.artifact
- Scaffold(
- snackbarHost = { SnackbarHost(LocalSnackbarHostState.current) },
- topBar = {
- TopAppBar(
- title = { Text(artifact.name) },
- navigationIcon = { NavigateBackButton(onNavigateBack) },
- )
- }
- ) { innerPadding ->
- LazyColumn(
- modifier = Modifier.padding(innerPadding).readableContent().fillMaxSize().padding(MaterialTheme.spacing.space250),
- verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space125)
- ) {
- // Chapters
- item {
- Text(
- text = stringResource(Res.string.chapters),
- style = MaterialTheme.typography.labelMedium
- )
- }
- if (artifactDetailUIState.chapters.isEmpty()) {
- item { Text(stringResource(Res.string.no_chapters_yet)) }
- } else {
- items(
- items = artifactDetailUIState.chapters,
- key = { chapter -> chapter.id }
- ) { chapter ->
- Card(
- onClick = {
- onNavigateToRoute.invoke(
- ChapterDetailRoute(
- activeUserPublicKey = activeUserPublicKey,
- chapterId = chapter.id,
- chatRoomId = chatRoomId,
- relayHint = relayHint
- )
- )
- }
- ) {
- ListItem(
- leadingContent = {
- Icon(
- Icons.Default.Article,
- contentDescription = "Chapter"
- )
- },
- overlineContent = { Text(stringResource(Res.string.chapter, chapter.index)) },
- headlineContent = { Text(chapter.name) },
- supportingContent = {
- Text(stringResource(Res.string.words_characters, chapter.wordCount, chapter.characterCount))
- }
- )
- }
- }
- }
-
- item {
- TextButton(
- enabled = artifactDetailUIState.versions.isNotEmpty(),
- onClick = {
- onNavigateToRoute.invoke(
- AddChapterRoute(
- activeUserPublicKey = activeUserPublicKey,
- artifactId = artifact.id,
- chatRoomId = chatRoomId,
- relayHint = relayHint
- )
- )
- }
- ) {
- Icon(
- Icons.Default.PostAdd,
- contentDescription = "Add chapter"
- )
- Spacer(modifier = Modifier.width(MaterialTheme.spacing.space125))
- Text(stringResource(Res.string.add_chapter))
- }
- }
-
- item { HorizontalDivider() }
-
- // Translations
- item {
- Text(
- text = stringResource(Res.string.translations),
- style = MaterialTheme.typography.labelMedium
- )
- }
- if (artifactDetailUIState.translations.isEmpty()) {
- item { Text(stringResource(Res.string.no_translations_yet)) }
- } else {
- items(
- items = artifactDetailUIState.translations,
- key = { translation -> translation.id }
- ) { translation ->
- Card(
- onClick = {
- onNavigateToRoute.invoke(
- TranslationArtifactVersionDetailRoute(
- activeUserPublicKey = activeUserPublicKey,
- translationArtifactVersionId = translation.id,
- chatRoomId = chatRoomId,
- relayHint = relayHint
- )
- )
- }
- ) {
- ListItem(
- leadingContent = {
- Icon(
- Icons.Default.Translate,
- contentDescription = "Translation"
- )
- },
- headlineContent = { Text(translation.name) },
- supportingContent = { Text(translation.visibility) }
- )
- }
- }
- }
-
- item {
- TextButton(
- enabled = artifactDetailUIState.versions.isNotEmpty(),
- onClick = {
- onNavigateToRoute.invoke(
- AddTranslationRoute(
- activeUserPublicKey = activeUserPublicKey,
- artifactId = artifact.id,
- chatRoomId = chatRoomId,
- relayHint = relayHint
- )
- )
- }
- ) {
- Icon(
- Icons.Default.Translate,
- contentDescription = "Add translation"
- )
- Spacer(modifier = Modifier.width(MaterialTheme.spacing.space125))
- Text(stringResource(Res.string.add_translation))
- }
- }
-
- item { HorizontalDivider() }
-
- // Details
- item {
- Text(
- text = stringResource(Res.string.details),
- style = MaterialTheme.typography.labelMedium
- )
- }
- item {
- Card {
- DetailRow(label = "Name", value = artifact.name)
- DetailRow(label = "Url", value = artifact.url)
- DetailRow(label = "Visibility", value = artifact.visibility)
- DetailRow(label = "License", value = artifact.license)
- DetailRow(label = "Dialect", value = artifact.dialectId)
- DetailRow(label = "Author", value = artifact.publicKey)
- DetailRow(label = "Created", value = artifact.createdAt.toString())
- }
- }
-
- // Versions
- item {
- Text(
- text = stringResource(Res.string.versions),
- style = MaterialTheme.typography.labelMedium
- )
- }
- if (artifactDetailUIState.versions.isEmpty()) {
- item { Text(stringResource(Res.string.no_versions)) }
- } else {
- items(
- items = artifactDetailUIState.versions,
- key = { version -> version.id }
- ) { version ->
- Card {
- ListItem(
- headlineContent = { Text(version.versionLabel) },
- overlineContent = { Text(stringResource(Res.string.version)) }
- )
- }
- }
- }
- }
- }
- }
-
- ArtifactDetailUIState.Loading -> {
- Column(
- modifier = Modifier.fillMaxWidth().padding(MaterialTheme.spacing.space250),
- horizontalAlignment = Alignment.CenterHorizontally,
- verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space250)
- ) {
- Spacer(modifier = Modifier.weight(1f))
- Text(
- text = stringResource(Res.string.artifact_detail),
- style = MaterialTheme.typography.bodyLarge,
- textAlign = TextAlign.Center
- )
- LoadingDataIndicator(fillScreen = false)
- Spacer(modifier = Modifier.weight(2f))
- }
- }
- }
- }
-
- LaunchedEffect(true) {
- if (initialArtifactDetailUIState == ArtifactDetailUIState.Loading) {
- artifactDetailViewModel.initiateArtifactDetail()
- }
- }
-}
-
-@ConformancePreviews
-@Composable
-private fun ArtifactDetailScreenPreview() {
- BennuTheme {
- Surface(modifier = Modifier.fillMaxSize()) {
- ArtifactDetailScreen(
- activeUserPublicKey = "",
- artifactId = "artifactId",
- chatRoomId = "chatRoomId",
- relayHint = null,
- initialArtifactDetailUIState = ArtifactDetailUIState.Loaded(
- artifact = MantraArtifact(
- id = "artifactId",
- publicKey = "author",
- name = "To Kill a Mockingbird",
- url = "https://harper.com/2-kill-Bird",
- visibility = "private",
- dialectId = "dialectId",
- license = "cc",
- chatRoomId = "chatRoomId",
- signature = ""
- )
- ),
- mantraRepository = MantraRepository.NO_OP_MANTRA_REPOSITORY,
- onNavigateToRoute = {},
- onNavigateBack = {}
- )
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/ChapterDetailScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/ChapterDetailScreen.kt
deleted file mode 100644
index cdb12652..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/ChapterDetailScreen.kt
+++ /dev/null
@@ -1,220 +0,0 @@
-package com.machankura.bennu.compose.ui.composable
-
-import androidx.compose.foundation.layout.Arrangement
-import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.Spacer
-import androidx.compose.foundation.layout.fillMaxSize
-import androidx.compose.foundation.layout.fillMaxWidth
-import androidx.compose.foundation.layout.height
-import androidx.compose.foundation.layout.padding
-import androidx.compose.foundation.lazy.LazyColumn
-import androidx.compose.foundation.lazy.items
-import androidx.compose.material.icons.Icons
-import androidx.compose.material.icons.filled.Segment
-import androidx.compose.material3.Card
-import androidx.compose.material3.ExperimentalMaterial3Api
-import androidx.compose.material3.HorizontalDivider
-import androidx.compose.material3.Icon
-import androidx.compose.material3.ListItem
-import androidx.compose.material3.MaterialTheme
-import androidx.compose.material3.Scaffold
-import androidx.compose.material3.Surface
-import androidx.compose.material3.Text
-import androidx.compose.material3.TopAppBar
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.LaunchedEffect
-import androidx.compose.ui.Alignment
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.text.style.TextAlign
-import androidx.compose.ui.unit.dp
-import androidx.lifecycle.viewmodel.compose.viewModel
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.machankura.bennu.compose.database.model.MantraChapter
-import com.machankura.bennu.compose.repository.MantraRepository
-import com.machankura.bennu.compose.ui.composable.widgets.LoadingDataIndicator
-import com.machankura.bennu.compose.ui.theme.BennuTheme
-import com.machankura.bennu.compose.ui.view.model.ChapterDetailViewModel
-import com.machankura.bennu.compose.ui.view.state.ChapterDetailUIState
-import com.machankura.bennu.compose.ui.theme.spacing
-import bennu.composeapp.generated.resources.Res
-import org.jetbrains.compose.resources.stringResource
-import bennu.composeapp.generated.resources.chapter_detail
-import bennu.composeapp.generated.resources.no_chunks
-import bennu.composeapp.generated.resources.original_text
-import bennu.composeapp.generated.resources.chapter_words_characters
-import bennu.composeapp.generated.resources.chunk
-import bennu.composeapp.generated.resources.chunks
-import bennu.composeapp.generated.resources.words_characters
-import androidx.compose.material3.SnackbarHost
-import com.machankura.bennu.compose.ui.composable.widgets.LocalSnackbarHostState
-import com.machankura.bennu.compose.ui.theme.readableContent
-import com.machankura.bennu.compose.ui.composable.widgets.ScreenStateTransition
-import com.machankura.bennu.compose.ui.composable.widgets.NavigateBackButton
-import com.machankura.bennu.compose.ui.theme.ConformancePreviews
-
-@OptIn(ExperimentalMaterial3Api::class)
-@Composable
-fun ChapterDetailScreen(
- activeUserPublicKey: HexKey,
- chapterId: String,
- chatRoomId: String,
- relayHint: String?,
- initialChapterDetailUIState: ChapterDetailUIState = ChapterDetailUIState.Loading,
- mantraRepository: MantraRepository,
- onNavigateBack: () -> Unit,
-) {
- val chapterDetailViewModel: ChapterDetailViewModel = viewModel(
- factory = ChapterDetailViewModel.factory(
- activeUserPublicKey = activeUserPublicKey,
- chapterId = chapterId,
- chatRoomId = chatRoomId,
- relayHint = relayHint,
- initialChapterDetailUIState = initialChapterDetailUIState,
- mantraRepository = mantraRepository,
- )
- )
-
- ScreenStateTransition(chapterDetailViewModel.chapterDetailUIState) { uiState ->
- when (val chapterDetailUIState = uiState) {
- is ChapterDetailUIState.Error -> {
- Column(
- modifier = Modifier.fillMaxWidth(),
- horizontalAlignment = Alignment.CenterHorizontally
- ) {
- Spacer(modifier = Modifier.height(MaterialTheme.spacing.space600))
- Text(text = chapterDetailUIState.message)
- }
- }
-
- is ChapterDetailUIState.Loaded -> {
- val chapter = chapterDetailUIState.chapter
- Scaffold(
- snackbarHost = { SnackbarHost(LocalSnackbarHostState.current) },
- topBar = {
- TopAppBar(
- title = { Text(chapter.name) },
- navigationIcon = { NavigateBackButton(onNavigateBack) },
- )
- }
- ) { innerPadding ->
- LazyColumn(
- modifier = Modifier.padding(innerPadding).readableContent().fillMaxSize().padding(MaterialTheme.spacing.space250),
- verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space125)
- ) {
- item {
- Text(
- text = stringResource(Res.string.chapter_words_characters, chapter.index, chapter.wordCount, chapter.characterCount),
- style = MaterialTheme.typography.labelMedium
- )
- }
-
- // Original text (markdown, shown as-is).
- item {
- Text(
- text = stringResource(Res.string.original_text),
- style = MaterialTheme.typography.labelMedium
- )
- }
- item {
- Card {
- Text(
- modifier = Modifier.padding(MaterialTheme.spacing.containerPadding),
- text = chapter.originalText,
- style = MaterialTheme.typography.bodyMedium
- )
- }
- }
-
- item { HorizontalDivider() }
-
- // Chunks
- item {
- Text(
- text = stringResource(Res.string.chunks, chapterDetailUIState.chunks.size),
- style = MaterialTheme.typography.labelMedium
- )
- }
- if (chapterDetailUIState.chunks.isEmpty()) {
- item { Text(stringResource(Res.string.no_chunks)) }
- } else {
- items(
- items = chapterDetailUIState.chunks,
- key = { chunk -> chunk.id }
- ) { chunk ->
- Card {
- ListItem(
- leadingContent = {
- Icon(
- Icons.Default.Segment,
- contentDescription = "Chunk"
- )
- },
- overlineContent = { Text(stringResource(Res.string.chunk, chunk.index)) },
- headlineContent = { Text(chunk.text) },
- supportingContent = {
- Text(stringResource(Res.string.words_characters, chunk.wordCount, chunk.characterCount))
- }
- )
- }
- }
- }
- }
- }
- }
-
- ChapterDetailUIState.Loading -> {
- Column(
- modifier = Modifier.fillMaxWidth().padding(MaterialTheme.spacing.space250),
- horizontalAlignment = Alignment.CenterHorizontally,
- verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space250)
- ) {
- Spacer(modifier = Modifier.weight(1f))
- Text(
- text = stringResource(Res.string.chapter_detail),
- style = MaterialTheme.typography.bodyLarge,
- textAlign = TextAlign.Center
- )
- LoadingDataIndicator(fillScreen = false)
- Spacer(modifier = Modifier.weight(2f))
- }
- }
- }
- }
-
- LaunchedEffect(true) {
- if (initialChapterDetailUIState == ChapterDetailUIState.Loading) {
- chapterDetailViewModel.initiateChapterDetail()
- }
- }
-}
-
-@ConformancePreviews
-@Composable
-private fun ChapterDetailScreenPreview() {
- BennuTheme {
- Surface(modifier = Modifier.fillMaxSize()) {
- ChapterDetailScreen(
- activeUserPublicKey = "",
- chapterId = "chapterId",
- chatRoomId = "chatRoomId",
- relayHint = null,
- initialChapterDetailUIState = ChapterDetailUIState.Loaded(
- chapter = MantraChapter(
- id = "chapterId",
- artifactVersionId = "versionId",
- publicKey = "author",
- name = "Chapter 1 — The Beginning",
- originalText = "When he was nearly thirteen...\n\nWhen enough years had gone by...",
- index = 0,
- wordCount = 12,
- characterCount = 64,
- signature = "",
- chatRoomId = "chatRoomId"
- )
- ),
- mantraRepository = MantraRepository.NO_OP_MANTRA_REPOSITORY,
- onNavigateBack = {}
- )
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/ChatRoomDetailScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/ChatRoomDetailScreen.kt
index a2ef8fdf..b01ee84b 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/ChatRoomDetailScreen.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/ChatRoomDetailScreen.kt
@@ -76,11 +76,10 @@ import com.machankura.bennu.compose.database.model.Profile
import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
import com.machankura.bennu.compose.database.model.intermdiate.LocalParticipant
import com.machankura.bennu.compose.repository.ChatRepository
-import com.machankura.bennu.compose.repository.MantraRepository
import com.machankura.bennu.compose.repository.NostrRepository
import com.machankura.bennu.compose.ui.composable.navigation.routes.ProfilePreviewRoute
import com.machankura.bennu.compose.ui.composable.navigation.routes.Route
-import com.machankura.bennu.compose.ui.composable.navigation.routes.DkgRitualRoute
+import com.machankura.bennu.compose.ui.composable.navigation.routes.CreateSharedKeyRoute
import com.machankura.bennu.compose.ui.composable.navigation.routes.ProposeGroupEventRoute
import com.machankura.bennu.compose.ui.composable.navigation.routes.GroupNostrProfileRoute
import com.machankura.bennu.compose.ui.composable.navigation.routes.GroupRelaysRoute
@@ -172,7 +171,6 @@ fun ChatRoomDetailScreen(
initialChatRoomDetailUIState: ChatRoomDetailUIState = ChatRoomDetailUIState.Loading,
nostrRepository: NostrRepository,
chatRepository: ChatRepository,
- mantraRepository: MantraRepository,
onNavigateToRoute: (Route) -> Unit,
onPopBackToRoute: (Route) -> Unit,
onNavigateBack: () -> Unit,
@@ -184,7 +182,6 @@ fun ChatRoomDetailScreen(
initialChatRoomDetailUIState = initialChatRoomDetailUIState,
nostrRepository = nostrRepository,
chatRepository = chatRepository,
- mantraRepository = mantraRepository,
activeUserPublicKey = activeUserPublicKey
)
)
@@ -619,12 +616,17 @@ fun ChatRoomDetailScreen(
// -- and those are reached from the transcript line that
// names the ceremony they are about, never from here,
// which has no way to say which.
+ //
+ // To the creation screen, which hands over to the group's
+ // ceremony if it already has one: the ceremony screen only
+ // shows a ceremony it is named, and this button has none
+ // to name. See docs/ceremony-creation.md.
if (chatRoomDetailUIState.localChatRoom.chatRoom.mlsGroupState == null) {
item {
TextButton(
onClick = {
onNavigateToRoute.invoke(
- DkgRitualRoute(
+ CreateSharedKeyRoute(
activeUserPublicKey = activeUserPublicKey,
chatRoomId = chatRoomId
)
@@ -1418,7 +1420,6 @@ private fun ChatRoomMessagingScreenPreview() {
),
nostrRepository = NostrRepository.NO_OP_NOSTR_REPOSITORY,
chatRepository = ChatRepository.NO_OP_CHAT_REPOSITORY,
- mantraRepository = MantraRepository.NO_OP_MANTRA_REPOSITORY,
onNavigateToRoute = {},
onPopBackToRoute = {},
onNavigateBack = {},
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/CreateSharedKeyScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/CreateSharedKeyScreen.kt
new file mode 100644
index 00000000..bd6fd170
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/CreateSharedKeyScreen.kt
@@ -0,0 +1,306 @@
+package com.machankura.bennu.compose.ui.composable
+
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.verticalScroll
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.Add
+import androidx.compose.material.icons.filled.Key
+import androidx.compose.material.icons.filled.Remove
+import androidx.compose.material3.Button
+import androidx.compose.material3.CircularProgressIndicator
+import androidx.compose.material3.ExperimentalMaterial3Api
+import androidx.compose.material3.FilledIconButton
+import androidx.compose.material3.Icon
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Scaffold
+import androidx.compose.material3.SnackbarHost
+import androidx.compose.material3.Surface
+import androidx.compose.material3.Text
+import androidx.compose.material3.TopAppBar
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.text.style.TextOverflow
+import androidx.compose.ui.unit.dp
+import androidx.lifecycle.viewmodel.compose.viewModel
+import bennu.composeapp.generated.resources.Res
+import bennu.composeapp.generated.resources.a_shared_key_needs_at_least_members
+import bennu.composeapp.generated.resources.couldn_t_load_this_group
+import bennu.composeapp.generated.resources.couldn_t_read_your_keys
+import bennu.composeapp.generated.resources.couldn_t_start_the_key_ceremony
+import bennu.composeapp.generated.resources.everyone_has_to_be_online_at_the_same_time
+import bennu.composeapp.generated.resources.how_many_members_will_it_take_to_sign
+import bennu.composeapp.generated.resources.of
+import bennu.composeapp.generated.resources.shared_key
+import bennu.composeapp.generated.resources.shared_key_for
+import bennu.composeapp.generated.resources.start_key_ceremony
+import bennu.composeapp.generated.resources.the_group_can_hold_one_key_together_split_so
+import bennu.composeapp.generated.resources.this_is_fixed_once_the_ceremony_runs
+import bennu.composeapp.generated.resources.this_room_was_made_from_a_key_the_group_already_holds
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.StateFlow
+import org.jetbrains.compose.resources.stringResource
+import com.machankura.bennu.compose.database.model.ChatRoom
+import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
+import com.machankura.bennu.compose.identity.Identity
+import com.machankura.bennu.compose.managers.ChillDkgRitualManager
+import com.machankura.bennu.compose.repository.ChatRepository
+import com.machankura.bennu.compose.repository.DkgRepository
+import com.machankura.bennu.compose.ui.composable.widgets.Decorative
+import com.machankura.bennu.compose.ui.composable.widgets.EmptyState
+import com.machankura.bennu.compose.ui.composable.widgets.ErrorState
+import com.machankura.bennu.compose.ui.composable.widgets.LoadingDataIndicator
+import com.machankura.bennu.compose.ui.composable.widgets.LocalSnackbarHostState
+import com.machankura.bennu.compose.ui.composable.widgets.NavigateBackButton
+import com.machankura.bennu.compose.ui.composable.widgets.ScreenStateTransition
+import com.machankura.bennu.compose.ui.theme.BennuTheme
+import com.machankura.bennu.compose.ui.theme.ConformancePreviews
+import com.machankura.bennu.compose.ui.theme.readableContent
+import com.machankura.bennu.compose.ui.theme.spacing
+import com.machankura.bennu.compose.ui.view.model.CreateSharedKeyViewModel
+import com.machankura.bennu.compose.ui.view.state.CreateSharedKeyUIState
+
+/**
+ * Starts a NIP-17 group's own key ceremony: the quorum, and one button.
+ *
+ * The only screen that does. The ceremony screen it hands over to shows a
+ * ceremony and never offers to start one, because doing both from one button
+ * slot is how a member approving a subgroup's ceremony opened a second, whole-room
+ * one in the parent's room. See docs/ceremony-creation.md.
+ *
+ * [onCeremonyOpened] is called with the ceremony to show, whether this screen
+ * opened it or found one already there. The caller replaces this screen with it,
+ * so back from the ceremony goes wherever the member came from.
+ */
+@OptIn(ExperimentalMaterial3Api::class)
+@Composable
+fun CreateSharedKeyScreen(
+ activeUserPublicKey: HexKey,
+ chatRoomId: String,
+ initialUIState: CreateSharedKeyUIState = CreateSharedKeyUIState.Loading,
+ activeIdentityStateFlow: StateFlow,
+ chatRepository: ChatRepository,
+ dkgRepository: DkgRepository,
+ onCeremonyOpened: (dkgSessionId: String) -> Unit,
+ onNavigateBack: () -> Unit,
+) {
+ val viewModel: CreateSharedKeyViewModel = viewModel(
+ factory = CreateSharedKeyViewModel.factory(
+ chatRoomId = chatRoomId,
+ activeUserPublicKey = activeUserPublicKey,
+ initialUIState = initialUIState,
+ activeIdentityStateFlow = activeIdentityStateFlow,
+ chatRepository = chatRepository,
+ dkgRepository = dkgRepository,
+ )
+ )
+
+ LaunchedEffect(true) {
+ if (initialUIState == CreateSharedKeyUIState.Loading) {
+ viewModel.initiate()
+ }
+ }
+
+ val state = viewModel.uiState
+
+ LaunchedEffect(state) {
+ if (state is CreateSharedKeyUIState.Existing) onCeremonyOpened(state.dkgSessionId)
+ }
+
+ Scaffold(
+ snackbarHost = { SnackbarHost(LocalSnackbarHostState.current) },
+ topBar = {
+ TopAppBar(
+ title = {
+ // The room's name only once it is loaded; before that, and on a
+ // refusal, the plain title rather than "Shared key for " and
+ // nothing.
+ val subject = (state as? CreateSharedKeyUIState.Loaded)?.localChatRoom?.chatRoom?.subject
+ Text(
+ text = subject
+ ?.let { stringResource(Res.string.shared_key_for, it) }
+ ?: stringResource(Res.string.shared_key),
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis
+ )
+ },
+ navigationIcon = { NavigateBackButton(onNavigateBack) },
+ )
+ }
+ ) { innerPadding ->
+ ScreenStateTransition(state) { uiState ->
+ when (uiState) {
+ // Existing is a hand-over in flight: nothing to draw but the wait.
+ CreateSharedKeyUIState.Loading,
+ is CreateSharedKeyUIState.Existing -> LoadingDataIndicator(
+ modifier = Modifier.padding(innerPadding).fillMaxSize()
+ )
+
+ is CreateSharedKeyUIState.Error -> ErrorState(
+ modifier = Modifier.padding(innerPadding).readableContent(),
+ message = when (uiState.reason) {
+ CreateSharedKeyUIState.Error.Reason.ROOM_NOT_FOUND ->
+ stringResource(Res.string.couldn_t_load_this_group)
+ CreateSharedKeyUIState.Error.Reason.NO_KEYS ->
+ stringResource(Res.string.couldn_t_read_your_keys)
+ CreateSharedKeyUIState.Error.Reason.NOT_STARTED ->
+ stringResource(Res.string.couldn_t_start_the_key_ceremony)
+ },
+ onRetry = viewModel::initiate,
+ )
+
+ is CreateSharedKeyUIState.Refused -> EmptyState(
+ modifier = Modifier.padding(innerPadding).readableContent(),
+ icon = Icons.Default.Key,
+ message = when (uiState.reason) {
+ CreateSharedKeyUIState.Refused.Reason.MARMOT_ROOM ->
+ stringResource(Res.string.this_room_was_made_from_a_key_the_group_already_holds)
+ CreateSharedKeyUIState.Refused.Reason.TOO_FEW_MEMBERS ->
+ stringResource(
+ Res.string.a_shared_key_needs_at_least_members,
+ ChillDkgRitualManager.MINIMUM_PARTICIPANTS
+ )
+ },
+ )
+
+ is CreateSharedKeyUIState.Loaded -> {
+ val isActionPending = viewModel.isActionPending.value
+
+ Column(
+ modifier = Modifier
+ .padding(innerPadding)
+ .readableContent()
+ .fillMaxSize()
+ .verticalScroll(rememberScrollState())
+ .padding(MaterialTheme.spacing.containerPadding),
+ verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.itemGap)
+ ) {
+ Text(
+ text = stringResource(Res.string.the_group_can_hold_one_key_together_split_so),
+ style = MaterialTheme.typography.bodyMedium
+ )
+
+ Text(
+ text = stringResource(
+ Res.string.everyone_has_to_be_online_at_the_same_time,
+ uiState.participantCount
+ ),
+ style = MaterialTheme.typography.bodyMedium
+ )
+
+ SharedKeyQuorumStepper(
+ threshold = viewModel.threshold.value,
+ participantCount = uiState.participantCount,
+ quorumRange = viewModel.quorumRange(),
+ onThresholdChange = viewModel::setThreshold
+ )
+
+ Button(
+ modifier = Modifier.fillMaxWidth(),
+ enabled = !isActionPending,
+ onClick = { viewModel.create(onCreated = onCeremonyOpened) }
+ ) {
+ if (isActionPending) {
+ CircularProgressIndicator(modifier = Modifier.size(20.dp))
+ } else {
+ Icon(Icons.Default.Key, contentDescription = Decorative)
+ Text(
+ modifier = Modifier.padding(start = MaterialTheme.spacing.relatedGap),
+ text = stringResource(Res.string.start_key_ceremony)
+ )
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+/** Same shape as the group-creation quorum picker, so the choice reads the same. */
+@Composable
+private fun SharedKeyQuorumStepper(
+ threshold: Int,
+ participantCount: Int,
+ quorumRange: IntRange,
+ onThresholdChange: (Int) -> Unit,
+) {
+ Column(
+ modifier = Modifier.fillMaxWidth().padding(top = MaterialTheme.spacing.space50),
+ verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space50)
+ ) {
+ Text(
+ text = stringResource(Res.string.how_many_members_will_it_take_to_sign),
+ style = MaterialTheme.typography.titleSmall
+ )
+
+ Row(
+ modifier = Modifier.fillMaxWidth(),
+ horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space200),
+ verticalAlignment = Alignment.CenterVertically
+ ) {
+ FilledIconButton(
+ onClick = { onThresholdChange(threshold - 1) },
+ enabled = threshold > quorumRange.first
+ ) {
+ Icon(Icons.Default.Remove, contentDescription = "Fewer signers")
+ }
+
+ Text(
+ text = stringResource(Res.string.of, threshold, participantCount),
+ style = MaterialTheme.typography.titleMedium
+ )
+
+ FilledIconButton(
+ onClick = { onThresholdChange(threshold + 1) },
+ enabled = threshold < quorumRange.last
+ ) {
+ Icon(Icons.Default.Add, contentDescription = "More signers")
+ }
+ }
+
+ Text(
+ text = stringResource(Res.string.this_is_fixed_once_the_ceremony_runs),
+ style = MaterialTheme.typography.labelMedium
+ )
+ }
+}
+
+@ConformancePreviews
+@Composable
+private fun CreateSharedKeyScreenPreview() {
+ BennuTheme {
+ Surface(modifier = Modifier.fillMaxSize()) {
+ CreateSharedKeyScreen(
+ activeUserPublicKey = "",
+ chatRoomId = "chatRoomId",
+ initialUIState = CreateSharedKeyUIState.Loaded(
+ localChatRoom = LocalChatRoom(
+ chatRoom = ChatRoom(
+ id = "chatRoomId",
+ userPublicKey = "",
+ subject = "Group discussions",
+ description = null,
+ mlsGroupState = null,
+ )
+ ),
+ participantCount = 3,
+ ),
+ activeIdentityStateFlow = MutableStateFlow(null),
+ chatRepository = ChatRepository.NO_OP_CHAT_REPOSITORY,
+ dkgRepository = DkgRepository.NO_OP_DKG_REPOSITORY,
+ onCeremonyOpened = {},
+ onNavigateBack = {},
+ )
+ }
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/DkgApprovalScaffold.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/DkgApprovalScaffold.kt
index ebc36d6b..cc11d7a6 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/DkgApprovalScaffold.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/DkgApprovalScaffold.kt
@@ -65,7 +65,7 @@ internal fun DkgApprovalScaffold(
approveLabel: String,
activeUserPublicKey: HexKey,
chatRoomId: String,
- dkgSessionId: String? = null,
+ dkgSessionId: String,
activeIdentityStateFlow: StateFlow,
chatRepository: ChatRepository,
dkgRepository: DkgRepository,
@@ -118,23 +118,6 @@ internal fun DkgApprovalScaffold(
}
is DkgRitualUIState.Loaded -> {
- // Loaded means the room is loaded, not the ritual: [initiate] sets
- // this state and only then starts collecting the session, so the
- // first emission always has a null session and a null pending step.
- // Reading that as "nothing to approve" would flash the empty state
- // on the way in, which looks exactly like the screen not working.
- if (state.session == null) {
- Column(
- modifier = Modifier.fillMaxWidth().padding(padding).readableContent().padding(MaterialTheme.spacing.space250),
- horizontalAlignment = Alignment.CenterHorizontally
- ) {
- Spacer(modifier = Modifier.height(MaterialTheme.spacing.space600))
- CircularProgressIndicator()
- }
-
- return@Scaffold
- }
-
// The ritual may have moved on since this screen was opened -- a
// redelivery can carry it forward, and the member may have approved
// on another device. Approving anyway would be approving a step that
@@ -201,10 +184,10 @@ internal fun DkgApprovalScaffold(
}
Button(
- onClick = {
- dkgRitualViewModel.approve(step)
- onDone()
- },
+ // Closes once the approval has gone out, not on the
+ // press: closing clears the view model and would cancel
+ // the publish with it. The button spins meanwhile.
+ onClick = { dkgRitualViewModel.approve(step, onApproved = onDone) },
enabled = !isActionPending,
modifier = Modifier.weight(1f)
) {
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/DkgJoinApprovalScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/DkgJoinApprovalScreen.kt
index a3c9c9d0..ed214e07 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/DkgJoinApprovalScreen.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/DkgJoinApprovalScreen.kt
@@ -32,7 +32,7 @@ import com.machankura.bennu.compose.ui.theme.spacing
fun DkgJoinApprovalScreen(
activeUserPublicKey: HexKey,
chatRoomId: String,
- dkgSessionId: String? = null,
+ dkgSessionId: String,
activeIdentityStateFlow: StateFlow,
chatRepository: ChatRepository,
dkgRepository: DkgRepository,
@@ -55,7 +55,7 @@ fun DkgJoinApprovalScreen(
Text(
text = "$group is creating a shared key that takes " +
- "${session?.threshold ?: 0} of ${state.participantCount} members to sign with.",
+ "${session.threshold} of ${state.participantCount} members to sign with.",
style = MaterialTheme.typography.bodyLarge
)
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/DkgRitualScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/DkgRitualScreen.kt
index e77f5151..8e5c882a 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/DkgRitualScreen.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/DkgRitualScreen.kt
@@ -13,14 +13,12 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
-import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.CheckCircle
import androidx.compose.material.icons.filled.ContentCopy
import androidx.compose.material.icons.filled.Groups
import androidx.compose.material.icons.filled.ErrorOutline
import androidx.compose.material.icons.filled.Key
import androidx.compose.material.icons.filled.RadioButtonUnchecked
-import androidx.compose.material.icons.filled.Remove
import androidx.compose.material3.BottomAppBar
import androidx.compose.material3.Button
import androidx.compose.material3.Card
@@ -36,7 +34,19 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
+import androidx.compose.material3.AlertDialog
+import androidx.compose.material3.ButtonDefaults
+import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
+import bennu.composeapp.generated.resources.abandon
+import bennu.composeapp.generated.resources.abandon_ceremony
+import bennu.composeapp.generated.resources.abandon_this_key_ceremony_question
+import bennu.composeapp.generated.resources.cancel
+import bennu.composeapp.generated.resources.it_ends_for_everyone_in_it_no_key_is_created
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@@ -57,7 +67,6 @@ import com.machankura.bennu.compose.database.model.intermdiate.LocalParticipant
import com.machankura.bennu.compose.database.model.types.DkgRitualStage
import com.machankura.bennu.compose.database.model.types.FrostSigningStage
import com.machankura.bennu.compose.extensions.memberName
-import com.machankura.bennu.compose.managers.ChillDkgRitualManager
import com.machankura.bennu.compose.repository.ChatRepository
import com.machankura.bennu.compose.repository.DkgRepository
import com.machankura.bennu.compose.ui.composable.widgets.LoadingDataIndicator
@@ -65,6 +74,8 @@ import com.machankura.bennu.compose.ui.composable.widgets.profile.ProfileColor
import com.machankura.bennu.compose.ui.theme.BennuTheme
import com.machankura.bennu.compose.database.model.types.DkgApprovalStep
import com.machankura.bennu.compose.ui.composable.navigation.routes.DkgJoinApprovalRoute
+import com.machankura.bennu.compose.ui.composable.navigation.routes.SelectSubgroupAdminsRoute
+import com.machankura.bennu.compose.ui.composable.navigation.routes.CreateSharedKeyRoute
import com.machankura.bennu.compose.ui.composable.navigation.routes.DkgRound1ApprovalRoute
import com.machankura.bennu.compose.ui.composable.navigation.routes.DkgRound2ApprovalRoute
import com.machankura.bennu.compose.ui.composable.navigation.routes.Route
@@ -87,7 +98,6 @@ import bennu.composeapp.generated.resources.before_the_subgroup_exists_its_paren
import bennu.composeapp.generated.resources.the_parent_group_is_certifying_this_subgroup
import bennu.composeapp.generated.resources.the_parent_group_could_not_certify_this_subgroup
import bennu.composeapp.generated.resources.the_parent_group_has_certified_this_subgroup
-import bennu.composeapp.generated.resources.how_many_members_will_it_take_to_sign
import bennu.composeapp.generated.resources.key
import bennu.composeapp.generated.resources.members
import bennu.composeapp.generated.resources.nothing_was_created_and_no_key_exists_it_is
@@ -95,19 +105,15 @@ import bennu.composeapp.generated.resources.review_and_confirm
import bennu.composeapp.generated.resources.review_and_contribute
import bennu.composeapp.generated.resources.review_and_join
import bennu.composeapp.generated.resources.shared_key
-import bennu.composeapp.generated.resources.start_key_ceremony
import bennu.composeapp.generated.resources.the_ceremony_was_abandoned
-import bennu.composeapp.generated.resources.the_group_can_hold_one_key_together_split_so
import bennu.composeapp.generated.resources.the_group_has_a_shared_key
import bennu.composeapp.generated.resources.the_group_has_agreed_what_the_admin_room
import bennu.composeapp.generated.resources.the_group_could_not_agree_what_the_admin
import bennu.composeapp.generated.resources.the_group_is_agreeing_what_the_admin_room
import bennu.composeapp.generated.resources.agree_the_groups_signing_key
import bennu.composeapp.generated.resources.before_the_room_exists_the_group_signs
-import bennu.composeapp.generated.resources.this_is_fixed_once_the_ceremony_runs
import bennu.composeapp.generated.resources.try_again
import bennu.composeapp.generated.resources.your_share_of_it_is_on_this_device_only_your
-import bennu.composeapp.generated.resources.everyone_has_to_be_online_at_the_same_time
import bennu.composeapp.generated.resources.of
import bennu.composeapp.generated.resources.of_members_will_be_needed_to_sign_with_this
import bennu.composeapp.generated.resources.shared_key_for
@@ -120,21 +126,26 @@ import com.machankura.bennu.compose.ui.composable.widgets.buttons.ExtendedFab
import com.machankura.bennu.compose.ui.theme.ConformancePreviews
/**
- * The shared-key ceremony: a ChillDKG ritual run across the group's NIP-17
- * chat, shown as a ladder of rounds so members can see it is moving and who it
- * is waiting on.
+ * One shared-key ceremony: a ChillDKG ritual, shown as a ladder of rounds so
+ * members can see it is moving and who it is waiting on.
*
* A DKG needs *everyone* present, which is unusual for a chat feature and the
* main thing this screen has to communicate — hence a count against every step
* rather than an indeterminate spinner.
+ *
+ * It shows a ceremony and never starts one. It used to do both, from the same
+ * slot in the bottom bar the approvals use, and a member coming back from
+ * approving a subgroup's ceremony found "Start key ceremony" where "Review and
+ * join" had been. Starting lives in `CreateSharedKeyScreen` and the subgroup
+ * picker, which know what a ceremony is for -- see docs/ceremony-creation.md.
*/
@OptIn(ExperimentalMaterial3ExpressiveApi::class, ExperimentalMaterial3Api::class)
@Composable
fun DkgRitualScreen(
activeUserPublicKey: HexKey,
chatRoomId: String,
- /** Which of the room's ceremonies to show; null takes the newest. */
- dkgSessionId: String? = null,
+ /** Which of the room's ceremonies to show -- see `DkgRitualRoute.dkgSessionId`. */
+ dkgSessionId: String,
initialDkgRitualUIState: DkgRitualUIState = DkgRitualUIState.Loading,
activeIdentityStateFlow: StateFlow,
chatRepository: ChatRepository,
@@ -168,7 +179,7 @@ fun DkgRitualScreen(
is DkgRitualUIState.Loaded -> {
val session = dkgRitualUIState.session
val participantCount = dkgRitualUIState.participantCount
- val canStartRitual = dkgRitualViewModel.canStartRitual()
+ var isConfirmingAbandon by remember { mutableStateOf(false) }
val isActionPending = dkgRitualViewModel.isActionPending.value
Scaffold(
@@ -177,7 +188,16 @@ fun DkgRitualScreen(
TopAppBar(
title = {
Text(
- text = stringResource(Res.string.shared_key_for, dkgRitualUIState.localChatRoom.chatRoom.subject ?: "this group"),
+ // The ceremony's name, not the room's: a subgroup's
+ // runs in its parent's room, and "Shared key for
+ // #Checkers" over Tapscript's ceremony names the
+ // one group it is not for.
+ text = stringResource(
+ Res.string.shared_key_for,
+ session.subject
+ ?: dkgRitualUIState.localChatRoom.chatRoom.subject
+ ?: "this group"
+ ),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
@@ -207,17 +227,17 @@ fun DkgRitualScreen(
DkgApprovalStep.HOST_KEY -> DkgJoinApprovalRoute(
activeUserPublicKey = activeUserPublicKey,
chatRoomId = chatRoomId,
- dkgSessionId = dkgRitualUIState.session?.id
+ dkgSessionId = session.id
)
DkgApprovalStep.ROUND_1 -> DkgRound1ApprovalRoute(
activeUserPublicKey = activeUserPublicKey,
chatRoomId = chatRoomId,
- dkgSessionId = dkgRitualUIState.session?.id
+ dkgSessionId = session.id
)
DkgApprovalStep.ROUND_2 -> DkgRound2ApprovalRoute(
activeUserPublicKey = activeUserPublicKey,
chatRoomId = chatRoomId,
- dkgSessionId = dkgRitualUIState.session?.id
+ dkgSessionId = session.id
)
}
)
@@ -230,34 +250,26 @@ fun DkgRitualScreen(
return@Scaffold
}
- // Any member can open a ritual — the coordinator has no say in
- // the key — but only when there isn't one already running.
- if (canStartRitual) {
+ // A failed ceremony is tried again from the screen that knows what
+ // it was for, never from here: this screen only shows a ceremony.
+ if (session.stage == DkgRitualStage.FAILED) {
BottomAppBar(
floatingActionButton = {
ExtendedFab(
- label = if (session == null) {
- stringResource(Res.string.start_key_ceremony)
- } else {
- stringResource(Res.string.try_again)
- },
- icon = {
- if (isActionPending) {
- CircularProgressIndicator(modifier = Modifier.size(20.dp))
- } else {
- Icon(Icons.Default.Key, contentDescription = "Start")
- }
- },
- onClick = { dkgRitualViewModel.startRitual() }
+ label = stringResource(Res.string.try_again),
+ icon = { Icon(Icons.Default.Key, contentDescription = Decorative) },
+ onClick = {
+ onNavigateToRoute(
+ retryRoute(
+ activeUserPublicKey = activeUserPublicKey,
+ chatRoomId = chatRoomId,
+ session = session,
+ )
+ )
+ }
)
},
- actions = {
- Text(
- modifier = Modifier.padding(start = MaterialTheme.spacing.space200),
- text = stringResource(Res.string.of, dkgRitualViewModel.threshold.value, participantCount),
- style = MaterialTheme.typography.labelLarge
- )
- }
+ actions = {}
)
}
}
@@ -271,32 +283,6 @@ fun DkgRitualScreen(
.padding(MaterialTheme.spacing.space125),
verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space125)
) {
- if (session == null) {
- Text(
- text = stringResource(Res.string.the_group_can_hold_one_key_together_split_so),
- style = MaterialTheme.typography.bodyMedium
- )
-
- Text(
- text = stringResource(Res.string.everyone_has_to_be_online_at_the_same_time, participantCount),
- style = MaterialTheme.typography.bodyMedium
- )
-
- if (canStartRitual) {
- QuorumStepper(
- threshold = dkgRitualViewModel.threshold.value,
- participantCount = participantCount,
- quorumRange = dkgRitualViewModel.quorumRange(),
- onThresholdChange = dkgRitualViewModel::setThreshold
- )
- } else {
- Text(
- text = "A shared key needs at least " +
- "${ChillDkgRitualManager.MINIMUM_PARTICIPANTS} members to split it between.",
- style = MaterialTheme.typography.labelLarge
- )
- }
- } else {
RitualProgress(
session = session,
participantCount = participantCount,
@@ -318,7 +304,44 @@ fun DkgRitualScreen(
dkgRitualViewModel.createAdminGroup(onNavigateToRoute)
}
)
- }
+
+ // Here rather than on the approval screens, where the
+ // consequence can be read against the whole ceremony:
+ // it ends for everyone, not just for this member.
+ if (dkgRitualUIState.canAbandon) {
+ TextButton(
+ onClick = { isConfirmingAbandon = true },
+ enabled = !isActionPending,
+ colors = ButtonDefaults.textButtonColors(
+ contentColor = MaterialTheme.colorScheme.error
+ )
+ ) {
+ Text(stringResource(Res.string.abandon_ceremony))
+ }
+ }
+ }
+
+ if (isConfirmingAbandon) {
+ AlertDialog(
+ onDismissRequest = { isConfirmingAbandon = false },
+ title = { Text(stringResource(Res.string.abandon_this_key_ceremony_question)) },
+ text = { Text(stringResource(Res.string.it_ends_for_everyone_in_it_no_key_is_created)) },
+ confirmButton = {
+ TextButton(
+ onClick = {
+ isConfirmingAbandon = false
+ dkgRitualViewModel.abandon()
+ }
+ ) {
+ Text(stringResource(Res.string.abandon))
+ }
+ },
+ dismissButton = {
+ TextButton(onClick = { isConfirmingAbandon = false }) {
+ Text(stringResource(Res.string.cancel))
+ }
+ },
+ )
}
}
}
@@ -348,6 +371,25 @@ fun DkgRitualScreen(
}
}
+/**
+ * Where a failed ceremony is tried again: the screen that starts that kind.
+ *
+ * A group's own goes back to `CreateSharedKeyScreen`. A subgroup's goes back to
+ * the picker, filled in from the ceremony that failed, because trying again is a
+ * new ceremony over choices the member may want to change -- an admin who never
+ * showed up, say.
+ */
+internal fun retryRoute(activeUserPublicKey: HexKey, chatRoomId: String, session: DkgSession): Route =
+ session.parentChatRoomId
+ ?.let { parent ->
+ SelectSubgroupAdminsRoute(
+ activeUserPublicKey = activeUserPublicKey,
+ parentChatRoomId = parent,
+ retrying = session.id,
+ )
+ }
+ ?: CreateSharedKeyRoute(activeUserPublicKey = activeUserPublicKey, chatRoomId = chatRoomId)
+
/** The ladder, and the members it is climbing. */
@Composable
private fun RitualProgress(
@@ -815,55 +857,6 @@ private fun RitualStep(
}
}
-/** Same shape as the group-creation quorum picker, so the choice reads the same. */
-@Composable
-private fun QuorumStepper(
- threshold: Int,
- participantCount: Int,
- quorumRange: IntRange,
- onThresholdChange: (Int) -> Unit,
-) {
- Column(
- modifier = Modifier.fillMaxWidth().padding(top = MaterialTheme.spacing.space50),
- verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space50)
- ) {
- Text(
- text = stringResource(Res.string.how_many_members_will_it_take_to_sign),
- style = MaterialTheme.typography.titleSmall
- )
-
- Row(
- modifier = Modifier.fillMaxWidth(),
- horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space200),
- verticalAlignment = Alignment.CenterVertically
- ) {
- FilledIconButton(
- onClick = { onThresholdChange(threshold - 1) },
- enabled = threshold > quorumRange.first
- ) {
- Icon(Icons.Default.Remove, contentDescription = "Fewer signers")
- }
-
- Text(
- text = stringResource(Res.string.of, threshold, participantCount),
- style = MaterialTheme.typography.titleMedium
- )
-
- FilledIconButton(
- onClick = { onThresholdChange(threshold + 1) },
- enabled = threshold < quorumRange.last
- ) {
- Icon(Icons.Default.Add, contentDescription = "More signers")
- }
- }
-
- Text(
- text = stringResource(Res.string.this_is_fixed_once_the_ceremony_runs),
- style = MaterialTheme.typography.labelMedium
- )
- }
-}
-
@ConformancePreviews
@Composable
private fun DkgRitualScreenPreview() {
@@ -872,17 +865,29 @@ private fun DkgRitualScreenPreview() {
DkgRitualScreen(
activeUserPublicKey = "",
chatRoomId = "chatRoomId",
+ dkgSessionId = "session",
initialDkgRitualUIState = DkgRitualUIState.Loaded(
localChatRoom = LocalChatRoom(
chatRoom = ChatRoom(
- id = "",
+ id = "chatRoomId",
userPublicKey = "",
subject = "Group discussions",
description = "See something... say something.",
initialGiftWrapPayloadId = null,
mlsGroupState = null
),
- )
+ ),
+ session = DkgSession(
+ id = "session",
+ chatRoomId = "chatRoomId",
+ coordinatorPublicKey = "",
+ userPublicKey = "",
+ threshold = 2,
+ participantCount = 3,
+ hostPublicKey = "",
+ round1Random = "",
+ round2AuxRandom = "",
+ ),
),
activeIdentityStateFlow = MutableStateFlow(null),
chatRepository = ChatRepository.NO_OP_CHAT_REPOSITORY,
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/DkgRound1ApprovalScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/DkgRound1ApprovalScreen.kt
index 6c8d9259..d2c43ed7 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/DkgRound1ApprovalScreen.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/DkgRound1ApprovalScreen.kt
@@ -36,7 +36,7 @@ import bennu.composeapp.generated.resources.you
fun DkgRound1ApprovalScreen(
activeUserPublicKey: HexKey,
chatRoomId: String,
- dkgSessionId: String? = null,
+ dkgSessionId: String,
activeIdentityStateFlow: StateFlow,
chatRepository: ChatRepository,
dkgRepository: DkgRepository,
@@ -58,7 +58,7 @@ fun DkgRound1ApprovalScreen(
Text(
text = "Everyone has joined. ${state.participantCount} members are making a key that " +
- "takes ${session?.threshold ?: 0} of them to sign with.",
+ "takes ${session.threshold} of them to sign with.",
style = MaterialTheme.typography.bodyLarge
)
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/DkgRound2ApprovalScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/DkgRound2ApprovalScreen.kt
index 1e0def45..128f402a 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/DkgRound2ApprovalScreen.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/DkgRound2ApprovalScreen.kt
@@ -37,7 +37,7 @@ import bennu.composeapp.generated.resources.this_is_the_last_thing_the_ceremony_
fun DkgRound2ApprovalScreen(
activeUserPublicKey: HexKey,
chatRoomId: String,
- dkgSessionId: String? = null,
+ dkgSessionId: String,
activeIdentityStateFlow: StateFlow,
chatRepository: ChatRepository,
dkgRepository: DkgRepository,
@@ -59,7 +59,7 @@ fun DkgRound2ApprovalScreen(
Text(
text = "Everyone's contributions have been combined into a " +
- "${session?.threshold ?: 0}-of-${state.participantCount} key.",
+ "${session.threshold}-of-${state.participantCount} key.",
style = MaterialTheme.typography.bodyLarge
)
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/SelectChatRoomTypeScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/SelectChatRoomTypeScreen.kt
index 6b5de38e..ec17dce2 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/SelectChatRoomTypeScreen.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/SelectChatRoomTypeScreen.kt
@@ -32,6 +32,9 @@ import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
+import androidx.compose.material3.TextButton
+import com.machankura.bennu.compose.ui.composable.navigation.routes.CreateSharedKeyRoute
+import bennu.composeapp.generated.resources.start_the_key_ceremony
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@@ -223,6 +226,25 @@ fun SelectChatRoomTypeScreen(
text = stringResource(Res.string.was_created_but_its_shared_key_ceremony, name),
style = MaterialTheme.typography.bodyMedium
)
+
+ // Straight to the one screen that starts a group's own
+ // ceremony, rather than leaving the member to find it
+ // through the group's details.
+ selectChatRoomTypeViewModel.createdChatRoomId.value?.let { createdChatRoomId ->
+ TextButton(
+ modifier = Modifier.padding(horizontal = MaterialTheme.spacing.space100),
+ onClick = {
+ onNavigateToRoute(
+ CreateSharedKeyRoute(
+ activeUserPublicKey = activeUserPublicKey,
+ chatRoomId = createdChatRoomId,
+ )
+ )
+ }
+ ) {
+ Text(stringResource(Res.string.start_the_key_ceremony))
+ }
+ }
}
}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/SelectSubgroupAdminsScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/SelectSubgroupAdminsScreen.kt
index 8eebdb79..d464218f 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/SelectSubgroupAdminsScreen.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/SelectSubgroupAdminsScreen.kt
@@ -81,6 +81,8 @@ import com.machankura.bennu.compose.ui.view.state.SelectSubgroupAdminsUIState
fun SelectSubgroupAdminsScreen(
activeUserPublicKey: HexKey,
parentChatRoomId: String,
+ /** A failed subgroup ceremony to start from; see `SelectSubgroupAdminsRoute.retrying`. */
+ retrying: String? = null,
initialUIState: SelectSubgroupAdminsUIState = SelectSubgroupAdminsUIState.Loading,
activeIdentityStateFlow: StateFlow,
chatRepository: ChatRepository,
@@ -92,6 +94,7 @@ fun SelectSubgroupAdminsScreen(
factory = SelectSubgroupAdminsViewModel.factory(
activeUserPublicKey = activeUserPublicKey,
parentChatRoomId = parentChatRoomId,
+ retrying = retrying,
initialUIState = initialUIState,
activeIdentityStateFlow = activeIdentityStateFlow,
chatRepository = chatRepository,
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/TranslateChunkScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/TranslateChunkScreen.kt
deleted file mode 100644
index d6c751fb..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/TranslateChunkScreen.kt
+++ /dev/null
@@ -1,275 +0,0 @@
-package com.machankura.bennu.compose.ui.composable
-
-import androidx.compose.foundation.layout.Arrangement
-import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.Spacer
-import androidx.compose.foundation.layout.fillMaxSize
-import androidx.compose.foundation.layout.fillMaxWidth
-import androidx.compose.foundation.layout.height
-import androidx.compose.foundation.layout.padding
-import androidx.compose.foundation.layout.imePadding
-import androidx.compose.foundation.rememberScrollState
-import androidx.compose.foundation.text.input.rememberTextFieldState
-import androidx.compose.foundation.verticalScroll
-import androidx.compose.material.icons.Icons
-import androidx.compose.material.icons.filled.Add
-import androidx.compose.material3.BottomAppBar
-import androidx.compose.material3.Card
-import androidx.compose.material3.ExperimentalMaterial3Api
-import androidx.compose.material3.Icon
-import androidx.compose.material3.MaterialTheme
-import androidx.compose.material3.OutlinedTextField
-import androidx.compose.material3.Scaffold
-import androidx.compose.material3.Surface
-import androidx.compose.material3.Text
-import androidx.compose.material3.TopAppBar
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.LaunchedEffect
-import androidx.compose.ui.Alignment
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.text.style.TextAlign
-import androidx.compose.ui.unit.dp
-import androidx.lifecycle.viewmodel.compose.viewModel
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.machankura.bennu.compose.database.model.ChatRoom
-import com.machankura.bennu.compose.database.model.MantraChunk
-import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
-import com.machankura.bennu.compose.repository.ChatRepository
-import com.machankura.bennu.compose.repository.FrostSigningRepository
-import com.machankura.bennu.compose.repository.MantraRepository
-import com.machankura.bennu.compose.ui.composable.navigation.routes.FrostSigningRoute
-import com.machankura.bennu.compose.ui.composable.navigation.routes.ImplementationPendingRoute
-import com.machankura.bennu.compose.ui.composable.navigation.routes.Route
-import com.machankura.bennu.compose.ui.composable.widgets.LoadingDataIndicator
-import com.machankura.bennu.compose.ui.theme.BennuTheme
-import com.machankura.bennu.compose.ui.view.model.TranslateChunkViewModel
-import com.machankura.bennu.compose.ui.view.state.TranslateChunkUIState
-import com.machankura.bennu.compose.ui.theme.spacing
-import bennu.composeapp.generated.resources.Res
-import org.jetbrains.compose.resources.stringResource
-import bennu.composeapp.generated.resources.enter_the_translation_for_this_chunk
-import bennu.composeapp.generated.resources.original
-import bennu.composeapp.generated.resources.propose_translation
-import bennu.composeapp.generated.resources.translate_chunk
-import bennu.composeapp.generated.resources.translated_text
-import bennu.composeapp.generated.resources.translation
-import androidx.compose.material3.SnackbarHost
-import com.machankura.bennu.compose.ui.composable.widgets.LocalSnackbarHostState
-import com.machankura.bennu.compose.ui.theme.readableContent
-import com.machankura.bennu.compose.ui.composable.widgets.ScreenStateTransition
-import com.machankura.bennu.compose.ui.composable.widgets.NavigateBackButton
-import com.machankura.bennu.compose.ui.composable.widgets.buttons.ExtendedFab
-import com.machankura.bennu.compose.ui.theme.ConformancePreviews
-
-@OptIn(ExperimentalMaterial3Api::class)
-@Composable
-fun TranslateChunkScreen(
- activeUserPublicKey: HexKey,
- translationChapterId: String,
- chunkId: String,
- chatRoomId: String,
- relayHint: String?,
- initialTranslateChunkUIState: TranslateChunkUIState = TranslateChunkUIState.Loading,
- mantraRepository: MantraRepository,
- chatRepository: ChatRepository,
- frostSigningRepository: FrostSigningRepository,
- onNavigateToRouteAndPopUpInclusive: (Route) -> Unit,
- onNavigateToRoute: (Route) -> Unit,
- onNavigateBack: () -> Unit,
-) {
- val translateChunkViewModel: TranslateChunkViewModel = viewModel(
- factory = TranslateChunkViewModel.factory(
- activeUserPublicKey = activeUserPublicKey,
- translationChapterId = translationChapterId,
- chunkId = chunkId,
- chatRoomId = chatRoomId,
- relayHint = relayHint,
- initialTranslateChunkUIState = initialTranslateChunkUIState,
- mantraRepository = mantraRepository,
- chatRepository = chatRepository,
- frostSigningRepository = frostSigningRepository,
- )
- )
-
- ScreenStateTransition(translateChunkViewModel.translateChunkUIState) { uiState ->
- when (val translateChunkUIState = uiState) {
- is TranslateChunkUIState.Error -> {
- Column(
- modifier = Modifier.fillMaxWidth(),
- horizontalAlignment = Alignment.CenterHorizontally
- ) {
- Spacer(modifier = Modifier.height(MaterialTheme.spacing.space600))
- Text(text = translateChunkUIState.message)
- }
- }
-
- is TranslateChunkUIState.Loaded -> {
- val translationFieldState = rememberTextFieldState(translateChunkUIState.existingTranslationText)
-
- // imePadding: this screen has a text field, and without it the software
- // keyboard covers whatever is being typed into.
- Scaffold(
- snackbarHost = { SnackbarHost(LocalSnackbarHostState.current) },
- modifier = Modifier.imePadding(),
- topBar = {
- TopAppBar(
- title = { Text(stringResource(Res.string.translate_chunk)) },
- navigationIcon = { NavigateBackButton(onNavigateBack) },
- )
- },
- bottomBar = {
- BottomAppBar(
- actions = {},
- floatingActionButton = {
- ExtendedFab(
- label = stringResource(Res.string.propose_translation),
- icon = { Icon(Icons.Default.Add, contentDescription = "Propose translation") },
- enabled = translateChunkUIState.canSign,
- onClick = {
- translateChunkViewModel.proposeTranslation(
- localChatRoom = translateChunkUIState.localChatRoom,
- originalChunk = translateChunkUIState.originalChunk,
- translationField = translationFieldState,
- onSuccess = { sessionId ->
- // Onto the session rather than back to
- // the chapter table. Nothing has been
- // translated yet -- the chunk is
- // translated when enough members sign --
- // so a table still showing it untranslated
- // would read as a failure.
- onNavigateToRouteAndPopUpInclusive.invoke(
- FrostSigningRoute(
- activeUserPublicKey = activeUserPublicKey,
- chatRoomId = chatRoomId,
- sessionId = sessionId
- )
- )
- },
- onFailure = {
- onNavigateToRoute.invoke(
- ImplementationPendingRoute("Failed translation")
- )
- }
- )
- }
- )
- }
- )
- }
- ) { innerPadding ->
- Column(
- modifier = Modifier
- .padding(innerPadding)
- .readableContent()
- .fillMaxSize()
- .verticalScroll(rememberScrollState())
- .padding(MaterialTheme.spacing.space250),
- verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space125)
- ) {
- if (!translateChunkUIState.canSign) {
- Text(
- text = "This group has no shared key, so it cannot sign a " +
- "translation. Run a shared key ceremony first.",
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.error
- )
- }
-
- Text(
- text = stringResource(Res.string.original),
- style = MaterialTheme.typography.labelMedium
- )
- Card {
- Text(
- modifier = Modifier.padding(MaterialTheme.spacing.containerPadding),
- text = translateChunkUIState.originalChunk.text,
- style = MaterialTheme.typography.bodyMedium
- )
- }
-
- Text(
- text = stringResource(Res.string.translation),
- style = MaterialTheme.typography.labelMedium
- )
- OutlinedTextField(
- modifier = Modifier.fillMaxWidth(),
- state = translationFieldState,
- label = { Text(stringResource(Res.string.translated_text)) },
- placeholder = { Text(stringResource(Res.string.enter_the_translation_for_this_chunk)) },
- )
- }
- }
- }
-
- TranslateChunkUIState.Loading -> {
- Column(
- modifier = Modifier.fillMaxWidth().padding(MaterialTheme.spacing.space250),
- horizontalAlignment = Alignment.CenterHorizontally,
- verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space250)
- ) {
- Spacer(modifier = Modifier.weight(1f))
- Text(
- text = stringResource(Res.string.translate_chunk),
- style = MaterialTheme.typography.bodyLarge,
- textAlign = TextAlign.Center
- )
- LoadingDataIndicator(fillScreen = false)
- Spacer(modifier = Modifier.weight(2f))
- }
- }
- }
- }
-
- LaunchedEffect(true) {
- if (initialTranslateChunkUIState == TranslateChunkUIState.Loading) {
- translateChunkViewModel.initiateTranslateChunk()
- }
- }
-}
-
-@ConformancePreviews
-@Composable
-private fun TranslateChunkScreenPreview() {
- BennuTheme {
- Surface(modifier = Modifier.fillMaxSize()) {
- TranslateChunkScreen(
- activeUserPublicKey = "",
- translationChapterId = "translationChapterId",
- chunkId = "chunkId",
- chatRoomId = "chatRoomId",
- relayHint = null,
- initialTranslateChunkUIState = TranslateChunkUIState.Loaded(
- localChatRoom = LocalChatRoom(
- chatRoom = ChatRoom(
- id = "chatRoomId",
- userPublicKey = "",
- subject = "Message title",
- description = "See something. Say somethin",
- initialGiftWrapPayloadId = "sdfaer",
- mlsGroupState = null
- ),
- ),
- originalChunk = MantraChunk(
- id = "chunkId",
- chapterId = "chapterId",
- publicKey = "author",
- text = "When he was nearly thirteen, my brother Jem got his arm badly broken at the elbow.",
- index = 0,
- wordCount = 0,
- characterCount = 0,
- signature = "",
- chatRoomId = "chatRoomId"
- ),
- existingTranslationText = "",
- canSign = true
- ),
- mantraRepository = MantraRepository.NO_OP_MANTRA_REPOSITORY,
- chatRepository = ChatRepository.NO_OP_CHAT_REPOSITORY,
- frostSigningRepository = FrostSigningRepository.NO_OP_FROST_SIGNING_REPOSITORY,
- onNavigateToRouteAndPopUpInclusive = {},
- onNavigateToRoute = {},
- onNavigateBack = {}
- )
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/TranslationArtifactVersionDetailScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/TranslationArtifactVersionDetailScreen.kt
deleted file mode 100644
index 2e04ac4e..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/TranslationArtifactVersionDetailScreen.kt
+++ /dev/null
@@ -1,310 +0,0 @@
-package com.machankura.bennu.compose.ui.composable
-
-import androidx.compose.foundation.layout.Arrangement
-import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.Spacer
-import androidx.compose.foundation.layout.fillMaxSize
-import androidx.compose.foundation.layout.fillMaxWidth
-import androidx.compose.foundation.layout.height
-import androidx.compose.foundation.layout.padding
-import androidx.compose.foundation.lazy.LazyColumn
-import androidx.compose.foundation.lazy.items
-import androidx.compose.material.icons.Icons
-import androidx.compose.material.icons.filled.Article
-import androidx.compose.material.icons.filled.PlaylistAdd
-import androidx.compose.material3.Card
-import androidx.compose.material3.ExperimentalMaterial3Api
-import androidx.compose.material3.HorizontalDivider
-import androidx.compose.material3.Icon
-import androidx.compose.material3.ListItem
-import androidx.compose.material3.MaterialTheme
-import androidx.compose.material3.Scaffold
-import androidx.compose.material3.Surface
-import androidx.compose.material3.Text
-import androidx.compose.material3.TextButton
-import androidx.compose.material3.TopAppBar
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.LaunchedEffect
-import androidx.compose.ui.Alignment
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.text.style.TextAlign
-import androidx.compose.ui.unit.dp
-import androidx.lifecycle.viewmodel.compose.viewModel
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.machankura.bennu.compose.database.model.MantraTranslationArtifactVersion
-import com.machankura.bennu.compose.repository.ChatRepository
-import com.machankura.bennu.compose.repository.FrostSigningRepository
-import com.machankura.bennu.compose.repository.MantraRepository
-import com.machankura.bennu.compose.ui.composable.navigation.routes.FrostSigningRoute
-import com.machankura.bennu.compose.ui.composable.navigation.routes.Route
-import com.machankura.bennu.compose.ui.composable.navigation.routes.TranslationChapterRoute
-import com.machankura.bennu.compose.ui.composable.widgets.DetailRow
-import com.machankura.bennu.compose.ui.composable.widgets.LoadingDataIndicator
-import com.machankura.bennu.compose.ui.theme.BennuTheme
-import com.machankura.bennu.compose.ui.view.model.TranslationArtifactVersionDetailViewModel
-import com.machankura.bennu.compose.ui.view.state.TranslationArtifactVersionDetailUIState
-import com.machankura.bennu.compose.ui.theme.spacing
-import bennu.composeapp.generated.resources.Res
-import org.jetbrains.compose.resources.stringResource
-import bennu.composeapp.generated.resources.chapters
-import bennu.composeapp.generated.resources.details
-import bennu.composeapp.generated.resources.no_chapters
-import bennu.composeapp.generated.resources.propose
-import bennu.composeapp.generated.resources.this_group_has_no_shared_key_so_it_cannot
-import bennu.composeapp.generated.resources.translation_detail
-import bennu.composeapp.generated.resources.chapter
-import bennu.composeapp.generated.resources.chunks_translated
-import androidx.compose.material3.SnackbarHost
-import com.machankura.bennu.compose.ui.composable.widgets.LocalSnackbarHostState
-import com.machankura.bennu.compose.ui.theme.readableContent
-import com.machankura.bennu.compose.ui.composable.widgets.ScreenStateTransition
-import com.machankura.bennu.compose.ui.composable.widgets.NavigateBackButton
-import com.machankura.bennu.compose.ui.theme.ConformancePreviews
-
-@OptIn(ExperimentalMaterial3Api::class)
-@Composable
-fun TranslationArtifactVersionDetailScreen(
- activeUserPublicKey: HexKey,
- translationArtifactVersionId: String,
- chatRoomId: String,
- relayHint: String?,
- initialTranslationArtifactVersionDetailUIState: TranslationArtifactVersionDetailUIState = TranslationArtifactVersionDetailUIState.Loading,
- mantraRepository: MantraRepository,
- chatRepository: ChatRepository,
- frostSigningRepository: FrostSigningRepository,
- onNavigateToRoute: (Route) -> Unit,
- onNavigateBack: () -> Unit,
-) {
- val translationDetailViewModel: TranslationArtifactVersionDetailViewModel = viewModel(
- factory = TranslationArtifactVersionDetailViewModel.factory(
- activeUserPublicKey = activeUserPublicKey,
- translationArtifactVersionId = translationArtifactVersionId,
- chatRoomId = chatRoomId,
- relayHint = relayHint,
- initialTranslationArtifactVersionDetailUIState = initialTranslationArtifactVersionDetailUIState,
- mantraRepository = mantraRepository,
- chatRepository = chatRepository,
- frostSigningRepository = frostSigningRepository,
- )
- )
-
- ScreenStateTransition(translationDetailViewModel.translationDetailUIState) { uiState ->
- when (val translationDetailUIState = uiState) {
- is TranslationArtifactVersionDetailUIState.Error -> {
- Column(
- modifier = Modifier.fillMaxWidth(),
- horizontalAlignment = Alignment.CenterHorizontally
- ) {
- Spacer(modifier = Modifier.height(MaterialTheme.spacing.space600))
- Text(text = translationDetailUIState.message)
- }
- }
-
- is TranslationArtifactVersionDetailUIState.Loaded -> {
- val translation = translationDetailUIState.translation
- Scaffold(
- snackbarHost = { SnackbarHost(LocalSnackbarHostState.current) },
- topBar = {
- TopAppBar(
- title = { Text(translation.name) },
- navigationIcon = { NavigateBackButton(onNavigateBack) },
- )
- }
- ) { innerPadding ->
- LazyColumn(
- modifier = Modifier.padding(innerPadding).readableContent().fillMaxSize().padding(MaterialTheme.spacing.space250),
- verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space125)
- ) {
- // Chapters the source version has and this translation
- // does not. Above the list rather than after it: a chapter
- // that is not here is invisible from a list of the ones
- // that are.
- val localChatRoom = translationDetailUIState.localChatRoom
- val missingChapters = translationDetailUIState.missingChapters
-
- if (missingChapters.isNotEmpty()) {
- item {
- Card {
- ListItem(
- leadingContent = {
- Icon(
- Icons.Default.PlaylistAdd,
- contentDescription = "Chapters missing from this translation"
- )
- },
- headlineContent = {
- Text(
- "${missingChapters.size} " +
- (if (missingChapters.size == 1) "chapter is" else "chapters are") +
- " not in this translation yet"
- )
- },
- supportingContent = {
- Text(
- if (!translationDetailUIState.canSign) {
- stringResource(Res.string.this_group_has_no_shared_key_so_it_cannot)
- } else {
- "They were signed into the artifact after this " +
- "translation. Ask the group to add them so they " +
- "can be translated."
- }
- )
- },
- trailingContent = {
- TextButton(
- enabled = localChatRoom != null &&
- translationDetailUIState.canSign &&
- !translationDetailViewModel.isActionPending.value,
- onClick = {
- if (localChatRoom == null) return@TextButton
-
- translationDetailViewModel.catchUpMissingChapters(
- localChatRoom = localChatRoom,
- missingChapters = missingChapters,
- onSuccess = { sessionId ->
- onNavigateToRoute.invoke(
- FrostSigningRoute(
- activeUserPublicKey = activeUserPublicKey,
- chatRoomId = chatRoomId,
- sessionId = sessionId
- )
- )
- },
- onFailure = {}
- )
- }
- ) {
- Text(stringResource(Res.string.propose))
- }
- }
- )
- }
- }
-
- item { HorizontalDivider() }
- }
-
- // Chapters with translation progress
- item {
- Text(
- text = stringResource(Res.string.chapters),
- style = MaterialTheme.typography.labelMedium
- )
- }
- if (translationDetailUIState.chapters.isEmpty()) {
- item { Text(stringResource(Res.string.no_chapters)) }
- } else {
- items(
- items = translationDetailUIState.chapters,
- key = { progress -> progress.chapter.id }
- ) { progress ->
- Card(
- onClick = {
- onNavigateToRoute.invoke(
- TranslationChapterRoute(
- activeUserPublicKey = activeUserPublicKey,
- translationChapterId = progress.chapter.id,
- chatRoomId = chatRoomId,
- relayHint = relayHint
- )
- )
- }
- ) {
- ListItem(
- leadingContent = {
- Icon(
- Icons.Default.Article,
- contentDescription = "Chapter"
- )
- },
- headlineContent = { Text(stringResource(Res.string.chapter, progress.chapter.index)) },
- supportingContent = {
- Text(stringResource(Res.string.chunks_translated, progress.translatedChunks, progress.totalChunks))
- }
- )
- }
- }
- }
-
- item { HorizontalDivider() }
-
- // Details
- item {
- Text(
- text = stringResource(Res.string.details),
- style = MaterialTheme.typography.labelMedium
- )
- }
- item {
- Card {
- DetailRow(label = "Name", value = translation.name)
- DetailRow(label = "Dialect", value = translation.dialectId)
- DetailRow(label = "Visibility", value = translation.visibility)
- DetailRow(label = "License", value = translation.license)
- DetailRow(label = "Source version", value = translation.artifactVersionId)
- DetailRow(label = "Author", value = translation.publicKey)
- DetailRow(label = "Created", value = translation.createdAt.toString())
- }
- }
- }
- }
- }
-
- TranslationArtifactVersionDetailUIState.Loading -> {
- Column(
- modifier = Modifier.fillMaxWidth().padding(MaterialTheme.spacing.space250),
- horizontalAlignment = Alignment.CenterHorizontally,
- verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space250)
- ) {
- Spacer(modifier = Modifier.weight(1f))
- Text(
- text = stringResource(Res.string.translation_detail),
- style = MaterialTheme.typography.bodyLarge,
- textAlign = TextAlign.Center
- )
- LoadingDataIndicator(fillScreen = false)
- Spacer(modifier = Modifier.weight(2f))
- }
- }
- }
- }
-
- LaunchedEffect(true) {
- if (initialTranslationArtifactVersionDetailUIState == TranslationArtifactVersionDetailUIState.Loading) {
- translationDetailViewModel.initiateTranslationArtifactVersionDetail()
- }
- }
-}
-
-@ConformancePreviews
-@Composable
-private fun TranslationArtifactVersionDetailScreenPreview() {
- BennuTheme {
- Surface(modifier = Modifier.fillMaxSize()) {
- TranslationArtifactVersionDetailScreen(
- activeUserPublicKey = "",
- translationArtifactVersionId = "translationId",
- chatRoomId = "chatRoomId",
- relayHint = null,
- initialTranslationArtifactVersionDetailUIState = TranslationArtifactVersionDetailUIState.Loaded(
- translation = MantraTranslationArtifactVersion(
- id = "translationId",
- publicKey = "author",
- artifactVersionId = "versionId",
- dialectId = "dialectId",
- name = "Sesotho",
- visibility = "private",
- license = "cc",
- signature = "",
- chatRoomId = "chatRoomId"
- )
- ),
- mantraRepository = MantraRepository.NO_OP_MANTRA_REPOSITORY,
- chatRepository = ChatRepository.NO_OP_CHAT_REPOSITORY,
- frostSigningRepository = FrostSigningRepository.NO_OP_FROST_SIGNING_REPOSITORY,
- onNavigateToRoute = {},
- onNavigateBack = {}
- )
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/TranslationChapterScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/TranslationChapterScreen.kt
deleted file mode 100644
index 2c1a0b88..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/TranslationChapterScreen.kt
+++ /dev/null
@@ -1,279 +0,0 @@
-package com.machankura.bennu.compose.ui.composable
-
-import androidx.compose.foundation.clickable
-import androidx.compose.foundation.layout.Arrangement
-import androidx.compose.foundation.layout.Box
-import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.IntrinsicSize
-import androidx.compose.foundation.layout.Row
-import androidx.compose.foundation.layout.Spacer
-import androidx.compose.foundation.layout.fillMaxHeight
-import androidx.compose.foundation.layout.fillMaxSize
-import androidx.compose.foundation.layout.fillMaxWidth
-import androidx.compose.foundation.layout.height
-import androidx.compose.foundation.layout.padding
-import androidx.compose.foundation.lazy.LazyColumn
-import androidx.compose.foundation.lazy.items
-import androidx.compose.material.icons.Icons
-import androidx.compose.material.icons.filled.ChevronRight
-import androidx.compose.material3.ExperimentalMaterial3Api
-import androidx.compose.material3.HorizontalDivider
-import androidx.compose.material3.Icon
-import androidx.compose.material3.MaterialTheme
-import androidx.compose.material3.Scaffold
-import androidx.compose.material3.Surface
-import androidx.compose.material3.Text
-import androidx.compose.material3.TopAppBar
-import androidx.compose.material3.VerticalDivider
-import androidx.compose.material3.minimumInteractiveComponentSize
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.LaunchedEffect
-import androidx.compose.ui.Alignment
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.text.font.FontWeight
-import androidx.compose.ui.text.style.TextAlign
-import androidx.compose.ui.unit.dp
-import androidx.lifecycle.viewmodel.compose.viewModel
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.machankura.bennu.compose.database.model.MantraChunk
-import com.machankura.bennu.compose.repository.MantraRepository
-import com.machankura.bennu.compose.ui.composable.navigation.routes.Route
-import com.machankura.bennu.compose.ui.composable.navigation.routes.TranslateChunkRoute
-import com.machankura.bennu.compose.ui.composable.widgets.LoadingDataIndicator
-import com.machankura.bennu.compose.ui.theme.BennuTheme
-import com.machankura.bennu.compose.ui.view.model.TranslationChapterViewModel
-import com.machankura.bennu.compose.ui.view.state.ChunkTranslationPair
-import com.machankura.bennu.compose.ui.view.state.TranslationChapterUIState
-import com.machankura.bennu.compose.ui.theme.spacing
-import bennu.composeapp.generated.resources.Res
-import org.jetbrains.compose.resources.stringResource
-import bennu.composeapp.generated.resources.chapter_translation
-import bennu.composeapp.generated.resources.this_chapter_has_no_chunks
-import androidx.compose.material3.SnackbarHost
-import com.machankura.bennu.compose.ui.composable.widgets.LocalSnackbarHostState
-import com.machankura.bennu.compose.ui.theme.readableContent
-import com.machankura.bennu.compose.ui.composable.widgets.ScreenStateTransition
-import com.machankura.bennu.compose.ui.composable.widgets.NavigateBackButton
-import com.machankura.bennu.compose.ui.theme.ConformancePreviews
-
-@OptIn(ExperimentalMaterial3Api::class)
-@Composable
-fun TranslationChapterScreen(
- activeUserPublicKey: HexKey,
- translationChapterId: String,
- chatRoomId: String,
- relayHint: String?,
- initialTranslationChapterUIState: TranslationChapterUIState = TranslationChapterUIState.Loading,
- mantraRepository: MantraRepository,
- onNavigateToRoute: (Route) -> Unit,
- onNavigateBack: () -> Unit,
-) {
- val translationChapterViewModel: TranslationChapterViewModel = viewModel(
- factory = TranslationChapterViewModel.factory(
- activeUserPublicKey = activeUserPublicKey,
- translationChapterId = translationChapterId,
- chatRoomId = chatRoomId,
- relayHint = relayHint,
- initialTranslationChapterUIState = initialTranslationChapterUIState,
- mantraRepository = mantraRepository,
- )
- )
-
- ScreenStateTransition(translationChapterViewModel.translationChapterUIState) { uiState ->
- when (val translationChapterUIState = uiState) {
- is TranslationChapterUIState.Error -> {
- Column(
- modifier = Modifier.fillMaxWidth(),
- horizontalAlignment = Alignment.CenterHorizontally
- ) {
- Spacer(modifier = Modifier.height(MaterialTheme.spacing.space600))
- Text(text = translationChapterUIState.message)
- }
- }
-
- is TranslationChapterUIState.Loaded -> {
- Scaffold(
- snackbarHost = { SnackbarHost(LocalSnackbarHostState.current) },
- topBar = {
- TopAppBar(
- title = { Text(stringResource(Res.string.chapter_translation)) },
- navigationIcon = { NavigateBackButton(onNavigateBack) },
- )
- }
- ) { innerPadding ->
- LazyColumn(
- modifier = Modifier.padding(innerPadding).readableContent().fillMaxSize()
- ) {
- // Header row: dialect names.
- item {
- TableRow(
- left = {
- Text(
- text = translationChapterUIState.originalDialectName,
- fontWeight = FontWeight.Bold
- )
- },
- right = {
- Text(
- text = translationChapterUIState.translationDialectName,
- fontWeight = FontWeight.Bold
- )
- },
- )
- HorizontalDivider()
- }
-
- if (translationChapterUIState.rows.isEmpty()) {
- item {
- Box(
- modifier = Modifier.fillMaxWidth().padding(MaterialTheme.spacing.containerPadding),
- contentAlignment = Alignment.Center
- ) {
- Text(stringResource(Res.string.this_chapter_has_no_chunks))
- }
- }
- } else {
- items(
- items = translationChapterUIState.rows,
- key = { pair -> pair.originalChunk.id }
- ) { pair ->
- ChunkTranslationRow(
- pair = pair,
- onClick = {
- onNavigateToRoute.invoke(
- TranslateChunkRoute(
- activeUserPublicKey = activeUserPublicKey,
- translationChapterId = translationChapterId,
- chunkId = pair.originalChunk.id,
- chatRoomId = chatRoomId,
- relayHint = relayHint
- )
- )
- }
- )
- HorizontalDivider()
- }
- }
- }
- }
- }
-
- TranslationChapterUIState.Loading -> {
- Column(
- modifier = Modifier.fillMaxWidth().padding(MaterialTheme.spacing.space250),
- horizontalAlignment = Alignment.CenterHorizontally,
- verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space250)
- ) {
- Spacer(modifier = Modifier.weight(1f))
- Text(
- text = stringResource(Res.string.chapter_translation),
- style = MaterialTheme.typography.bodyLarge,
- textAlign = TextAlign.Center
- )
- LoadingDataIndicator(fillScreen = false)
- Spacer(modifier = Modifier.weight(2f))
- }
- }
- }
- }
-
- LaunchedEffect(true) {
- if (initialTranslationChapterUIState == TranslationChapterUIState.Loading) {
- translationChapterViewModel.initiateTranslationChapter()
- }
- }
-}
-
-@Composable
-private fun ChunkTranslationRow(
- pair: ChunkTranslationPair,
- onClick: () -> Unit,
-) {
- val translated = pair.translationChunk?.text?.takeIf { it.isNotBlank() }
- TableRow(
- left = { Text(pair.originalChunk.text) },
- // The whole translation cell opens the chunk translation editor. When
- // there is no translation yet, the original text is shown greyed out as
- // a placeholder. It stays plain text, laid out like the original cell
- // beside it, rather than a button with its own shape and padding.
- rightModifier = Modifier.minimumInteractiveComponentSize()
- .clickable(onClick = onClick),
- right = {
- Row(verticalAlignment = Alignment.CenterVertically) {
- Text(
- modifier = Modifier.weight(1f),
- text = translated ?: pair.originalChunk.text,
- color = if (translated != null) {
- MaterialTheme.colorScheme.onSurface
- } else {
- MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
- }
- )
- Icon(
- Icons.Default.ChevronRight,
- contentDescription = "Translate this chunk",
- tint = MaterialTheme.colorScheme.onSurfaceVariant
- )
- }
- },
- )
-}
-
-@Composable
-private fun TableRow(
- left: @Composable () -> Unit,
- right: @Composable () -> Unit,
- rightModifier: Modifier = Modifier,
-) {
- Row(
- modifier = Modifier.fillMaxWidth().height(IntrinsicSize.Min)
- ) {
- Box(modifier = Modifier.weight(1f).padding(MaterialTheme.spacing.space150)) { left() }
- VerticalDivider(modifier = Modifier.fillMaxHeight())
- Box(modifier = Modifier.weight(1f).then(rightModifier).padding(MaterialTheme.spacing.space150)) { right() }
- }
-}
-
-@ConformancePreviews
-@Composable
-private fun TranslationChapterScreenPreview() {
- BennuTheme {
- Surface(modifier = Modifier.fillMaxSize()) {
- TranslationChapterScreen(
- activeUserPublicKey = "",
- translationChapterId = "translationChapterId",
- chatRoomId = "chatRoomId",
- relayHint = null,
- initialTranslationChapterUIState = TranslationChapterUIState.Loaded(
- originalDialectName = "English",
- translationDialectName = "Sesotho",
- rows = listOf(
- ChunkTranslationPair(
- originalChunk = sampleChunk("c1", "When he was nearly thirteen, my brother Jem got his arm badly broken."),
- translationChunk = null
- ),
- ChunkTranslationPair(
- originalChunk = sampleChunk("c2", "When enough years had gone by to enable us to look back on them..."),
- translationChunk = null
- ),
- )
- ),
- mantraRepository = MantraRepository.NO_OP_MANTRA_REPOSITORY,
- onNavigateToRoute = {},
- onNavigateBack = {}
- )
- }
- }
-}
-
-private fun sampleChunk(id: String, text: String) = MantraChunk(
- id = id,
- chapterId = "chapterId",
- publicKey = "author",
- text = text,
- index = 0,
- wordCount = 0,
- characterCount = 0,
- signature = "",
- chatRoomId = "chatRoomId"
-)
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/BennuNavHost.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/BennuNavHost.kt
index b1601927..2e31db87 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/BennuNavHost.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/BennuNavHost.kt
@@ -40,6 +40,7 @@ import com.machankura.bennu.compose.ui.composable.ChatRoomDetailScreen
import com.machankura.bennu.compose.ui.composable.ChatRoomMessagingScreen
import com.machankura.bennu.compose.ui.composable.CreateProfileScreen
import com.machankura.bennu.compose.ui.composable.DkgJoinApprovalScreen
+import com.machankura.bennu.compose.ui.composable.CreateSharedKeyScreen
import com.machankura.bennu.compose.ui.composable.DkgRitualScreen
import com.machankura.bennu.compose.ui.composable.DkgRound1ApprovalScreen
import com.machankura.bennu.compose.ui.composable.DkgRound2ApprovalScreen
@@ -86,6 +87,7 @@ import com.machankura.bennu.compose.ui.composable.navigation.routes.ChatRoomDeta
import com.machankura.bennu.compose.ui.composable.navigation.routes.ChatRoomMessagingRoute
import com.machankura.bennu.compose.ui.composable.navigation.routes.CreateProfileRoute
import com.machankura.bennu.compose.ui.composable.navigation.routes.DkgJoinApprovalRoute
+import com.machankura.bennu.compose.ui.composable.navigation.routes.CreateSharedKeyRoute
import com.machankura.bennu.compose.ui.composable.navigation.routes.DkgRitualRoute
import com.machankura.bennu.compose.ui.composable.navigation.routes.DkgRound1ApprovalRoute
import com.machankura.bennu.compose.ui.composable.navigation.routes.DkgRound2ApprovalRoute
@@ -143,10 +145,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
-import com.machankura.bennu.compose.database.repository.DatabaseMantraRepository
-import com.machankura.bennu.compose.ui.composable.AddArtifactScreen
-import com.machankura.bennu.compose.ui.composable.navigation.routes.AddArtifactRoute
-import com.machankura.bennu.compose.ui.composable.navigation.routes.AddDialectRoute
import com.machankura.bennu.compose.ui.composable.navigation.routes.EditGroupNostrProfileRoute
import com.machankura.bennu.compose.ui.composable.navigation.routes.AddGroupPostRoute
import com.machankura.bennu.compose.ui.composable.navigation.routes.BroadcastGroupSignedEventRoute
@@ -162,23 +160,8 @@ import fr.acinq.phoenix.managers.NodeParamsManager
import com.machankura.bennu.compose.ui.composable.navigation.routes.GroupPostsRoute
import com.machankura.bennu.compose.ui.composable.navigation.routes.FrostSigningRoute
import com.machankura.bennu.compose.ui.composable.navigation.routes.ProposalListRoute
-import com.machankura.bennu.compose.ui.composable.navigation.routes.AddChapterRoute
-import com.machankura.bennu.compose.ui.composable.navigation.routes.AddTranslationRoute
-import com.machankura.bennu.compose.ui.composable.navigation.routes.ArtifactDetailRoute
-import com.machankura.bennu.compose.ui.composable.navigation.routes.ChapterDetailRoute
-import com.machankura.bennu.compose.ui.composable.navigation.routes.TranslateChunkRoute
-import com.machankura.bennu.compose.ui.composable.navigation.routes.TranslationChapterRoute
-import com.machankura.bennu.compose.ui.composable.navigation.routes.TranslationArtifactVersionDetailRoute
-import com.machankura.bennu.compose.ui.composable.ArtifactDetailScreen
-import com.machankura.bennu.compose.ui.composable.AddChapterScreen
-import com.machankura.bennu.compose.ui.composable.AddDialectScreen
import com.machankura.bennu.compose.ui.composable.FrostSigningScreen
import com.machankura.bennu.compose.ui.composable.ProposalListScreen
-import com.machankura.bennu.compose.ui.composable.AddTranslationArtifactVersionScreen
-import com.machankura.bennu.compose.ui.composable.ChapterDetailScreen
-import com.machankura.bennu.compose.ui.composable.TranslateChunkScreen
-import com.machankura.bennu.compose.ui.composable.TranslationChapterScreen
-import com.machankura.bennu.compose.ui.composable.TranslationArtifactVersionDetailScreen
@Composable
fun BennuNavHost(
@@ -247,12 +230,6 @@ fun BennuNavHost(
applicationIOScope
)
}
- val databaseMantraRepository = remember {
- DatabaseMantraRepository(
- database = auxDatabaseManager.auxDatabase,
- applicationIOScope
- )
- }
val searchRepository = remember {
DatabaseSearchRepository(
@@ -637,6 +614,7 @@ fun BennuNavHost(
SelectSubgroupAdminsScreen(
activeUserPublicKey = route.activeUserPublicKey,
parentChatRoomId = route.parentChatRoomId,
+ retrying = route.retrying,
activeIdentityStateFlow = sovereignWalletViewModel.activeIdentity,
chatRepository = databaseChatRepository,
dkgRepository = databaseDkgRepository,
@@ -648,6 +626,32 @@ fun BennuNavHost(
}
)
}
+ composable { backStackEntry ->
+ val route = backStackEntry.toRoute()
+
+ CreateSharedKeyScreen(
+ activeUserPublicKey = route.activeUserPublicKey,
+ chatRoomId = route.chatRoomId,
+ activeIdentityStateFlow = sovereignWalletViewModel.activeIdentity,
+ chatRepository = databaseChatRepository,
+ dkgRepository = databaseDkgRepository,
+ // Replaces this screen with the ceremony, whether it was just
+ // opened or was already there, so back from the ceremony goes
+ // wherever the member came from rather than to a second offer.
+ onCeremonyOpened = { dkgSessionId ->
+ navController.navigate(
+ DkgRitualRoute(
+ activeUserPublicKey = route.activeUserPublicKey,
+ chatRoomId = route.chatRoomId,
+ dkgSessionId = dkgSessionId
+ )
+ ) {
+ popUpTo { inclusive = true }
+ }
+ },
+ onNavigateBack = { navController.popBackStack() }
+ )
+ }
composable { backStackEntry ->
val route = backStackEntry.toRoute()
@@ -1077,7 +1081,6 @@ fun BennuNavHost(
relayHint = route.relayHint,
nostrRepository = databaseNostrRepository,
chatRepository = databaseChatRepository,
- mantraRepository = databaseMantraRepository,
onNavigateToRoute = { actionRoute ->
navController.navigate(
route = actionRoute
@@ -1140,67 +1143,6 @@ fun BennuNavHost(
},
)
}
- composable { backStackEntry ->
- val route = backStackEntry.toRoute()
-
- AddArtifactScreen(
- activeUserPublicKey = route.activeUserPublicKey,
- chatRoomId = route.chatRoomId,
- relayHint = route.relayHint,
- nostrRepository = databaseNostrRepository,
- chatRepository = databaseChatRepository,
- mantraRepository = databaseMantraRepository,
- frostSigningRepository = databaseFrostSigningRepository,
- onNavigateToRouteAndPopUpInclusive = { signingRoute ->
- // Replace this add screen so back returns to the group rather
- // than to a form whose proposal has already gone out.
- navController.navigate(
- route = signingRoute
- ) {
- popUpTo(route) {
- inclusive = true
- }
- }
- },
- onNavigateToRoute = { actionRoute ->
- navController.navigate(
- route = actionRoute
- )
- },
- onNavigateBack = {
- navController.popBackStack()
- }
- )
- }
- composable { backStackEntry ->
- val route = backStackEntry.toRoute()
-
- AddDialectScreen(
- activeUserPublicKey = route.activeUserPublicKey,
- chatRoomId = route.chatRoomId,
- relayHint = route.relayHint,
- nostrRepository = databaseNostrRepository,
- chatRepository = databaseChatRepository,
- frostSigningRepository = databaseFrostSigningRepository,
- onNavigateToRouteAndPopUpInclusive = { signingRoute ->
- // Replace this add screen so back returns to the group rather
- // than to a form whose proposal has already gone out.
- navController.navigate(route = signingRoute) {
- popUpTo {
- inclusive = true
- }
- }
- },
- onNavigateToRoute = { actionRoute ->
- navController.navigate(
- route = actionRoute
- )
- },
- onNavigateBack = {
- navController.popBackStack()
- }
- )
- }
composable { backStackEntry ->
val route = backStackEntry.toRoute()
@@ -1447,170 +1389,6 @@ fun BennuNavHost(
initialFilter = route.filter
)
}
- composable { backStackEntry ->
- val route = backStackEntry.toRoute()
-
- ArtifactDetailScreen(
- activeUserPublicKey = route.activeUserPublicKey,
- artifactId = route.artifactId,
- chatRoomId = route.chatRoomId,
- relayHint = route.relayHint,
- mantraRepository = databaseMantraRepository,
- onNavigateToRoute = { actionRoute ->
- navController.navigate(
- route = actionRoute
- )
- },
- onNavigateBack = {
- navController.popBackStack()
- }
- )
- }
- composable { backStackEntry ->
- val route = backStackEntry.toRoute()
-
- ChapterDetailScreen(
- activeUserPublicKey = route.activeUserPublicKey,
- chapterId = route.chapterId,
- chatRoomId = route.chatRoomId,
- relayHint = route.relayHint,
- mantraRepository = databaseMantraRepository,
- onNavigateBack = {
- navController.popBackStack()
- }
- )
- }
- composable { backStackEntry ->
- val route = backStackEntry.toRoute()
-
- TranslationArtifactVersionDetailScreen(
- activeUserPublicKey = route.activeUserPublicKey,
- translationArtifactVersionId = route.translationArtifactVersionId,
- chatRoomId = route.chatRoomId,
- relayHint = route.relayHint,
- mantraRepository = databaseMantraRepository,
- chatRepository = databaseChatRepository,
- frostSigningRepository = databaseFrostSigningRepository,
- onNavigateToRoute = { actionRoute ->
- navController.navigate(
- route = actionRoute
- )
- },
- onNavigateBack = {
- navController.popBackStack()
- }
- )
- }
- composable { backStackEntry ->
- val route = backStackEntry.toRoute()
-
- TranslationChapterScreen(
- activeUserPublicKey = route.activeUserPublicKey,
- translationChapterId = route.translationChapterId,
- chatRoomId = route.chatRoomId,
- relayHint = route.relayHint,
- mantraRepository = databaseMantraRepository,
- onNavigateToRoute = { actionRoute ->
- navController.navigate(
- route = actionRoute
- )
- },
- onNavigateBack = {
- navController.popBackStack()
- }
- )
- }
- composable { backStackEntry ->
- val route = backStackEntry.toRoute()
-
- TranslateChunkScreen(
- activeUserPublicKey = route.activeUserPublicKey,
- translationChapterId = route.translationChapterId,
- chunkId = route.chunkId,
- chatRoomId = route.chatRoomId,
- relayHint = route.relayHint,
- mantraRepository = databaseMantraRepository,
- chatRepository = databaseChatRepository,
- frostSigningRepository = databaseFrostSigningRepository,
- onNavigateToRouteAndPopUpInclusive = { signingRoute ->
- // Replace this editor so back returns to the chapter table
- // rather than to a form whose proposal has already gone out.
- // The table itself is left alone: nothing is translated until
- // the group signs, so there is nothing new for it to show.
- navController.navigate(route = signingRoute) {
- popUpTo {
- inclusive = true
- }
- }
- },
- onNavigateToRoute = { actionRoute ->
- navController.navigate(route = actionRoute)
- },
- onNavigateBack = {
- navController.popBackStack()
- }
- )
- }
- composable { backStackEntry ->
- val route = backStackEntry.toRoute()
-
- AddTranslationArtifactVersionScreen(
- activeUserPublicKey = route.activeUserPublicKey,
- artifactId = route.artifactId,
- chatRoomId = route.chatRoomId,
- relayHint = route.relayHint,
- mantraRepository = databaseMantraRepository,
- chatRepository = databaseChatRepository,
- frostSigningRepository = databaseFrostSigningRepository,
- onNavigateToRouteAndPopUpInclusive = { signingRoute ->
- // Replace this screen so back returns to the artifact rather
- // than to a form whose proposal has already gone out.
- navController.navigate(route = signingRoute) {
- popUpTo {
- inclusive = true
- }
- }
- },
- onNavigateToRoute = { actionRoute ->
- navController.navigate(
- route = actionRoute
- )
- },
- onNavigateBack = {
- navController.popBackStack()
- }
- )
- }
- composable { backStackEntry ->
- val route = backStackEntry.toRoute()
-
- AddChapterScreen(
- activeUserPublicKey = route.activeUserPublicKey,
- artifactId = route.artifactId,
- chatRoomId = route.chatRoomId,
- relayHint = route.relayHint,
- mantraRepository = databaseMantraRepository,
- chatRepository = databaseChatRepository,
- frostSigningRepository = databaseFrostSigningRepository,
- onNavigateToRouteAndPopUpInclusive = { signingRoute ->
- // Replace this add screen so back returns to the artifact
- // rather than to a form whose proposal has already gone out.
- navController.navigate(route = signingRoute) {
- popUpTo {
- inclusive = true
- }
- }
- },
- onNavigateToRoute = { actionRoute ->
- navController.navigate(
- route = actionRoute
- )
- },
- onNavigateBack = {
- navController.popBackStack()
- }
- )
- }
composable { backStackEntry ->
val route = backStackEntry.toRoute()
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/AddArtifactRoute.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/AddArtifactRoute.kt
deleted file mode 100755
index 5c481e8f..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/AddArtifactRoute.kt
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.machankura.bennu.compose.ui.composable.navigation.routes
-
-import kotlinx.serialization.Serializable
-
-@Serializable
-data class AddArtifactRoute(
- val activeUserPublicKey: String,
- val chatRoomId: String, // TODO: have this as a publicKey
- val relayHint: String?
-): Route()
\ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/AddChapterRoute.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/AddChapterRoute.kt
deleted file mode 100644
index c6d2dfa8..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/AddChapterRoute.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.machankura.bennu.compose.ui.composable.navigation.routes
-
-import kotlinx.serialization.Serializable
-
-@Serializable
-data class AddChapterRoute(
- val activeUserPublicKey: String,
- val artifactId: String,
- val chatRoomId: String,
- val relayHint: String?
-): Route()
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/AddDialectRoute.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/AddDialectRoute.kt
deleted file mode 100644
index 6ef108c4..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/AddDialectRoute.kt
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.machankura.bennu.compose.ui.composable.navigation.routes
-
-import kotlinx.serialization.Serializable
-
-@Serializable
-data class AddDialectRoute(
- val activeUserPublicKey: String,
- val chatRoomId: String, // TODO: have this as a publicKey
- val relayHint: String?
-): Route()
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/AddTranslationRoute.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/AddTranslationRoute.kt
deleted file mode 100644
index ecaaa079..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/AddTranslationRoute.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.machankura.bennu.compose.ui.composable.navigation.routes
-
-import kotlinx.serialization.Serializable
-
-@Serializable
-data class AddTranslationRoute(
- val activeUserPublicKey: String,
- val artifactId: String,
- val chatRoomId: String,
- val relayHint: String?
-): Route()
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/ArtifactDetailRoute.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/ArtifactDetailRoute.kt
deleted file mode 100644
index 64d9574e..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/ArtifactDetailRoute.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.machankura.bennu.compose.ui.composable.navigation.routes
-
-import kotlinx.serialization.Serializable
-
-@Serializable
-data class ArtifactDetailRoute(
- val activeUserPublicKey: String,
- val artifactId: String,
- val chatRoomId: String,
- val relayHint: String?
-): Route()
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/ChapterDetailRoute.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/ChapterDetailRoute.kt
deleted file mode 100644
index 605e6395..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/ChapterDetailRoute.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.machankura.bennu.compose.ui.composable.navigation.routes
-
-import kotlinx.serialization.Serializable
-
-@Serializable
-data class ChapterDetailRoute(
- val activeUserPublicKey: String,
- val chapterId: String,
- val chatRoomId: String,
- val relayHint: String?
-): Route()
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/CreateSharedKeyRoute.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/CreateSharedKeyRoute.kt
new file mode 100644
index 00000000..6e81c652
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/CreateSharedKeyRoute.kt
@@ -0,0 +1,19 @@
+package com.machankura.bennu.compose.ui.composable.navigation.routes
+
+import kotlinx.serialization.Serializable
+
+/**
+ * Starting a NIP-17 group's own key ceremony, and nothing else.
+ *
+ * The one place a group that has no key yet asks for one. Group creation and
+ * the subgroup picker start their own ceremonies because they already know what
+ * each is for; this is for a group that exists and has none. The ceremony screen
+ * that follows only ever shows a ceremony -- it used to offer to start one too,
+ * from the same button the approvals used, which is how a member joining a
+ * subgroup's ceremony opened a second. See docs/ceremony-creation.md.
+ */
+@Serializable
+data class CreateSharedKeyRoute(
+ val activeUserPublicKey: String,
+ val chatRoomId: String,
+): Route()
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/DkgJoinApprovalRoute.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/DkgJoinApprovalRoute.kt
index 64e5e00d..b757b139 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/DkgJoinApprovalRoute.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/DkgJoinApprovalRoute.kt
@@ -14,6 +14,6 @@ import kotlinx.serialization.Serializable
data class DkgJoinApprovalRoute(
val activeUserPublicKey: String,
val chatRoomId: String,
- /** The ceremony being approved; null takes the room's newest. */
- val dkgSessionId: String? = null
+ /** The ceremony being approved. Required, for the reason `DkgRitualRoute`'s is. */
+ val dkgSessionId: String
): Route()
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/DkgRitualRoute.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/DkgRitualRoute.kt
index bb4763fb..1da46e3b 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/DkgRitualRoute.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/DkgRitualRoute.kt
@@ -3,7 +3,7 @@ package com.machankura.bennu.compose.ui.composable.navigation.routes
import kotlinx.serialization.Serializable
/**
- * The shared-key ceremony for one NIP-17 group.
+ * One shared-key ceremony, shown and never started.
*
* Deliberately says nothing about *what the ceremony is for*. A subgroup's
* ceremony grows the ladder by a rung -- the parent's birth certificate -- and
@@ -17,13 +17,15 @@ data class DkgRitualRoute(
val activeUserPublicKey: String,
val chatRoomId: String,
/**
- * Which of the room's ceremonies to show, when the caller knows.
+ * Which of the room's ceremonies to show. Required: this screen shows a
+ * ceremony and never offers to start one, so a caller without a ceremony to
+ * name is asking to start one and goes to `CreateSharedKeyRoute` instead.
*
- * A room can hold more than one -- a subgroup whose admins are the whole
- * group runs in the room the group's own ceremony ran in -- so "the room's
- * ceremony" does not name one thing. A transcript line knows which it is
- * about and passes it; a caller with only a room passes null and gets the
- * newest, which is the best answer available to it.
+ * A room can hold more than one -- a parent's room hosts every subgroup
+ * ceremony the group runs -- so "the room's ceremony" does not name one
+ * thing, and falling back to the newest is how a second, whole-room ceremony
+ * once ended up on the screen in place of a subgroup's. See
+ * docs/ceremony-creation.md.
*/
- val dkgSessionId: String? = null
+ val dkgSessionId: String
): Route()
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/DkgRound1ApprovalRoute.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/DkgRound1ApprovalRoute.kt
index f3c18ea2..ec2fbc97 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/DkgRound1ApprovalRoute.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/DkgRound1ApprovalRoute.kt
@@ -14,6 +14,6 @@ import kotlinx.serialization.Serializable
data class DkgRound1ApprovalRoute(
val activeUserPublicKey: String,
val chatRoomId: String,
- /** The ceremony being approved; null takes the room's newest. */
- val dkgSessionId: String? = null
+ /** The ceremony being approved. Required, for the reason `DkgRitualRoute`'s is. */
+ val dkgSessionId: String
): Route()
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/DkgRound2ApprovalRoute.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/DkgRound2ApprovalRoute.kt
index cf55bccc..be82d781 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/DkgRound2ApprovalRoute.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/DkgRound2ApprovalRoute.kt
@@ -14,6 +14,6 @@ import kotlinx.serialization.Serializable
data class DkgRound2ApprovalRoute(
val activeUserPublicKey: String,
val chatRoomId: String,
- /** The ceremony being approved; null takes the room's newest. */
- val dkgSessionId: String? = null
+ /** The ceremony being approved. Required, for the reason `DkgRitualRoute`'s is. */
+ val dkgSessionId: String
): Route()
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/SelectSubgroupAdminsRoute.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/SelectSubgroupAdminsRoute.kt
index 4a15b10e..ffab974d 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/SelectSubgroupAdminsRoute.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/SelectSubgroupAdminsRoute.kt
@@ -16,5 +16,12 @@ import kotlinx.serialization.Serializable
data class SelectSubgroupAdminsRoute(
val activeUserPublicKey: String,
val parentChatRoomId: String,
- val relayHint: String? = null
+ val relayHint: String? = null,
+ /**
+ * A failed subgroup ceremony this is trying again, whose name, admins and
+ * quorum the picker starts from. Every one of them can still be changed, and
+ * every refusal runs again: a retry is a new ceremony, not the old one
+ * resumed.
+ */
+ val retrying: String? = null,
): Route()
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/TranslateChunkRoute.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/TranslateChunkRoute.kt
deleted file mode 100644
index f377c1ae..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/TranslateChunkRoute.kt
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.machankura.bennu.compose.ui.composable.navigation.routes
-
-import kotlinx.serialization.Serializable
-
-@Serializable
-data class TranslateChunkRoute(
- val activeUserPublicKey: String,
- val translationChapterId: String,
- val chunkId: String,
- val chatRoomId: String,
- val relayHint: String?
-): Route()
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/TranslationArtifactVersionDetailRoute.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/TranslationArtifactVersionDetailRoute.kt
deleted file mode 100644
index c3150b4c..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/TranslationArtifactVersionDetailRoute.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.machankura.bennu.compose.ui.composable.navigation.routes
-
-import kotlinx.serialization.Serializable
-
-@Serializable
-data class TranslationArtifactVersionDetailRoute(
- val activeUserPublicKey: String,
- val translationArtifactVersionId: String,
- val chatRoomId: String,
- val relayHint: String?
-): Route()
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/TranslationChapterRoute.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/TranslationChapterRoute.kt
deleted file mode 100644
index 8133a75b..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/routes/TranslationChapterRoute.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.machankura.bennu.compose.ui.composable.navigation.routes
-
-import kotlinx.serialization.Serializable
-
-@Serializable
-data class TranslationChapterRoute(
- val activeUserPublicKey: String,
- val translationChapterId: String,
- val chatRoomId: String,
- val relayHint: String?
-): Route()
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/widgets/DetailRow.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/widgets/DetailRow.kt
deleted file mode 100644
index bfb75ffc..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/widgets/DetailRow.kt
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.machankura.bennu.compose.ui.composable.widgets
-
-import androidx.compose.material3.ListItem
-import androidx.compose.material3.Text
-import androidx.compose.runtime.Composable
-
-/** A labelled value row for detail screens (label above, value below). */
-@Composable
-fun DetailRow(label: String, value: String) {
- ListItem(
- overlineContent = { Text(label) },
- headlineContent = { Text(value) }
- )
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/widgets/chat/ChatTranscript.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/widgets/chat/ChatTranscript.kt
index b3cf1793..074ad720 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/widgets/chat/ChatTranscript.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/widgets/chat/ChatTranscript.kt
@@ -110,7 +110,7 @@ import com.machankura.bennu.compose.ui.composable.widgets.ErrorState
@Composable
fun ChatTranscript(
viewModel: ChatMessageListViewModel,
- onOpenSharedKey: (dkgSessionId: String?) -> Unit,
+ onOpenSharedKey: (dkgSessionId: String) -> Unit,
/**
* Opens the signing this line is about, by session id -- or the room's
* whole list of proposals when the line predates [ChatMessage.frostSigningSessionId]
@@ -265,9 +265,13 @@ fun ChatTranscript(
// The line knows which ceremony it is
// about; the room does not. Passing it is
// what stops a subgroup's request opening
- // the group's own finished ceremony.
- onClick = {
- onOpenSharedKey(localChatMessage.chatMessage.dkgSessionId)
+ // the group's own finished ceremony. A
+ // line that names none opens nothing: the
+ // ceremony screen shows the ceremony it is
+ // named, and guessing one is how a
+ // subgroup's got buried under another.
+ onClick = localChatMessage.chatMessage.dkgSessionId?.let { dkgSessionId ->
+ { onOpenSharedKey(dkgSessionId) }
}
)
return@items
@@ -792,7 +796,8 @@ private fun RitualNotice(
localChatMessage: LocalChatMessage,
isAnswered: Boolean,
isSettled: Boolean,
- onClick: () -> Unit,
+ /** Null for a line that names no ceremony, which then opens nothing. */
+ onClick: (() -> Unit)?,
) {
val chatMessage = localChatMessage.chatMessage
@@ -875,7 +880,7 @@ private fun RitualNotice(
modifier = Modifier
.fillMaxWidth()
.minimumInteractiveComponentSize()
- .clickable(onClick = onClick)
+ .clickable(enabled = onClick != null) { onClick?.invoke() }
.padding(horizontal = MaterialTheme.spacing.space250, vertical = MaterialTheme.spacing.space125),
horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.space125),
verticalAlignment = Alignment.CenterVertically
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/AddArtifactViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/AddArtifactViewModel.kt
deleted file mode 100644
index bad5507c..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/AddArtifactViewModel.kt
+++ /dev/null
@@ -1,186 +0,0 @@
-package com.machankura.bennu.compose.ui.view.model
-
-import androidx.compose.foundation.text.input.TextFieldState
-import androidx.compose.foundation.text.input.clearText
-import androidx.compose.runtime.MutableState
-import androidx.compose.runtime.getValue
-import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.setValue
-import androidx.lifecycle.ViewModel
-import androidx.lifecycle.ViewModelProvider
-import androidx.lifecycle.viewModelScope
-import androidx.lifecycle.viewmodel.initializer
-import androidx.lifecycle.viewmodel.viewModelFactory
-import com.machankura.bennu.compose.repository.ChatRepository
-import com.machankura.bennu.compose.repository.NostrRepository
-import co.touchlab.kermit.Logger
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.IO
-import kotlinx.coroutines.launch
-import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
-import com.machankura.bennu.compose.nostr.nip30303.ArtifactEvent
-import com.machankura.bennu.compose.nostr.nip30303.ArtifactVersionEvent
-import com.machankura.bennu.compose.repository.FrostSigningRepository
-import com.machankura.bennu.compose.repository.MantraRepository
-import com.machankura.bennu.compose.ui.view.state.AddArtifactUIState
-
-class AddArtifactViewModel(
- val chatRoomId: String,
- val activeUserPublicKey: HexKey,
- val relayHint: String?,
- initialAddArtifactUIState: AddArtifactUIState,
- val nostrRepository: NostrRepository,
- val chatRepository: ChatRepository,
- val mantraRepository: MantraRepository,
- val frostSigningRepository: FrostSigningRepository,
-): ViewModel() {
-
- var addArtifactUIState: AddArtifactUIState by mutableStateOf(initialAddArtifactUIState)
- private set
-
- private val logger = Logger.withTag(TAG)
-
- val isActionPending: MutableState = mutableStateOf(false)
-
- fun initiateChatRoomDetail() {
- logger.d("compressed (most likely chat room): $chatRoomId")
- // Get ChatRoomById
- viewModelScope.launch(Dispatchers.IO) {
- val localChatRoom = chatRepository.getChatRoomByIdentifier(chatRoomId)
-
- addArtifactUIState = if (localChatRoom == null) {
- // Initiate new chat... and navigate to new chat...
- AddArtifactUIState.Error("Couldn't find the chat room")
- } else {
- AddArtifactUIState.Loaded(
- localChatRoom = localChatRoom,
- dialects = mantraRepository.getDialects(localChatRoom.chatRoom.id),
- canSign = frostSigningRepository.canSign(chatRoomId),
- )
- }
- }
- }
-
- /**
- * Asks the group to sign an artifact into its library.
- *
- * The artifact is not created here and does not exist yet. What goes out is
- * a proposal to sign it, and the artifact appears -- on every member's
- * device at once, authored by this room's own key rather than by whoever
- * typed it -- when enough members have signed. That author is the room's id:
- * signing runs at the path the room was derived at, so an artifact says
- * which library it belongs to simply by being signed.
- *
- * That is the difference from submitting one. A submission says "I am
- * putting this in front of the group" and the group's only recourse
- * afterwards is social. A signature is the group saying it, and it takes a
- * quorum to say. A library is the group's, so the second is the honest one.
- *
- * Two events, one session: the artifact and the version it starts life with,
- * which a chapter later hangs off. All-or-nothing, which is right here --
- * an artifact with no version is inert, since nothing can attach to it.
- */
- fun addArtifact(
- localChatRoom: LocalChatRoom,
- nameField: TextFieldState,
- urlField: TextFieldState,
- versionLabelField: TextFieldState,
- dialectId: HexKey?,
- visibility: String = MantraRepository.DEFAULT_VISIBILITY,
- license: String = MantraRepository.DEFAULT_LICENSE,
- onSuccess: (sessionId: String) -> Unit,
- onFailure: () -> Unit
- ) {
- val name = nameField.text.toString()
- val url = urlField.text.toString()
- val versionLabel = versionLabelField.text.toString()
-
- // An artifact requires an existing source dialect; they are signed into
- // existence from the group detail screen, not here.
- if (name.isBlank() || url.isBlank() || versionLabel.isBlank() || dialectId.isNullOrBlank()) {
- onFailure.invoke()
- return
- }
-
- // Guard against double submits from repeated FAB taps.
- if (isActionPending.value) return
- isActionPending.value = true
-
- viewModelScope.launch(Dispatchers.IO) {
- // The label rides on the artifact and the version is signed beside
- // it, in the same batch. A first version proposed on its own would
- // cost a second quorum for one form, which is why it used to be
- // derived on arrival instead; a batch costs one quorum, so the row a
- // chapter hangs off can carry the group's signature rather than
- // being rebuilt from the artifact by every device that holds it.
- val artifactEventTemplate = ArtifactEvent.build(
- name = name,
- url = url,
- visibility = visibility,
- license = license,
- dialectId = dialectId,
- versionLabel = versionLabel,
- )
-
- val session = runCatching {
- frostSigningRepository.proposeSigningBatch(
- localChatRoom = localChatRoom,
- userPublicKey = activeUserPublicKey,
- lead = artifactEventTemplate,
- // The version names the artifact it is of, and that id is a
- // hash over the group's key at the room's path -- neither of
- // which this screen knows or should. The artifact comes back
- // built, and the version is read off the label it declares.
- dependents = ArtifactVersionEvent::initialVersionOf
- )
- }.onFailure { error ->
- logger.e("Failed to propose an artifact for signing", error)
- }.getOrNull()
-
- if (session != null) {
- nameField.clearText()
- urlField.clearText()
- versionLabelField.clearText()
-
- viewModelScope.launch(Dispatchers.Main) {
- onSuccess.invoke(session.id)
- }
- } else {
- viewModelScope.launch(Dispatchers.Main) {
- onFailure.invoke()
- }
- }
-
- isActionPending.value = false
- }
- }
-
- companion object {
- private const val TAG = "AddArtifactViewModel"
-
- fun factory(
- activeUserPublicKey: HexKey,
- chatRoomId: String,
- relayHint: String?,
- initialAddArtifactUIState: AddArtifactUIState = AddArtifactUIState.Loading,
- nostrRepository: NostrRepository,
- chatRepository: ChatRepository,
- mantraRepository: MantraRepository,
- frostSigningRepository: FrostSigningRepository
- ): ViewModelProvider.Factory = viewModelFactory {
- initializer {
- AddArtifactViewModel(
- activeUserPublicKey = activeUserPublicKey,
- chatRoomId = chatRoomId,
- relayHint = relayHint,
- initialAddArtifactUIState = initialAddArtifactUIState,
- nostrRepository = nostrRepository,
- chatRepository = chatRepository,
- mantraRepository = mantraRepository,
- frostSigningRepository = frostSigningRepository
- )
- }
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/AddChapterViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/AddChapterViewModel.kt
deleted file mode 100644
index 4411786d..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/AddChapterViewModel.kt
+++ /dev/null
@@ -1,291 +0,0 @@
-package com.machankura.bennu.compose.ui.view.model
-
-import androidx.compose.foundation.text.input.TextFieldState
-import androidx.compose.foundation.text.input.clearText
-import androidx.compose.runtime.MutableState
-import androidx.compose.runtime.getValue
-import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.setValue
-import androidx.lifecycle.ViewModel
-import androidx.lifecycle.ViewModelProvider
-import androidx.lifecycle.viewModelScope
-import androidx.lifecycle.viewmodel.initializer
-import androidx.lifecycle.viewmodel.viewModelFactory
-import co.touchlab.kermit.Logger
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.IO
-import kotlinx.coroutines.launch
-import com.machankura.bennu.compose.database.model.MantraArtifactVersion
-import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
-import com.machankura.bennu.compose.managers.FrostSigningManager
-import com.machankura.bennu.compose.managers.TranslationScaffold
-import com.machankura.bennu.compose.nostr.nip30303.ChapterEvent
-import com.machankura.bennu.compose.nostr.nip30303.ChunkEvent
-import com.machankura.bennu.compose.repository.ChatRepository
-import com.machankura.bennu.compose.repository.FrostSigningRepository
-import com.machankura.bennu.compose.repository.MantraRepository
-import com.machankura.bennu.compose.text.Markdown
-import com.machankura.bennu.compose.ui.view.state.AddChapterUIState
-
-class AddChapterViewModel(
- val artifactId: String,
- val chatRoomId: String,
- val activeUserPublicKey: HexKey,
- val relayHint: String?,
- initialAddChapterUIState: AddChapterUIState,
- val mantraRepository: MantraRepository,
- val chatRepository: ChatRepository,
- val frostSigningRepository: FrostSigningRepository,
-): ViewModel() {
-
- var addChapterUIState: AddChapterUIState by mutableStateOf(initialAddChapterUIState)
- private set
-
- private val logger = Logger.withTag(TAG)
-
- val isActionPending: MutableState = mutableStateOf(false)
-
- fun initiateAddChapter() {
- viewModelScope.launch(Dispatchers.IO) {
- val artifact = mantraRepository.getArtifact(artifactId)
- val localChatRoom = chatRepository.getChatRoomByIdentifier(chatRoomId)
-
- addChapterUIState = when {
- artifact == null -> AddChapterUIState.Error("Couldn't find the artifact")
- localChatRoom == null -> AddChapterUIState.Error("Couldn't find the chat room")
- else -> AddChapterUIState.Loaded(
- localChatRoom = localChatRoom,
- artifact = artifact,
- // Chapters attach to an artifact version; use the latest one.
- artifactVersion = mantraRepository.getArtifactVersions(artifactId).firstOrNull(),
- canSign = frostSigningRepository.canSign(chatRoomId),
- )
- }
- }
- }
-
- /**
- * Asks the group to sign a chapter, and every chunk it splits into, in one
- * session.
- *
- * Nothing is created here. What goes out is a proposal to sign the lot, and
- * the chapter and its chunks appear on every member's device at once,
- * authored by this room's own key rather than by whoever pasted the text,
- * when enough members have signed. That author is the room's id: signing
- * runs at the path the room was derived at, so a chapter says which group's
- * artifact it belongs to simply by being signed.
- *
- * That is the difference from submitting one. A submission says "I am
- * putting this in front of the group" and the group's only recourse
- * afterwards is social. A signature is the group saying it, and it takes a
- * quorum to say. The text everyone will translate from is the group's, so
- * the second is the honest one.
- *
- * The chunks travel as their own events rather than being split back out of
- * the signed chapter on each device, so that each one carries the group's
- * signature over its own text -- a translation is of a chunk, and a chunk
- * that can be checked on its own is worth more than one that can only be
- * checked by re-deriving it. What it costs is [MAX_CHUNKS_PER_CHAPTER]: the
- * batch is capped, the chapter takes one of its places, and a chapter with
- * more paragraphs than the rest cannot be proposed at all.
- */
- fun addChapter(
- localChatRoom: LocalChatRoom,
- artifactVersion: MantraArtifactVersion,
- nameField: TextFieldState,
- originalTextField: TextFieldState,
- onSuccess: (sessionId: String) -> Unit,
- onFailure: () -> Unit
- ) {
- val name = nameField.text.toString()
- val originalText = originalTextField.text.toString()
- val paragraphs = Markdown.splitParagraphs(originalText)
-
- // The cap is the group's, not this screen's, and proposing past it
- // throws rather than failing softly. The form says so as it is typed;
- // this is the check that has to hold when it does not.
- if (name.isBlank() || paragraphs.isEmpty() || paragraphs.size > MAX_CHUNKS_PER_CHAPTER) {
- onFailure.invoke()
- return
- }
-
- // Guard against double submits from repeated FAB taps.
- if (isActionPending.value) return
- isActionPending.value = true
-
- viewModelScope.launch(Dispatchers.IO) {
- // Where this chapter sits in the version, read now rather than
- // derived on arrival: the index is signed into the event, and a
- // device applying it cannot recount from a version other members
- // may have added to in a different order. The scaffolding proposed
- // below is placed at the same one, so a translation chapter agrees
- // with the chapter it stands for.
- val chapterIndex = mantraRepository.getChaptersForArtifactVersion(artifactVersion.id).size
-
- val chapterEventTemplate = ChapterEvent.build(
- artifactVersionId = artifactVersion.id,
- name = name,
- originalText = originalText,
- index = chapterIndex,
- wordCount = Markdown.wordCount(originalText),
- characterCount = Markdown.characterCount(originalText),
- )
-
- val session = runCatching {
- frostSigningRepository.proposeSigningBatch(
- localChatRoom = localChatRoom,
- userPublicKey = activeUserPublicKey,
- lead = chapterEventTemplate,
- // A chunk names the chapter it belongs to, and that id is a
- // hash over the group's key at the room's path -- neither of
- // which this screen knows or should. The chapter comes back
- // built, and the chunks are cut from the text it carries.
- dependents = ChunkEvent::splitOf
- )
- }.onFailure { error ->
- logger.e("Failed to propose a chapter for signing", error)
- }.getOrNull()
-
- if (session != null) {
- // Before navigating, not after: the route this screen sits on
- // is popped on success, which clears this view model and takes
- // `viewModelScope` with it. Scaffolding launched afterwards
- // would be cancelled somewhere in the middle.
- scaffoldIntoTranslations(
- localChatRoom = localChatRoom,
- artifactVersion = artifactVersion,
- chapterIndex = chapterIndex,
- chapterSessionId = session.id,
- )
-
- nameField.clearText()
- originalTextField.clearText()
-
- viewModelScope.launch(Dispatchers.Main) {
- onSuccess.invoke(session.id)
- }
- } else {
- viewModelScope.launch(Dispatchers.Main) {
- onFailure.invoke()
- }
- }
-
- isActionPending.value = false
- }
- }
-
- /**
- * Asks the group to scaffold this chapter into every translation of the
- * version, in sessions of their own.
- *
- * Its own session rather than more items on the chapter's, because the two
- * would otherwise compete for one batch: a chapter is capped at
- * [MAX_CHUNKS_PER_CHAPTER] paragraphs, and every dialect the group works in
- * would take one of those places away. How long a chapter may be and how
- * many languages it is read in have nothing to do with each other, and a
- * shared cap would make the first move whenever somebody else did the
- * second.
- *
- * Sessions run independently -- every message carries the session it
- * belongs to, and each mints its own nonce material -- so a second one
- * opened here costs the admins another approval and nothing else.
- *
- * **What a separate session gives up.** A batch is all-or-nothing; two
- * sessions are not. If the chapter fails to reach a quorum while this one
- * succeeds, these are valid signatures over rows naming a chapter nobody
- * has: they fail a foreign key on the way in, are logged by
- * `applySignedEvent`, and never become rows. Harmless, and not recoverable
- * either -- a re-proposed chapter is a different id -- so the catch-up on
- * the translation is what fills the gap afterwards.
- *
- * The chapter is named as the group will author it: [chapterSessionId]'s
- * first item is the unsigned chapter, whose id is the hash its signers are
- * putting their shares behind, and it is settled at proposal time rather
- * than when the quorum arrives.
- *
- * Failure here is logged and swallowed. The chapter has already been
- * proposed and is the thing that was asked for; losing it because its
- * scaffolding could not be opened would be the wrong way round.
- */
- private suspend fun scaffoldIntoTranslations(
- localChatRoom: LocalChatRoom,
- artifactVersion: MantraArtifactVersion,
- chapterIndex: Int,
- chapterSessionId: String,
- ) {
- runCatching {
- val translations = mantraRepository
- .getTranslationsForArtifactVersion(artifactVersion.id)
- .ifEmpty { return@runCatching }
-
- val chapter = frostSigningRepository
- .unsignedEvents(frostSigningRepository.getItems(chapterSessionId))
- .firstOrNull() ?: return@runCatching
-
- // One session per MAX_BATCH_SIZE translations. A group with more
- // dialects than a batch holds is not a group this should refuse;
- // it is one that answers twice.
- translations.chunked(FrostSigningManager.MAX_BATCH_SIZE).forEach { batch ->
- frostSigningRepository.proposeSigningBatch(
- localChatRoom = localChatRoom,
- userPublicKey = activeUserPublicKey,
- events = TranslationScaffold.chaptersOf(
- translationArtifactVersionIds = batch.map { it.id },
- chapters = listOf(
- TranslationScaffold.SourceChapter(
- id = chapter.id,
- index = chapterIndex,
- )
- ),
- createdAt = chapter.createdAt,
- )
- )
- }
- }.onFailure { error ->
- logger.e(
- "Proposed the chapter but could not ask for it in this version's translations",
- error
- )
- }
- }
-
- companion object {
- private const val TAG = "AddChapterViewModel"
-
- /**
- * The most paragraphs a chapter can be proposed with.
- *
- * A chapter is signed together with a chunk per paragraph, and the
- * session signs at most [FrostSigningManager.MAX_BATCH_SIZE] events. The
- * chapter is one of them, so the paragraphs get the rest. A longer
- * chapter has to be split into two, which is a real limit and belongs in
- * front of whoever is typing rather than in a failure afterwards.
- */
- const val MAX_CHUNKS_PER_CHAPTER: Int = FrostSigningManager.MAX_BATCH_SIZE - 1
-
- fun factory(
- activeUserPublicKey: HexKey,
- artifactId: String,
- chatRoomId: String,
- relayHint: String?,
- initialAddChapterUIState: AddChapterUIState = AddChapterUIState.Loading,
- mantraRepository: MantraRepository,
- chatRepository: ChatRepository,
- frostSigningRepository: FrostSigningRepository,
- ): ViewModelProvider.Factory = viewModelFactory {
- initializer {
- AddChapterViewModel(
- activeUserPublicKey = activeUserPublicKey,
- artifactId = artifactId,
- chatRoomId = chatRoomId,
- relayHint = relayHint,
- initialAddChapterUIState = initialAddChapterUIState,
- mantraRepository = mantraRepository,
- chatRepository = chatRepository,
- frostSigningRepository = frostSigningRepository,
- )
- }
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/AddDialectViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/AddDialectViewModel.kt
deleted file mode 100644
index 4e693c7d..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/AddDialectViewModel.kt
+++ /dev/null
@@ -1,164 +0,0 @@
-package com.machankura.bennu.compose.ui.view.model
-
-import androidx.compose.foundation.text.input.TextFieldState
-import androidx.compose.foundation.text.input.clearText
-import androidx.compose.runtime.MutableState
-import androidx.compose.runtime.getValue
-import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.setValue
-import androidx.lifecycle.ViewModel
-import androidx.lifecycle.ViewModelProvider
-import androidx.lifecycle.viewModelScope
-import androidx.lifecycle.viewmodel.initializer
-import androidx.lifecycle.viewmodel.viewModelFactory
-import co.touchlab.kermit.Logger
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.IO
-import kotlinx.coroutines.launch
-import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
-import com.machankura.bennu.compose.repository.ChatRepository
-import com.machankura.bennu.compose.repository.FrostSigningRepository
-import com.machankura.bennu.compose.repository.NostrRepository
-import com.machankura.bennu.compose.nostr.nip30303.DialectEvent
-import com.machankura.bennu.compose.ui.view.state.AddDialectUIState
-
-class AddDialectViewModel(
- val chatRoomId: String,
- val activeUserPublicKey: HexKey,
- val relayHint: String?,
- initialAddDialectUIState: AddDialectUIState,
- val nostrRepository: NostrRepository,
- val chatRepository: ChatRepository,
- val frostSigningRepository: FrostSigningRepository,
-): ViewModel() {
-
- var addDialectUIState: AddDialectUIState by mutableStateOf(initialAddDialectUIState)
- private set
-
- private val logger = Logger.withTag(TAG)
-
- val isActionPending: MutableState = mutableStateOf(false)
-
- /**
- * Whether this group holds a key it can sign with.
- *
- * Read before the form is offered: a group without one cannot make a dialect
- * this way at all, and a button that always fails is worse than no button.
- */
- suspend fun canSign(): Boolean = frostSigningRepository.canSign(chatRoomId)
-
- fun initiateAddDialect() {
- logger.d("compressed (most likely chat room): $chatRoomId")
- viewModelScope.launch(Dispatchers.IO) {
- val localChatRoom = chatRepository.getChatRoomByIdentifier(chatRoomId)
-
- addDialectUIState = if (localChatRoom == null) {
- AddDialectUIState.Error("Couldn't find the chat room")
- } else {
- AddDialectUIState.Loaded(
- localChatRoom = localChatRoom,
- canSign = frostSigningRepository.canSign(chatRoomId),
- )
- }
- }
- }
-
- /**
- * Asks the group to sign a new dialect into existence.
- *
- * The dialect is not created here and does not exist yet. What goes out is a
- * proposal to sign it, and the dialect appears -- on every member's device at
- * once, authored by this room's own key rather than by whoever typed it --
- * when enough members have signed. That author is the room's id: signing runs
- * at the path the room was derived at, so a dialect says which room made it
- * simply by being signed.
- *
- * That is the difference from submitting one. A submission says "I am putting
- * this in front of the group" and the group's only recourse afterwards is
- * social. A signature is the group saying it, and it takes a quorum to say.
- */
- fun addDialect(
- localChatRoom: LocalChatRoom,
- nameField: TextFieldState,
- countryField: TextFieldState,
- languageField: TextFieldState,
- onSuccess: (sessionId: String) -> Unit,
- onFailure: () -> Unit
- ) {
- val name = nameField.text.toString()
- val country = countryField.text.toString()
- val language = languageField.text.toString()
-
- if (name.isBlank() || country.isBlank() || language.isBlank()) {
- onFailure.invoke()
- return
- }
-
- // Guard against double submits from repeated FAB taps.
- if (isActionPending.value) return
- isActionPending.value = true
-
- viewModelScope.launch(Dispatchers.IO) {
- val dialectEventTemplate = DialectEvent.build(
- name = name,
- country = country,
- language = language,
- )
-
- val session = runCatching {
- frostSigningRepository.proposeSigning(
- localChatRoom = localChatRoom,
- userPublicKey = activeUserPublicKey,
- kind = dialectEventTemplate.kind,
- tags = dialectEventTemplate.tags,
- content = dialectEventTemplate.content,
- )
- }.onFailure { error ->
- logger.e("Failed to propose a dialect for signing", error)
- }.getOrNull()
-
- if (session != null) {
- nameField.clearText()
- countryField.clearText()
- languageField.clearText()
-
- viewModelScope.launch(Dispatchers.Main) {
- onSuccess.invoke(session.id)
- }
- } else {
- viewModelScope.launch(Dispatchers.Main) {
- onFailure.invoke()
- }
- }
-
- isActionPending.value = false
- }
- }
-
- companion object {
- private const val TAG = "AddDialectViewModel"
-
- fun factory(
- activeUserPublicKey: HexKey,
- chatRoomId: String,
- relayHint: String?,
- initialAddDialectUIState: AddDialectUIState = AddDialectUIState.Loading,
- nostrRepository: NostrRepository,
- chatRepository: ChatRepository,
- frostSigningRepository: FrostSigningRepository
- ): ViewModelProvider.Factory = viewModelFactory {
- initializer {
- AddDialectViewModel(
- activeUserPublicKey = activeUserPublicKey,
- chatRoomId = chatRoomId,
- relayHint = relayHint,
- initialAddDialectUIState = initialAddDialectUIState,
- nostrRepository = nostrRepository,
- chatRepository = chatRepository,
- frostSigningRepository = frostSigningRepository
- )
- }
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/AddTranslationArtifactVersionViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/AddTranslationArtifactVersionViewModel.kt
deleted file mode 100644
index 0f7693f5..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/AddTranslationArtifactVersionViewModel.kt
+++ /dev/null
@@ -1,260 +0,0 @@
-package com.machankura.bennu.compose.ui.view.model
-
-import androidx.compose.runtime.MutableState
-import androidx.compose.runtime.getValue
-import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.setValue
-import androidx.lifecycle.ViewModel
-import androidx.lifecycle.ViewModelProvider
-import androidx.lifecycle.viewModelScope
-import androidx.lifecycle.viewmodel.initializer
-import androidx.lifecycle.viewmodel.viewModelFactory
-import co.touchlab.kermit.Logger
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.IO
-import kotlinx.coroutines.launch
-import com.machankura.bennu.compose.database.model.MantraArtifact
-import com.machankura.bennu.compose.database.model.MantraArtifactVersion
-import com.machankura.bennu.compose.database.model.MantraChapter
-import com.machankura.bennu.compose.database.model.MantraDialect
-import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
-import com.machankura.bennu.compose.managers.FrostSigningManager
-import com.machankura.bennu.compose.managers.TranslationScaffold
-import com.machankura.bennu.compose.nostr.nip30303.TranslationArtifactVersionEvent
-import com.machankura.bennu.compose.repository.ChatRepository
-import com.machankura.bennu.compose.repository.FrostSigningRepository
-import com.machankura.bennu.compose.repository.MantraRepository
-import com.machankura.bennu.compose.ui.view.state.AddTranslationArtifactVersionUIState
-
-class AddTranslationArtifactVersionViewModel(
- val artifactId: String,
- val chatRoomId: String,
- val activeUserPublicKey: HexKey,
- val relayHint: String?,
- initialAddTranslationArtifactVersionUIState: AddTranslationArtifactVersionUIState,
- val mantraRepository: MantraRepository,
- val chatRepository: ChatRepository,
- val frostSigningRepository: FrostSigningRepository,
-): ViewModel() {
-
- var addTranslationArtifactVersionUIState: AddTranslationArtifactVersionUIState by mutableStateOf(initialAddTranslationArtifactVersionUIState)
- private set
-
- private val logger = Logger.withTag(TAG)
-
- val isActionPending: MutableState = mutableStateOf(false)
-
- fun initiateAddTranslation() {
- viewModelScope.launch(Dispatchers.IO) {
- val artifact = mantraRepository.getArtifact(artifactId)
- val localChatRoom = chatRepository.getChatRoomByIdentifier(chatRoomId)
-
- // Translations attach to an artifact version; use the latest one.
- val artifactVersion = mantraRepository.getArtifactVersions(artifactId).firstOrNull()
-
- addTranslationArtifactVersionUIState = if (artifact == null || localChatRoom == null) {
- AddTranslationArtifactVersionUIState.Error("Couldn't find the artifact")
- } else {
- AddTranslationArtifactVersionUIState.Loaded(
- artifact = artifact,
- localChatRoom = localChatRoom,
- dialects = mantraRepository.getDialects(chatRoomId),
- artifactVersion = artifactVersion,
- chapters = artifactVersion
- ?.let { mantraRepository.getChaptersForArtifactVersion(it.id) }
- .orEmpty(),
- canSign = frostSigningRepository.canSign(chatRoomId),
- )
- }
- }
- }
-
- /**
- * Asks the group to sign a translation of the artifact, and a translation
- * chapter for every chapter it has, in one session.
- *
- * Nothing is created here. What goes out is a proposal to sign the lot, and
- * the translation and its chapters appear on every member's device at once,
- * authored by this room's own key rather than by whoever picked the dialect,
- * when enough members have signed. That author is the room's id: signing
- * runs at the path the room was derived at, so a translation says which
- * group's artifact it belongs to simply by being signed.
- *
- * That is the difference from submitting one. A submission says "I am
- * putting this in front of the group" and the group's only recourse
- * afterwards is social. A signature is the group saying it, and it takes a
- * quorum to say. A translation is what the group's readers will read the
- * artifact as, so the second is the honest one.
- *
- * The chapters travel with it rather than being scaffolded on each device,
- * for the same reason the chapter's chunks do: a translation chapter that
- * carries the group's signature can be checked by anybody holding it, and a
- * translation with no chapters is one nobody can start translating. What it
- * costs is [MAX_CHAPTERS_PER_TRANSLATION]: the batch is capped, the
- * translation takes one of its places, and an artifact with more chapters
- * than the rest cannot be translated in one session at all.
- */
- fun addTranslation(
- localChatRoom: LocalChatRoom,
- artifact: MantraArtifact,
- artifactVersion: MantraArtifactVersion,
- dialect: MantraDialect,
- chapters: List,
- onSuccess: (sessionId: String) -> Unit,
- onFailure: () -> Unit
- ) {
- // Guard against double submits from repeated FAB taps.
- if (isActionPending.value) return
- isActionPending.value = true
-
- viewModelScope.launch(Dispatchers.IO) {
- val translationEventTemplate = TranslationArtifactVersionEvent.build(
- artifactVersionId = artifactVersion.id,
- dialectId = dialect.id,
- // The translation is named after its dialect, and inherits the
- // source artifact's visibility and license: it is the same work
- // in another tongue, not a new one to license afresh.
- name = dialect.name,
- visibility = artifact.visibility,
- license = artifact.license,
- )
-
- val session = runCatching {
- frostSigningRepository.proposeSigningBatch(
- localChatRoom = localChatRoom,
- userPublicKey = activeUserPublicKey,
- lead = translationEventTemplate,
- // A translation chapter names the translation it belongs to,
- // and that id is a hash over the group's key at the room's
- // path -- neither of which this screen knows or should. The
- // translation comes back built, and the chapters are laid
- // out against it.
- dependents = { translation ->
- TranslationScaffold.chaptersOf(
- translationArtifactVersionIds = listOf(translation.id),
- chapters = chapters.take(MAX_CHAPTERS_PER_TRANSLATION)
- .map(TranslationScaffold.SourceChapter::of),
- createdAt = translation.createdAt,
- )
- }
- )
- }.onFailure { error ->
- logger.e("Failed to propose a translation for signing", error)
- }.getOrNull()
-
- if (session != null) {
- // Before navigating, not after: the route this screen sits on
- // is popped on success, which clears this view model and takes
- // `viewModelScope` with it.
- scaffoldRemainingChapters(
- localChatRoom = localChatRoom,
- chapters = chapters.drop(MAX_CHAPTERS_PER_TRANSLATION),
- translationSessionId = session.id,
- )
-
- viewModelScope.launch(Dispatchers.Main) {
- onSuccess.invoke(session.id)
- }
- } else {
- viewModelScope.launch(Dispatchers.Main) {
- onFailure.invoke()
- }
- }
-
- isActionPending.value = false
- }
- }
-
- /**
- * Asks the group for the chapters that did not fit the translation's own
- * session, in sessions of their own.
- *
- * The alternative was refusing to translate an artifact of more than
- * [MAX_CHAPTERS_PER_TRANSLATION] chapters at all, which is a cap on how
- * long a book may be dressed up as a cap on a batch. A group with a longer
- * one answers more than once instead.
- *
- * The translation is named as the group will author it: the first item of
- * [translationSessionId] is the unsigned translation, and its id is settled
- * at proposal time rather than when the quorum arrives.
- *
- * These carry the same cost as any second session, and the same one the
- * chapter side carries: if the translation itself fails to reach a quorum
- * these are valid signatures over rows naming a translation nobody has.
- * They fail a foreign key on the way in, are logged, and never become rows
- * -- and the catch-up on the translation is what fills the gap afterwards.
- */
- private suspend fun scaffoldRemainingChapters(
- localChatRoom: LocalChatRoom,
- chapters: List,
- translationSessionId: String,
- ) {
- if (chapters.isEmpty()) return
-
- runCatching {
- val translation = frostSigningRepository
- .unsignedEvents(frostSigningRepository.getItems(translationSessionId))
- .firstOrNull() ?: return@runCatching
-
- chapters.chunked(FrostSigningManager.MAX_BATCH_SIZE).forEach { batch ->
- frostSigningRepository.proposeSigningBatch(
- localChatRoom = localChatRoom,
- userPublicKey = activeUserPublicKey,
- events = TranslationScaffold.chaptersOf(
- translationArtifactVersionIds = listOf(translation.id),
- chapters = batch.map(TranslationScaffold.SourceChapter::of),
- createdAt = translation.createdAt,
- )
- )
- }
- }.onFailure { error ->
- logger.e(
- "Proposed the translation but could not ask for the chapters past the first session",
- error
- )
- }
- }
-
- companion object {
- private const val TAG = "AddTranslationViewModel"
-
- /**
- * How many chapters ride in the translation's own session.
- *
- * The translation is signed together with a chapter apiece, and a
- * session signs at most [FrostSigningManager.MAX_BATCH_SIZE] events. The
- * translation is one of them, so the chapters get the rest.
- *
- * A cap on the session, not on the work: an artifact with more chapters
- * than this is not refused, it is proposed in more than one session. A
- * limit whoever is looking at the screen can do nothing about is not a
- * limit worth telling them to work around.
- */
- const val MAX_CHAPTERS_PER_TRANSLATION: Int = FrostSigningManager.MAX_BATCH_SIZE - 1
-
- fun factory(
- activeUserPublicKey: HexKey,
- artifactId: String,
- chatRoomId: String,
- relayHint: String?,
- initialAddTranslationArtifactVersionUIState: AddTranslationArtifactVersionUIState = AddTranslationArtifactVersionUIState.Loading,
- mantraRepository: MantraRepository,
- chatRepository: ChatRepository,
- frostSigningRepository: FrostSigningRepository,
- ): ViewModelProvider.Factory = viewModelFactory {
- initializer {
- AddTranslationArtifactVersionViewModel(
- activeUserPublicKey = activeUserPublicKey,
- artifactId = artifactId,
- chatRoomId = chatRoomId,
- relayHint = relayHint,
- initialAddTranslationArtifactVersionUIState = initialAddTranslationArtifactVersionUIState,
- mantraRepository = mantraRepository,
- chatRepository = chatRepository,
- frostSigningRepository = frostSigningRepository,
- )
- }
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/ArtifactDetailViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/ArtifactDetailViewModel.kt
deleted file mode 100644
index 926dd046..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/ArtifactDetailViewModel.kt
+++ /dev/null
@@ -1,74 +0,0 @@
-package com.machankura.bennu.compose.ui.view.model
-
-import androidx.compose.runtime.getValue
-import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.setValue
-import androidx.lifecycle.ViewModel
-import androidx.lifecycle.ViewModelProvider
-import androidx.lifecycle.viewModelScope
-import androidx.lifecycle.viewmodel.initializer
-import androidx.lifecycle.viewmodel.viewModelFactory
-import co.touchlab.kermit.Logger
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.IO
-import kotlinx.coroutines.launch
-import com.machankura.bennu.compose.repository.MantraRepository
-import com.machankura.bennu.compose.ui.view.state.ArtifactDetailUIState
-
-class ArtifactDetailViewModel(
- val artifactId: String,
- val chatRoomId: String,
- val activeUserPublicKey: HexKey,
- val relayHint: String?,
- initialArtifactDetailUIState: ArtifactDetailUIState,
- val mantraRepository: MantraRepository,
-): ViewModel() {
-
- var artifactDetailUIState: ArtifactDetailUIState by mutableStateOf(initialArtifactDetailUIState)
- private set
-
- private val logger = Logger.withTag(TAG)
-
- fun initiateArtifactDetail() {
- logger.d("initiateArtifactDetail: $artifactId")
- viewModelScope.launch(Dispatchers.IO) {
- val artifact = mantraRepository.getArtifact(artifactId)
-
- artifactDetailUIState = if (artifact == null) {
- ArtifactDetailUIState.Error("Couldn't find the artifact")
- } else {
- ArtifactDetailUIState.Loaded(
- artifact = artifact,
- versions = mantraRepository.getArtifactVersions(artifactId),
- chapters = mantraRepository.getChaptersForArtifact(artifactId),
- translations = mantraRepository.getTranslationsForArtifact(artifactId),
- )
- }
- }
- }
-
- companion object {
- private const val TAG = "ArtifactDetailViewModel"
-
- fun factory(
- activeUserPublicKey: HexKey,
- artifactId: String,
- chatRoomId: String,
- relayHint: String?,
- initialArtifactDetailUIState: ArtifactDetailUIState = ArtifactDetailUIState.Loading,
- mantraRepository: MantraRepository,
- ): ViewModelProvider.Factory = viewModelFactory {
- initializer {
- ArtifactDetailViewModel(
- activeUserPublicKey = activeUserPublicKey,
- artifactId = artifactId,
- chatRoomId = chatRoomId,
- relayHint = relayHint,
- initialArtifactDetailUIState = initialArtifactDetailUIState,
- mantraRepository = mantraRepository,
- )
- }
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/ChapterDetailViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/ChapterDetailViewModel.kt
deleted file mode 100644
index 62ad9653..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/ChapterDetailViewModel.kt
+++ /dev/null
@@ -1,72 +0,0 @@
-package com.machankura.bennu.compose.ui.view.model
-
-import androidx.compose.runtime.getValue
-import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.setValue
-import androidx.lifecycle.ViewModel
-import androidx.lifecycle.ViewModelProvider
-import androidx.lifecycle.viewModelScope
-import androidx.lifecycle.viewmodel.initializer
-import androidx.lifecycle.viewmodel.viewModelFactory
-import co.touchlab.kermit.Logger
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.IO
-import kotlinx.coroutines.launch
-import com.machankura.bennu.compose.repository.MantraRepository
-import com.machankura.bennu.compose.ui.view.state.ChapterDetailUIState
-
-class ChapterDetailViewModel(
- val chapterId: String,
- val chatRoomId: String,
- val activeUserPublicKey: HexKey,
- val relayHint: String?,
- initialChapterDetailUIState: ChapterDetailUIState,
- val mantraRepository: MantraRepository,
-): ViewModel() {
-
- var chapterDetailUIState: ChapterDetailUIState by mutableStateOf(initialChapterDetailUIState)
- private set
-
- private val logger = Logger.withTag(TAG)
-
- fun initiateChapterDetail() {
- logger.d("initiateChapterDetail: $chapterId")
- viewModelScope.launch(Dispatchers.IO) {
- val chapter = mantraRepository.getChapter(chapterId)
-
- chapterDetailUIState = if (chapter == null) {
- ChapterDetailUIState.Error("Couldn't find the chapter")
- } else {
- ChapterDetailUIState.Loaded(
- chapter = chapter,
- chunks = mantraRepository.getChunksForChapter(chapterId),
- )
- }
- }
- }
-
- companion object {
- private const val TAG = "ChapterDetailViewModel"
-
- fun factory(
- activeUserPublicKey: HexKey,
- chapterId: String,
- chatRoomId: String,
- relayHint: String?,
- initialChapterDetailUIState: ChapterDetailUIState = ChapterDetailUIState.Loading,
- mantraRepository: MantraRepository,
- ): ViewModelProvider.Factory = viewModelFactory {
- initializer {
- ChapterDetailViewModel(
- activeUserPublicKey = activeUserPublicKey,
- chapterId = chapterId,
- chatRoomId = chatRoomId,
- relayHint = relayHint,
- initialChapterDetailUIState = initialChapterDetailUIState,
- mantraRepository = mantraRepository,
- )
- }
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/ChatRoomDetailViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/ChatRoomDetailViewModel.kt
index a7f77e8b..ac4802d0 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/ChatRoomDetailViewModel.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/ChatRoomDetailViewModel.kt
@@ -13,7 +13,6 @@ import androidx.lifecycle.viewmodel.initializer
import androidx.lifecycle.viewmodel.viewModelFactory
import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
import com.machankura.bennu.compose.repository.ChatRepository
-import com.machankura.bennu.compose.repository.MantraRepository
import com.machankura.bennu.compose.repository.NostrRepository
import com.machankura.bennu.compose.ui.composable.navigation.routes.HomeRoute
import com.machankura.bennu.compose.ui.composable.navigation.routes.Route
@@ -33,7 +32,6 @@ class ChatRoomDetailViewModel(
initialChatRoomDetailUIState: ChatRoomDetailUIState,
val nostrRepository: NostrRepository,
val chatRepository: ChatRepository,
- val mantraRepository: MantraRepository,
): ViewModel() {
var chatRoomDetailUIState: ChatRoomDetailUIState by mutableStateOf(initialChatRoomDetailUIState)
@@ -219,7 +217,6 @@ class ChatRoomDetailViewModel(
initialChatRoomDetailUIState: ChatRoomDetailUIState = ChatRoomDetailUIState.Loading,
nostrRepository: NostrRepository,
chatRepository: ChatRepository,
- mantraRepository: MantraRepository,
): ViewModelProvider.Factory = viewModelFactory {
initializer {
ChatRoomDetailViewModel(
@@ -229,7 +226,6 @@ class ChatRoomDetailViewModel(
initialChatRoomDetailUIState = initialChatRoomDetailUIState,
nostrRepository = nostrRepository,
chatRepository = chatRepository,
- mantraRepository = mantraRepository,
)
}
}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/CreateSharedKeyViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/CreateSharedKeyViewModel.kt
new file mode 100644
index 00000000..be4898e6
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/CreateSharedKeyViewModel.kt
@@ -0,0 +1,184 @@
+package com.machankura.bennu.compose.ui.view.model
+
+import androidx.compose.runtime.MutableState
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.setValue
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.ViewModelProvider
+import androidx.lifecycle.viewModelScope
+import androidx.lifecycle.viewmodel.initializer
+import androidx.lifecycle.viewmodel.viewModelFactory
+import co.touchlab.kermit.Logger
+import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.IO
+import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.first
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
+import com.machankura.bennu.compose.database.model.types.ChatRoomType
+import com.machankura.bennu.compose.database.model.types.DkgRitualStage
+import com.machankura.bennu.compose.identity.Identity
+import com.machankura.bennu.compose.managers.ChillDkgRitualManager
+import com.machankura.bennu.compose.repository.ChatRepository
+import com.machankura.bennu.compose.repository.DkgRepository
+import com.machankura.bennu.compose.ui.view.state.CreateSharedKeyUIState
+import com.machankura.bennu.compose.ui.view.state.CreateSharedKeyUIState.Refused.Reason
+
+/**
+ * Starts a NIP-17 group's own key ceremony.
+ *
+ * Everything about *starting* that the ceremony screen used to carry: the
+ * quorum, the size check, and the proposal. The ceremony screen only shows one
+ * now, so nothing it draws can be mistaken for a way to open another.
+ *
+ * The refusals are made here rather than by hiding a button, so the screen can
+ * say why, and `ChillDkgRitualManager.proposeRitual` makes the Marmot one again
+ * underneath -- a screen not drawing something is not a guard.
+ */
+class CreateSharedKeyViewModel(
+ val chatRoomId: String,
+ val activeUserPublicKey: HexKey,
+ initialUIState: CreateSharedKeyUIState,
+ val activeIdentityStateFlow: StateFlow,
+ val chatRepository: ChatRepository,
+ val dkgRepository: DkgRepository,
+) : ViewModel() {
+
+ var uiState: CreateSharedKeyUIState by mutableStateOf(initialUIState)
+ private set
+
+ private val logger = Logger.withTag(TAG)
+
+ val isActionPending: MutableState = mutableStateOf(false)
+
+ /**
+ * The quorum the ceremony will generate a key for. Pre-filled with the same
+ * majority default the group-creation screen offers.
+ */
+ val threshold: MutableState = mutableStateOf(ChatRoomType.MINIMUM_QUORUM)
+
+ fun initiate() {
+ uiState = CreateSharedKeyUIState.Loading
+
+ viewModelScope.launch(Dispatchers.IO) {
+ val localChatRoom = chatRepository.getChatRoomByIdentifier(chatRoomId)
+ if (localChatRoom == null) {
+ uiState = CreateSharedKeyUIState.Error(CreateSharedKeyUIState.Error.Reason.ROOM_NOT_FOUND)
+ return@launch
+ }
+
+ if (ChillDkgRitualManager.isMarmotRoom(localChatRoom)) {
+ uiState = CreateSharedKeyUIState.Refused(Reason.MARMOT_ROOM)
+ return@launch
+ }
+
+ if (!ChillDkgRitualManager.canRunRitual(localChatRoom)) {
+ uiState = CreateSharedKeyUIState.Refused(Reason.TOO_FEW_MEMBERS)
+ return@launch
+ }
+
+ // The room's own, which in a NIP-17 room is every ceremony it holds:
+ // subgroups run in their parent's Marmot room. A finished one counts --
+ // the group has its key, and the ceremony screen is where the next step
+ // after it is offered.
+ val own = dkgRepository.observeLatestSessionForChatRoom(chatRoomId, parentChatRoomId = null)
+ .first()
+ if (own != null && own.stage != DkgRitualStage.FAILED) {
+ uiState = CreateSharedKeyUIState.Existing(own.id)
+ return@launch
+ }
+
+ val participantCount = ChillDkgRitualManager.memberPublicKeys(localChatRoom).size
+ threshold.value = ChatRoomType.defaultQuorum(participantCount)
+ .coerceIn(quorumRange(participantCount))
+
+ uiState = CreateSharedKeyUIState.Loaded(
+ localChatRoom = localChatRoom,
+ participantCount = participantCount,
+ )
+ }
+ }
+
+ fun quorumRange(): IntRange {
+ val loaded = uiState as? CreateSharedKeyUIState.Loaded
+ ?: return ChatRoomType.quorumRange(ChatRoomType.MINIMUM_QUORUM)
+
+ return quorumRange(loaded.participantCount)
+ }
+
+ // Below the minimum the range runs backwards and is empty, which `coerceIn`
+ // rejects outright. There is no ceremony to run at that size either.
+ private fun quorumRange(participantCount: Int): IntRange =
+ ChatRoomType.quorumRange(maxOf(participantCount, ChatRoomType.MINIMUM_QUORUM))
+
+ fun setThreshold(value: Int) {
+ if (isActionPending.value) return
+
+ threshold.value = value.coerceIn(quorumRange())
+ }
+
+ /**
+ * Opens the ceremony, making this device its coordinator, and hands over to
+ * the screen that shows it.
+ */
+ fun create(onCreated: (dkgSessionId: String) -> Unit) {
+ if (isActionPending.value) return
+
+ val loaded = uiState as? CreateSharedKeyUIState.Loaded ?: return
+
+ val nostrPrivateKey = activeIdentityStateFlow.value?.nostrPrivateKey
+ if (nostrPrivateKey == null) {
+ uiState = CreateSharedKeyUIState.Error(CreateSharedKeyUIState.Error.Reason.NO_KEYS)
+ return
+ }
+
+ isActionPending.value = true
+
+ viewModelScope.launch(Dispatchers.IO) {
+ // A ceremony somebody else opened since this screen loaded comes back
+ // here rather than a second one -- `proposeRitual` checks again.
+ val session = dkgRepository.proposeRitual(
+ localChatRoom = loaded.localChatRoom,
+ userPublicKey = activeUserPublicKey,
+ nostrPrivateKey = nostrPrivateKey.value.toByteArray(),
+ threshold = threshold.value
+ )
+
+ isActionPending.value = false
+
+ if (session == null) {
+ logger.e("Failed to start a key ceremony in $chatRoomId")
+ uiState = CreateSharedKeyUIState.Error(CreateSharedKeyUIState.Error.Reason.NOT_STARTED)
+ return@launch
+ }
+
+ withContext(Dispatchers.Main) { onCreated(session.id) }
+ }
+ }
+
+ companion object {
+ private const val TAG = "CreateSharedKeyViewModel"
+
+ fun factory(
+ chatRoomId: String,
+ activeUserPublicKey: HexKey,
+ initialUIState: CreateSharedKeyUIState = CreateSharedKeyUIState.Loading,
+ activeIdentityStateFlow: StateFlow,
+ chatRepository: ChatRepository,
+ dkgRepository: DkgRepository,
+ ): ViewModelProvider.Factory = viewModelFactory {
+ initializer {
+ CreateSharedKeyViewModel(
+ chatRoomId = chatRoomId,
+ activeUserPublicKey = activeUserPublicKey,
+ initialUIState = initialUIState,
+ activeIdentityStateFlow = activeIdentityStateFlow,
+ chatRepository = chatRepository,
+ dkgRepository = dkgRepository,
+ )
+ }
+ }
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/DkgRitualViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/DkgRitualViewModel.kt
index 0929979d..0b0e07ef 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/DkgRitualViewModel.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/DkgRitualViewModel.kt
@@ -10,9 +10,7 @@ import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.initializer
import androidx.lifecycle.viewmodel.viewModelFactory
import com.machankura.bennu.compose.database.model.types.DkgApprovalStep
-import com.machankura.bennu.compose.database.model.types.DkgRitualStage
import com.machankura.bennu.compose.database.model.types.FrostSigningStage
-import com.machankura.bennu.compose.database.model.types.ChatRoomType
import com.machankura.bennu.compose.managers.ChillDkgRitualManager
import com.machankura.bennu.compose.managers.MarmotGroupCreation
import com.machankura.bennu.compose.managers.SharedKeyDerivation
@@ -35,25 +33,42 @@ import com.vitorpamplona.quartz.nip01Core.core.Kind
import com.machankura.bennu.compose.identity.Identity
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
-import kotlinx.coroutines.Job
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.combine
+import kotlinx.coroutines.flow.distinctUntilChanged
+import kotlinx.coroutines.flow.filter
+import kotlinx.coroutines.flow.flatMapLatest
+import kotlinx.coroutines.flow.flowOf
+import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.flow.mapLatest
+import com.machankura.bennu.compose.database.model.DkgSession
+import com.machankura.bennu.compose.database.model.FrostSigningSession
+import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
+import com.machankura.bennu.compose.database.model.intermdiate.LocalFrostSigningSession
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
/**
- * Watches a group's ChillDKG ritual, and opens one on request.
+ * Watches one ChillDKG ritual, and the steps that follow it.
*
* Nothing here drives the protocol — the ritual advances in
* [ChillDkgRitualManager] as messages arrive on the inbound path, so this only
* has to read the session and show it moving.
+ *
+ * It never opens one. That is `CreateSharedKeyViewModel`'s job for a group's own
+ * key, and the subgroup picker's for a subgroup's: a screen that showed a
+ * ceremony and offered to start one from the same button is how a member
+ * approving a subgroup's ceremony opened a second -- see
+ * docs/ceremony-creation.md.
*/
+@OptIn(ExperimentalCoroutinesApi::class)
class DkgRitualViewModel(
val chatRoomId: String,
val activeUserPublicKey: HexKey,
- /**
- * The ceremony to show, when the caller knew which. Null falls back to the
- * room's newest -- see [DkgRitualRoute.dkgSessionId].
- */
- val dkgSessionId: String? = null,
+ /** The ceremony to show -- see [DkgRitualRoute.dkgSessionId]. */
+ val dkgSessionId: String,
initialDkgRitualUIState: DkgRitualUIState,
val activeIdentityStateFlow: StateFlow,
val chatRepository: ChatRepository,
@@ -67,73 +82,24 @@ class DkgRitualViewModel(
val isActionPending: MutableState = mutableStateOf(false)
- /** Watches the current session's messages; replaced whenever the session changes. */
- private var messageObserver: Job? = null
-
- /** Watches the room's signing sessions, which is where the key state is agreed. */
- private var keyStateObserver: Job? = null
-
- /** Watches the parent certifying this subgroup; re-pointed as the purpose is learned. */
- private var certificateObserver: Job? = null
+ /** Whether [initiate] has run. The view model's to decide, not the screen's. */
+ private var initiated = false
/**
- * The parent [observeCertificate] is currently watching, so a re-emission of
- * the same session does not tear the watchers down and stand them up again.
+ * Members the admin room is waiting on for a key package. The one part of the
+ * state an action writes rather than a flow, so it is a flow too, and goes
+ * through the same single write as everything else.
*/
- private var watchedParentChatRoomId: HexKey? = null
-
- /** The ceremony [observeForCeremony] is currently watching. */
- private var watchedSessionId: String? = null
-
- /**
- * The quorum the ritual will generate a key for. Pre-filled with the same
- * majority default the group-creation screen offers.
- *
- * TODO: the quorum chosen at creation time is not persisted on ChatRoom, so
- * it cannot be read back here. Storing it there would let this default to
- * what the group was actually promised rather than re-deriving it.
- */
- val threshold: MutableState = mutableStateOf(ChatRoomType.MINIMUM_QUORUM)
-
- /**
- * Whether this device can open a ceremony right now.
- *
- * Any member may: ChillDKG gives the coordinator no say in the outcome, and a
- * NIP-17 room records no creator to reserve the job for. What rules it out is
- * a ceremony already running, or a group too small to split a key across.
- */
- fun canStartRitual(): Boolean {
- val loaded = dkgRitualUIState as? DkgRitualUIState.Loaded ?: return false
-
- if (loaded.session != null && loaded.session.stage != DkgRitualStage.FAILED) return false
-
- // Not just the ceremony on screen. A room can hold more than one, and this
- // screen exists to offer one to a room that has none -- so a room with a
- // ceremony running under a different purpose must not be offered another,
- // whatever this screen happens to be showing.
- if (loaded.roomHasCeremony) return false
-
- return ChillDkgRitualManager.canRunRitual(loaded.localChatRoom)
- }
-
- fun quorumRange(): IntRange {
- val loaded = dkgRitualUIState as? DkgRitualUIState.Loaded
- ?: return ChatRoomType.quorumRange(ChatRoomType.MINIMUM_QUORUM)
-
- // Below the minimum the range runs backwards and is empty, which `coerceIn`
- // rejects outright. There is no ritual to run at that size either.
- return ChatRoomType.quorumRange(
- maxOf(loaded.participantCount, ChatRoomType.MINIMUM_QUORUM)
- )
- }
-
- fun setThreshold(value: Int) {
- if (isActionPending.value) return
-
- threshold.value = value.coerceIn(quorumRange())
- }
+ private val adminGroupBlockedOn = MutableStateFlow>(emptyList())
fun initiate() {
+ // The screen asks every time it comes back into view -- returning from an
+ // approval screen, say -- and starting again used to reset the state to
+ // "no ceremony" and stack a second set of watchers on the first. The
+ // first run's watchers are still running, so there is nothing to start.
+ if (initiated) return
+ initiated = true
+
viewModelScope.launch(Dispatchers.IO) {
val localChatRoom = chatRepository.getChatRoomByIdentifier(chatRoomId)
if (localChatRoom == null) {
@@ -141,210 +107,164 @@ class DkgRitualViewModel(
return@launch
}
- dkgRitualUIState = DkgRitualUIState.Loaded(localChatRoom = localChatRoom)
- threshold.value = ChatRoomType
- .defaultQuorum(ChillDkgRitualManager.memberPublicKeys(localChatRoom).size)
- .coerceIn(quorumRange())
+ // One writer. Every part of the screen used to be its own coroutine
+ // reading the state, copying one field and writing it back, and one
+ // that read before another wrote put the other's field back the way it
+ // was -- which could leave the screen with no ceremony on it, offering
+ // to start one. Now each part is a flow and the state is built from all
+ // of them at once.
+ ceremonyState(localChatRoom).collect { state ->
+ // An action that failed has said so; a later emission must not
+ // paper over it.
+ if (dkgRitualUIState is DkgRitualUIState.Error) return@collect
- observeKeyState()
-
- // Room-scoped, deliberately. Only the member who opened a subgroup
- // arrives here knowing it is one -- everybody else reaches this screen
- // from the room, through the transcript's ritual notice or the group's
- // details, neither of which has a purpose to hand it. Filtering by one
- // here left every other member looking at a room whose ceremony had
- // started and being told none had.
- //
- // So the purpose is read off the session rather than required to open
- // it. `getLatestSessionFor` is still scoped where scoping is the
- // question being asked -- "may I open another" -- in `proposeRitual`
- // and `refuseCeremonyRoom`.
- // The named ceremony where the caller knew which, and the room's
- // newest otherwise. A room holds more than one the moment a subgroup's
- // admins are the whole group, and then "the room's newest" is whichever
- // ceremony was opened last -- routinely the group's own, already
- // finished, while the subgroup's request goes unanswered underneath it.
- val sessions = dkgSessionId
- ?.let { dkgRepository.observeSessionById(it) }
- ?: dkgRepository.observeLatestSessionForChatRoom(chatRoomId)
-
- // Whether the room has any ceremony at all, which is a different
- // question from which one is being shown -- see
- // `DkgRitualUIState.roomHasCeremony`.
- launch {
- dkgRepository.observeLatestSessionForChatRoom(chatRoomId).collect { newest ->
- val current = dkgRitualUIState as? DkgRitualUIState.Loaded ?: return@collect
-
- dkgRitualUIState = current.copy(
- roomHasCeremony = newest != null && newest.stage != DkgRitualStage.FAILED
- )
- }
+ dkgRitualUIState = state
}
+ }
+ }
- sessions.collect { session ->
- val loaded = (dkgRitualUIState as? DkgRitualUIState.Loaded)
- ?: DkgRitualUIState.Loaded(localChatRoom = localChatRoom)
+ /**
+ * The whole screen as one flow, so no part of it can overwrite another.
+ *
+ * The purpose -- a group's own key or a subgroup's -- is read off the
+ * session rather than handed in, because only the member who opened a
+ * subgroup arrives knowing it is one; everybody else comes from a transcript
+ * line that names the ceremony and nothing more.
+ */
+ private fun ceremonyState(localChatRoom: LocalChatRoom): Flow {
+ val sessions = dkgRepository.observeSessionById(dkgSessionId)
- // The session is the only thing that knows what the ceremony is
- // for. The route used to carry it too, which was right for the one
- // member who opened the subgroup and null for everybody else.
- val parent = session?.parentChatRoomId
+ // The session in which the group agrees what its admin room will sign
+ // with. The room a ceremony runs in signs nothing else, so the newest
+ // session in it is the key state's -- but it is matched on the kind it
+ // carries anyway, so a room that one day signs something else does not
+ // confuse the two.
+ val keyStateSession = dkgRepository.observeSigningSessions(chatRoomId)
+ .map { it.firstCarrying(GroupKeyStateEvent.KIND) }
- dkgRitualUIState = loaded.copy(
+ // Everything about one ceremony, re-pointed when the ceremony or its
+ // purpose changes -- which for a member arriving cold is once -- and not
+ // on every change to the session row.
+ val parts = sessions
+ .map { it?.id to it?.parentChatRoomId }
+ .distinctUntilChanged()
+ .flatMapLatest { (sessionId, parent) -> ceremonyParts(sessionId, parent) }
+
+ return combine(
+ sessions,
+ parts,
+ keyStateSession,
+ adminGroupBlockedOn,
+ ) { session, ceremony, keyState, blockedOn ->
+ Snapshot(session, ceremony, keyState, blockedOn)
+ }
+ // The parts lag the session by one emission when the ceremony changes;
+ // a state that drew one ceremony's counts under another's name is the
+ // thing this is here to stop.
+ .filter { it.ceremony.sessionId == it.session?.id }
+ .mapLatest { snapshot ->
+ // A ceremony this device has no row for. Every way here names one
+ // the device recorded -- a transcript line it wrote, or one it has
+ // just opened -- so this is a bug to say out loud rather than an
+ // empty screen to fill with an offer.
+ val session = snapshot.session
+ ?: return@mapLatest DkgRitualUIState.Error("Couldn't find this key ceremony")
+ val ceremony = snapshot.ceremony
+
+ DkgRitualUIState.Loaded(
+ localChatRoom = localChatRoom,
session = session,
- parentChatRoomId = parent,
- pendingApproval = session?.let { dkgRepository.pendingApproval(it) }
+ hostKeyParticipants = ceremony.hostKeyParticipants,
+ round1Participants = ceremony.round1Participants,
+ round2Participants = ceremony.round2Participants,
+ // Computed here, before the one write, rather than read and
+ // written around a suspension: whether round 1 can be asked
+ // for depends on how many host keys have arrived, which only
+ // the messages flow sees.
+ pendingApproval = dkgRepository.pendingApproval(session),
+ adminGroupBlockedOn = snapshot.adminGroupBlockedOn,
+ keyStateSession = snapshot.keyStateSession,
+ isKeyStateSigned = ceremony.isKeyStateSigned,
+ parentChatRoomId = session.parentChatRoomId,
+ isCertified = ceremony.isCertified,
+ certificateSession = ceremony.certificateSession,
)
-
- // Re-point the per-ceremony watchers whenever the ceremony or its
- // purpose changes, which for a member arriving cold is once.
- // Everything downstream of this -- the key state, the certificate
- // -- is about one ceremony, and the room cannot say which.
- if (session?.id != watchedSessionId || parent != watchedParentChatRoomId) {
- watchedSessionId = session?.id
- watchedParentChatRoomId = parent
- observeForCeremony(session?.id, parent)
- }
-
- // Re-point the message watcher at whatever session is current. An
- // abandoned ritual's counts must not keep ticking over the new one.
- messageObserver?.cancel()
- if (session != null) {
- messageObserver = viewModelScope.launch(Dispatchers.IO) {
- dkgRepository.observeMessages(session.id).collect { messages ->
- val current = dkgRitualUIState as? DkgRitualUIState.Loaded ?: return@collect
-
- fun senders(kind: Kind) = messages
- .filter { it.kind == kind }
- .map { it.participantPublicKey }
- .toSet()
-
- dkgRitualUIState = current.copy(
- hostKeyParticipants = senders(DkgRitualEvents.HOST_KEY),
- round1Participants = senders(DkgRitualEvents.ROUND_1),
- round2Participants = senders(DkgRitualEvents.ROUND_2),
- // Recomputed here as well as on the session, because
- // whether round 1 can be asked for depends on how many
- // host keys have arrived, which only this flow sees.
- pendingApproval = current.session
- ?.let { dkgRepository.pendingApproval(it) }
- )
- }
- }
- }
}
- }
}
/**
- * Follows the group agreeing what its admin room will sign with.
+ * One ceremony's messages, whether its key state has been signed, and -- for
+ * a subgroup -- whether its parent has certified it.
*
- * Nothing here watches a [GroupKeyState] row, because there is no room yet
- * for one to belong to -- being able to follow this before the room exists
- * is the point. What is watched instead is the session, for how the signing
- * is going, and the signed event, for whether it finished.
- *
- * The room a ceremony runs in signs nothing else, so the newest session in
- * it is the key state's -- but it is matched on the kind it carries anyway,
- * so a room that one day signs something else does not confuse the two.
+ * The certificate is read off the *parent's* signed events and sessions
+ * rather than this room's: it is made where the parent's key can sign it,
+ * which is never the ceremony's room. An ordinary ceremony passes no parent
+ * and gets nothing watched there, which is exactly right.
*/
- private fun observeKeyState() {
- keyStateObserver?.cancel()
- keyStateObserver = viewModelScope.launch(Dispatchers.IO) {
- // Two flows because they answer two questions off two tables. How
- // the signing is going is the session row; whether it finished is
- // the signed event, and only that second one can be asked at all
- // before there is a room -- which is the whole point of asking it.
- launch {
- dkgRepository.observeSigningSessions(chatRoomId).collect { sessions ->
- val loaded = dkgRitualUIState as? DkgRitualUIState.Loaded ?: return@collect
+ private fun ceremonyParts(sessionId: String?, parentChatRoomId: HexKey?): Flow {
+ if (sessionId == null) return flowOf(CeremonyParts(sessionId = null))
- dkgRitualUIState = loaded.copy(
- keyStateSession = sessions.firstOrNull { local ->
- local.items.any { item ->
- runCatching {
- Event.fromJson(item.unsignedEventJson).kind
- }.getOrNull() == GroupKeyStateEvent.KIND
- }
- }?.session
- )
- }
+ val certified = parentChatRoomId
+ ?.let { parent -> dkgRepository.observeBirthCertificate(sessionId, parent).map { it != null } }
+ ?: flowOf(false)
+
+ val certificateSession = parentChatRoomId
+ ?.let { parent ->
+ dkgRepository.observeSigningSessions(parent)
+ .map { it.firstCarrying(SubgroupBirthCertificateEvent.KIND) }
}
+ ?: flowOf(null)
+ return combine(
+ dkgRepository.observeMessages(sessionId),
+ // Asked by ceremony rather than by room: the room holds however many
+ // ceremonies it holds, and the answer is about this one's key.
+ dkgRepository.observeSignedGroupKeyState(sessionId).map { it != null },
+ certified,
+ certificateSession,
+ ) { messages, isKeyStateSigned, isCertified, certificate ->
+ fun senders(kind: Kind) = messages
+ .filter { it.kind == kind }
+ .map { it.participantPublicKey }
+ .toSet()
+ CeremonyParts(
+ sessionId = sessionId,
+ hostKeyParticipants = senders(DkgRitualEvents.HOST_KEY),
+ round1Participants = senders(DkgRitualEvents.ROUND_1),
+ round2Participants = senders(DkgRitualEvents.ROUND_2),
+ isKeyStateSigned = isKeyStateSigned,
+ isCertified = isCertified,
+ certificateSession = certificate,
+ )
}
}
- /**
- * Follows one ceremony: whether its key state has been signed, and -- for a
- * subgroup -- whether its parent has certified it.
- *
- * Off the *parent's* signed events and sessions rather than this room's: the
- * certificate is made where the parent's key can sign it, which is never the
- * ceremony's room.
- *
- * Started from the session collector rather than at init, because a member
- * who did not open the subgroup has no idea it is one until the proposal they
- * were sent turns up. Cancelled and restarted on a change, the way the
- * message watcher is -- an ordinary ceremony passes null and gets nothing
- * watched, which is exactly right.
- */
- private fun observeForCeremony(dkgSessionId: String?, parentChatRoomId: HexKey?) {
- certificateObserver?.cancel()
-
- if (dkgSessionId == null) {
- dkgRitualUIState = (dkgRitualUIState as? DkgRitualUIState.Loaded)
- ?.copy(isKeyStateSigned = false, isCertified = false, certificateSession = null)
- ?: dkgRitualUIState
- return
- }
-
- certificateObserver = viewModelScope.launch(Dispatchers.IO) {
- // Whether the group has agreed what the room this ceremony's key
- // derives will sign with. Asked by ceremony rather than by room: the
- // room holds however many ceremonies it holds, and the answer is
- // about this one's key.
- launch {
- dkgRepository.observeSignedGroupKeyState(dkgSessionId).collect { state ->
- val loaded = dkgRitualUIState as? DkgRitualUIState.Loaded ?: return@collect
-
- dkgRitualUIState = loaded.copy(isKeyStateSigned = state != null)
- }
+ /** The signing session carrying an event of [kind], if there is one. */
+ private fun List.firstCarrying(kind: Kind): FrostSigningSession? =
+ firstOrNull { local ->
+ local.items.any { item ->
+ runCatching { Event.fromJson(item.unsignedEventJson).kind }.getOrNull() == kind
}
+ }?.session
- if (parentChatRoomId == null) {
- dkgRitualUIState = (dkgRitualUIState as? DkgRitualUIState.Loaded)
- ?.copy(isCertified = false, certificateSession = null)
- ?: dkgRitualUIState
- return@launch
- }
+ /** What [ceremonyParts] knows about the ceremony named by [sessionId]. */
+ private data class CeremonyParts(
+ val sessionId: String?,
+ val hostKeyParticipants: Set = emptySet(),
+ val round1Participants: Set = emptySet(),
+ val round2Participants: Set = emptySet(),
+ val isKeyStateSigned: Boolean = false,
+ val isCertified: Boolean = false,
+ val certificateSession: FrostSigningSession? = null,
+ )
- launch {
- dkgRepository.observeBirthCertificate(dkgSessionId, parentChatRoomId)
- .collect { certificate ->
- val loaded = dkgRitualUIState as? DkgRitualUIState.Loaded ?: return@collect
-
- dkgRitualUIState = loaded.copy(isCertified = certificate != null)
- }
- }
-
- launch {
- dkgRepository.observeSigningSessions(parentChatRoomId).collect { sessions ->
- val loaded = dkgRitualUIState as? DkgRitualUIState.Loaded ?: return@collect
-
- dkgRitualUIState = loaded.copy(
- certificateSession = sessions.firstOrNull { local ->
- local.items.any { item ->
- runCatching {
- Event.fromJson(item.unsignedEventJson).kind
- }.getOrNull() == SubgroupBirthCertificateEvent.KIND
- }
- }?.session
- )
- }
- }
- }
- }
+ private data class Snapshot(
+ val session: DkgSession?,
+ val ceremony: CeremonyParts,
+ val keyStateSession: FrostSigningSession?,
+ val adminGroupBlockedOn: List,
+ )
/**
* Asks the group to sign what its admin room will sign with.
@@ -354,13 +274,13 @@ class DkgRitualViewModel(
* ceremony's coordinator, who is also the member who will create the room.
*
* Nothing here waits for the answer: the signing runs on arriving messages
- * like everything else, and the screen follows it through [observeKeyState].
+ * like everything else, and the screen follows it through [ceremonyState].
*/
fun proposeKeyState() {
if (isActionPending.value) return
val loaded = dkgRitualUIState as? DkgRitualUIState.Loaded ?: return
- val session = loaded.session ?: return
+ val session = loaded.session
if (session.thresholdPublicKey == null) return
// Nothing to ask for, and nobody to ask twice. A failed session is the
@@ -416,7 +336,7 @@ class DkgRitualViewModel(
* does by construction -- they are a parent admin, that is how they got here.
*
* Nothing waits for the answer. The session runs on arriving messages like
- * every other, and [observeKeyState] follows it.
+ * every other, and [ceremonyState] follows it.
*/
fun proposeBirthCertificate() {
if (isActionPending.value) return
@@ -426,7 +346,7 @@ class DkgRitualViewModel(
// any of the subgroup's admins -- see `SubgroupManager` -- and they reach
// this screen from the room, with no route to have told them anything.
val parent = loaded.parentChatRoomId ?: return
- val session = loaded.session ?: return
+ val session = loaded.session
if (session.thresholdPublicKey == null) return
// Nothing to ask for, and nobody to ask twice. A failed session is the
@@ -466,36 +386,21 @@ class DkgRitualViewModel(
}
}
- /** Opens a ritual, making this device its coordinator, and publishes the proposal. */
- fun startRitual() {
+ /**
+ * Ends this ceremony for everyone in it. The screen asks the member to confirm
+ * first; the session flow delivers the failed row, so nothing is set here.
+ */
+ fun abandon() {
if (isActionPending.value) return
val loaded = dkgRitualUIState as? DkgRitualUIState.Loaded ?: return
-
- val nostrPrivateKey = activeIdentityStateFlow.value?.nostrPrivateKey
- if (nostrPrivateKey == null) {
- dkgRitualUIState = DkgRitualUIState.Error("Couldn't read your keys. Please try again.")
- return
- }
+ if (!loaded.canAbandon) return
isActionPending.value = true
viewModelScope.launch(Dispatchers.IO) {
- val session = dkgRepository.proposeRitual(
- localChatRoom = loaded.localChatRoom,
- userPublicKey = activeUserPublicKey,
- nostrPrivateKey = nostrPrivateKey.value.toByteArray(),
- threshold = threshold.value
- )
-
+ dkgRepository.abandon(loaded.localChatRoom, loaded.session.id)
isActionPending.value = false
-
- if (session == null) {
- logger.e("Failed to start DKG ritual for $chatRoomId")
- dkgRitualUIState = DkgRitualUIState.Error("Couldn't start the key ceremony. Please try again.")
- }
- // On success the session flow above delivers the new row; no need to
- // set it here and risk racing the observer.
}
}
@@ -505,12 +410,17 @@ class DkgRitualViewModel(
* Takes the step rather than reading it back from the state so a screen opened
* for one step cannot approve a different one it has since moved on to — the
* manager checks it against the ritual again and ignores a mismatch.
+ *
+ * [onApproved] runs once the approval has been sent, not when the button is
+ * pressed. The approval screens close on it, and closing one clears this view
+ * model and cancels its scope -- so closing first could cut the publish off,
+ * and on the last approval of a round nothing arrives afterwards to resume it.
*/
- fun approve(step: DkgApprovalStep) {
+ fun approve(step: DkgApprovalStep, onApproved: () -> Unit = {}) {
if (isActionPending.value) return
val loaded = dkgRitualUIState as? DkgRitualUIState.Loaded ?: return
- val session = loaded.session ?: return
+ val session = loaded.session
val nostrPrivateKey = activeIdentityStateFlow.value?.nostrPrivateKey
if (nostrPrivateKey == null) {
@@ -531,6 +441,8 @@ class DkgRitualViewModel(
isActionPending.value = false
// The session flow delivers the updated row and with it the next pending
// step, so nothing is set here.
+
+ withContext(Main) { onApproved() }
}
}
@@ -559,7 +471,7 @@ class DkgRitualViewModel(
if (isActionPending.value) return
val loaded = dkgRitualUIState as? DkgRitualUIState.Loaded ?: return
- val session = loaded.session ?: return
+ val session = loaded.session
val thresholdPublicKey = session.thresholdPublicKey ?: return
// The screen offers nothing until the group has signed, so this is a
@@ -594,7 +506,7 @@ class DkgRitualViewModel(
?: if (subgroupParent != null) "Subgroup" else "Group"
isActionPending.value = true
- dkgRitualUIState = loaded.copy(adminGroupBlockedOn = emptyList())
+ adminGroupBlockedOn.value = emptyList()
viewModelScope.launch(Dispatchers.IO) {
val outcome = chatRepository.createMarmotGroup(
@@ -621,15 +533,13 @@ class DkgRitualViewModel(
// Named rather than counted. A member cannot publish a key
// package on somebody else's behalf, so the only useful thing
// to say is whose door to knock on.
- dkgRitualUIState = loaded.copy(
- adminGroupBlockedOn = outcome.missing.map { publicKey ->
- loaded.ritualMembers
- .firstOrNull { it.participant.participantPublicKey == publicKey }
- ?.profile
- ?.humanReadableNameOrPubkey()
- ?: publicKey.take(12)
- }
- )
+ adminGroupBlockedOn.value = outcome.missing.map { publicKey ->
+ loaded.ritualMembers
+ .firstOrNull { it.participant.participantPublicKey == publicKey }
+ ?.profile
+ ?.humanReadableNameOrPubkey()
+ ?: publicKey.take(12)
+ }
}
is MarmotGroupCreation.Outcome.Failed -> {
@@ -659,13 +569,6 @@ class DkgRitualViewModel(
}
}
- override fun onCleared() {
- messageObserver?.cancel()
- keyStateObserver?.cancel()
- certificateObserver?.cancel()
- super.onCleared()
- }
-
companion object {
private const val TAG = "DkgRitualViewModel"
@@ -675,7 +578,7 @@ class DkgRitualViewModel(
fun factory(
chatRoomId: String,
activeUserPublicKey: HexKey,
- dkgSessionId: String? = null,
+ dkgSessionId: String,
initialDkgRitualUIState: DkgRitualUIState = DkgRitualUIState.Loading,
activeIdentityStateFlow: StateFlow,
chatRepository: ChatRepository,
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/SelectSubgroupAdminsViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/SelectSubgroupAdminsViewModel.kt
index 9e3a5e17..2e641906 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/SelectSubgroupAdminsViewModel.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/SelectSubgroupAdminsViewModel.kt
@@ -16,6 +16,7 @@ import com.machankura.bennu.compose.identity.Identity
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import com.machankura.bennu.compose.database.model.types.ChatRoomType
@@ -49,6 +50,8 @@ import com.machankura.bennu.compose.ui.view.state.SelectSubgroupAdminsUIState
class SelectSubgroupAdminsViewModel(
val activeUserPublicKey: HexKey,
val parentChatRoomId: String,
+ /** A failed subgroup ceremony to start from; see `SelectSubgroupAdminsRoute.retrying`. */
+ val retrying: String? = null,
initialUIState: SelectSubgroupAdminsUIState,
val activeIdentityStateFlow: StateFlow,
val chatRepository: ChatRepository,
@@ -78,6 +81,9 @@ class SelectSubgroupAdminsViewModel(
val threshold: MutableState = mutableStateOf(ChatRoomType.MINIMUM_QUORUM)
+ /** Whether [retrying] has been read into the form, which happens once. */
+ private var prefilled = false
+
fun initiate() {
viewModelScope.launch(Dispatchers.IO) {
val parentRoom = chatRepository.getChatRoomByIdentifier(parentChatRoomId)
@@ -97,10 +103,42 @@ class SelectSubgroupAdminsViewModel(
candidates = candidates,
)
+ // Before the key-package lookup, so anybody who can no longer be
+ // welcomed is unpicked by the same rule as a fresh pick would be.
+ prefillFromRetry(candidates.map { it.participant.participantPublicKey }.toSet())
+
resolveKeyPackages(candidates.map { it.participant.participantPublicKey })
}
}
+ /**
+ * Starts the form from the failed ceremony this is trying again.
+ *
+ * Only from one that was this parent's subgroup, and only admins who are
+ * still in the parent: the ceremony recorded who it was with, and the
+ * parent's membership may have moved since. Once, because the screen asks
+ * to start again every time it comes back into view and a member's edits
+ * must not be put back.
+ */
+ private suspend fun prefillFromRetry(candidates: Set) {
+ val sessionId = retrying ?: return
+ if (prefilled) return
+ prefilled = true
+
+ val failed = dkgRepository.observeSessionById(sessionId).first() ?: return
+ if (failed.parentChatRoomId != parentChatRoomId) return
+
+ name.value = failed.subject.orEmpty()
+
+ selectedPublicKeys.clear()
+ selectedPublicKeys.addAll(
+ failed.participantPublicKeySet().orEmpty()
+ .filter { it != activeUserPublicKey && it in candidates }
+ )
+
+ threshold.value = failed.threshold.coerceIn(quorumRange())
+ }
+
/**
* Asks every candidate's key package up front.
*
@@ -265,14 +303,6 @@ class SelectSubgroupAdminsViewModel(
// arrive -- which is now literally the same place every other
// admin answers from, through the ritual notices that name their
// own ceremony.
- //
- // Sending them to the shared-key screen instead was actively
- // harmful: that screen's job is to *offer* a ceremony to a room
- // that has none, so the coordinator arrived at a "Start key
- // ceremony" button seconds after starting one, and pressing it
- // opened a second -- for no subgroup, so `proposeRitual`'s guard
- // did not recognise it as a duplicate -- which then buried the
- // subgroup's under the room's newest.
onNavigateToRoute(
ChatRoomMessagingRoute(
activeUserPublicKey = activeUserPublicKey,
@@ -290,6 +320,7 @@ class SelectSubgroupAdminsViewModel(
fun factory(
activeUserPublicKey: HexKey,
parentChatRoomId: String,
+ retrying: String? = null,
initialUIState: SelectSubgroupAdminsUIState = SelectSubgroupAdminsUIState.Loading,
activeIdentityStateFlow: StateFlow,
chatRepository: ChatRepository,
@@ -299,6 +330,7 @@ class SelectSubgroupAdminsViewModel(
SelectSubgroupAdminsViewModel(
activeUserPublicKey = activeUserPublicKey,
parentChatRoomId = parentChatRoomId,
+ retrying = retrying,
initialUIState = initialUIState,
activeIdentityStateFlow = activeIdentityStateFlow,
chatRepository = chatRepository,
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/TranslateChunkViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/TranslateChunkViewModel.kt
deleted file mode 100644
index 38e195ca..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/TranslateChunkViewModel.kt
+++ /dev/null
@@ -1,175 +0,0 @@
-package com.machankura.bennu.compose.ui.view.model
-
-import androidx.compose.foundation.text.input.TextFieldState
-import androidx.compose.runtime.MutableState
-import androidx.compose.runtime.getValue
-import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.setValue
-import androidx.lifecycle.ViewModel
-import androidx.lifecycle.ViewModelProvider
-import androidx.lifecycle.viewModelScope
-import androidx.lifecycle.viewmodel.initializer
-import androidx.lifecycle.viewmodel.viewModelFactory
-import co.touchlab.kermit.Logger
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.IO
-import kotlinx.coroutines.launch
-import com.machankura.bennu.compose.database.model.MantraChunk
-import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
-import com.machankura.bennu.compose.nostr.nip30303.TranslationChunkEvent
-import com.machankura.bennu.compose.repository.ChatRepository
-import com.machankura.bennu.compose.repository.FrostSigningRepository
-import com.machankura.bennu.compose.repository.MantraRepository
-import com.machankura.bennu.compose.ui.view.state.TranslateChunkUIState
-
-class TranslateChunkViewModel(
- val translationChapterId: String,
- val chunkId: String,
- val chatRoomId: String,
- val activeUserPublicKey: HexKey,
- val relayHint: String?,
- initialTranslateChunkUIState: TranslateChunkUIState,
- val mantraRepository: MantraRepository,
- val chatRepository: ChatRepository,
- val frostSigningRepository: FrostSigningRepository,
-): ViewModel() {
-
- var translateChunkUIState: TranslateChunkUIState by mutableStateOf(initialTranslateChunkUIState)
- private set
-
- private val logger = Logger.withTag(TAG)
-
- val isActionPending: MutableState = mutableStateOf(false)
-
- fun initiateTranslateChunk() {
- viewModelScope.launch(Dispatchers.IO) {
- val originalChunk = mantraRepository.getChunk(chunkId)
- val localChatRoom = chatRepository.getChatRoomByIdentifier(chatRoomId)
-
- translateChunkUIState = when {
- originalChunk == null -> TranslateChunkUIState.Error("Couldn't find the chunk")
- localChatRoom == null -> TranslateChunkUIState.Error("Couldn't find the chat room")
- else -> TranslateChunkUIState.Loaded(
- localChatRoom = localChatRoom,
- originalChunk = originalChunk,
- // What the group has already signed for this chunk, so a
- // retranslation starts from it rather than from nothing.
- existingTranslationText = mantraRepository
- .getTranslationChunks(translationChapterId)
- .firstOrNull { it.chunkId == chunkId }
- ?.text
- .orEmpty(),
- canSign = frostSigningRepository.canSign(chatRoomId),
- )
- }
- }
- }
-
- /**
- * Asks the group to sign this chunk's translation.
- *
- * The translation is not saved here and does not exist yet. What goes out is
- * a proposal to sign it, and the translated chunk appears -- on every
- * member's device at once, authored by this room's own key rather than by
- * whoever typed it -- when enough members have signed. That author is the
- * room's id: signing runs at the path the room was derived at, so a
- * translated chunk says which group rendered it simply by being signed.
- *
- * That is the difference from submitting one. A submission says "I am
- * putting this in front of the group" and the group's only recourse
- * afterwards is social. A signature is the group saying it, and it takes a
- * quorum to say. What a chunk means in another tongue is a claim the group
- * is making about somebody else's words, so the second is the honest one.
- *
- * A retranslation goes the same way: the event carries a different text and
- * so a different id, and it replaces the one the group signed before rather
- * than editing it -- there is nothing here to edit, since the old text is
- * already signed.
- */
- fun proposeTranslation(
- localChatRoom: LocalChatRoom,
- originalChunk: MantraChunk,
- translationField: TextFieldState,
- onSuccess: (sessionId: String) -> Unit,
- onFailure: () -> Unit
- ) {
- val text = translationField.text.toString()
- if (text.isBlank()) {
- onFailure.invoke()
- return
- }
-
- // Guard against double submits from repeated FAB taps.
- if (isActionPending.value) return
- isActionPending.value = true
-
- viewModelScope.launch(Dispatchers.IO) {
- val translationChunkEventTemplate = TranslationChunkEvent.build(
- translationChapterId = translationChapterId,
- chunkId = originalChunk.id,
- // The translation sits where the chunk it translates sits. Read
- // off the source rather than counted here: a chapter is
- // translated a chunk at a time and in no particular order, so
- // counting what is translated so far would number them by who
- // got there first.
- index = originalChunk.index,
- text = text,
- )
-
- val session = runCatching {
- frostSigningRepository.proposeSigning(
- localChatRoom = localChatRoom,
- userPublicKey = activeUserPublicKey,
- kind = translationChunkEventTemplate.kind,
- tags = translationChunkEventTemplate.tags,
- content = translationChunkEventTemplate.content,
- )
- }.onFailure { error ->
- logger.e("Failed to propose a translation for signing", error)
- }.getOrNull()
-
- if (session != null) {
- viewModelScope.launch(Dispatchers.Main) {
- onSuccess.invoke(session.id)
- }
- } else {
- viewModelScope.launch(Dispatchers.Main) {
- onFailure.invoke()
- }
- }
-
- isActionPending.value = false
- }
- }
-
- companion object {
- private const val TAG = "TranslateChunkViewModel"
-
- fun factory(
- activeUserPublicKey: HexKey,
- translationChapterId: String,
- chunkId: String,
- chatRoomId: String,
- relayHint: String?,
- initialTranslateChunkUIState: TranslateChunkUIState = TranslateChunkUIState.Loading,
- mantraRepository: MantraRepository,
- chatRepository: ChatRepository,
- frostSigningRepository: FrostSigningRepository,
- ): ViewModelProvider.Factory = viewModelFactory {
- initializer {
- TranslateChunkViewModel(
- activeUserPublicKey = activeUserPublicKey,
- translationChapterId = translationChapterId,
- chunkId = chunkId,
- chatRoomId = chatRoomId,
- relayHint = relayHint,
- initialTranslateChunkUIState = initialTranslateChunkUIState,
- mantraRepository = mantraRepository,
- chatRepository = chatRepository,
- frostSigningRepository = frostSigningRepository,
- )
- }
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/TranslationArtifactVersionDetailViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/TranslationArtifactVersionDetailViewModel.kt
deleted file mode 100644
index 1ef0431c..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/TranslationArtifactVersionDetailViewModel.kt
+++ /dev/null
@@ -1,172 +0,0 @@
-package com.machankura.bennu.compose.ui.view.model
-
-import androidx.compose.runtime.MutableState
-import androidx.compose.runtime.getValue
-import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.setValue
-import androidx.lifecycle.ViewModel
-import androidx.lifecycle.ViewModelProvider
-import androidx.lifecycle.viewModelScope
-import androidx.lifecycle.viewmodel.initializer
-import androidx.lifecycle.viewmodel.viewModelFactory
-import co.touchlab.kermit.Logger
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import com.vitorpamplona.quartz.utils.TimeUtils
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.IO
-import kotlinx.coroutines.launch
-import com.machankura.bennu.compose.database.model.MantraChapter
-import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
-import com.machankura.bennu.compose.managers.FrostSigningManager
-import com.machankura.bennu.compose.managers.TranslationScaffold
-import com.machankura.bennu.compose.repository.ChatRepository
-import com.machankura.bennu.compose.repository.FrostSigningRepository
-import com.machankura.bennu.compose.repository.MantraRepository
-import com.machankura.bennu.compose.ui.view.state.TranslationChapterProgress
-import com.machankura.bennu.compose.ui.view.state.TranslationArtifactVersionDetailUIState
-
-class TranslationArtifactVersionDetailViewModel(
- val translationArtifactVersionId: String,
- val chatRoomId: String,
- val activeUserPublicKey: HexKey,
- val relayHint: String?,
- initialTranslationArtifactVersionDetailUIState: TranslationArtifactVersionDetailUIState,
- val mantraRepository: MantraRepository,
- val chatRepository: ChatRepository,
- val frostSigningRepository: FrostSigningRepository,
-): ViewModel() {
-
- var translationDetailUIState: TranslationArtifactVersionDetailUIState by mutableStateOf(initialTranslationArtifactVersionDetailUIState)
- private set
-
- private val logger = Logger.withTag(TAG)
-
- val isActionPending: MutableState = mutableStateOf(false)
-
- fun initiateTranslationArtifactVersionDetail() {
- logger.d("initiateTranslationArtifactVersionDetail: $translationArtifactVersionId")
- viewModelScope.launch(Dispatchers.IO) {
- val translation = mantraRepository.getTranslation(translationArtifactVersionId)
-
- translationDetailUIState = if (translation == null) {
- TranslationArtifactVersionDetailUIState.Error("Couldn't find the translation")
- } else {
- val translationChapters = mantraRepository.getTranslationChapters(translationArtifactVersionId)
- val chapters = translationChapters.map { chapter ->
- val chunks = mantraRepository.getTranslationChunks(chapter.id)
- TranslationChapterProgress(
- chapter = chapter,
- totalChunks = chunks.size,
- translatedChunks = chunks.count { it.text.isNotBlank() },
- )
- }
-
- TranslationArtifactVersionDetailUIState.Loaded(
- translation = translation,
- chapters = chapters,
- localChatRoom = chatRepository.getChatRoomByIdentifier(chatRoomId),
- missingChapters = TranslationScaffold.chaptersMissingFrom(
- translationChapters = translationChapters,
- sourceChapters = mantraRepository
- .getChaptersForArtifactVersion(translation.artifactVersionId),
- ),
- canSign = frostSigningRepository.canSign(chatRoomId),
- )
- }
- }
- }
-
- /**
- * Asks the group to put the chapters this translation is missing into it.
- *
- * The scaffolding a chapter is signed with covers the translations that
- * existed when it was proposed, and the scaffolding a translation is signed
- * with covers the chapters that existed when *it* was proposed. Two things
- * proposed at the same moment see neither the other, and a session that
- * fails to reach a quorum leaves nothing behind to try again with. Neither
- * is a bug that can be designed out of a snapshot taken at proposal time --
- * so this is the pass that reconciles them, run when somebody notices.
- *
- * It proposes only what is missing, matched on the source chapter each
- * translation chapter names, so running it on a translation that is already
- * complete proposes nothing rather than a second copy of everything.
- */
- fun catchUpMissingChapters(
- localChatRoom: LocalChatRoom,
- missingChapters: List,
- onSuccess: (sessionId: String) -> Unit,
- onFailure: () -> Unit
- ) {
- if (missingChapters.isEmpty()) {
- onFailure.invoke()
- return
- }
-
- // Guard against double submits from repeated taps.
- if (isActionPending.value) return
- isActionPending.value = true
-
- viewModelScope.launch(Dispatchers.IO) {
- // One timestamp for the lot, so a catch-up reads as the one act it
- // is rather than as chapters that happen to share a minute.
- val createdAt = TimeUtils.now()
-
- val sessions = runCatching {
- // One session per MAX_BATCH_SIZE chapters. A translation far
- // enough behind to need more than a batch holds is not one to
- // refuse; it is one the group answers for more than once.
- missingChapters.chunked(FrostSigningManager.MAX_BATCH_SIZE).mapNotNull { batch ->
- frostSigningRepository.proposeSigningBatch(
- localChatRoom = localChatRoom,
- userPublicKey = activeUserPublicKey,
- events = TranslationScaffold.chaptersOf(
- translationArtifactVersionIds = listOf(translationArtifactVersionId),
- chapters = batch.map(TranslationScaffold.SourceChapter::of),
- createdAt = createdAt,
- )
- )
- }
- }.onFailure { error ->
- logger.e("Failed to propose this translation's missing chapters", error)
- }.getOrNull().orEmpty()
-
- // The first, because it is the one that opened; the rest are in the
- // room's session list beside it.
- val session = sessions.firstOrNull()
-
- viewModelScope.launch(Dispatchers.Main) {
- if (session != null) onSuccess.invoke(session.id) else onFailure.invoke()
- }
-
- isActionPending.value = false
- }
- }
-
- companion object {
- private const val TAG = "TranslationArtifactVersionDetailViewModel"
-
- fun factory(
- activeUserPublicKey: HexKey,
- translationArtifactVersionId: String,
- chatRoomId: String,
- relayHint: String?,
- initialTranslationArtifactVersionDetailUIState: TranslationArtifactVersionDetailUIState = TranslationArtifactVersionDetailUIState.Loading,
- mantraRepository: MantraRepository,
- chatRepository: ChatRepository,
- frostSigningRepository: FrostSigningRepository,
- ): ViewModelProvider.Factory = viewModelFactory {
- initializer {
- TranslationArtifactVersionDetailViewModel(
- activeUserPublicKey = activeUserPublicKey,
- translationArtifactVersionId = translationArtifactVersionId,
- chatRoomId = chatRoomId,
- relayHint = relayHint,
- initialTranslationArtifactVersionDetailUIState = initialTranslationArtifactVersionDetailUIState,
- mantraRepository = mantraRepository,
- chatRepository = chatRepository,
- frostSigningRepository = frostSigningRepository,
- )
- }
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/TranslationChapterViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/TranslationChapterViewModel.kt
deleted file mode 100644
index 8a61891e..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/TranslationChapterViewModel.kt
+++ /dev/null
@@ -1,98 +0,0 @@
-package com.machankura.bennu.compose.ui.view.model
-
-import androidx.compose.runtime.getValue
-import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.setValue
-import androidx.lifecycle.ViewModel
-import androidx.lifecycle.ViewModelProvider
-import androidx.lifecycle.viewModelScope
-import androidx.lifecycle.viewmodel.initializer
-import androidx.lifecycle.viewmodel.viewModelFactory
-import co.touchlab.kermit.Logger
-import com.vitorpamplona.quartz.nip01Core.core.HexKey
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.IO
-import kotlinx.coroutines.launch
-import com.machankura.bennu.compose.repository.MantraRepository
-import com.machankura.bennu.compose.ui.view.state.ChunkTranslationPair
-import com.machankura.bennu.compose.ui.view.state.TranslationChapterUIState
-
-class TranslationChapterViewModel(
- val translationChapterId: String,
- val chatRoomId: String,
- val activeUserPublicKey: HexKey,
- val relayHint: String?,
- initialTranslationChapterUIState: TranslationChapterUIState,
- val mantraRepository: MantraRepository,
-): ViewModel() {
-
- var translationChapterUIState: TranslationChapterUIState by mutableStateOf(initialTranslationChapterUIState)
- private set
-
- private val logger = Logger.withTag(TAG)
-
- fun initiateTranslationChapter() {
- logger.d("initiateTranslationChapter: $translationChapterId")
- viewModelScope.launch(Dispatchers.IO) {
- val translationChapter = mantraRepository.getTranslationChapter(translationChapterId)
- val sourceChapter = translationChapter?.let { mantraRepository.getChapter(it.chapterId) }
-
- translationChapterUIState = if (translationChapter == null || sourceChapter == null) {
- TranslationChapterUIState.Error("Couldn't find the translation chapter")
- } else {
- // Original dialect: source chapter -> version -> artifact -> dialect.
- val originalDialectName = mantraRepository.getArtifactVersion(sourceChapter.artifactVersionId)
- ?.let { mantraRepository.getArtifact(it.artifactId) }
- ?.let { mantraRepository.getDialect(it.dialectId) }
- ?.name ?: "Original"
-
- // Translation dialect: translation version -> dialect.
- val translationDialectName = mantraRepository.getTranslation(translationChapter.translationArtifactVersionId)
- ?.let { mantraRepository.getDialect(it.dialectId) }
- ?.name ?: "Translation"
-
- // Pair each original chunk with its translation chunk (by chunkId).
- val translationChunksByChunkId = mantraRepository
- .getTranslationChunks(translationChapter.id)
- .associateBy { it.chunkId }
-
- val rows = mantraRepository.getChunksForChapter(sourceChapter.id).map { originalChunk ->
- ChunkTranslationPair(
- originalChunk = originalChunk,
- translationChunk = translationChunksByChunkId[originalChunk.id],
- )
- }
-
- TranslationChapterUIState.Loaded(
- originalDialectName = originalDialectName,
- translationDialectName = translationDialectName,
- rows = rows,
- )
- }
- }
- }
-
- companion object {
- private const val TAG = "TranslationChapterViewModel"
-
- fun factory(
- activeUserPublicKey: HexKey,
- translationChapterId: String,
- chatRoomId: String,
- relayHint: String?,
- initialTranslationChapterUIState: TranslationChapterUIState = TranslationChapterUIState.Loading,
- mantraRepository: MantraRepository,
- ): ViewModelProvider.Factory = viewModelFactory {
- initializer {
- TranslationChapterViewModel(
- activeUserPublicKey = activeUserPublicKey,
- translationChapterId = translationChapterId,
- chatRoomId = chatRoomId,
- relayHint = relayHint,
- initialTranslationChapterUIState = initialTranslationChapterUIState,
- mantraRepository = mantraRepository,
- )
- }
- }
- }
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/AddArtifactUIState.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/AddArtifactUIState.kt
deleted file mode 100755
index 4de694a1..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/AddArtifactUIState.kt
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.machankura.bennu.compose.ui.view.state
-
-import com.machankura.bennu.compose.database.model.MantraDialect
-import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
-
-sealed interface AddArtifactUIState {
- data class Loaded(
- val localChatRoom: LocalChatRoom,
- val dialects: List = emptyList(),
-
- /**
- * Whether the group holds a shared key. An artifact is signed into
- * existence now rather than submitted, so a group without one cannot
- * add one here at all.
- */
- val canSign: Boolean = false,
- ): AddArtifactUIState
-
- data class Error(
- val message: String
- ): AddArtifactUIState
-
- data object Loading: AddArtifactUIState
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/AddChapterUIState.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/AddChapterUIState.kt
deleted file mode 100644
index 89ff2ca2..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/AddChapterUIState.kt
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.machankura.bennu.compose.ui.view.state
-
-import com.machankura.bennu.compose.database.model.MantraArtifact
-import com.machankura.bennu.compose.database.model.MantraArtifactVersion
-import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
-
-sealed interface AddChapterUIState {
- data class Loaded(
- val localChatRoom: LocalChatRoom,
- val artifact: MantraArtifact,
-
- /**
- * The version the chapter would attach to: the artifact's latest.
- *
- * Null on an artifact that has none, which is one nothing can be added
- * to -- a chapter hangs off a version rather than off an artifact.
- */
- val artifactVersion: MantraArtifactVersion? = null,
-
- /**
- * Whether the group holds a shared key. A chapter is signed into
- * existence now rather than submitted, so a group without one cannot
- * add one here at all.
- */
- val canSign: Boolean = false,
- ): AddChapterUIState
-
- data class Error(
- val message: String
- ): AddChapterUIState
-
- data object Loading: AddChapterUIState
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/AddDialectUIState.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/AddDialectUIState.kt
deleted file mode 100644
index 21951d3a..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/AddDialectUIState.kt
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.machankura.bennu.compose.ui.view.state
-
-import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
-
-sealed interface AddDialectUIState {
- data class Loaded(
- val localChatRoom: LocalChatRoom,
-
- /**
- * Whether the group holds a shared key. A dialect is signed into
- * existence now rather than submitted, so a group without one cannot
- * make one here at all.
- */
- val canSign: Boolean = false,
- ): AddDialectUIState
-
- data class Error(
- val message: String
- ): AddDialectUIState
-
- data object Loading: AddDialectUIState
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/AddTranslationArtifactVersionUIState.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/AddTranslationArtifactVersionUIState.kt
deleted file mode 100644
index 36edc1c9..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/AddTranslationArtifactVersionUIState.kt
+++ /dev/null
@@ -1,52 +0,0 @@
-package com.machankura.bennu.compose.ui.view.state
-
-import com.machankura.bennu.compose.database.model.MantraArtifact
-import com.machankura.bennu.compose.database.model.MantraArtifactVersion
-import com.machankura.bennu.compose.database.model.MantraChapter
-import com.machankura.bennu.compose.database.model.MantraDialect
-import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
-
-sealed interface AddTranslationArtifactVersionUIState {
- data class Loaded(
- val localChatRoom: LocalChatRoom,
- val artifact: MantraArtifact,
-
- /**
- * The dialects this room has signed into existence. A translation is
- * into one of them and only one of them: an invented dialect is a
- * dialect nobody agreed to, and the room already has a screen for
- * asking the group for a new one.
- */
- val dialects: List = emptyList(),
-
- /**
- * The version being translated: the artifact's latest.
- *
- * Null on an artifact that has none, which is one there is nothing to
- * translate -- a translation is of a version rather than of an artifact.
- */
- val artifactVersion: MantraArtifactVersion? = null,
-
- /**
- * The chapters of that version, which the translation is laid out
- * against: a translation chapter each, signed in the same session.
- *
- * Held here rather than re-read when proposing, so that the count the
- * form shows is the count the group is asked to sign.
- */
- val chapters: List = emptyList(),
-
- /**
- * Whether the group holds a shared key. A translation is signed into
- * existence now rather than submitted, so a group without one cannot
- * start one here at all.
- */
- val canSign: Boolean = false,
- ): AddTranslationArtifactVersionUIState
-
- data class Error(
- val message: String
- ): AddTranslationArtifactVersionUIState
-
- data object Loading: AddTranslationArtifactVersionUIState
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/ArtifactDetailUIState.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/ArtifactDetailUIState.kt
deleted file mode 100644
index 468ed2d2..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/ArtifactDetailUIState.kt
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.machankura.bennu.compose.ui.view.state
-
-import com.machankura.bennu.compose.database.model.MantraArtifact
-import com.machankura.bennu.compose.database.model.MantraArtifactVersion
-import com.machankura.bennu.compose.database.model.MantraChapter
-import com.machankura.bennu.compose.database.model.MantraTranslationArtifactVersion
-
-sealed interface ArtifactDetailUIState {
- data class Loaded(
- val artifact: MantraArtifact,
- val versions: List = emptyList(),
- val chapters: List = emptyList(),
- val translations: List = emptyList(),
- ): ArtifactDetailUIState
-
- data class Error(
- val message: String
- ): ArtifactDetailUIState
-
- data object Loading: ArtifactDetailUIState
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/ChapterDetailUIState.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/ChapterDetailUIState.kt
deleted file mode 100644
index 33b9d74b..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/ChapterDetailUIState.kt
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.machankura.bennu.compose.ui.view.state
-
-import com.machankura.bennu.compose.database.model.MantraChapter
-import com.machankura.bennu.compose.database.model.MantraChunk
-
-sealed interface ChapterDetailUIState {
- data class Loaded(
- val chapter: MantraChapter,
- val chunks: List = emptyList(),
- ): ChapterDetailUIState
-
- data class Error(
- val message: String
- ): ChapterDetailUIState
-
- data object Loading: ChapterDetailUIState
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/CreateSharedKeyUIState.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/CreateSharedKeyUIState.kt
new file mode 100644
index 00000000..3942a9b9
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/CreateSharedKeyUIState.kt
@@ -0,0 +1,40 @@
+package com.machankura.bennu.compose.ui.view.state
+
+import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
+
+sealed interface CreateSharedKeyUIState {
+ /** The room, and how many people a ceremony in it would be split across. */
+ data class Loaded(
+ val localChatRoom: LocalChatRoom,
+ val participantCount: Int,
+ ) : CreateSharedKeyUIState
+
+ /**
+ * The group already has a ceremony that has not failed -- running, or finished
+ * with a key. The screen hands over to it rather than offering a second: a
+ * second is another participant set for every member to reconcile, and the key
+ * the first produced would be left with nothing pointing at it.
+ */
+ data class Existing(val dkgSessionId: String) : CreateSharedKeyUIState
+
+ /** This room cannot hold a ceremony of its own, and the screen says why. */
+ data class Refused(val reason: Reason) : CreateSharedKeyUIState {
+ enum class Reason {
+ /**
+ * A Marmot room's id is derived from the key it already has, so a key
+ * of its own is one it could never answer to. It hosts its subgroups'
+ * ceremonies, which are started from the subgroup picker.
+ */
+ MARMOT_ROOM,
+
+ /** A key held by one person is just a key. */
+ TOO_FEW_MEMBERS,
+ }
+ }
+
+ data class Error(val reason: Reason) : CreateSharedKeyUIState {
+ enum class Reason { ROOM_NOT_FOUND, NO_KEYS, NOT_STARTED }
+ }
+
+ data object Loading : CreateSharedKeyUIState
+}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/DkgRitualUIState.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/DkgRitualUIState.kt
index 5d5e2761..f1313293 100644
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/DkgRitualUIState.kt
+++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/DkgRitualUIState.kt
@@ -7,14 +7,19 @@ import com.machankura.bennu.compose.database.model.Participant
import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
import com.machankura.bennu.compose.database.model.intermdiate.LocalParticipant
import com.machankura.bennu.compose.database.model.types.DkgApprovalStep
+import com.machankura.bennu.compose.database.model.types.DkgRitualStage
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.machankura.bennu.compose.managers.ChillDkgRitualManager
sealed interface DkgRitualUIState {
data class Loaded(
val localChatRoom: LocalChatRoom,
- /** Null until somebody opens a ritual. */
- val session: DkgSession? = null,
+ /**
+ * The ceremony this screen was named. Never absent once loaded: the screen
+ * shows a ceremony and does not offer to start one, so there is no state
+ * in which it has none to show -- see docs/ceremony-creation.md.
+ */
+ val session: DkgSession,
/**
* Who has published each round's message, for the progress ladder.
*
@@ -63,18 +68,6 @@ sealed interface DkgRitualUIState {
* signed first. It is what gates creating the room.
*/
val isKeyStateSigned: Boolean = false,
- /**
- * Whether this room already holds a ceremony that has not failed --
- * whichever one [session] happens to be showing.
- *
- * Two different questions, and conflating them opened a second ceremony
- * in a room that already had one. [session] is the ceremony being looked
- * at; this is whether the room has any. `proposeRitual`'s guard is scoped
- * by purpose, so a room holding a subgroup's ceremony would happily take
- * a second one for no subgroup -- and then "the room's newest ceremony"
- * is the new empty one and the subgroup's is buried under it.
- */
- val roomHasCeremony: Boolean = false,
/**
* The group this ceremony is making a subgroup of, or null for an
* ordinary one.
@@ -124,9 +117,7 @@ sealed interface DkgRitualUIState {
.distinctBy { it.participant.participantPublicKey }
.associateBy { it.participant.participantPublicKey }
- val participants = session
- ?.let { ChillDkgRitualManager.participantsOf(it, localChatRoom) }
- ?: roomMembers.keys
+ val participants = ChillDkgRitualManager.participantsOf(session, localChatRoom)
return (participants + hostKeyParticipants + round1Participants + round2Participants)
.map { publicKey ->
@@ -142,13 +133,20 @@ sealed interface DkgRitualUIState {
}
/**
- * The `n` of the t-of-n. Counted over people, not participant rows — a room
- * can hold the same member twice — and taken from the session once one
- * exists, because that is the count every device agreed to run the ritual on.
+ * Whether this member can end the ceremony for everyone: while it is still
+ * running, and only if they are in it. See `ChillDkgRitualManager.abandon`.
+ */
+ val canAbandon: Boolean
+ get() = session.stage != DkgRitualStage.COMPLETE &&
+ session.stage != DkgRitualStage.FAILED &&
+ session.userPublicKey in ChillDkgRitualManager.participantsOf(session, localChatRoom)
+
+ /**
+ * The `n` of the t-of-n, as the session has it, because that is the count
+ * every device agreed to run the ritual on.
*/
val participantCount: Int
- get() = session?.participantCount
- ?: ChillDkgRitualManager.memberPublicKeys(localChatRoom).size
+ get() = session.participantCount
}
data class Error(
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/TranslateChunkUIState.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/TranslateChunkUIState.kt
deleted file mode 100644
index b6281d6c..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/TranslateChunkUIState.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.machankura.bennu.compose.ui.view.state
-
-import com.machankura.bennu.compose.database.model.MantraChunk
-import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
-
-sealed interface TranslateChunkUIState {
- data class Loaded(
- val localChatRoom: LocalChatRoom,
- val originalChunk: MantraChunk,
- val existingTranslationText: String = "",
-
- /**
- * Whether the group holds a shared key. A translation is signed into
- * existence now rather than saved, so a group without one cannot
- * translate a chunk here at all.
- */
- val canSign: Boolean = false,
- ): TranslateChunkUIState
-
- data class Error(
- val message: String
- ): TranslateChunkUIState
-
- data object Loading: TranslateChunkUIState
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/TranslationArtifactVersionDetailUIState.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/TranslationArtifactVersionDetailUIState.kt
deleted file mode 100644
index 3d67b44a..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/TranslationArtifactVersionDetailUIState.kt
+++ /dev/null
@@ -1,48 +0,0 @@
-package com.machankura.bennu.compose.ui.view.state
-
-import com.machankura.bennu.compose.database.model.MantraChapter
-import com.machankura.bennu.compose.database.model.MantraTranslationArtifactVersion
-import com.machankura.bennu.compose.database.model.MantraTranslationChapter
-import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
-
-/** A translation chapter with how many of its chunks have been translated. */
-data class TranslationChapterProgress(
- val chapter: MantraTranslationChapter,
- val totalChunks: Int,
- val translatedChunks: Int,
-)
-
-sealed interface TranslationArtifactVersionDetailUIState {
- data class Loaded(
- val translation: MantraTranslationArtifactVersion,
- val chapters: List = emptyList(),
-
- /**
- * The room this translation belongs to, which is who would sign the
- * chapters it is missing. Null when it cannot be read, which is a
- * translation nothing can be proposed for.
- */
- val localChatRoom: LocalChatRoom? = null,
-
- /**
- * Chapters of the source version this translation has nothing for.
- *
- * A translation covers the chapters that existed when it was proposed,
- * and a chapter signed afterwards is scaffolded into it by a session of
- * that chapter's own -- which the two can miss, by being proposed at the
- * same moment or by one of them not reaching a quorum. This is what is
- * left over when they do, and it is shown rather than inferred because
- * a chapter nobody can translate is invisible from the translation.
- */
- val missingChapters: List = emptyList(),
-
- /** Whether the group holds a shared key, without which nothing can be proposed. */
- val canSign: Boolean = false,
- ): TranslationArtifactVersionDetailUIState
-
- data class Error(
- val message: String
- ): TranslationArtifactVersionDetailUIState
-
- data object Loading: TranslationArtifactVersionDetailUIState
-}
diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/TranslationChapterUIState.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/TranslationChapterUIState.kt
deleted file mode 100644
index 0f2b8a08..00000000
--- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/TranslationChapterUIState.kt
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.machankura.bennu.compose.ui.view.state
-
-import com.machankura.bennu.compose.database.model.MantraChunk
-import com.machankura.bennu.compose.database.model.MantraTranslationChunk
-
-/**
- * An original chunk paired with its translation chunk. [translationChunk] is
- * null (or has blank text) when the chunk hasn't been translated yet, in which
- * case the UI shows the original text as a greyed-out placeholder.
- */
-data class ChunkTranslationPair(
- val originalChunk: MantraChunk,
- val translationChunk: MantraTranslationChunk?,
-)
-
-sealed interface TranslationChapterUIState {
- data class Loaded(
- val originalDialectName: String,
- val translationDialectName: String,
- val rows: List = emptyList(),
- ): TranslationChapterUIState
-
- data class Error(
- val message: String
- ): TranslationChapterUIState
-
- data object Loading: TranslationChapterUIState
-}
diff --git a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/database/model/RumorIdAgreementTest.kt b/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/database/model/RumorIdAgreementTest.kt
deleted file mode 100644
index d897746c..00000000
--- a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/database/model/RumorIdAgreementTest.kt
+++ /dev/null
@@ -1,175 +0,0 @@
-package com.machankura.bennu.compose.database.model
-
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
-import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
-import kotlin.test.Test
-import kotlin.test.assertEquals
-import com.machankura.bennu.compose.nostr.nip30303.ArtifactEvent
-import com.machankura.bennu.compose.nostr.nip30303.ArtifactVersionEvent
-import com.machankura.bennu.compose.nostr.nip30303.ChapterEvent
-import com.machankura.bennu.compose.nostr.nip30303.ChunkEvent
-import com.machankura.bennu.compose.nostr.nip30303.DialectEvent
-import com.machankura.bennu.compose.nostr.nip30303.SubmissionEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationArtifactVersionEvent
-import com.machankura.bennu.compose.nostr.nip30303.tags.ArtifactIdTag
-
-/**
- * The row on disk and the payload on the wire have to be the same event.
- *
- * `MantraDao` writes an entity whose id comes from `MantraX.fromXEventTemplate`,
- * and separately builds the rumor it submits with `rumorOf`, which hashes the
- * template itself. Both are supposed to produce one id. Nothing checks that they
- * do, and nothing would notice if they stopped:
- *
- * - the submission would carry a `payloadId` naming an event nobody has,
- * - `MarmotInnerEvent.payloadEventId` would stop matching the row it carries,
- * so `deleteByPayloadEventId` would silently un-queue nothing and superseded
- * translations would go out anyway,
- * - and every receiver would create a *second* row rather than converging on
- * the sender's, because entity ids are content hashes and the two sides would
- * be hashing different things.
- *
- * All of that is silent. The ids are opaque hex either way.
- */
-class RumorIdAgreementTest {
- private val author = "a".repeat(64)
- private val chatRoomId = "room"
- private val other = "b".repeat(64)
-
- /** Exactly what `MantraDao.rumorOf` does, and it must stay exactly that. */
- private fun rumorIdOf(template: EventTemplate<*>): String = EventHasher.hashId(
- pubKey = author,
- createdAt = template.createdAt,
- kind = template.kind,
- tags = template.tags,
- content = template.content
- )
-
- @Test
- fun `a dialect's row and its rumor agree`() {
- val template = DialectEvent.build(name = "Sesotho", country = "Lesotho", language = "st")
-
- val entity = MantraDialect.fromDialectEventTemplate(
- dialectEventTemplate = template,
- chatRoomId = chatRoomId,
- userPublicKey = author
- )
-
- assertEquals(rumorIdOf(template), entity?.id)
- }
-
- @Test
- fun `an artifact's row and its rumor agree`() {
- val template = ArtifactEvent.build(
- name = "In Detention",
- url = "example.com",
- visibility = "private",
- license = "cc",
- dialectId = other,
- versionLabel = "1.0"
- )
-
- val entity = MantraArtifact.fromArtifactEventTemplate(
- artifactEventTemplate = template,
- chatRoomId = chatRoomId,
- userPublicKey = author
- )
-
- assertEquals(rumorIdOf(template), entity?.id)
- }
-
- @Test
- fun `an artifact version's row and its rumor agree`() {
- val template = ArtifactVersionEvent.build(content = "1.0") {
- addUnique(ArtifactIdTag.assemble(other))
- }
-
- val entity = MantraArtifactVersion.fromArtifactVersionEventTemplate(
- artifactVersionEventTemplate = template,
- chatRoomId = chatRoomId,
- userPublicKey = author
- )
-
- assertEquals(rumorIdOf(template), entity?.id)
- }
-
- @Test
- fun `a chapter's and a chunk's rows agree with their rumors`() {
- val chapter = ChapterEvent.build(
- artifactVersionId = other,
- name = "Chapter 1",
- originalText = "some text",
- index = 0,
- wordCount = 2,
- characterCount = 9
- )
- val chunk = ChunkEvent.build(
- chapterId = other,
- text = "some text",
- index = 0,
- wordCount = 2,
- characterCount = 9
- )
-
- assertEquals(
- rumorIdOf(chapter),
- MantraChapter.fromChapterEventTemplate(chapter, chatRoomId, author)?.id
- )
- assertEquals(
- rumorIdOf(chunk),
- MantraChunk.fromChunkEventTemplate(chunk, chatRoomId, author)?.id
- )
- }
-
- @Test
- fun `a translation version's row and its rumor agree`() {
- val template = TranslationArtifactVersionEvent.build(
- artifactVersionId = other,
- dialectId = other,
- name = "Sesotho",
- visibility = "private",
- license = "cc"
- )
-
- val entity = MantraTranslationArtifactVersion.fromTranslationArtifactVersionEventTemplate(
- translationArtifactVersionEventTemplate = template,
- chatRoomId = chatRoomId,
- userPublicKey = author
- )
-
- assertEquals(rumorIdOf(template), entity?.id)
- }
-
- @Test
- fun `the submission names the id the row was written under`() {
- // The end of the chain the rest of this file checks a link of: what a
- // receiver reads out of the envelope has to be the id the sender stored.
- val template = DialectEvent.build(name = "Sesotho", country = "Lesotho", language = "st")
- val entity = MantraDialect.fromDialectEventTemplate(template, chatRoomId, author)
-
- val payload = Event(
- id = rumorIdOf(template),
- pubKey = author,
- createdAt = template.createdAt,
- kind = template.kind,
- tags = template.tags,
- content = template.content,
- sig = ""
- )
- val submission = SubmissionEvent.build(payload = payload)
-
- val readBack = SubmissionEvent(
- id = "f".repeat(64),
- pubKey = author,
- createdAt = submission.createdAt,
- tags = submission.tags,
- content = submission.content,
- sig = ""
- )
-
- assertEquals(entity?.id, readBack.payloadId())
- assertEquals(entity?.id, readBack.payload()?.id)
- assertEquals(DialectEvent.KIND, readBack.payloadKind())
- }
-}
diff --git a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/managers/GroupKeyStateTest.kt b/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/managers/GroupKeyStateTest.kt
index 4a922454..d31ad9d3 100644
--- a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/managers/GroupKeyStateTest.kt
+++ b/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/managers/GroupKeyStateTest.kt
@@ -1,5 +1,8 @@
package com.machankura.bennu.compose.managers
+import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
+import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
+import com.vitorpamplona.quartz.nip65RelayList.AdvertisedRelayListEvent
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
@@ -26,9 +29,6 @@ import com.machankura.bennu.compose.extensions.toHex
import com.machankura.bennu.compose.nostr.frost.GroupKeyStateEvent
import com.machankura.bennu.compose.nostr.subgroup.SubgroupBirthCertificateEvent
import com.machankura.bennu.compose.nostr.subgroup.SubgroupParentage
-import com.machankura.bennu.compose.nostr.nip30303.ArtifactEvent
-import com.machankura.bennu.compose.nostr.nip30303.ChapterEvent
-import com.machankura.bennu.compose.nostr.nip30303.DialectEvent
/**
* What a room's key state is allowed to convince a member of.
@@ -555,7 +555,7 @@ class GroupKeyStateTest {
/** An event of [kind] authored and signed by [author]'s room at [path]. */
private fun signedByRoom(
- kind: Int = DialectEvent.KIND,
+ kind: Int = TextNoteEvent.KIND,
content: String = "isiZulu",
tags: Array> = arrayOf(arrayOf("name", "isiZulu")),
createdAt: Long = 1_700_000_500,
@@ -605,17 +605,18 @@ class GroupKeyStateTest {
@Test
fun `the verifier does not care what kind it is looking at`() {
- // The point of splitting it out: a chronicle carries documents rather than
- // key states, and none of the three checks knows the difference.
+ // The point of splitting it out: a chronicle carries the group's work
+ // rather than key states, and none of the three checks knows the
+ // difference.
//
// Note the last one. A GroupKeyStateEvent signed by the room passes here
- // exactly as a dialect does, which is why the chronicle needs an allowlist
+ // exactly as a post does, which is why the chronicle needs an allowlist
// of kinds on top of this and cannot treat "the group signed it" as
// permission to apply it.
listOf(
- DialectEvent.KIND,
- ArtifactEvent.KIND,
- ChapterEvent.KIND,
+ TextNoteEvent.KIND,
+ MetadataEvent.KIND,
+ AdvertisedRelayListEvent.KIND,
GroupKeyStateEvent.KIND
).forEach { kind ->
assertTrue(
@@ -627,9 +628,9 @@ class GroupKeyStateTest {
@Test
fun `a rumor nobody signed is not a group signature`() {
- // Every nip30303 event on the wire today is a rumor: the signature is
- // empty and the author is the member who sent it, because what vouches
- // for it is the MLS frame. Neither half survives this check, which is
+ // A member's message in a room is a rumor: the signature is empty and
+ // the author is the member who sent it, because what vouches for it is
+ // the MLS frame. Neither half survives this check, which is
// what makes "the group signed it" mean something narrower than "it
// arrived from the group".
val member = PrivateKey(
@@ -642,13 +643,13 @@ class GroupKeyStateTest {
id = EventHasher.hashId(
pubKey = memberPubKey,
createdAt = 1_700_000_500,
- kind = DialectEvent.KIND,
+ kind = TextNoteEvent.KIND,
tags = tags,
content = "isiZulu"
),
pubKey = memberPubKey,
createdAt = 1_700_000_500,
- kind = DialectEvent.KIND,
+ kind = TextNoteEvent.KIND,
tags = tags,
content = "isiZulu",
sig = ""
@@ -668,13 +669,13 @@ class GroupKeyStateTest {
id = EventHasher.hashId(
pubKey = chatRoomId,
createdAt = 1_700_000_500,
- kind = DialectEvent.KIND,
+ kind = TextNoteEvent.KIND,
tags = tags,
content = "isiZulu"
),
pubKey = chatRoomId,
createdAt = 1_700_000_500,
- kind = DialectEvent.KIND,
+ kind = TextNoteEvent.KIND,
tags = tags,
content = "isiZulu",
sig = "9".repeat(128)
diff --git a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/managers/SignedArtifactTest.kt b/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/managers/SignedArtifactTest.kt
deleted file mode 100644
index 8190e758..00000000
--- a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/managers/SignedArtifactTest.kt
+++ /dev/null
@@ -1,297 +0,0 @@
-package com.machankura.bennu.compose.managers
-
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
-import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
-import com.vitorpamplona.quartz.nip01Core.crypto.Nip01Crypto
-import fr.acinq.bitcoin.ByteVector
-import fr.acinq.bitcoin.ByteVector32
-import fr.acinq.bitcoin.PrivateKey
-import fr.acinq.bitcoin.crypto.frost.Frost
-import fr.acinq.bitcoin.crypto.frost.IndividualNonce
-import fr.acinq.bitcoin.crypto.frost.KeyMaterial
-import fr.acinq.bitcoin.crypto.frost.SecretNonce
-import fr.acinq.bitcoin.crypto.frost.Session
-import fr.acinq.bitcoin.crypto.frost.TweakCache
-import kotlin.test.Test
-import kotlin.test.assertEquals
-import kotlin.test.assertNotEquals
-import kotlin.test.assertNotNull
-import kotlin.test.assertTrue
-import com.machankura.bennu.compose.database.model.FrostSigningItem
-import com.machankura.bennu.compose.database.model.MantraArtifact
-import com.machankura.bennu.compose.database.model.MantraArtifactVersion
-import com.machankura.bennu.compose.extensions.toHex
-import com.machankura.bennu.compose.nostr.nip30303.ArtifactEvent
-import com.machankura.bennu.compose.nostr.nip30303.ArtifactVersionEvent
-
-/**
- * An artifact the group signed, from proposal to rows, against real FROST.
- *
- * Adding an artifact used to write a row and submit it; the row said the
- * submitter wrote it, because they had. Now the group signs it, and the claim
- * this test exists to hold is that the artifact every device ends up with is
- * the group's: authored by the threshold key, carrying a signature that
- * verifies, with an id every member arrives at independently.
- *
- * None of that is visible when it breaks. A row whose author is the proposer
- * looks exactly like a row whose author is the group -- both are opaque hex --
- * and a group that disagrees about the id has two artifacts that look like one.
- */
-class SignedArtifactTest {
- private val participants = 3
- private val threshold = 2
-
- /** The member who filled in the form. Nothing they own should end up on the row. */
- private val proposer = "9".repeat(64)
- private val dialectId = "b".repeat(64)
-
- /** Stands in for a completed ceremony; the test is about what gets signed, not the DKG. */
- private val keyMaterial: KeyMaterial = Frost.trustedDealerKeygen(
- thresholdSecretKey = PrivateKey(
- ByteVector32("1c0ffee0000000000000000000000000000000000000000000000000000000a1")
- ),
- nParticipants = participants,
- threshold = threshold
- )
-
- /**
- * The room the group signs in: derived from its key at the admin path, which
- * is what makes the room's id and the key it signs as one value.
- */
- private val room: SharedKeyDerivation.Derived = SharedKeyDerivation.derive(
- thresholdPublicKey = keyMaterial.thresholdPublicKey.value.toHex(),
- path = SharedKeyDerivation.MARMOT_ADMIN_GROUP_PATH
- )
-
- private val tweakCache: TweakCache = room.cache
-
- /** The group's nostr identity here, which is also [chatRoomId]. */
- private val groupPubKey = room.hex
-
- private val chatRoomId = room.hex
-
- private fun proposalTemplate(versionLabel: String = "1.0") = ArtifactEvent.build(
- name = "In Detention",
- url = "https://example.com/in-detention",
- visibility = "private",
- license = "cc",
- dialectId = dialectId,
- versionLabel = versionLabel,
- createdAt = 1_700_000_000L,
- )
-
- /**
- * Exactly what `FrostSigningManager.unsignedEventOf` does, and it must stay
- * exactly that: the proposer's fields re-authored under the group's key.
- */
- private fun unsignedEventOf(template: com.vitorpamplona.quartz.nip01Core.signers.EventTemplate<*>) = Event(
- id = EventHasher.hashId(
- pubKey = groupPubKey,
- createdAt = template.createdAt,
- kind = template.kind,
- tags = template.tags,
- content = template.content
- ),
- pubKey = groupPubKey,
- createdAt = template.createdAt,
- kind = template.kind,
- tags = template.tags,
- content = template.content,
- sig = ""
- )
-
- private fun itemOver(unsignedEvent: Event) = FrostSigningItem(
- sessionId = "s".repeat(64),
- itemIndex = 0,
- unsignedEventJson = unsignedEvent.toJson(),
- eventId = unsignedEvent.id,
- nonceRandom = "f".repeat(64)
- )
-
- /** A quorum signing the item's event, in the manager's order. */
- private fun groupSignature(item: FrostSigningItem): String {
- val message = ByteVector(item.eventId.hexToByteArray())
- val signerIds = listOf(0, 1)
-
- val nonces = signerIds.map { signerId ->
- SecretNonce.generate(
- sessionRandom = ByteVector32("a".repeat(63) + "${signerId + 1}"),
- secretShare = keyMaterial.secretShares[signerId],
- publicShare = keyMaterial.publicShares[signerId],
- tweakedThresholdPublicKey = tweakCache.tweakedPublicKey,
- message = message,
- extraInput = null
- )
- }
-
- val signingSession = Session.create(
- aggregatedNonce = IndividualNonce.aggregate(nonces.map { it.second }).right!!,
- signerIds = signerIds.map { it.toUInt() },
- signerPublicShares = signerIds.map { keyMaterial.publicShares[it] },
- nParticipants = participants,
- threshold = threshold,
- tweakCache = tweakCache,
- message = message
- )
-
- val partials = signerIds.mapIndexed { position, signerId ->
- signingSession.sign(
- nonces[position].first,
- keyMaterial.secretShares[signerId],
- signerId.toUInt()
- ).right!!
- }
-
- return signingSession.aggregateSigs(partials).right!!.toByteArray().toHex()
- }
-
- /** Everything from the form to the row a device holds afterwards. */
- private fun signedArtifactEvent(versionLabel: String = "1.0"): ArtifactEvent {
- val item = itemOver(unsignedEventOf(proposalTemplate(versionLabel)))
- val signed = FrostSigningManager.signedEvent(item, groupSignature(item))
-
- return ArtifactEvent(
- signed.id, signed.pubKey, signed.createdAt, signed.tags, signed.content, signed.sig
- )
- }
-
- @Test
- fun `the artifact the group signs is authored by the group not the proposer`() {
- val artifact = MantraArtifact.fromArtifactEvent(signedArtifactEvent(), chatRoomId)
-
- assertNotNull(artifact)
- assertEquals(groupPubKey, artifact.publicKey)
- assertNotEquals(proposer, artifact.publicKey)
- }
-
- @Test
- fun `the group it is authored by is the room it was signed in`() {
- // Signing runs at the room's derivation path, so the author is the room's
- // own id rather than the bare threshold key. That is what lets anybody
- // holding the row check it without being told which key to expect -- and
- // it is why the path a session signs at cannot come from the proposer.
- val artifact = MantraArtifact.fromArtifactEvent(signedArtifactEvent(), chatRoomId)
-
- assertEquals(chatRoomId, artifact?.publicKey)
- assertNotEquals(
- keyMaterial.thresholdPublicKey.xOnly().value.toHex(),
- artifact?.publicKey,
- "an artifact must be signed by the room's key, not by the group's root key"
- )
- }
-
- @Test
- fun `the row's id is the id the group put its signature to`() {
- // Every device builds this row from the same signed event, so the id has
- // to be the one that was signed rather than anything recomputed from the
- // proposer. Otherwise members converge on nothing and each holds its own
- // copy of what is meant to be one artifact.
- val item = itemOver(unsignedEventOf(proposalTemplate()))
- val signed = FrostSigningManager.signedEvent(item, groupSignature(item))
-
- val artifact = MantraArtifact.fromArtifactEvent(
- ArtifactEvent(signed.id, signed.pubKey, signed.createdAt, signed.tags, signed.content, signed.sig),
- chatRoomId
- )
-
- assertEquals(item.eventId, artifact?.id)
- }
-
- @Test
- fun `the signature on the row verifies against the row's own id and author`() {
- // The payoff of signing rather than submitting: the row carries proof the
- // group made it, checkable by anybody holding it.
- val artifact = MantraArtifact.fromArtifactEvent(signedArtifactEvent(), chatRoomId)
-
- assertNotNull(artifact)
- assertTrue(
- Nip01Crypto.verify(
- signature = artifact.signature.hexToByteArray(),
- hash = artifact.id.hexToByteArray(),
- pubKey = artifact.publicKey.hexToByteArray()
- ),
- "an artifact row should carry a signature the group's key made over its own id"
- )
- }
-
- @Test
- fun `what the form asked for is what the group signed`() {
- // The fields travel as tags through a session that knows nothing about
- // artifacts. Anything dropped in there is signed away silently.
- val artifact = MantraArtifact.fromArtifactEvent(signedArtifactEvent(), chatRoomId)
-
- assertEquals("In Detention", artifact?.name)
- assertEquals("https://example.com/in-detention", artifact?.url)
- assertEquals("private", artifact?.visibility)
- assertEquals("cc", artifact?.license)
- assertEquals(dialectId, artifact?.dialectId)
- }
-
- /** The second item of the batch, through the same quorum as the first. */
- private fun signedInitialVersionEvent(versionLabel: String = "1.0"): ArtifactVersionEvent {
- // Built from the unsigned lead, which is what `proposeSigningBatch` hands
- // to `dependents` -- the artifact's id is settled at proposal, not at
- // signature, which is the only reason a version can name it at all.
- val lead = unsignedEventOf(proposalTemplate(versionLabel))
- val item = itemOver(unsignedEventOf(ArtifactVersionEvent.initialVersionOf(lead).single()))
- val signed = FrostSigningManager.signedEvent(item, groupSignature(item))
-
- return ArtifactVersionEvent(
- signed.id, signed.pubKey, signed.createdAt, signed.tags, signed.content, signed.sig
- )
- }
-
- @Test
- fun `the artifact arrives with the first version hanging off it`() {
- // A chapter attaches to a version rather than to an artifact, so an
- // artifact that arrives without one is inert. Both come out of one
- // batch, so neither can arrive without the other.
- val artifact = MantraArtifact.fromArtifactEvent(
- signedArtifactEvent(versionLabel = "First Edition"), chatRoomId
- )
- val version = MantraArtifactVersion.fromArtifactVersionEvent(
- signedInitialVersionEvent(versionLabel = "First Edition"), chatRoomId
- )
-
- assertNotNull(version)
- assertEquals(artifact?.id, version.artifactId)
- assertEquals("First Edition", version.versionLabel)
- assertEquals(groupPubKey, version.publicKey)
- }
-
- @Test
- fun `the first version carries the group's signature over its own id`() {
- // The point of signing it rather than deriving it. A derived version was
- // authored by the group and signed by nobody -- indistinguishable, on the
- // row, from one somebody made up, and the parent of every chapter in it.
- val version = MantraArtifactVersion.fromArtifactVersionEvent(
- signedInitialVersionEvent(), chatRoomId
- )
-
- assertNotNull(version)
- assertNotEquals("", version.signature)
- assertTrue(
- Nip01Crypto.verify(
- signature = version.signature.hexToByteArray(),
- hash = version.id.hexToByteArray(),
- pubKey = version.publicKey.hexToByteArray()
- ),
- "a first version should carry a signature the group's key made over its own id"
- )
- }
-
- @Test
- fun `the version is a second message signed under its own nonce`() {
- // Two items of a batch are two independent FROST instances: k signatures
- // over k ids, never one signature stretched over both. A version whose
- // signature verified against the artifact's id would mean a nonce had
- // been reused, which is how a share is extracted rather than a cosmetic
- // mix-up.
- val artifact = signedArtifactEvent()
- val version = signedInitialVersionEvent()
-
- assertNotEquals(artifact.id, version.id)
- assertNotEquals(artifact.sig, version.sig)
- }
-}
diff --git a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/managers/SignedChapterTest.kt b/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/managers/SignedChapterTest.kt
deleted file mode 100644
index dcfbe7c8..00000000
--- a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/managers/SignedChapterTest.kt
+++ /dev/null
@@ -1,354 +0,0 @@
-package com.machankura.bennu.compose.managers
-
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
-import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
-import com.vitorpamplona.quartz.nip01Core.crypto.Nip01Crypto
-import fr.acinq.bitcoin.ByteVector
-import fr.acinq.bitcoin.ByteVector32
-import fr.acinq.bitcoin.PrivateKey
-import fr.acinq.bitcoin.crypto.frost.Frost
-import fr.acinq.bitcoin.crypto.frost.IndividualNonce
-import fr.acinq.bitcoin.crypto.frost.KeyMaterial
-import fr.acinq.bitcoin.crypto.frost.SecretNonce
-import fr.acinq.bitcoin.crypto.frost.Session
-import fr.acinq.bitcoin.crypto.frost.TweakCache
-import kotlin.test.Test
-import kotlin.test.assertEquals
-import kotlin.test.assertNotEquals
-import kotlin.test.assertNotNull
-import kotlin.test.assertTrue
-import com.machankura.bennu.compose.database.model.FrostSigningItem
-import com.machankura.bennu.compose.database.model.MantraChapter
-import com.machankura.bennu.compose.database.model.MantraChunk
-import com.machankura.bennu.compose.extensions.toHex
-import com.machankura.bennu.compose.nostr.nip30303.ChapterEvent
-import com.machankura.bennu.compose.nostr.nip30303.ChunkEvent
-
-/**
- * A chapter and its chunks the group signed, from proposal to rows, against
- * real FROST.
- *
- * Adding a chapter used to write the rows and submit them, one submission for
- * the chapter and one per paragraph; the rows said the submitter wrote them,
- * because they had. Now the group signs the lot in one session, and the claim
- * this test exists to hold is that every row a device ends up with is the
- * group's: authored by the threshold key, carrying a signature that verifies
- * over its own id, with the chunks naming the chapter that was signed beside
- * them.
- *
- * None of that is visible when it breaks. A row whose author is the proposer
- * looks exactly like a row whose author is the group -- both are opaque hex --
- * and a chunk that names the wrong chapter is a foreign key away from vanishing
- * with no sign of why.
- *
- * A batch is k independent FROST instances, so the signatures here are made one
- * per item, each over its own message with its own nonces, which is the only
- * way they can be made.
- */
-class SignedChapterTest {
- private val participants = 3
- private val threshold = 2
-
- /** The member who pasted the text. Nothing they own should end up on the rows. */
- private val proposer = "9".repeat(64)
- private val artifactVersionId = "b".repeat(64)
-
- private val originalText = "The first paragraph.\n\nThe second paragraph."
-
- /** Stands in for a completed ceremony; the test is about what gets signed, not the DKG. */
- private val keyMaterial: KeyMaterial = Frost.trustedDealerKeygen(
- thresholdSecretKey = PrivateKey(
- ByteVector32("1c0ffee0000000000000000000000000000000000000000000000000000000a1")
- ),
- nParticipants = participants,
- threshold = threshold
- )
-
- /**
- * The room the group signs in: derived from its key at the admin path, which
- * is what makes the room's id and the key it signs as one value.
- */
- private val room: SharedKeyDerivation.Derived = SharedKeyDerivation.derive(
- thresholdPublicKey = keyMaterial.thresholdPublicKey.value.toHex(),
- path = SharedKeyDerivation.MARMOT_ADMIN_GROUP_PATH
- )
-
- private val tweakCache: TweakCache = room.cache
-
- /** The group's nostr identity here, which is also [chatRoomId]. */
- private val groupPubKey = room.hex
-
- private val chatRoomId = room.hex
-
- private fun proposalTemplate(
- name: String = "Chapter 1",
- text: String = originalText,
- index: Int = 0,
- ) = ChapterEvent.build(
- artifactVersionId = artifactVersionId,
- name = name,
- originalText = text,
- index = index,
- wordCount = 6,
- characterCount = text.length,
- createdAt = 1_700_000_000L,
- )
-
- /**
- * Exactly what `FrostSigningManager.unsignedEventOf` does, and it must stay
- * exactly that: the proposer's fields re-authored under the group's key.
- */
- private fun unsignedEventOf(template: com.vitorpamplona.quartz.nip01Core.signers.EventTemplate<*>) = Event(
- id = EventHasher.hashId(
- pubKey = groupPubKey,
- createdAt = template.createdAt,
- kind = template.kind,
- tags = template.tags,
- content = template.content
- ),
- pubKey = groupPubKey,
- createdAt = template.createdAt,
- kind = template.kind,
- tags = template.tags,
- content = template.content,
- sig = ""
- )
-
- private fun itemsOver(unsignedEvents: List) = unsignedEvents.mapIndexed { index, event ->
- FrostSigningItem(
- sessionId = "s".repeat(64),
- itemIndex = index,
- unsignedEventJson = event.toJson(),
- eventId = event.id,
- // One seed per item, never shared: two messages under one nonce is
- // how a share is extracted.
- nonceRandom = "f".repeat(63) + "${index + 1}"
- )
- }
-
- /** A quorum signing one item's event, in the manager's order. */
- private fun groupSignature(item: FrostSigningItem): String {
- val message = ByteVector(item.eventId.hexToByteArray())
- val signerIds = listOf(0, 1)
-
- val nonces = signerIds.map { signerId ->
- SecretNonce.generate(
- sessionRandom = ByteVector32(
- "a".repeat(62) + "${item.itemIndex + 1}${signerId + 1}"
- ),
- secretShare = keyMaterial.secretShares[signerId],
- publicShare = keyMaterial.publicShares[signerId],
- tweakedThresholdPublicKey = tweakCache.tweakedPublicKey,
- message = message,
- extraInput = null
- )
- }
-
- val signingSession = Session.create(
- aggregatedNonce = IndividualNonce.aggregate(nonces.map { it.second }).right!!,
- signerIds = signerIds.map { it.toUInt() },
- signerPublicShares = signerIds.map { keyMaterial.publicShares[it] },
- nParticipants = participants,
- threshold = threshold,
- tweakCache = tweakCache,
- message = message
- )
-
- val partials = signerIds.mapIndexed { position, signerId ->
- signingSession.sign(
- nonces[position].first,
- keyMaterial.secretShares[signerId],
- signerId.toUInt()
- ).right!!
- }
-
- return signingSession.aggregateSigs(partials).right!!.toByteArray().toHex()
- }
-
- /**
- * The batch a proposal makes: the chapter, then a chunk per paragraph, cut
- * from the chapter after it is authored under the group's key -- exactly
- * what `AddChapterViewModel` hands `proposeSigningBatch` as lead and
- * dependents.
- */
- private fun proposedBatch(
- name: String = "Chapter 1",
- text: String = originalText,
- index: Int = 0,
- ): List {
- val chapter = unsignedEventOf(proposalTemplate(name, text, index))
-
- return listOf(chapter) + ChunkEvent.splitOf(chapter).map(::unsignedEventOf)
- }
-
- /** Everything from the form to the rows a device holds afterwards. */
- private fun signedBatch(
- name: String = "Chapter 1",
- text: String = originalText,
- index: Int = 0,
- ): List = itemsOver(proposedBatch(name, text, index)).map { item ->
- FrostSigningManager.signedEvent(item, groupSignature(item))
- }
-
- private fun signedChapterEvent(
- name: String = "Chapter 1",
- text: String = originalText,
- index: Int = 0,
- ): ChapterEvent = signedBatch(name, text, index).first().let { signed ->
- ChapterEvent(
- signed.id, signed.pubKey, signed.createdAt, signed.tags, signed.content, signed.sig
- )
- }
-
- private fun signedChunkEvents(
- text: String = originalText,
- ): List = signedBatch(text = text).drop(1).map { signed ->
- ChunkEvent(
- signed.id, signed.pubKey, signed.createdAt, signed.tags, signed.content, signed.sig
- )
- }
-
- @Test
- fun `the chapter the group signs is authored by the group not the proposer`() {
- val chapter = MantraChapter.fromChapterEvent(signedChapterEvent(), chatRoomId)
-
- assertNotNull(chapter)
- assertEquals(groupPubKey, chapter.publicKey)
- assertNotEquals(proposer, chapter.publicKey)
- }
-
- @Test
- fun `the group it is authored by is the room it was signed in`() {
- // Signing runs at the room's derivation path, so the author is the room's
- // own id rather than the bare threshold key. That is what lets anybody
- // holding the row check it without being told which key to expect -- and
- // it is why the path a session signs at cannot come from the proposer.
- val chapter = MantraChapter.fromChapterEvent(signedChapterEvent(), chatRoomId)
-
- assertEquals(chatRoomId, chapter?.publicKey)
- assertNotEquals(
- keyMaterial.thresholdPublicKey.xOnly().value.toHex(),
- chapter?.publicKey,
- "a chapter must be signed by the room's key, not by the group's root key"
- )
- }
-
- @Test
- fun `the row's id is the id the group put its signature to`() {
- // Every device builds this row from the same signed event, so the id has
- // to be the one that was signed rather than anything recomputed from the
- // proposer. Otherwise members converge on nothing and each holds its own
- // copy of what is meant to be one chapter.
- val item = itemsOver(proposedBatch()).first()
- val signed = FrostSigningManager.signedEvent(item, groupSignature(item))
-
- val chapter = MantraChapter.fromChapterEvent(
- ChapterEvent(signed.id, signed.pubKey, signed.createdAt, signed.tags, signed.content, signed.sig),
- chatRoomId
- )
-
- assertEquals(item.eventId, chapter?.id)
- }
-
- @Test
- fun `the signature on the row verifies against the row's own id and author`() {
- // The payoff of signing rather than submitting: the row carries proof the
- // group made it, checkable by anybody holding it.
- val chapter = MantraChapter.fromChapterEvent(signedChapterEvent(), chatRoomId)
-
- assertNotNull(chapter)
- assertTrue(
- Nip01Crypto.verify(
- signature = chapter.signature.hexToByteArray(),
- hash = chapter.id.hexToByteArray(),
- pubKey = chapter.publicKey.hexToByteArray()
- ),
- "a chapter row should carry a signature the group's key made over its own id"
- )
- }
-
- @Test
- fun `what the form asked for is what the group signed`() {
- // The fields travel as tags through a session that knows nothing about
- // chapters. Anything dropped in there is signed away silently -- and the
- // original text most of all, since the chunks are split out of it.
- val chapter = MantraChapter.fromChapterEvent(
- signedChapterEvent(name = "In Detention", index = 2),
- chatRoomId
- )
-
- assertEquals("In Detention", chapter?.name)
- assertEquals(originalText, chapter?.originalText)
- assertEquals(artifactVersionId, chapter?.artifactVersionId)
- assertEquals(2, chapter?.index)
- }
-
- @Test
- fun `the chapter is signed with a chunk for every paragraph`() {
- // One session, one approval, and a row per paragraph at the end of it.
- // A translation is of a chunk rather than of a chapter, so a chapter
- // that arrived without them could not be worked on.
- val batch = signedBatch()
-
- assertEquals(3, batch.size)
- assertEquals(ChapterEvent.KIND, batch.first().kind)
- assertTrue(batch.drop(1).all { it.kind == ChunkEvent.KIND })
- }
-
- @Test
- fun `every chunk the group signed names the chapter it signed beside it`() {
- // The batch is applied in item order, so the chapter row is written
- // first and the chunks hang off it. A chunk naming anything else fails a
- // foreign key and disappears with no sign of why.
- val batch = signedBatch()
- val chapter = MantraChapter.fromChapterEvent(
- batch.first().let {
- ChapterEvent(it.id, it.pubKey, it.createdAt, it.tags, it.content, it.sig)
- },
- chatRoomId
- )
-
- val chunks = signedChunkEvents().map { MantraChunk.fromChunkEvent(it, chatRoomId) }
-
- assertEquals(2, chunks.size)
- assertTrue(chunks.all { it?.chapterId == chapter?.id })
- assertEquals(listOf("The first paragraph.", "The second paragraph."), chunks.map { it?.text })
- assertEquals(listOf(0, 1), chunks.map { it?.index })
- }
-
- @Test
- fun `each chunk row carries a signature the group made over its own id`() {
- // The point of signing the chunks rather than splitting them out of the
- // chapter on arrival: a chunk can be checked on its own, by anybody
- // holding it, without re-deriving it from anything.
- signedChunkEvents().forEach { signed ->
- val chunk = MantraChunk.fromChunkEvent(signed, chatRoomId)
-
- assertNotNull(chunk)
- assertEquals(groupPubKey, chunk.publicKey)
- assertNotEquals(proposer, chunk.publicKey)
- assertTrue(
- Nip01Crypto.verify(
- signature = chunk.signature.hexToByteArray(),
- hash = chunk.id.hexToByteArray(),
- pubKey = chunk.publicKey.hexToByteArray()
- ),
- "a chunk row should carry a signature the group's key made over its own id"
- )
- }
- }
-
- @Test
- fun `the chapter and its chunks are different messages to sign`() {
- // A batch is k FROST instances precisely because it has to be: one nonce
- // over two messages leaks the share. That the items are distinct
- // messages is the premise -- `FrostSigningRoundTest` and
- // `SignedGroupKeyStateTest` hold the manager to giving each its own
- // nonce; what a chapter has to hold up is that its own items are not
- // secretly one message repeated.
- val batch = proposedBatch(text = "Again.\n\nAgain.")
-
- assertEquals(batch.size, batch.map { it.id }.toSet().size)
- }
-}
diff --git a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/managers/TranslationScaffoldTest.kt b/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/managers/TranslationScaffoldTest.kt
deleted file mode 100644
index 2290545f..00000000
--- a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/managers/TranslationScaffoldTest.kt
+++ /dev/null
@@ -1,183 +0,0 @@
-package com.machankura.bennu.compose.managers
-
-import kotlin.test.Test
-import kotlin.test.assertEquals
-import kotlin.test.assertTrue
-import com.machankura.bennu.compose.database.model.MantraChapter
-import com.machankura.bennu.compose.database.model.MantraTranslationChapter
-import com.machankura.bennu.compose.nostr.nip30303.TranslationChapterEvent
-import com.machankura.bennu.compose.nostr.nip30303.tags.ChapterIdTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.IndexTag
-import com.machankura.bennu.compose.nostr.nip30303.tags.TranslationArtifactVersionIdTag
-
-/**
- * The join between a translation and the chapters it is of, as a pure function.
- *
- * Both ends arrive on their own schedule, so this is built from three
- * directions -- a translation being proposed, a chapter being proposed, and a
- * catch-up filling in what the two missed. What it must not do is disagree with
- * itself about what a translation covers depending on which direction it was
- * built from.
- */
-class TranslationScaffoldTest {
-
- private val translationA = "a".repeat(64)
- private val translationB = "b".repeat(64)
-
- private fun sourceChapter(index: Int, id: String = "c$index".padEnd(64, 'f')) = MantraChapter(
- id = id,
- artifactVersionId = "v".repeat(64),
- publicKey = "p".repeat(64),
- name = "Chapter ${index + 1}",
- originalText = "Paragraph.",
- index = index,
- wordCount = 1,
- characterCount = 10,
- signature = "",
- chatRoomId = "r".repeat(64),
- )
-
- private fun translationChapterFor(chapter: MantraChapter, translationId: String) =
- MantraTranslationChapter(
- id = "t${chapter.id}".take(64),
- publicKey = "p".repeat(64),
- chapterId = chapter.id,
- translationArtifactVersionId = translationId,
- index = chapter.index,
- signature = "",
- chatRoomId = "r".repeat(64),
- )
-
- private fun parse(templates: List>) =
- templates.map { template ->
- Triple(
- template.tags.firstNotNullOfOrNull(TranslationArtifactVersionIdTag::parse)?.ref?.eventId,
- template.tags.firstNotNullOfOrNull(ChapterIdTag::parse)?.ref?.eventId,
- template.tags.firstNotNullOfOrNull(IndexTag::parse)?.index,
- )
- }
-
- @Test
- fun `a translation's chapters stay together and in reading order`() {
- val chapters = (0..2).map(::sourceChapter)
-
- val templates = TranslationScaffold.chaptersOf(
- translationArtifactVersionIds = listOf(translationA, translationB),
- chapters = chapters.map(TranslationScaffold.SourceChapter::of),
- createdAt = 1_000,
- )
-
- // Item order is the order a session signs and applies in, so it is
- // fixed here rather than left to a caller. Translations outer, chapters
- // inner: one translation's chapters are contiguous and in order.
- assertEquals(
- listOf(
- Triple(translationA, chapters[0].id, 0),
- Triple(translationA, chapters[1].id, 1),
- Triple(translationA, chapters[2].id, 2),
- Triple(translationB, chapters[0].id, 0),
- Triple(translationB, chapters[1].id, 1),
- Triple(translationB, chapters[2].id, 2),
- ),
- parse(templates)
- )
- }
-
- @Test
- fun `a chapter proposed on its own is scaffolded into every translation`() {
- // The other direction: one chapter, every existing translation. This is
- // what a chapter's own scaffolding session carries.
- val templates = TranslationScaffold.chaptersOf(
- translationArtifactVersionIds = listOf(translationA, translationB),
- chapters = listOf(TranslationScaffold.SourceChapter(id = "z".repeat(64), index = 7)),
- createdAt = 1_000,
- )
-
- assertEquals(
- listOf(
- Triple(translationA, "z".repeat(64), 7),
- Triple(translationB, "z".repeat(64), 7),
- ),
- parse(templates)
- )
- }
-
- @Test
- fun `a catch-up keeps each chapter's own position not the position in the gap`() {
- val chapters = (0..5).map(::sourceChapter)
-
- // A catch-up proposes a subset, and the subset is not contiguous.
- // Counting the list would renumber chapters 3 and 5 as 1 and 2, which
- // is a translation that reads in a different order than the work.
- val templates = TranslationScaffold.chaptersOf(
- translationArtifactVersionIds = listOf(translationA),
- chapters = listOf(chapters[3], chapters[5]).map(TranslationScaffold.SourceChapter::of),
- createdAt = 1_000,
- )
-
- assertEquals(listOf(3, 5), parse(templates).map { it.third })
- }
-
- @Test
- fun `the whole scaffolding carries one timestamp`() {
- val templates = TranslationScaffold.chaptersOf(
- translationArtifactVersionIds = listOf(translationA, translationB),
- chapters = (0..2).map(::sourceChapter).map(TranslationScaffold.SourceChapter::of),
- createdAt = 4_242,
- )
-
- // Read once by the caller rather than per template, so a scaffolding
- // proposed as one act reads as one.
- assertEquals(listOf(4_242L), templates.map { it.createdAt }.distinct())
- }
-
- @Test
- fun `nothing to scaffold when there is nothing on one side`() {
- assertTrue(
- TranslationScaffold.chaptersOf(
- translationArtifactVersionIds = emptyList(),
- chapters = listOf(TranslationScaffold.SourceChapter("z".repeat(64), 0)),
- createdAt = 1_000,
- ).isEmpty()
- )
-
- assertTrue(
- TranslationScaffold.chaptersOf(
- translationArtifactVersionIds = listOf(translationA),
- chapters = emptyList(),
- createdAt = 1_000,
- ).isEmpty()
- )
- }
-
- @Test
- fun `what is missing is matched on the chapter named not on how many there are`() {
- val chapters = (0..3).map(::sourceChapter)
-
- // Chapter 1 never landed but chapter 2 did, which a count would read as
- // "the last one is missing" and scaffold the wrong chapter.
- val missing = TranslationScaffold.chaptersMissingFrom(
- translationChapters = listOf(chapters[0], chapters[2]).map {
- translationChapterFor(it, translationA)
- },
- sourceChapters = chapters,
- )
-
- assertEquals(listOf(chapters[1].id, chapters[3].id), missing.map { it.id })
- }
-
- @Test
- fun `a translation that is already complete is missing nothing`() {
- val chapters = (0..2).map(::sourceChapter)
-
- // So that running a catch-up twice proposes nothing the second time,
- // rather than a second copy of every chapter under fresh ids.
- assertEquals(
- emptyList(),
- TranslationScaffold.chaptersMissingFrom(
- translationChapters = chapters.map { translationChapterFor(it, translationA) },
- sourceChapters = chapters,
- )
- )
- }
-}
diff --git a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/MarmotPayloadBoundsTest.kt b/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/MarmotPayloadBoundsTest.kt
index a53528c4..39f48fa2 100644
--- a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/MarmotPayloadBoundsTest.kt
+++ b/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/MarmotPayloadBoundsTest.kt
@@ -11,8 +11,8 @@ import com.vitorpamplona.quartz.nip01Core.tags.people.PTag
import com.vitorpamplona.quartz.nip17Dm.messages.ChatMessageEvent
import com.vitorpamplona.quartz.nip59Giftwrap.rumors.RumorAssembler
import com.machankura.bennu.compose.nostr.chronicle.ChronicleEvent
-import com.machankura.bennu.compose.nostr.nip30303.ChunkEvent
-import com.machankura.bennu.compose.nostr.nip30303.DialectEvent
+import com.machankura.bennu.compose.nostr.chronicle.TEST_KINDS
+import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
@@ -52,6 +52,10 @@ class MarmotPayloadBoundsTest {
count = 1,
recipient = recipient,
createdAt = at,
+ // The app's own list carries nothing at the moment, so the page is
+ // built over the chronicle tests' list: what is under test is the
+ // envelope's size, not which kinds fill it.
+ kinds = TEST_KINDS,
)
// From the template's fields, as the outbound queue assembles every rumor from
// the row's: the typed template is not what goes through RumorAssembler.
@@ -74,7 +78,7 @@ class MarmotPayloadBoundsTest {
@Test
fun `a chronicle page of the most smallest payloads is a conformant app event`() {
val payloads = (0 until ChronicleEvent.MAX_PAGE_EVENTS).map {
- signedPayload(DialectEvent.KIND, content = "d", id = it.toString().padStart(64, '0'))
+ signedPayload(TextNoteEvent.KIND, content = "d", id = it.toString().padStart(64, '0'))
}
assertConformant(chronicleAppEvent(payloads))
@@ -90,7 +94,7 @@ class MarmotPayloadBoundsTest {
while (length < 4_096) append("{\"k\":\"v\",\"n\":[\"a\",\"b\"]}")
}
val payloads = (0 until ChronicleEvent.MAX_PAGE_EVENTS).map {
- signedPayload(ChunkEvent.KIND, content = dense, id = it.toString().padStart(64, '0'))
+ signedPayload(TextNoteEvent.KIND, content = dense, id = it.toString().padStart(64, '0'))
}
// As many dense payloads as the byte cap admits, measured the way the packer
// measures them: by the bytes the page occupies once escaped into the app
diff --git a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/chronicle/ChronicleEventTest.kt b/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/chronicle/ChronicleEventTest.kt
index 22542fb3..bb56ec7d 100644
--- a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/chronicle/ChronicleEventTest.kt
+++ b/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/chronicle/ChronicleEventTest.kt
@@ -14,19 +14,10 @@ import com.machankura.bennu.compose.nostr.chronicle.tags.ChronicleRecipientTag
import com.machankura.bennu.compose.nostr.frost.FrostSigningEvents
import com.machankura.bennu.compose.nostr.frost.GroupKeyStateEvent
import com.machankura.bennu.compose.nostr.subgroup.SubgroupBirthCertificateEvent
-import com.machankura.bennu.compose.nostr.nip30303.ArtifactEvent
-import com.machankura.bennu.compose.nostr.nip30303.ArtifactVersionEvent
-import com.machankura.bennu.compose.nostr.nip30303.ChapterEvent
-import com.machankura.bennu.compose.nostr.nip30303.ChunkEvent
-import com.machankura.bennu.compose.nostr.nip30303.DialectEvent
-import com.machankura.bennu.compose.nostr.nip30303.SubmissionEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationArtifactVersionContributorListEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationArtifactVersionEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationChapterContributorListEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationChapterEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationChunkEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationContributorListEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationEvent
+import com.machankura.bennu.compose.nostr.wallet.GroupWalletStatementEvent
+import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
+import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
+import com.vitorpamplona.quartz.nip65RelayList.AdvertisedRelayListEvent
/**
* The envelope a chronicle travels in: what it carries, what it refuses, and the
@@ -35,6 +26,10 @@ import com.machankura.bennu.compose.nostr.nip30303.TranslationEvent
* Nothing here verifies a signature -- that is `GroupKeyStateTest`'s half, and
* `ChronicleManager`'s at apply time. What these cover is the framing, and the two
* bounds a page has to hold whoever sent it.
+ *
+ * The app's own list of kinds is empty, so what a chronicle may carry and the
+ * order it applies in are tested against [TEST_KINDS]; the framing and the caps
+ * do not care what kind a payload is.
*/
class ChronicleEventTest {
private val recipient = "d".repeat(64)
@@ -59,8 +54,8 @@ class ChronicleEventTest {
@Test
fun `what is encoded is what comes back whole`() {
val events = listOf(
- payload(DialectEvent.KIND, "isiZulu"),
- payload(ArtifactEvent.KIND, "an artifact"),
+ payload(MetadataEvent.KIND, "{\"name\":\"Ekklesia\"}"),
+ payload(TextNoteEvent.KIND, "a post"),
)
val decoded = ChronicleEvent.decodePage(ChronicleEvent.encodePage(events))
@@ -81,7 +76,7 @@ class ChronicleEventTest {
// object for a batch of one so that builds predating batching can read
// it. Both chronicle kinds are new, so there is no such build and no reason
// to carry the second shape.
- val encoded = ChronicleEvent.encodePage(listOf(payload(DialectEvent.KIND)))
+ val encoded = ChronicleEvent.encodePage(listOf(payload(TextNoteEvent.KIND)))
assertTrue(encoded.startsWith("["), "a page is always an array")
assertTrue(encoded.endsWith("]"))
@@ -90,7 +85,7 @@ class ChronicleEventTest {
@Test
fun `a page that is not an array is not a page`() {
- assertNull(ChronicleEvent.decodePage(payload(DialectEvent.KIND).toJson()))
+ assertNull(ChronicleEvent.decodePage(payload(TextNoteEvent.KIND).toJson()))
assertNull(ChronicleEvent.decodePage(""))
assertNull(ChronicleEvent.decodePage("not json"))
assertNull(ChronicleEvent.decodePage("[unclosed"))
@@ -110,7 +105,7 @@ class ChronicleEventTest {
// whose signature does not verify is a well-framed page with one bad
// event in it, and dropping its honest neighbours would let one forgery
// deny an entire chronicle.
- val good = payload(DialectEvent.KIND)
+ val good = payload(TextNoteEvent.KIND)
assertNull(ChronicleEvent.decodePage("[${good.toJson()},\"not an event\"]"))
assertNull(ChronicleEvent.decodePage("[\"not an event\",${good.toJson()}]"))
@@ -121,7 +116,7 @@ class ChronicleEventTest {
@Test
fun `a page over the event cap is refused on the way in`() {
val overCap = (0..ChronicleEvent.MAX_PAGE_EVENTS).map {
- payload(DialectEvent.KIND, id = it.toString().padStart(64, '0'))
+ payload(TextNoteEvent.KIND, id = it.toString().padStart(64, '0'))
}
assertEquals(ChronicleEvent.MAX_PAGE_EVENTS + 1, overCap.size)
@@ -139,7 +134,7 @@ class ChronicleEventTest {
// runs, and the page-over-the-cap test above passes for the wrong reason.
// Both caps have to be re-sized together; this is what says so.
val atCap = (0 until ChronicleEvent.MAX_PAGE_EVENTS).map {
- payload(DialectEvent.KIND, id = it.toString().padStart(64, '0'))
+ payload(TextNoteEvent.KIND, id = it.toString().padStart(64, '0'))
}
val page = ChronicleEvent.encodePage(atCap)
@@ -157,7 +152,7 @@ class ChronicleEventTest {
// work a remote party can ask this device to do. A chronicle is the second
// place in this protocol where somebody else sets that size.
val huge = ChronicleEvent.encodePage(
- listOf(payload(DialectEvent.KIND, content = "x".repeat(ChronicleEvent.MAX_PAGE_BYTES)))
+ listOf(payload(TextNoteEvent.KIND, content = "x".repeat(ChronicleEvent.MAX_PAGE_BYTES)))
)
assertTrue(huge.encodeToByteArray().size > ChronicleEvent.MAX_PAGE_BYTES)
@@ -170,7 +165,7 @@ class ChronicleEventTest {
// this were measured in characters the cap would let through up to four
// times what it says.
val wide = "世".repeat(ChronicleEvent.MAX_PAGE_BYTES / 2)
- val page = ChronicleEvent.encodePage(listOf(payload(DialectEvent.KIND, content = wide)))
+ val page = ChronicleEvent.encodePage(listOf(payload(TextNoteEvent.KIND, content = wide)))
assertTrue(page.length < ChronicleEvent.MAX_PAGE_BYTES)
assertTrue(page.encodeToByteArray().size > ChronicleEvent.MAX_PAGE_BYTES)
@@ -180,42 +175,24 @@ class ChronicleEventTest {
// ---- What a chronicle may carry ---------------------------------------
@Test
- fun `the allowlist is every kind the group signs and only those`() {
+ fun `a kind set admits what it lists and nothing else`() {
listOf(
- DialectEvent.KIND,
- ArtifactEvent.KIND,
- ArtifactVersionEvent.KIND,
- ChapterEvent.KIND,
- ChunkEvent.KIND,
- TranslationArtifactVersionEvent.KIND,
- TranslationChapterEvent.KIND,
- TranslationChunkEvent.KIND,
- ).forEach { assertTrue(ChronicleEvent.isChroniclable(it), "kind $it should be chroniclable") }
+ AdvertisedRelayListEvent.KIND,
+ MetadataEvent.KIND,
+ TextNoteEvent.KIND,
+ ).forEach { assertTrue(TEST_KINDS.isChroniclable(it), "kind $it should be chroniclable") }
- assertEquals(8, ChronicleEvent.CHRONICLABLE_KINDS.size)
- }
+ assertEquals(3, TEST_KINDS.all.size)
+ assertFalse(TEST_KINDS.isEmpty())
- @Test
- fun `the translated text is chroniclable now that the group signs it`() {
- // Worth its own case because it was the feature's headline limitation for
- // as long as `saveTranslation` wrote the row and queued the member's own
- // rumor. A chronicle can only carry what the receiver can check, so a
- // translation nobody signed could not travel, and a new member got the
- // whole structure and none of the prose.
- assertTrue(ChronicleEvent.isChroniclable(TranslationChunkEvent.KIND))
+ // Group-signed, with an arm in applyInnerEvent, and still refused: being
+ // signed is not what earns a kind its place, being on the list is.
+ assertFalse(TEST_KINDS.isChroniclable(GroupWalletStatementEvent.KIND))
+ assertNull(TEST_KINDS.applyRank(GroupWalletStatementEvent.KIND))
- // Same shape, same fix: the version an artifact starts life with used to
- // be derived on arrival, so it was authored by the group with no
- // signature to show for it. It is the second item of the artifact's batch
- // now.
- assertTrue(ChronicleEvent.isChroniclable(ArtifactVersionEvent.KIND))
- }
-
- @Test
- fun `the kinds nobody signs are still left out`() {
- // Nothing builds one of these at all; the inbound arm exists and no
- // producer does.
- assertFalse(ChronicleEvent.isChroniclable(TranslationEvent.KIND))
+ // And the empty list admits nothing at all.
+ assertTrue(ChronicleKinds.NONE.isEmpty())
+ assertFalse(ChronicleKinds.NONE.isChroniclable(TextNoteEvent.KIND))
}
@Test
@@ -226,7 +203,8 @@ class ChronicleEventTest {
// validly signed statement about what the room signs with, replayed by
// whoever kept a copy. Nothing but this stops it.
assertFalse(ChronicleEvent.isChroniclable(GroupKeyStateEvent.KIND))
- assertNull(ChronicleEvent.applyRank(GroupKeyStateEvent.KIND))
+ assertFalse(TEST_KINDS.isChroniclable(GroupKeyStateEvent.KIND))
+ assertNull(TEST_KINDS.applyRank(GroupKeyStateEvent.KIND))
}
@Test
@@ -244,12 +222,14 @@ class ChronicleEventTest {
// chronicle may carry an event its own key did not sign, which no
// chroniclable kind does. See docs/subgroups.md.
assertFalse(ChronicleEvent.isChroniclable(SubgroupBirthCertificateEvent.KIND))
- assertNull(ChronicleEvent.applyRank(SubgroupBirthCertificateEvent.KIND))
+ assertFalse(TEST_KINDS.isChroniclable(SubgroupBirthCertificateEvent.KIND))
+ assertNull(TEST_KINDS.applyRank(SubgroupBirthCertificateEvent.KIND))
}
@Test
- fun `a chronicle carries documents not envelopes or protocol`() {
- assertFalse(ChronicleEvent.isChroniclable(SubmissionEvent.KIND))
+ fun `a chronicle carries the group's work not envelopes or protocol`() {
+ // Against the app's own list, which is the one that will grow: the day a
+ // kind is added back, none of these may come with it.
assertFalse(ChronicleEvent.isChroniclable(ChronicleEvent.KIND))
assertFalse(ChronicleEvent.isChroniclable(ChronicleRequestEvent.KIND))
FrostSigningEvents.ALL.forEach {
@@ -257,86 +237,57 @@ class ChronicleEventTest {
}
}
- @Test
- fun `the contributor lists are left out while nothing applies them`() {
- // Not an oversight. ChatMessage.applyInnerEvent has no arm that writes a
- // row for any of these, so chronicling them would cost bytes and restore
- // nothing. They belong in the list on the day that changes.
- assertFalse(ChronicleEvent.isChroniclable(TranslationArtifactVersionContributorListEvent.KIND))
- assertFalse(ChronicleEvent.isChroniclable(TranslationChapterContributorListEvent.KIND))
- assertFalse(ChronicleEvent.isChroniclable(TranslationContributorListEvent.KIND))
- }
-
// ---- Dependency order ------------------------------------------------
@Test
- fun `the order is the foreign keys not the kind numbers`() {
- fun rank(kind: Int) = assertNotNull(ChronicleEvent.applyRank(kind), "kind $kind has no rank")
+ fun `the order is the list's not the kind numbers'`() {
+ fun rank(kind: Int) = assertNotNull(TEST_KINDS.applyRank(kind), "kind $kind has no rank")
- // Every one of these is a foreign key in Room, so a chronicle applied the
- // other way round is a constraint violation rather than a wrong answer.
- assertTrue(rank(DialectEvent.KIND) < rank(ArtifactEvent.KIND))
- assertTrue(rank(ArtifactEvent.KIND) < rank(ArtifactVersionEvent.KIND))
- assertTrue(rank(ArtifactVersionEvent.KIND) < rank(ChapterEvent.KIND))
- assertTrue(rank(ChapterEvent.KIND) < rank(ChunkEvent.KIND))
- assertTrue(rank(ArtifactVersionEvent.KIND) < rank(TranslationArtifactVersionEvent.KIND))
- assertTrue(rank(DialectEvent.KIND) < rank(TranslationArtifactVersionEvent.KIND))
- assertTrue(rank(TranslationArtifactVersionEvent.KIND) < rank(TranslationChapterEvent.KIND))
- assertTrue(rank(ChapterEvent.KIND) < rank(TranslationChapterEvent.KIND))
-
- // A translated chunk hangs off both sides at once -- the source chunk it
- // translates and the translation chapter it sits in -- so it is last.
- assertTrue(rank(ChunkEvent.KIND) < rank(TranslationChunkEvent.KIND))
- assertTrue(rank(TranslationChapterEvent.KIND) < rank(TranslationChunkEvent.KIND))
+ // In the app the list is the database's foreign keys, so a chronicle
+ // applied the other way round is a constraint violation rather than a
+ // wrong answer. Here it is only the test's own order, which is enough to
+ // show the machinery follows the list.
+ assertTrue(rank(AdvertisedRelayListEvent.KIND) < rank(MetadataEvent.KIND))
+ assertTrue(rank(MetadataEvent.KIND) < rank(TextNoteEvent.KIND))
// And the numbers really do disagree with the order, which is why this is
// a list rather than a sortedBy { kind }.
- assertTrue(DialectEvent.KIND > ArtifactEvent.KIND)
- assertTrue(rank(DialectEvent.KIND) < rank(ArtifactEvent.KIND))
+ assertTrue(AdvertisedRelayListEvent.KIND > MetadataEvent.KIND)
+ assertTrue(rank(AdvertisedRelayListEvent.KIND) < rank(MetadataEvent.KIND))
}
@Test
- fun `sorting a page puts what is referenced before what refers to it`() {
+ fun `sorting a page puts it in the list's order`() {
val jumbled = listOf(
- payload(TranslationChunkEvent.KIND),
- payload(TranslationChapterEvent.KIND),
- payload(ChunkEvent.KIND),
- payload(DialectEvent.KIND),
- payload(TranslationArtifactVersionEvent.KIND),
- payload(ChapterEvent.KIND),
- payload(ArtifactVersionEvent.KIND),
- payload(ArtifactEvent.KIND),
+ payload(TextNoteEvent.KIND),
+ payload(MetadataEvent.KIND),
+ payload(AdvertisedRelayListEvent.KIND),
)
assertEquals(
listOf(
- DialectEvent.KIND,
- ArtifactEvent.KIND,
- ArtifactVersionEvent.KIND,
- ChapterEvent.KIND,
- ChunkEvent.KIND,
- TranslationArtifactVersionEvent.KIND,
- TranslationChapterEvent.KIND,
- TranslationChunkEvent.KIND,
+ AdvertisedRelayListEvent.KIND,
+ MetadataEvent.KIND,
+ TextNoteEvent.KIND,
),
- ChronicleEvent.inApplyOrder(jumbled).map { it.kind }
+ TEST_KINDS.inApplyOrder(jumbled).map { it.kind }
)
}
@Test
fun `two of a kind keep the order they were handed in`() {
- // Nothing orders two chapters of one version, and keeping the caller's
- // order is one less thing that differs between two members assembling the
- // same chronicle.
- val chapters = listOf(
- payload(ChapterEvent.KIND, "one", id = "1".repeat(64)),
- payload(ChapterEvent.KIND, "two", id = "2".repeat(64)),
- payload(ChapterEvent.KIND, "three", id = "3".repeat(64)),
+ // Nothing orders two posts by the group, and keeping the caller's order
+ // is one less thing that differs between two members assembling the same
+ // chronicle.
+ val posts = listOf(
+ payload(TextNoteEvent.KIND, "one", id = "1".repeat(64)),
+ payload(TextNoteEvent.KIND, "two", id = "2".repeat(64)),
+ payload(TextNoteEvent.KIND, "three", id = "3".repeat(64)),
)
assertEquals(
listOf("one", "two", "three"),
- ChronicleEvent.inApplyOrder(chapters).map { it.content }
+ TEST_KINDS.inApplyOrder(posts).map { it.content }
)
}
@@ -345,12 +296,13 @@ class ChronicleEventTest {
@Test
fun `a page says which chronicle it is where in it and who for`() {
val template = ChronicleEvent.build(
- payloads = listOf(payload(DialectEvent.KIND)),
+ payloads = listOf(payload(TextNoteEvent.KIND)),
chronicleId = chronicleId,
index = 2,
count = 5,
recipient = recipient,
- createdAt = 1_700_000_100L
+ createdAt = 1_700_000_100L,
+ kinds = TEST_KINDS,
)
val readBack = ChronicleEvent(
@@ -406,17 +358,18 @@ class ChronicleEventTest {
// security -- the inbound one is the boundary -- but a page nobody can
// read back is better failed where it was made.
assertFailsWith {
- ChronicleEvent.build(emptyList(), chronicleId, 0, 1, recipient)
+ ChronicleEvent.build(emptyList(), chronicleId, 0, 1, recipient, kinds = TEST_KINDS)
}
assertFailsWith {
ChronicleEvent.build(
payloads = (0..ChronicleEvent.MAX_PAGE_EVENTS).map {
- payload(DialectEvent.KIND, id = it.toString().padStart(64, '0'))
+ payload(TextNoteEvent.KIND, id = it.toString().padStart(64, '0'))
},
chronicleId = chronicleId,
index = 0,
count = 1,
- recipient = recipient
+ recipient = recipient,
+ kinds = TEST_KINDS,
)
}
assertFailsWith {
@@ -425,18 +378,36 @@ class ChronicleEventTest {
chronicleId = chronicleId,
index = 0,
count = 1,
- recipient = recipient
+ recipient = recipient,
+ kinds = TEST_KINDS,
)
}
assertFailsWith {
ChronicleEvent.build(
payloads = listOf(
- payload(DialectEvent.KIND, content = "x".repeat(ChronicleEvent.MAX_PAGE_BYTES))
+ payload(TextNoteEvent.KIND, content = "x".repeat(ChronicleEvent.MAX_PAGE_BYTES))
),
chronicleId = chronicleId,
index = 0,
count = 1,
- recipient = recipient
+ recipient = recipient,
+ kinds = TEST_KINDS,
+ )
+ }
+ }
+
+ @Test
+ fun `the app's own list builds no page at all`() {
+ // The outbound half of the app carrying nothing: a payload the test list
+ // admits is refused under the default, so nothing that assembles a page
+ // without naming its kinds can put one on the wire.
+ assertFailsWith {
+ ChronicleEvent.build(
+ payloads = listOf(payload(TextNoteEvent.KIND)),
+ chronicleId = chronicleId,
+ index = 0,
+ count = 1,
+ recipient = recipient,
)
}
}
diff --git a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/chronicle/ChronicleRoundTripTest.kt b/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/chronicle/ChronicleRoundTripTest.kt
deleted file mode 100644
index 78e88c4c..00000000
--- a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/chronicle/ChronicleRoundTripTest.kt
+++ /dev/null
@@ -1,422 +0,0 @@
-package com.machankura.bennu.compose.nostr.chronicle
-
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
-import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
-import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
-import fr.acinq.bitcoin.ByteVector
-import fr.acinq.bitcoin.ByteVector32
-import fr.acinq.bitcoin.PrivateKey
-import fr.acinq.bitcoin.crypto.frost.Frost
-import fr.acinq.bitcoin.crypto.frost.IndividualNonce
-import fr.acinq.bitcoin.crypto.frost.KeyMaterial
-import fr.acinq.bitcoin.crypto.frost.SecretNonce
-import fr.acinq.bitcoin.crypto.frost.Session
-import fr.acinq.bitcoin.crypto.frost.TweakCache
-import kotlin.test.Test
-import kotlin.test.assertEquals
-import kotlin.test.assertFalse
-import kotlin.test.assertNotNull
-import kotlin.test.assertTrue
-import com.machankura.bennu.compose.database.model.MantraArtifact
-import com.machankura.bennu.compose.database.model.MantraArtifactVersion
-import com.machankura.bennu.compose.database.model.MantraChapter
-import com.machankura.bennu.compose.database.model.MantraChunk
-import com.machankura.bennu.compose.database.model.MantraDialect
-import com.machankura.bennu.compose.database.model.MantraTranslationArtifactVersion
-import com.machankura.bennu.compose.database.model.MantraTranslationChapter
-import com.machankura.bennu.compose.database.model.MantraTranslationChunk
-import com.machankura.bennu.compose.extensions.toHex
-import com.machankura.bennu.compose.managers.SharedKeyDerivation
-import com.machankura.bennu.compose.nostr.frost.GroupKeyStateEvent
-import com.machankura.bennu.compose.nostr.nip30303.ArtifactEvent
-import com.machankura.bennu.compose.nostr.nip30303.ArtifactVersionEvent
-import com.machankura.bennu.compose.nostr.nip30303.ChapterEvent
-import com.machankura.bennu.compose.nostr.nip30303.ChunkEvent
-import com.machankura.bennu.compose.nostr.nip30303.DialectEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationArtifactVersionEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationChapterEvent
-import com.machankura.bennu.compose.nostr.nip30303.TranslationChunkEvent
-
-/**
- * The assumption the chronicle's *fallback* rests on: a row can be turned back
- * into the event the group signed.
- *
- * Signed events used to be stored only as rows. `FrostSigningManager.complete`
- * applied one and what survived was a `Mantra*` row, so a chronicle had to
- * rebuild each payload with `toXEvent()` and hope it came out byte-identical --
- * and if it did not, the id changed, the signature no longer covered it, and
- * every receiver dropped the payload as a forgery, silently, one kind at a time.
- *
- * That is what the round-trip note on each `toXEvent` claims and what nothing
- * asserted until this ran. Every kind in `ChronicleEvent.CHRONICLABLE_KINDS` is
- * checked here against a real FROST quorum, because a signature that verifies is
- * the only evidence that the rebuild is faithful -- comparing fields would only
- * prove the test and the code agree about which fields matter.
- *
- * ### Deprecated, along with what it guards
- *
- * `GroupSignedEvent` keeps the events now, and `ChronicleManager.assemble` reads
- * them; the rebuild survives only for work signed before that table existed, and
- * so does this. Nothing else covers the `toXEvent()` methods, so **this whole
- * file goes when they do** -- see "Retiring the rebuild" in
- * docs/member-chronicle.md. Until then a kind that fails here cannot be chronicled
- * *from a row*, whatever the allowlist says, which for a pre-v13 room is the
- * same thing as not at all.
- */
-class ChronicleRoundTripTest {
- private val participants = 3
- private val threshold = 2
-
- /** Stands in for a completed ceremony; nothing here is about the DKG. */
- private val keyMaterial: KeyMaterial = Frost.trustedDealerKeygen(
- thresholdSecretKey = PrivateKey(
- ByteVector32("1c0ffee0000000000000000000000000000000000000000000000000000000a1")
- ),
- nParticipants = participants,
- threshold = threshold
- )
-
- private val room: SharedKeyDerivation.Derived = SharedKeyDerivation.derive(
- thresholdPublicKey = keyMaterial.thresholdPublicKey.value.toHex(),
- path = SharedKeyDerivation.MARMOT_ADMIN_GROUP_PATH
- )
-
- private val tweakCache: TweakCache = room.cache
-
- /** The group's identity, which is also the room's id. */
- private val chatRoomId = room.hex
-
- private val dialectId = "b".repeat(64)
- private val artifactVersionId = "c".repeat(64)
- private val chapterId = "d".repeat(64)
- private val translationArtifactVersionId = "e".repeat(64)
- private val translationChapterId = "f".repeat(64)
- private val chunkId = "a".repeat(64)
-
- /** Exactly what `FrostSigningManager.unsignedEventOf` does. */
- private fun unsignedEventOf(template: EventTemplate<*>) = Event(
- id = EventHasher.hashId(
- pubKey = chatRoomId,
- createdAt = template.createdAt,
- kind = template.kind,
- tags = template.tags,
- content = template.content
- ),
- pubKey = chatRoomId,
- createdAt = template.createdAt,
- kind = template.kind,
- tags = template.tags,
- content = template.content,
- sig = ""
- )
-
- /** A real quorum signing [eventId], in the manager's order. */
- private fun groupSignature(eventId: String): String {
- val message = ByteVector(eventId.hexToByteArray())
- val signerIds = listOf(0, 1)
-
- val nonces = signerIds.map { signerId ->
- SecretNonce.generate(
- sessionRandom = ByteVector32("a".repeat(63) + "${signerId + 1}"),
- secretShare = keyMaterial.secretShares[signerId],
- publicShare = keyMaterial.publicShares[signerId],
- tweakedThresholdPublicKey = tweakCache.tweakedPublicKey,
- message = message,
- extraInput = null
- )
- }
-
- val signingSession = Session.create(
- aggregatedNonce = IndividualNonce.aggregate(nonces.map { it.second }).right!!,
- signerIds = signerIds.map { it.toUInt() },
- signerPublicShares = signerIds.map { keyMaterial.publicShares[it] },
- nParticipants = participants,
- threshold = threshold,
- tweakCache = tweakCache,
- message = message
- )
-
- val partials = signerIds.mapIndexed { position, signerId ->
- signingSession.sign(
- nonces[position].first,
- keyMaterial.secretShares[signerId],
- signerId.toUInt()
- ).right!!
- }
-
- return signingSession.aggregateSigs(partials).right!!.toByteArray().toHex()
- }
-
- /** A template, signed by the group, the way a finished session leaves one. */
- private fun signed(template: EventTemplate<*>): Event {
- val unsigned = unsignedEventOf(template)
-
- return Event(
- id = unsigned.id,
- pubKey = unsigned.pubKey,
- createdAt = unsigned.createdAt,
- kind = unsigned.kind,
- tags = unsigned.tags,
- content = unsigned.content,
- sig = groupSignature(unsigned.id)
- )
- }
-
- /**
- * The claim, for one kind: sign it, file it as a row, rebuild it from the
- * row, and the group's signature still covers what comes out.
- */
- private fun assertRoundTrips(template: EventTemplate<*>, rebuild: (Event) -> Event?) {
- val signedEvent = signed(template)
- assertTrue(
- GroupKeyStateEvent.isSignedByRoom(signedEvent, chatRoomId),
- "the harness itself must produce a verifiable event"
- )
-
- val rebuilt = assertNotNull(
- rebuild(signedEvent),
- "kind ${template.kind} did not survive being turned into a row"
- )
-
- // Asserted before the signature so a failure says which half broke: an id
- // that moved means the tag order or a field changed in the rebuild, where
- // a signature that fails on a matching id would mean something stranger.
- assertEquals(
- signedEvent.id,
- rebuilt.id,
- "kind ${template.kind} came back with a different id"
- )
- assertEquals(
- signedEvent.sig,
- rebuilt.sig,
- "kind ${template.kind} lost the group's signature"
- )
- assertTrue(
- GroupKeyStateEvent.isSignedByRoom(rebuilt, chatRoomId),
- "kind ${template.kind} rebuilt into something the group's signature does not cover"
- )
- }
-
- @Test
- fun `a dialect survives the trip through a row`() {
- assertRoundTrips(
- DialectEvent.build(
- name = "isiZulu",
- country = "ZA",
- language = "zu",
- createdAt = 1_700_000_000L
- )
- ) { event ->
- MantraDialect.fromDialectEvent(
- DialectEvent(event.id, event.pubKey, event.createdAt, event.tags, event.content, event.sig),
- chatRoomId
- )?.toDialectEvent()
- }
- }
-
- @Test
- fun `an artifact survives the trip through a row`() {
- // The one that did not, when this test was written. Two faults, and the
- // second is the interesting one: `toArtifactEvent` put the alt tag last
- // where `build` puts it first, and it left out the version metadata
- // entirely -- because that tag is not on the row at all. It is consumed
- // into the artifact's first MantraArtifactVersion and dropped. So the
- // label has to come back from there, which is why it is a parameter.
- assertRoundTrips(
- ArtifactEvent.build(
- name = "In Detention",
- url = "https://example.com/in-detention",
- visibility = "private",
- license = "cc",
- dialectId = dialectId,
- versionLabel = "1.0",
- createdAt = 1_700_000_000L
- )
- ) { event ->
- MantraArtifact.fromArtifactEvent(
- ArtifactEvent(event.id, event.pubKey, event.createdAt, event.tags, event.content, event.sig),
- chatRoomId
- )?.toArtifactEvent(versionLabel = "1.0")
- }
- }
-
- @Test
- fun `an artifact rebuilt with the wrong version label is not the one that was signed`() {
- // What the parameter costs if a caller guesses. The label was part of
- // what the group put its signature to, so a rebuild carrying a different
- // one is a different event -- and it fails as a forgery rather than as a
- // mistake, which is why the assembler reads it off the initial version
- // rather than defaulting it.
- val signedEvent = signed(
- ArtifactEvent.build(
- name = "In Detention",
- url = "https://example.com/in-detention",
- visibility = "private",
- license = "cc",
- dialectId = dialectId,
- versionLabel = "1.0",
- createdAt = 1_700_000_000L
- )
- )
-
- val rebuilt = MantraArtifact.fromArtifactEvent(
- ArtifactEvent(
- signedEvent.id, signedEvent.pubKey, signedEvent.createdAt,
- signedEvent.tags, signedEvent.content, signedEvent.sig
- ),
- chatRoomId
- )?.toArtifactEvent(versionLabel = "2.0")
-
- assertNotNull(rebuilt)
- assertFalse(GroupKeyStateEvent.isSignedByRoom(rebuilt, chatRoomId))
- }
-
- @Test
- fun `an artifact version survives the trip through a row`() {
- // The second fault of the same shape, found the moment this kind became
- // chroniclable: `toArtifactVersionEvent` emitted [artifactId, alt] where
- // `build` emits [alt, artifactId]. It had been that way for as long as
- // nothing called it, which is what makes an unused rebuild dangerous
- // rather than merely dead -- the claim in its comment was never checked.
- //
- // Built through `initialVersionOf` rather than by hand, because that is
- // what the signing batch actually proposes.
- val artifact = signed(
- ArtifactEvent.build(
- name = "In Detention",
- url = "https://example.com/in-detention",
- visibility = "private",
- license = "cc",
- dialectId = dialectId,
- versionLabel = "1.0",
- createdAt = 1_700_000_000L
- )
- )
-
- assertRoundTrips(
- ArtifactVersionEvent.initialVersionOf(artifact).single()
- ) { event ->
- MantraArtifactVersion.fromArtifactVersionEvent(
- ArtifactVersionEvent(
- event.id, event.pubKey, event.createdAt, event.tags, event.content, event.sig
- ),
- chatRoomId
- )?.toArtifactVersionEvent()
- }
- }
-
- @Test
- fun `a translated chunk survives the trip through a row`() {
- // The translated text. Chroniclable only because the app stopped saving it
- // as its author's rumor and started asking the group to sign it -- until
- // then a new member got the whole structure and none of the prose.
- assertRoundTrips(
- TranslationChunkEvent.build(
- translationChapterId = translationChapterId,
- chunkId = chunkId,
- index = 0,
- text = "Wayeyindoda enezingxenye.",
- createdAt = 1_700_000_000L
- )
- ) { event ->
- MantraTranslationChunk.fromTranslationChunkEvent(
- TranslationChunkEvent(
- event.id, event.pubKey, event.createdAt, event.tags, event.content, event.sig
- ),
- chatRoomId
- )?.toTranslationChunkEvent()
- }
- }
-
- @Test
- fun `a chapter survives the trip through a row`() {
- assertRoundTrips(
- ChapterEvent.build(
- artifactVersionId = artifactVersionId,
- name = "Chapter One",
- originalText = "He was a man of parts.",
- index = 0,
- wordCount = 6,
- characterCount = 22,
- createdAt = 1_700_000_000L
- )
- ) { event ->
- MantraChapter.fromChapterEvent(
- ChapterEvent(event.id, event.pubKey, event.createdAt, event.tags, event.content, event.sig),
- chatRoomId
- )?.toChapterEvent()
- }
- }
-
- @Test
- fun `a chunk survives the trip through a row`() {
- assertRoundTrips(
- ChunkEvent.build(
- chapterId = chapterId,
- text = "He was a man of parts.",
- index = 0,
- wordCount = 6,
- characterCount = 22,
- createdAt = 1_700_000_000L
- )
- ) { event ->
- MantraChunk.fromChunkEvent(
- ChunkEvent(event.id, event.pubKey, event.createdAt, event.tags, event.content, event.sig),
- chatRoomId
- )?.toChunkEvent()
- }
- }
-
- @Test
- fun `a translation artifact version survives the trip through a row`() {
- assertRoundTrips(
- TranslationArtifactVersionEvent.build(
- artifactVersionId = artifactVersionId,
- dialectId = dialectId,
- name = "isiZulu",
- visibility = "private",
- license = "cc",
- createdAt = 1_700_000_000L
- )
- ) { event ->
- MantraTranslationArtifactVersion.fromTranslationArtifactVersionEvent(
- TranslationArtifactVersionEvent(
- event.id, event.pubKey, event.createdAt, event.tags, event.content, event.sig
- ),
- chatRoomId
- )?.toTranslationArtifactVersionEvent()
- }
- }
-
- @Test
- fun `a translation chapter survives the trip through a row`() {
- assertRoundTrips(
- TranslationChapterEvent.build(
- translationArtifactVersionId = translationArtifactVersionId,
- chapterId = chapterId,
- index = 0,
- createdAt = 1_700_000_000L
- )
- ) { event ->
- MantraTranslationChapter.fromTranslationChapterEvent(
- TranslationChapterEvent(
- event.id, event.pubKey, event.createdAt, event.tags, event.content, event.sig
- ),
- chatRoomId
- )?.toTranslationChapterEvent()
- }
- }
-
- @Test
- fun `every chroniclable kind has a round-trip test above`() {
- // The list and this file have to move together. A kind added to the
- // allowlist without a case here is one nobody has checked can be rebuilt,
- // and the failure is silent: the receiver drops it as a forgery.
- assertEquals(
- 8,
- ChronicleEvent.CHRONICLABLE_KINDS.size,
- "a chroniclable kind was added or removed; add or remove its round-trip case"
- )
- }
-}
diff --git a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/chronicle/ChronicleTestKinds.kt b/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/chronicle/ChronicleTestKinds.kt
new file mode 100644
index 00000000..73c237ef
--- /dev/null
+++ b/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/chronicle/ChronicleTestKinds.kt
@@ -0,0 +1,35 @@
+package com.machankura.bennu.compose.nostr.chronicle
+
+import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
+import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
+import com.vitorpamplona.quartz.nip65RelayList.AdvertisedRelayListEvent
+
+/**
+ * The kinds the chronicle tests chronicle, in the order they apply.
+ *
+ * The app's own list, [ChronicleEvent.KINDS], is empty, so the machinery is
+ * exercised with this one instead. It is not a proposal for what the app should
+ * carry -- see [ChronicleEvent.KINDS] for why each of these is left out there.
+ *
+ * Chosen for three properties:
+ *
+ * - **each is a group-signed kind `ChatMessage.applyInnerEvent` has an arm
+ * for**, so a payload goes down the real apply path rather than falling
+ * through to "unsupported";
+ * - **none of those arms writes a row of its own or throws** -- the group's
+ * profile, relay lists and posts are read straight off `GroupSignedEvent`
+ * -- so what a receiver holds afterwards is exactly the `GroupSignedEvent`
+ * rows the chronicle recorded, and comparing those is comparing the work;
+ * - **the order disagrees with the kind numbers** (10002 before 0 before 1),
+ * so a test that the order is the list's cannot pass by sorting on kind.
+ *
+ * A key state and a birth certificate are deliberately not here: they are what
+ * the allowlist has to refuse, so they are what the tests try to replay.
+ */
+internal val TEST_KINDS: ChronicleKinds = ChronicleKinds(
+ listOf(
+ AdvertisedRelayListEvent.KIND,
+ MetadataEvent.KIND,
+ TextNoteEvent.KIND,
+ )
+)
diff --git a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/nip30303/ArtifactEventTest.kt b/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/nip30303/ArtifactEventTest.kt
deleted file mode 100644
index c9db7fc0..00000000
--- a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/nip30303/ArtifactEventTest.kt
+++ /dev/null
@@ -1,118 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303
-
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
-import kotlin.test.Test
-import kotlin.test.assertEquals
-import kotlin.test.assertNull
-import com.machankura.bennu.compose.nostr.nip30303.tags.ArtifactVersionMetadataTag
-
-/**
- * What the form collects has to reach the members deciding whether to sign it.
- *
- * An artifact proposal leaves the proposer's device as a kind, a tag array and
- * a string, and everything a member is shown before signing -- and every row
- * built afterwards -- is read back out of those. A field that does not survive
- * the trip is not a visible failure: the artifact still appears, just without
- * a url, or a source dialect, or a first version, on every device but the one
- * that typed it.
- */
-class ArtifactEventTest {
- private val groupKey = "a".repeat(64)
- private val dialectId = "b".repeat(64)
-
- /** The event a member actually receives: bytes, with no template behind it. */
- private fun readBack(template: com.vitorpamplona.quartz.nip01Core.signers.EventTemplate) =
- ArtifactEvent(
- id = EventHasher.hashId(
- pubKey = groupKey,
- createdAt = template.createdAt,
- kind = template.kind,
- tags = template.tags,
- content = template.content,
- ),
- pubKey = groupKey,
- createdAt = template.createdAt,
- tags = template.tags,
- content = template.content,
- sig = "c".repeat(128),
- )
-
- private fun proposal(versionLabel: String = "1.0") = ArtifactEvent.build(
- name = "In Detention",
- url = "https://example.com/in-detention",
- visibility = "private",
- license = "cc",
- dialectId = dialectId,
- versionLabel = versionLabel,
- createdAt = 1_700_000_000L,
- )
-
- @Test
- fun `every field the form collects survives the trip through the tags`() {
- val artifact = readBack(proposal())
-
- assertEquals("In Detention", artifact.content)
- assertEquals("https://example.com/in-detention", artifact.url())
- assertEquals("private", artifact.visibility())
- assertEquals("cc", artifact.license())
- assertEquals(dialectId, artifact.dialectId())
- assertEquals("1.0", artifact.versionLabel())
- }
-
- @Test
- fun `the proposal is the artifact's kind so the signing screen can describe it`() {
- // The session carries a kind and nothing else to go on. Get this wrong
- // and members are asked to sign "event of kind 30300" -- a question
- // nobody can answer.
- assertEquals(ArtifactEvent.KIND, proposal().kind)
- }
-
- @Test
- fun `an artifact declares one version whatever an initializer adds`() {
- // addUnique, not add: two labels would leave receivers deriving two
- // different first versions depending on which one they read first.
- val template = ArtifactEvent.build(
- name = "In Detention",
- url = "https://example.com/in-detention",
- visibility = "private",
- license = "cc",
- dialectId = dialectId,
- versionLabel = "1.0",
- ) {
- addUnique(ArtifactVersionMetadataTag.assemble("2.0"))
- }
-
- assertEquals(
- 1,
- template.tags.count { it.firstOrNull() == ArtifactVersionMetadataTag.TAG_NAME }
- )
- }
-
- @Test
- fun `an artifact from before the label existed reads back as declaring none`() {
- // Not an error: it is what every artifact submitted the old way looks
- // like, and they have to keep parsing rather than failing to load.
- val template = proposal()
- val older = Event(
- id = "d".repeat(64),
- pubKey = groupKey,
- createdAt = template.createdAt,
- kind = template.kind,
- tags = template.tags
- .filterNot { it.firstOrNull() == ArtifactVersionMetadataTag.TAG_NAME }
- .toTypedArray(),
- content = template.content,
- sig = "",
- )
-
- val artifact = ArtifactEvent(
- older.id, older.pubKey, older.createdAt, older.tags, older.content, older.sig
- )
-
- assertNull(artifact.versionLabel())
- // Everything else still reads, so the artifact itself is unharmed.
- assertEquals(dialectId, artifact.dialectId())
- assertEquals("https://example.com/in-detention", artifact.url())
- }
-}
diff --git a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/nip30303/ChapterChunkSplitTest.kt b/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/nip30303/ChapterChunkSplitTest.kt
deleted file mode 100644
index 40e8990c..00000000
--- a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/nip30303/ChapterChunkSplitTest.kt
+++ /dev/null
@@ -1,196 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303
-
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
-import kotlin.test.Test
-import kotlin.test.assertEquals
-import kotlin.test.assertNotEquals
-import kotlin.test.assertTrue
-import com.machankura.bennu.compose.nostr.nip30303.tags.OriginalTextTag
-import com.machankura.bennu.compose.text.Markdown
-
-/**
- * The chunks a chapter is proposed with are cut from the chapter itself.
- *
- * A chapter and a chunk per paragraph go to the group as one batch, and the
- * chunks can only be built once the chapter has been authored under the group's
- * key — a chunk carries the chapter's id, and that id does not exist before
- * then. So the split takes the unsigned chapter the session is about to sign
- * and cuts from what it holds.
- *
- * What breaks quietly here is a chunk that names the wrong chapter, or none:
- * every id in sight is opaque hex, the batch signs whatever it is handed, and
- * the first sign of trouble is a chapter that arrives with no chunks under it
- * because every one of them failed a foreign key on the way in.
- */
-class ChapterChunkSplitTest {
- private val groupKey = "a".repeat(64)
- private val artifactVersionId = "b".repeat(64)
-
- private val twoParagraphs = "The first paragraph.\n\nThe second paragraph."
-
- /**
- * The chapter as the session will sign it: the proposer's fields re-authored
- * under the group's key, with the id computed from them.
- */
- private fun unsignedChapter(
- name: String = "Chapter 1",
- originalText: String = twoParagraphs,
- index: Int = 0,
- createdAt: Long = 1_700_000_000,
- ): Event {
- val template = ChapterEvent.build(
- artifactVersionId = artifactVersionId,
- name = name,
- originalText = originalText,
- index = index,
- wordCount = Markdown.wordCount(originalText),
- characterCount = Markdown.characterCount(originalText),
- createdAt = createdAt,
- )
-
- return Event(
- id = EventHasher.hashId(
- pubKey = groupKey,
- createdAt = template.createdAt,
- kind = template.kind,
- tags = template.tags,
- content = template.content
- ),
- pubKey = groupKey,
- createdAt = template.createdAt,
- kind = template.kind,
- tags = template.tags,
- content = template.content,
- sig = ""
- )
- }
-
- /** What a chunk template says once it is tags and a string, which is all it travels as. */
- private fun readBack(template: com.vitorpamplona.quartz.nip01Core.signers.EventTemplate) =
- ChunkEvent(
- id = EventHasher.hashId(
- pubKey = groupKey,
- createdAt = template.createdAt,
- kind = template.kind,
- tags = template.tags,
- content = template.content
- ),
- pubKey = groupKey,
- createdAt = template.createdAt,
- tags = template.tags,
- content = template.content,
- sig = ""
- )
-
- @Test
- fun `every chunk names the chapter it was cut from`() {
- // The whole reason the split happens against the built chapter rather
- // than against the form. A chunk naming anything else is a row that
- // cannot be written.
- val chapter = unsignedChapter()
-
- val chunks = ChunkEvent.splitOf(chapter).map(::readBack)
-
- assertEquals(2, chunks.size)
- assertTrue(chunks.all { it.chapterId() == chapter.id })
- }
-
- @Test
- fun `the chunks carry the chapter's text in order`() {
- val chunks = ChunkEvent.splitOf(unsignedChapter()).map(::readBack)
-
- assertEquals(listOf("The first paragraph.", "The second paragraph."), chunks.map { it.content })
- assertEquals(listOf(0, 1), chunks.map { it.index() })
- }
-
- @Test
- fun `each chunk counts its own paragraph rather than the chapter's`() {
- // The chapter's counts describe the whole text. A chunk that inherited
- // them would report every paragraph as the length of the chapter, and
- // any progress measured per chunk would be wrong by that factor.
- val chunks = ChunkEvent
- .splitOf(unsignedChapter(originalText = "One two three.\n\nFour."))
- .map(::readBack)
-
- assertEquals(listOf(3, 1), chunks.map { it.wordCount() })
- assertEquals(listOf("One two three.".length, "Four.".length), chunks.map { it.characterCount() })
- }
-
- @Test
- fun `the chunks are signed as of the chapter's own moment`() {
- // Reading the clock here would put the batch's items minutes apart on a
- // slow device, and a chapter signed at one time with chunks stamped at
- // another is a batch that reads as two events that happened to share a
- // session.
- val chapter = unsignedChapter(createdAt = 1_700_000_000)
-
- val chunks = ChunkEvent.splitOf(chapter)
-
- assertTrue(chunks.all { it.createdAt == 1_700_000_000L })
- }
-
- @Test
- fun `two identical paragraphs stay two chunks`() {
- // Ids are content hashes, so repeated text is where two chunks would
- // collide and the batch would carry one where the chapter has two. The
- // position is in the event, which is what keeps them apart.
- val chunks = ChunkEvent
- .splitOf(unsignedChapter(originalText = "Again.\n\nAgain."))
- .map(::readBack)
-
- assertEquals(2, chunks.size)
- assertNotEquals(chunks[0].id, chunks[1].id)
- }
-
- @Test
- fun `chapters that differ split into chunks that differ`() {
- // Two chapters with the same words are two chapters, and their chunks
- // belong to their own. Chunks of chapter three must not be chunks of
- // chapter one.
- val first = unsignedChapter(index = 0)
- val second = unsignedChapter(index = 3)
-
- val firstChunks = ChunkEvent.splitOf(first).map(::readBack)
- val secondChunks = ChunkEvent.splitOf(second).map(::readBack)
-
- assertNotEquals(first.id, second.id)
- assertEquals(firstChunks.map { it.content }, secondChunks.map { it.content })
- assertNotEquals(firstChunks.map { it.id }, secondChunks.map { it.id })
- }
-
- @Test
- fun `the split counts what the form counted`() {
- // The screen shows a chunk count as the text is typed and refuses to
- // propose past the batch cap on the strength of it. If the split
- // disagreed with that count, the form would allow a batch the session
- // then rejects -- or refuse one it would have taken.
- val text = "One.\n\nTwo.\n\n\nThree.\n\n \n\nFour."
-
- assertEquals(
- Markdown.splitParagraphs(text).size,
- ChunkEvent.splitOf(unsignedChapter(originalText = text)).size
- )
- }
-
- @Test
- fun `a chapter with no text to split proposes no chunks`() {
- assertEquals(emptyList(), ChunkEvent.splitOf(unsignedChapter(originalText = " ")))
-
- // And a chapter that declares no text at all, which is malformed rather
- // than empty: nothing to split, and nothing to throw over either.
- val declared = unsignedChapter()
- val silent = Event(
- id = declared.id,
- pubKey = declared.pubKey,
- createdAt = declared.createdAt,
- kind = declared.kind,
- tags = declared.tags.filterNot { it.firstOrNull() == OriginalTextTag.TAG_NAME }
- .toTypedArray(),
- content = declared.content,
- sig = declared.sig
- )
-
- assertEquals(emptyList(), ChunkEvent.splitOf(silent))
- }
-}
diff --git a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/nip30303/InitialArtifactVersionTest.kt b/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/nip30303/InitialArtifactVersionTest.kt
deleted file mode 100644
index 7d9e7f40..00000000
--- a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/nip30303/InitialArtifactVersionTest.kt
+++ /dev/null
@@ -1,160 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303
-
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
-import kotlin.test.Test
-import kotlin.test.assertEquals
-import kotlin.test.assertNotEquals
-import kotlin.test.assertNull
-import kotlin.test.assertTrue
-import com.machankura.bennu.compose.nostr.nip30303.tags.ArtifactVersionMetadataTag
-
-/**
- * The version an artifact starts life with, built to be signed beside it.
- *
- * It used to be derived on arrival from the label the artifact carries, because
- * proposing it on its own would have cost a second quorum for one form. A batch
- * costs one quorum, so it is signed now -- and a chapter hangs off this row,
- * which is the reason to care: a version nobody signed is a parent vouched for
- * by its own signed children rather than the other way round.
- *
- * What has to hold is that every input comes off the artifact. The id is not
- * settled here -- the signing session hashes it under the group's key -- so an
- * input read from anywhere else would not show up as a wrong row. It would show
- * up as two devices proposing two different batches, which reads as a batch that
- * simply never aggregates.
- */
-class InitialArtifactVersionTest {
- private val groupKey = "a".repeat(64)
- private val dialectId = "b".repeat(64)
-
- /**
- * The artifact as the session will sign it: the proposer's fields re-authored
- * under the group's key. This is what `proposeSigningBatch` hands to
- * `dependents`, so it is what the version has to be built from.
- */
- private fun leadArtifact(
- versionLabel: String = "1.0",
- createdAt: Long = 1_700_000_000,
- ): Event {
- val template = ArtifactEvent.build(
- name = "In Detention",
- url = "example.com",
- visibility = "private",
- license = "cc",
- dialectId = dialectId,
- versionLabel = versionLabel,
- createdAt = createdAt,
- )
-
- return Event(
- id = EventHasher.hashId(
- pubKey = groupKey,
- createdAt = template.createdAt,
- kind = template.kind,
- tags = template.tags,
- content = template.content
- ),
- pubKey = groupKey,
- createdAt = template.createdAt,
- kind = template.kind,
- tags = template.tags,
- content = template.content,
- sig = ""
- )
- }
-
- /** The version item as the session would author it, so the accessors read. */
- private fun versionOf(artifact: Event): ArtifactVersionEvent? =
- ArtifactVersionEvent.initialVersionOf(artifact).singleOrNull()?.let { template ->
- ArtifactVersionEvent(
- id = EventHasher.hashId(
- pubKey = groupKey,
- createdAt = template.createdAt,
- kind = template.kind,
- tags = template.tags,
- content = template.content
- ),
- pubKey = groupKey,
- createdAt = template.createdAt,
- tags = template.tags,
- content = template.content,
- sig = ""
- )
- }
-
- @Test
- fun `the version names the artifact it was built from`() {
- // The whole reason this takes the lead event rather than a form's fields:
- // the id it carries is a hash over the group's key at the room's path, so
- // there is no artifact to name until the proposal has been authored.
- val artifact = leadArtifact()
-
- assertEquals(artifact.id, versionOf(artifact)?.artifactId())
- }
-
- @Test
- fun `it carries the label the artifact declared`() {
- val artifact = leadArtifact(versionLabel = "First Edition")
-
- assertEquals("First Edition", versionOf(artifact)?.content)
- }
-
- @Test
- fun `it takes the artifact's own timestamp rather than the clock`() {
- // So the batch reads as one act. Reading the clock here would agree with
- // itself on one device and disagree between two that proposed the same
- // artifact a second apart -- which is a batch nobody can aggregate, and
- // the case nobody can reproduce on demand.
- val artifact = leadArtifact(createdAt = 1_700_000_042)
-
- assertEquals(1_700_000_042, versionOf(artifact)?.createdAt)
- }
-
- @Test
- fun `an artifact declares exactly one first version`() {
- // Item 0 is the artifact and item 1 is this, and a chapter hangs off
- // whichever version it finds. Two would make that a coin toss.
- assertEquals(1, ArtifactVersionEvent.initialVersionOf(leadArtifact()).size)
- }
-
- @Test
- fun `two devices build the same version from the same artifact`() {
- // Every signer authors the batch itself and signs the ids it arrives at.
- // Devices that disagree here produce partial signatures over different
- // messages, and the session stalls rather than saying why.
- val artifact = leadArtifact()
-
- assertEquals(versionOf(artifact)?.id, versionOf(artifact)?.id)
- }
-
- @Test
- fun `artifacts alike but for the label do not share a version`() {
- // The label is bound into the id rather than hung beside it, so renaming
- // a version cannot leave the row it replaces standing.
- val first = versionOf(leadArtifact(versionLabel = "1.0"))
- val second = versionOf(leadArtifact(versionLabel = "2.0"))
-
- assertNotEquals(first?.id, second?.id)
- }
-
- @Test
- fun `an artifact that declares no version proposes none`() {
- // Artifacts written before the artifact carried its first version. The
- // batch is then one item, which is what an artifact proposal used to be.
- val declared = leadArtifact()
- val silent = Event(
- id = declared.id,
- pubKey = declared.pubKey,
- createdAt = declared.createdAt,
- kind = declared.kind,
- tags = declared.tags.filterNot { it.firstOrNull() == ArtifactVersionMetadataTag.TAG_NAME }
- .toTypedArray(),
- content = declared.content,
- sig = declared.sig
- )
-
- assertTrue(ArtifactVersionEvent.initialVersionOf(silent).isEmpty())
- assertNull(versionOf(silent))
- }
-}
diff --git a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/nip30303/SubmissionEventTest.kt b/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/nip30303/SubmissionEventTest.kt
deleted file mode 100644
index 21149222..00000000
--- a/composeApp/src/commonTest/kotlin/com/machankura/bennu/compose/nostr/nip30303/SubmissionEventTest.kt
+++ /dev/null
@@ -1,126 +0,0 @@
-package com.machankura.bennu.compose.nostr.nip30303
-
-import com.vitorpamplona.quartz.nip01Core.core.Event
-import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
-import kotlin.test.Test
-import kotlin.test.assertEquals
-import kotlin.test.assertNotEquals
-import kotlin.test.assertNull
-
-/**
- * What a submission has to survive: the trip through a group.
- *
- * The envelope is only worth having if the event inside it comes out the other
- * side unchanged -- same id, same author, same signature. The moment any of
- * those is rewritten in transit, a group can no longer hold work by anyone but
- * its own members, which is the whole reason submissions exist.
- */
-class SubmissionEventTest {
- private val submitter = "a".repeat(64)
- private val outsider = "b".repeat(64)
-
- /** A dialect written by somebody who is not in the group. */
- private fun outsiderDialect(): Event {
- val template = DialectEvent.build(
- name = "Sesotho",
- country = "Lesotho",
- language = "st",
- createdAt = 1_700_000_000L,
- )
- return Event(
- id = EventHasher.hashId(
- pubKey = outsider,
- createdAt = template.createdAt,
- kind = template.kind,
- tags = template.tags,
- content = template.content,
- ),
- pubKey = outsider,
- createdAt = template.createdAt,
- kind = template.kind,
- tags = template.tags,
- content = template.content,
- sig = "c".repeat(128),
- )
- }
-
- /** Send a submission template and read it back the way inbound does. */
- private fun roundTrip(payload: Event): SubmissionEvent {
- val template = SubmissionEvent.build(payload = payload, createdAt = 1_700_000_100L)
- val onTheWire = Event.fromJson(
- Event(
- id = EventHasher.hashId(
- pubKey = submitter,
- createdAt = template.createdAt,
- kind = template.kind,
- tags = template.tags,
- content = template.content,
- ),
- pubKey = submitter,
- createdAt = template.createdAt,
- kind = template.kind,
- tags = template.tags,
- content = template.content,
- sig = "",
- ).toJson()
- )
-
- return SubmissionEvent(
- id = onTheWire.id,
- pubKey = onTheWire.pubKey,
- createdAt = onTheWire.createdAt,
- tags = onTheWire.tags,
- content = onTheWire.content,
- sig = onTheWire.sig,
- )
- }
-
- @Test
- fun `the payload comes back as the event that went in`() {
- val dialect = outsiderDialect()
-
- val payload = roundTrip(dialect).payload()
-
- assertEquals(dialect.id, payload?.id)
- assertEquals(dialect.pubKey, payload?.pubKey)
- assertEquals(dialect.kind, payload?.kind)
- assertEquals(dialect.content, payload?.content)
- assertEquals(dialect.sig, payload?.sig)
- }
-
- @Test
- fun `submitting does not make the submitter the author`() {
- val dialect = outsiderDialect()
-
- val submission = roundTrip(dialect)
-
- assertEquals(submitter, submission.pubKey)
- assertEquals(outsider, submission.payload()?.pubKey)
- assertNotEquals(submission.pubKey, submission.payload()?.pubKey)
- }
-
- @Test
- fun `the envelope names what it carries without being opened`() {
- val dialect = outsiderDialect()
-
- val submission = roundTrip(dialect)
-
- assertEquals(DialectEvent.KIND, submission.payloadKind())
- assertEquals(dialect.id, submission.payloadId())
- assertEquals(outsider, submission.payloadAuthor())
- }
-
- @Test
- fun `a payload the group cannot read is null rather than empty`() {
- val submission = SubmissionEvent(
- id = "d".repeat(64),
- pubKey = submitter,
- createdAt = 1_700_000_100L,
- tags = arrayOf(),
- content = "not an event",
- sig = "",
- )
-
- assertNull(submission.payload())
- }
-}
diff --git a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/database/dao/GroupSignedEventDaoJvmTest.kt b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/database/dao/GroupSignedEventDaoJvmTest.kt
index d29712a3..f60b13d2 100644
--- a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/database/dao/GroupSignedEventDaoJvmTest.kt
+++ b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/database/dao/GroupSignedEventDaoJvmTest.kt
@@ -32,8 +32,8 @@ import com.machankura.bennu.compose.database.model.NostrEvent
import com.machankura.bennu.compose.database.model.Profile
import com.machankura.bennu.compose.extensions.toHex
import com.machankura.bennu.compose.managers.SharedKeyDerivation
-import com.machankura.bennu.compose.nostr.nip30303.ArtifactEvent
-import com.machankura.bennu.compose.nostr.nip30303.DialectEvent
+import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
+import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
/**
* The table that keeps what a quorum signed, checked against a real quorum.
@@ -132,8 +132,8 @@ class GroupSignedEventDaoJvmTest {
)
}
- private val dialect = signed(
- DialectEvent.build(name = "isiZulu", country = "ZA", language = "zu", createdAt = 1_700_000_000L)
+ private val post = signed(
+ TextNoteEvent.build(note = "isiZulu", createdAt = 1_700_000_000L)
)
/**
@@ -169,7 +169,7 @@ class GroupSignedEventDaoJvmTest {
}
private fun rowFor(
- event: Event = dialect,
+ event: Event = post,
path: String? = derivationPath,
sessionId: String? = "session-1",
) = GroupSignedEvent.fromEvent(
@@ -184,20 +184,20 @@ class GroupSignedEventDaoJvmTest {
seedRoom()
db.groupSignedEventDao().record(rowFor())
- val stored = db.groupSignedEventDao().getById(dialect.id)
+ val stored = db.groupSignedEventDao().getById(post.id)
assertNotNull(stored, "the event just recorded could not be read back")
- assertEquals(dialect.pubKey, stored.publicKey)
- assertEquals(dialect.kind, stored.kind)
- assertEquals(dialect.content, stored.content)
- assertEquals(dialect.sig, stored.signature)
- assertEquals(dialect.createdAt, stored.createdAt.epochSeconds)
- assertContentEquals(dialect.tags.map { it.toList() }, stored.tags.map { it.toList() })
+ assertEquals(post.pubKey, stored.publicKey)
+ assertEquals(post.kind, stored.kind)
+ assertEquals(post.content, stored.content)
+ assertEquals(post.sig, stored.signature)
+ assertEquals(post.createdAt, stored.createdAt.epochSeconds)
+ assertContentEquals(post.tags.map { it.toList() }, stored.tags.map { it.toList() })
// The claim the columns exist to support: the group's signature is still
// checkable from the row, with nothing else on hand.
assertTrue(stored.verifies(), "the stored row no longer verifies as the room's")
- assertEquals(dialect.id, stored.toEvent().id)
+ assertEquals(post.id, stored.toEvent().id)
}
@Test
@@ -205,7 +205,7 @@ class GroupSignedEventDaoJvmTest {
seedRoom()
db.groupSignedEventDao().record(rowFor())
- val stored = db.groupSignedEventDao().getById(dialect.id)
+ val stored = db.groupSignedEventDao().getById(post.id)
assertNotNull(stored)
assertEquals(derivationPath, stored.derivationPath)
@@ -227,7 +227,7 @@ class GroupSignedEventDaoJvmTest {
seedRoom()
db.groupSignedEventDao().record(rowFor(path = null))
- val stored = db.groupSignedEventDao().getById(dialect.id)
+ val stored = db.groupSignedEventDao().getById(post.id)
assertNotNull(stored)
assertNull(stored.derivationPath)
@@ -245,7 +245,7 @@ class GroupSignedEventDaoJvmTest {
// state and never ran the session.
db.groupSignedEventDao().record(rowFor(path = null, sessionId = null))
- val stored = db.groupSignedEventDao().getById(dialect.id)
+ val stored = db.groupSignedEventDao().getById(post.id)
assertNotNull(stored)
assertEquals(derivationPath, stored.derivationPath)
@@ -259,7 +259,7 @@ class GroupSignedEventDaoJvmTest {
db.groupSignedEventDao().record(rowFor(path = null, sessionId = null))
db.groupSignedEventDao().record(rowFor())
- val stored = db.groupSignedEventDao().getById(dialect.id)
+ val stored = db.groupSignedEventDao().getById(post.id)
assertNotNull(stored)
assertEquals(derivationPath, stored.derivationPath)
@@ -270,31 +270,23 @@ class GroupSignedEventDaoJvmTest {
fun `a batch is filed together and reads back oldest first`() = runBlocking {
seedRoom()
- val artifact = signed(
- ArtifactEvent.build(
- name = "In Detention",
- url = "https://example.com/in-detention",
- visibility = "private",
- license = "cc",
- dialectId = dialect.id,
- versionLabel = "1.0",
- createdAt = 1_700_000_010L
- )
+ val profile = signed(
+ MetadataEvent.createNew(name = "In Detention", createdAt = 1_700_000_010L)
)
db.groupSignedEventDao().recordAll(
- listOf(rowFor(event = artifact), rowFor(event = dialect))
+ listOf(rowFor(event = profile), rowFor(event = post))
)
val dao = db.groupSignedEventDao()
assertEquals(
- listOf(dialect.id, artifact.id),
+ listOf(post.id, profile.id),
dao.getByChatRoomId(chatRoomId).map { it.id },
"a room's signed work has to come back in the order it can be applied in"
)
assertEquals(
- listOf(dialect.id),
- dao.getByChatRoomIdAndKind(chatRoomId, DialectEvent.KIND).map { it.id }
+ listOf(post.id),
+ dao.getByChatRoomIdAndKind(chatRoomId, TextNoteEvent.KIND).map { it.id }
)
assertEquals(2, dao.getByFrostSigningSessionId("session-1").size)
}
@@ -304,38 +296,11 @@ class GroupSignedEventDaoJvmTest {
seedRoom()
db.groupSignedEventDao().record(rowFor().copy(content = "isiXhosa"))
- val stored = db.groupSignedEventDao().getById(dialect.id)
+ val stored = db.groupSignedEventDao().getById(post.id)
assertNotNull(stored)
// The id is the hash of the fields, so an edited row is an event the
// group never signed. Nothing else has to be consulted to know that.
assertFalse(stored.verifies(), "an event with edited content must not verify")
}
-
- @Test
- fun `the row a signed event becomes points back at it`() = runBlocking {
- seedRoom()
- db.groupSignedEventDao().record(rowFor())
-
- ChatMessage.applyInnerEvent(
- database = db,
- groupId = chatRoomId,
- event = dialect,
- marmotGroupEventId = null,
- marmotInnerEventId = null,
- senderPublicKey = chatRoomId,
- isUserMessage = false,
- createdAt = Instant.fromEpochSeconds(dialect.createdAt),
- groupSignedEventId = dialect.id,
- )
-
- val row = db.mantraDialectDao().getDialectById(dialect.id)
- assertNotNull(row, "the dialect the group signed was not applied")
-
- // Both Marmot ids are null on a group-signed event -- no group event and
- // no inner event carried it -- so this column is the only provenance the
- // row has.
- assertNull(row.marmotGroupEventId)
- assertEquals(dialect.id, row.groupSignedEventId)
- }
}
diff --git a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/database/dao/MantraDaoJvmTest.kt b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/database/dao/MantraDaoJvmTest.kt
deleted file mode 100644
index 2ce2705e..00000000
--- a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/database/dao/MantraDaoJvmTest.kt
+++ /dev/null
@@ -1,206 +0,0 @@
-package com.machankura.bennu.compose.database.dao
-
-import androidx.room3.Room
-import kotlinx.coroutines.runBlocking
-import com.machankura.bennu.compose.database.BennuDatabase
-import com.machankura.bennu.compose.database.builder.getRoomDatabase
-import com.machankura.bennu.compose.database.model.ChatRoom
-import com.machankura.bennu.compose.database.model.MantraArtifact
-import com.machankura.bennu.compose.database.model.NostrEvent
-import com.machankura.bennu.compose.database.model.Profile
-import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
-import com.machankura.bennu.compose.nostr.nip30303.DialectEvent
-import com.machankura.bennu.compose.nostr.nip30303.SubmissionEvent
-import com.machankura.bennu.compose.repository.MantraRepository
-import kotlin.test.AfterTest
-import kotlin.test.Test
-import kotlin.test.assertEquals
-import kotlin.test.assertNotNull
-import kotlin.test.assertNull
-import kotlin.test.assertTrue
-
-/**
- * The nip30303 create-entity flow: every `add*` on [MantraDao] writes the entity and queues a
- * [SubmissionEvent] carrying the same event for the group, in one transaction.
- *
- * The invariant worth a test is the one `rumorOf` exists for. The entity's id is computed by
- * the `Mantra*.from*EventTemplate` factory and the payload's id is computed here, from the same
- * template -- so the row on disk and the payload on the wire are meant to be *the same event*,
- * not two copies of one. Nothing enforces that: both sides compile independently, both produce
- * a plausible 64-character id, and a divergence would only show up as a group that can never
- * match an arriving submission to the entity it was supposed to create.
- */
-class MantraDaoJvmTest {
-
- private val db: BennuDatabase = getRoomDatabase(
- Room.inMemoryDatabaseBuilder()
- )
-
- @AfterTest
- fun closeDb() = db.close()
-
- private val author = "a".repeat(64)
- private val roomId = "b".repeat(64)
-
- /** ChatRoom -> Profile -> NostrEvent, the foreign key chain a room hangs off. */
- private suspend fun seedRoom(): LocalChatRoom {
- val nostrEventId = "c".repeat(64)
- db.nostrEventDao().upsert(
- NostrEvent(
- id = nostrEventId,
- pubKey = author,
- kind = 0,
- tags = emptyArray(),
- content = "{}",
- sig = "0".repeat(128),
- )
- )
- db.profileDao().upsert(Profile(publicKey = author, userName = "author", nostrEventId = nostrEventId))
- val chatRoom = ChatRoom(
- id = roomId,
- userPublicKey = author,
- subject = "a translation room",
- description = null,
- mlsGroupState = null,
- )
- db.chatRoomDao().upsert(chatRoom)
- return LocalChatRoom(chatRoom = chatRoom)
- }
-
- private suspend fun submissions() = db.marmotInnerEventDao()
- .getByChatRoomAndKinds(roomId, listOf(SubmissionEvent.KIND))
-
- private suspend fun addDialect(name: String = "Sesotho") = db.mantraDao().addDialect(
- localChatRoom = seedRoom(),
- name = name,
- country = "ZA",
- language = "st",
- userPublicKey = author,
- )
-
- @Test
- fun `a dialect is stored and queued for the group in one call`() = runBlocking {
- val dialect = assertNotNull(addDialect(), "addDialect returned null")
-
- assertEquals("Sesotho", dialect.name)
- assertEquals(roomId, dialect.chatRoomId)
- assertEquals(author, dialect.publicKey)
- assertEquals(1, submissions().size, "the dialect was stored without being submitted")
- }
-
- /**
- * The `rumorOf` invariant, asserted across the seam: the submission records the payload's
- * id, and that id has to be the entity's own. If the two factories ever compute it
- * differently the group receives a submission whose payload matches nothing on disk.
- */
- @Test
- fun `the stored dialect and the submitted payload are the same event`() = runBlocking {
- val dialect = assertNotNull(addDialect())
-
- val submission = submissions().single()
-
- assertEquals(
- dialect.id,
- submission.payloadEventId,
- "the entity id and the submitted payload id have diverged",
- )
- }
-
- /**
- * The envelope is not the payload. A submission's own id is the SubmissionEvent's, which is
- * why `deleteByPayloadEventId` exists -- a superseded nip30303 event cannot be un-queued by
- * its own id.
- */
- @Test
- fun `the submission is an envelope with its own id`() = runBlocking {
- val dialect = assertNotNull(addDialect())
-
- val submission = submissions().single()
-
- assertEquals(SubmissionEvent.KIND, submission.kind)
- assertTrue(
- submission.id != dialect.id,
- "the envelope must not share the payload's id, or it could not be told apart",
- )
- assertEquals(author, submission.publicKey)
- assertEquals(roomId, submission.chatRoomId)
- }
-
- /**
- * `marmotGroupEventId == null` is what makes the row unprocessed, which is the state the
- * outbound pipeline selects on to encrypt it into a kind:445. Filed as processed, it would
- * be stored and never sent, and the group would never learn about the dialect.
- */
- @Test
- fun `the submission is queued unprocessed for the outbound pipeline`() = runBlocking {
- addDialect()
-
- val submission = submissions().single()
-
- assertNull(submission.marmotGroupEventId, "a queued submission must not look processed")
- }
-
- /** The room's feed reads ChatMessage, so an added entity has to leave a line behind. */
- @Test
- fun `a chat message line is written so the room shows the change`() = runBlocking {
- addDialect(name = "isiZulu")
-
- val submission = submissions().single()
- val chatMessage = db.chatMessageDao().getChatMessagesByMarmotInnerEventId(submission.id)
-
- assertNotNull(chatMessage, "no chat line was written for the submission")
- assertEquals("Added isiZulu as a dialect", chatMessage.content)
- assertEquals(roomId, chatMessage.chatRoomId)
- assertTrue(chatMessage.isUserMessage)
- }
-
- /**
- * A second entity type through the same path, because the store-and-submit shape is the
- * convention every `add*` follows rather than something `addDialect` does on its own.
- */
- @Test
- fun `an artifact version follows the same store-and-submit shape`() = runBlocking {
- val localChatRoom = seedRoom()
- val dialect = assertNotNull(
- db.mantraDao().addDialect(
- localChatRoom = localChatRoom,
- name = "Setswana",
- country = "ZA",
- language = "tn",
- userPublicKey = author,
- )
- )
- val artifactId = "d".repeat(64)
- db.mantraArtifactDao().upsert(
- MantraArtifact(
- id = artifactId,
- publicKey = author,
- name = "a text",
- url = "https://example.invalid/text",
- visibility = MantraRepository.DEFAULT_VISIBILITY,
- dialectId = dialect.id,
- license = MantraRepository.DEFAULT_LICENSE,
- chatRoomId = roomId,
- signature = "",
- )
- )
-
- val version = assertNotNull(
- db.mantraDao().addArtifactVersion(
- localChatRoom = localChatRoom,
- artifactId = artifactId,
- versionLabel = "first draft",
- userPublicKey = author,
- ),
- "addArtifactVersion returned null",
- )
-
- val versionSubmission = assertNotNull(
- submissions().singleOrNull { it.payloadEventId == version.id },
- "the artifact version was stored without a matching submission",
- )
- assertEquals(SubmissionEvent.KIND, versionSubmission.kind)
- assertNull(versionSubmission.marmotGroupEventId)
- assertEquals(2, submissions().size, "the dialect and the version should each be queued")
- }
-}
diff --git a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/database/migrations/RemoveDocumentsMigrationJvmTest.kt b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/database/migrations/RemoveDocumentsMigrationJvmTest.kt
new file mode 100644
index 00000000..6316ed77
--- /dev/null
+++ b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/database/migrations/RemoveDocumentsMigrationJvmTest.kt
@@ -0,0 +1,145 @@
+package com.machankura.bennu.compose.database.migrations
+
+import androidx.sqlite.SQLiteConnection
+import androidx.sqlite.driver.bundled.BundledSQLiteDriver
+import androidx.sqlite.execSQL
+import kotlinx.coroutines.runBlocking
+import kotlinx.serialization.json.Json
+import kotlinx.serialization.json.JsonObject
+import kotlinx.serialization.json.jsonArray
+import kotlinx.serialization.json.jsonObject
+import kotlinx.serialization.json.jsonPrimitive
+import java.io.File
+import kotlin.test.AfterTest
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertFalse
+import kotlin.test.assertTrue
+
+/**
+ * The v26 -> v27 migration, against a real database holding what it removes and
+ * what it must leave alone.
+ *
+ * Two deletes and a drop. The drop is the easy half: twelve tables nothing reads
+ * and a column only a submission ever set. The deletes are the half worth
+ * asserting, because a transcript has no undo -- one is aimed at the lines the
+ * removed document arms wrote, and the other at the raw-hex bubbles a
+ * subgroup's ceremony left in its parent's chat, found by the kind of the inner
+ * event behind them. An `unsupported` line over any other kind is still the only
+ * trace an unrecognised payload leaves, and has to survive.
+ *
+ * Built from the exported schemas rather than copied SQL, so the tables are
+ * exactly the ones a v26 install has, and the result is compared with what Room
+ * expects of v27. Run on a bare connection, the way the other migration tests
+ * are: Room's version wiring belongs to `PlatformDatabaseBuilder`.
+ */
+class RemoveDocumentsMigrationJvmTest {
+
+ private val connection: SQLiteConnection = BundledSQLiteDriver().open(":memory:")
+
+ @AfterTest
+ fun close() = connection.close()
+
+ private val schemas: File =
+ (File("schemas").takeIf { it.isDirectory } ?: File("composeApp/schemas"))
+ .resolve("com.machankura.bennu.compose.database.BennuDatabase")
+
+ private fun entities(version: Int): List =
+ Json.parseToJsonElement(schemas.resolve("$version.json").readText())
+ .jsonObject["database"]!!.jsonObject["entities"]!!.jsonArray
+ .map { it.jsonObject }
+
+ private fun JsonObject.tableName() = this["tableName"]!!.jsonPrimitive.content
+
+ private fun JsonObject.columns() =
+ this["fields"]!!.jsonArray.map { it.jsonObject["columnName"]!!.jsonPrimitive.content }.toSet()
+
+ /** Every v26 table, as Room created it. */
+ private fun createV26() {
+ entities(26).forEach { entity ->
+ val sql = entity["createSql"]!!.jsonPrimitive.content.replace("\${TABLE_NAME}", entity.tableName())
+ connection.execSQL(sql)
+ }
+ }
+
+ private fun tables(): Set = connection.prepare(
+ "SELECT name FROM sqlite_master WHERE type = 'table'"
+ ).use { statement ->
+ buildSet { while (statement.step()) add(statement.getText(0)) }
+ }
+
+ private fun columnsOf(table: String): Set