Rename to nostrGroupId and add MarmotCommitResult

This commit is contained in:
Kgothatso Ngako
2026-07-06 17:03:48 +02:00
parent bac2b783ee
commit 06c726c543
3 changed files with 186 additions and 18 deletions

View File

@@ -23,28 +23,19 @@ import at.torch.compose.exceptions.MarmotMissingChatGroupException
import at.torch.compose.exceptions.MarmotMissingKeyPackageBundleException
import at.torch.compose.exceptions.MarmotMissingNostrGroupDataExtension
import at.torch.compose.exceptions.MarmotNotMemberOfChatGroupException
import at.torch.compose.exceptions.MarmotUnsupportedWireFormatException
import at.torch.compose.exceptions.MarmotWelcomeEventMissingKeyPackageEventIdException
import at.torch.compose.extensions.exporterSecret
import at.torch.compose.extensions.toHex
import at.torch.compose.managers.MarmotInboundManager
import co.touchlab.kermit.Logger
import com.vitorpamplona.quartz.marmot.GroupEventResult
import com.vitorpamplona.quartz.marmot.mip00KeyPackages.KeyPackageEvent
import com.vitorpamplona.quartz.marmot.mip00KeyPackages.KeyPackageRelayListEvent
import com.vitorpamplona.quartz.marmot.mip02Welcome.WelcomeEvent
import com.vitorpamplona.quartz.marmot.mip03GroupMessages.GroupEventEncryption
import com.vitorpamplona.quartz.marmot.mls.codec.TlsReader
import com.vitorpamplona.quartz.marmot.mls.framing.ContentType
import com.vitorpamplona.quartz.marmot.mls.framing.MlsMessage
import com.vitorpamplona.quartz.marmot.mls.framing.PublicMessage
import com.vitorpamplona.quartz.marmot.mls.framing.WireFormat
import com.vitorpamplona.quartz.marmot.mls.group.MlsGroup
import com.vitorpamplona.quartz.marmot.mls.group.MlsGroupState
import com.vitorpamplona.quartz.marmot.mls.messages.KeyPackageBundle
import com.vitorpamplona.quartz.marmot.mls.messages.MlsKeyPackage
import com.vitorpamplona.quartz.marmot.mls.tree.Credential
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent

View File

@@ -1,7 +1,6 @@
package at.torch.compose.managers
import at.torch.compose.database.TorchDatabase
import at.torch.compose.database.model.ChatMessage
import at.torch.compose.database.model.intermdiate.LocalChatRoom
import at.torch.compose.exceptions.MarmotMissingChatGroupException
import at.torch.compose.exceptions.MarmotUnsupportedWireFormatException
@@ -27,7 +26,6 @@ import com.vitorpamplona.quartz.marmot.mls.schedule.KeySchedule
import com.vitorpamplona.quartz.marmot.mls.schedule.SecretTree
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import kotlin.time.Instant
object MarmotInboundManager {
private const val TAG = "MarmotInboundManager"
@@ -268,23 +266,24 @@ object MarmotInboundManager {
mlsGroup: MlsGroup,
groupEvent: GroupEvent
): GroupEventResult {
val groupId = mlsGroup.currentMarmotData()?.nostrGroupId ?: mlsGroup.groupId.toHex()
logger.d("handleCommitEvent: ${groupEvent.id}")
val nostrGroupId = mlsGroup.currentMarmotData()?.nostrGroupId ?: mlsGroup.groupId.toHex()
val currentEpoch = mlsGroup.epoch
commitTracker.addCommit(groupId, currentEpoch, groupEvent)
commitTracker.addCommit(nostrGroupId, currentEpoch, groupEvent)
// If this is the only commit for this epoch, apply immediately
val pending = commitTracker.pendingForEpoch(groupId, currentEpoch)
val pending = commitTracker.pendingForEpoch(nostrGroupId, currentEpoch)
return if (pending.size == 1) {
val result = applyCommit(
database,
mlsGroup,
groupEvent
)
commitTracker.clearEpoch(groupId, currentEpoch)
commitTracker.clearEpoch(nostrGroupId, currentEpoch)
result
} else {
GroupEventResult.CommitPending(groupId, currentEpoch)
GroupEventResult.CommitPending(nostrGroupId, currentEpoch)
}
}