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

@@ -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}")
)
}
}
}
}
}