From fc19583225fb111233d2f852e4358c8fac9bea29 Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Fri, 2 Oct 2026 23:51:13 +0200 Subject: [PATCH] feat(ios): declare publish cancellation to swift, and unshadow Platform Seven `@Throws` on the publish path now name `kotlin.coroutines.cancellation.CancellationException` alongside `NostrPublishException`. Without it a publish cancelled by the screen navigating away crosses the ObjC boundary as an unexpected throw rather than as the cancellation it is, and swift has no way to tell the two apart. Six of the seven already existed; `EventPublishTransport` had none, so the interface the group-signed path publishes through said less about itself than the implementation behind it. `Platform.ios.kt` also imported `kotlin.native.Platform`, which shadows the app's own `Platform` interface the file is there to implement. It was unused and nothing on this host compiles iosMain, so the compiler never said so. Co-Authored-By: Claude Opus 5 --- .../mantra/compose/network/relays/EventPublishTransport.kt | 1 + .../kotlin/press/mantra/compose/network/relays/RelayPool.kt | 2 +- .../mantra/compose/network/relays/RelaysSocketManager.kt | 4 ++-- .../mantra/compose/repository/NostrPublisherRepository.kt | 6 +++--- .../src/iosMain/kotlin/press/mantra/compose/Platform.ios.kt | 1 - 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/press/mantra/compose/network/relays/EventPublishTransport.kt b/composeApp/src/commonMain/kotlin/press/mantra/compose/network/relays/EventPublishTransport.kt index a15fd5db..f269f013 100644 --- a/composeApp/src/commonMain/kotlin/press/mantra/compose/network/relays/EventPublishTransport.kt +++ b/composeApp/src/commonMain/kotlin/press/mantra/compose/network/relays/EventPublishTransport.kt @@ -28,5 +28,6 @@ interface EventPublishTransport { * * @see RelayPool.publishEvent */ + @Throws(press.mantra.compose.exceptions.NostrPublishException::class, kotlin.coroutines.cancellation.CancellationException::class) suspend fun publishEvent(nostrEvent: NostrEvent, relays: Set): Flow } diff --git a/composeApp/src/commonMain/kotlin/press/mantra/compose/network/relays/RelayPool.kt b/composeApp/src/commonMain/kotlin/press/mantra/compose/network/relays/RelayPool.kt index a260a1d7..42c3e99f 100644 --- a/composeApp/src/commonMain/kotlin/press/mantra/compose/network/relays/RelayPool.kt +++ b/composeApp/src/commonMain/kotlin/press/mantra/compose/network/relays/RelayPool.kt @@ -286,7 +286,7 @@ class RelayPool( ) } - @Throws(press.mantra.compose.exceptions.NostrPublishException::class) + @Throws(press.mantra.compose.exceptions.NostrPublishException::class, kotlin.coroutines.cancellation.CancellationException::class) suspend fun publishEvent(nostrEvent: press.mantra.compose.database.model.NostrEvent, relays: Set = emptySet()): Flow { val relayUrls = relays.map { NormalizedRelayUrl(it.url).displayUrl() } diff --git a/composeApp/src/commonMain/kotlin/press/mantra/compose/network/relays/RelaysSocketManager.kt b/composeApp/src/commonMain/kotlin/press/mantra/compose/network/relays/RelaysSocketManager.kt index c79e7f7c..81db3293 100644 --- a/composeApp/src/commonMain/kotlin/press/mantra/compose/network/relays/RelaysSocketManager.kt +++ b/composeApp/src/commonMain/kotlin/press/mantra/compose/network/relays/RelaysSocketManager.kt @@ -100,7 +100,7 @@ class RelaysSocketManager( relayPool.closePool() } - @Throws(press.mantra.compose.exceptions.NostrPublishException::class) + @Throws(press.mantra.compose.exceptions.NostrPublishException::class, kotlin.coroutines.cancellation.CancellationException::class) suspend fun publishEvent(nostrEvent: press.mantra.compose.database.model.NostrEvent): Flow { return if (userRelays.isNotEmpty()) { relayPool.publishEvent( @@ -115,7 +115,7 @@ class RelaysSocketManager( } } - @Throws(press.mantra.compose.exceptions.NostrPublishException::class) + @Throws(press.mantra.compose.exceptions.NostrPublishException::class, kotlin.coroutines.cancellation.CancellationException::class) override suspend fun publishEvent(nostrEvent: press.mantra.compose.database.model.NostrEvent, relays: Set): Flow { logger.d("publishEvent: $nostrEvent") return relayPool.publishEvent( diff --git a/composeApp/src/commonMain/kotlin/press/mantra/compose/repository/NostrPublisherRepository.kt b/composeApp/src/commonMain/kotlin/press/mantra/compose/repository/NostrPublisherRepository.kt index ef911ca7..93bc0bfd 100644 --- a/composeApp/src/commonMain/kotlin/press/mantra/compose/repository/NostrPublisherRepository.kt +++ b/composeApp/src/commonMain/kotlin/press/mantra/compose/repository/NostrPublisherRepository.kt @@ -30,7 +30,7 @@ class NostrPublisherRepository( } } - @Throws(press.mantra.compose.exceptions.NostrPublishException::class) + @Throws(press.mantra.compose.exceptions.NostrPublishException::class, kotlin.coroutines.cancellation.CancellationException::class) private suspend fun publishAndImportEvent(signedNostrEvent: press.mantra.compose.database.model.NostrEvent, outboxRelays: List = emptyList()) { relaysSocketManager.publishEvent(signedNostrEvent) importEvent(signedNostrEvent) @@ -52,7 +52,7 @@ class NostrPublisherRepository( } } - @Throws(press.mantra.compose.exceptions.NostrPublishException::class, press.mantra.compose.exceptions.SignatureException::class) + @Throws(press.mantra.compose.exceptions.NostrPublishException::class, press.mantra.compose.exceptions.SignatureException::class, kotlin.coroutines.cancellation.CancellationException::class) suspend fun signPublishImportNostrEvent( unsignedNostrEvent: press.mantra.compose.database.model.UnsignedNostrEvent, outboxRelays: List, @@ -63,7 +63,7 @@ class NostrPublisherRepository( } - @Throws(press.mantra.compose.exceptions.NostrPublishException::class, press.mantra.compose.exceptions.SignatureException::class) + @Throws(press.mantra.compose.exceptions.NostrPublishException::class, press.mantra.compose.exceptions.SignatureException::class, kotlin.coroutines.cancellation.CancellationException::class) suspend fun publishRelayList(userId: String, relays: List): press.mantra.compose.database.model.NostrEvent { val signedNostrEvent = nostrNotary.signRelayListMetadata(userId = userId, relays = relays).unwrapOrThrow() relaysSocketManager.publishEvent(nostrEvent = signedNostrEvent, relays = relays.toSet()) diff --git a/composeApp/src/iosMain/kotlin/press/mantra/compose/Platform.ios.kt b/composeApp/src/iosMain/kotlin/press/mantra/compose/Platform.ios.kt index cfaf67f8..37ba5f43 100644 --- a/composeApp/src/iosMain/kotlin/press/mantra/compose/Platform.ios.kt +++ b/composeApp/src/iosMain/kotlin/press/mantra/compose/Platform.ios.kt @@ -1,7 +1,6 @@ package press.mantra.compose import platform.UIKit.UIDevice -import kotlin.native.Platform class IOSPlatform: Platform { override val name: String = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion