Bug fix on room creation

This commit is contained in:
Kgothatso Ngako
2026-06-18 17:54:09 +03:00
parent 55198de44e
commit ef92a33f56
5 changed files with 50 additions and 32 deletions

View File

@@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "6f2020861ae05ebf5290388d73772039",
"identityHash": "8e399a485acb36b98a516cf3d7480d8c",
"entities": [
{
"tableName": "BroadcastNostrEventReceipt",
@@ -608,7 +608,7 @@
},
{
"tableName": "ChatRoom",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `subject` TEXT, `initialGiftWrapPayloadId` INTEGER, `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 )",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `userPublicKey` TEXT NOT NULL, `subject` TEXT, `mlsGroupState` TEXT, `initialGiftWrapPayloadId` INTEGER, `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",
@@ -627,6 +627,11 @@
"columnName": "subject",
"affinity": "TEXT"
},
{
"fieldPath": "mlsGroupState",
"columnName": "mlsGroupState",
"affinity": "TEXT"
},
{
"fieldPath": "initialGiftWrapPayloadId",
"columnName": "initialGiftWrapPayloadId",
@@ -2869,7 +2874,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, '6f2020861ae05ebf5290388d73772039')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '8e399a485acb36b98a516cf3d7480d8c')"
]
}
}

View File

@@ -578,6 +578,7 @@ abstract class NostrDao(
decryptedGiftWrapPayload
}
// TODO: Handle MLS message/groups
val chatRoomId =
giftWrapPayload.aggregatedParticipantsPublicKey()
logger.d("ChatRoomId: $chatRoomId")
@@ -596,7 +597,8 @@ abstract class NostrDao(
userPublicKey = userPublicKey,
subject = decryptedGiftWrapPayload.parseSubject(),
createdAt = decryptedGiftWrapPayload.createdAt,
initialGiftWrapPayloadId = giftWrapPayload.id
initialGiftWrapPayloadId = giftWrapPayload.id,
mlsGroupState = null
)
)

View File

@@ -81,13 +81,13 @@ fun ChatRoomCreationScreen(
),
label = {
Text(
text = "Name (eg. Alan Turin)",
text = "Name (eg. Group Discussions)",
maxLines = 1,
)
},
placeholder = {
Text(
text = "Enter the name you want to use for your profile",
text = "Enter the name you want to use for your groupd",
maxLines = 1,
)
},
@@ -100,7 +100,7 @@ fun ChatRoomCreationScreen(
)
Text(
text = "This will be the display name for your profile and also important for search.",
text = "This will be the display name for this chat room.",
style = MaterialTheme.typography.labelMedium,
textAlign = TextAlign.Center
)
@@ -125,7 +125,7 @@ fun ChatRoomCreationScreen(
),
label = {
Text(
text = "Introduce yourself",
text = "What will be discussed in this chat room.",
maxLines = 1,
)
@@ -145,7 +145,7 @@ fun ChatRoomCreationScreen(
)
Text(
text = "This will be shown when people open your profile.",
text = "This will be shown when people open the chat for more details.",
style = MaterialTheme.typography.labelMedium,
textAlign = TextAlign.Center
)

View File

@@ -297,9 +297,16 @@ fun TorchNavHost(
val route = backStackEntry.toRoute<ChatRoomCreationRoute>()
ChatRoomCreationScreen(
activeUserPublicKey = route.activeUserPublicKey,
activeWalletStateFlow = sovereignWalletViewModel.activeWalletInUI,
nostrRepository = databaseNostrRepository,
chatRepository = databaseChatRepository
chatRepository = databaseChatRepository,
onNavigateToChatRoom = { chatRoomResultRoute ->
navController.navigate(
chatRoomResultRoute
) {
popUpTo(route)
}
}
)
}
composable<WriteNewNoteRoute> { backStackEntry ->

View File

@@ -20,6 +20,8 @@ import at.torch.compose.ui.view.state.form.ChatRoomCreationFormState
import at.torch.compose.ui.view.state.form.CreateProfileFormState
import co.touchlab.kermit.Logger
import com.vitorpamplona.quartz.marmot.mip01Groups.MarmotGroupData
import com.vitorpamplona.quartz.marmot.mls.crypto.Ed25519
import com.vitorpamplona.quartz.marmot.mls.crypto.Ed25519KeyPair
import com.vitorpamplona.quartz.marmot.mls.group.MlsGroup
import com.vitorpamplona.quartz.marmot.mls.group.MlsGroupState
import com.vitorpamplona.quartz.nip01Core.core.HexKey
@@ -77,31 +79,33 @@ class ChatRoomCreationViewModel(
val extras = listOf(metadata.toExtension())
val group = MlsGroup.create(keyPair.pubKey, keyPair.privKey, extras)
nostrPrivateKey.value.toByteArray().let { privateKey ->
val signingKeyPair = Ed25519.generateKeyPair()
// TODO: Use nostrPrivateKey Ed25519.publicFromPrivate(privateKey).let { ed25519pubKey ->
// Ed25519KeyPair(privateKey, ed25519pubKey)
// }
val group = MlsGroup.create(keyPair.pubKey, signingKeyPair.privateKey, extras)
viewModelScope.launch(Dispatchers.IO) {
val localChatRoom = chatRepository.getOrCreateChatRoom(
chatRoomId = group.groupId.toHex(),
activeUserPublicKey = keyPair.pubKey.toHexKey(),
relayHint = null,
defaultSubject = null,
mlsGroupState = group.saveState().encodeTls().toHex()
)
viewModelScope.launch(Dispatchers.IO) {
val localChatRoom = chatRepository.getOrCreateChatRoom(
chatRoomId = group.groupId.toHex(),
activeUserPublicKey = keyPair.pubKey.toHexKey(),
relayHint = null,
defaultSubject = null,
mlsGroupState = group.saveState().encodeTls().toHex()
)
if (localChatRoom == null) {
onNavigateToChatRoom.invoke(
ImplementationPendingRoute("Something went wrong")
)
} else {
onNavigateToChatRoom.invoke(
ImplementationPendingRoute("Chat Room view ${localChatRoom.chatRoom.id}")
)
if (localChatRoom == null) {
onNavigateToChatRoom.invoke(
ImplementationPendingRoute("Something went wrong")
)
} else {
onNavigateToChatRoom.invoke(
ImplementationPendingRoute("Chat Room view ${localChatRoom.chatRoom.id}")
)
}
}
}
}
}