diff --git a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/BroadcastAction.kt b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/BroadcastAction.kt index 5f94ffc52e..416c71f45f 100644 --- a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/BroadcastAction.kt +++ b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/BroadcastAction.kt @@ -3,23 +3,19 @@ package com.zegreatrob.coupling.server.action import com.zegreatrob.coupling.model.CouplingConnection import com.zegreatrob.coupling.model.Message import com.zegreatrob.coupling.server.action.connection.DisconnectPartyUserCommand -import com.zegreatrob.testmints.action.async.SimpleSuspendAction -import com.zegreatrob.testmints.action.async.SuspendActionExecuteSyntax +import com.zegreatrob.testmints.action.annotation.ActionMint -data class BroadcastAction(val connections: List, val message: Message) : - SimpleSuspendAction { - override val performFunc = link(Dispatcher::perform) - - interface Dispatcher : +@ActionMint +data class BroadcastAction(val connections: List, val message: Message) { + interface Dispatcher : SocketCommunicator, - SuspendActionExecuteSyntax, - DisconnectPartyUserCommand.Dispatcher { + CannonProvider where D : DisconnectPartyUserCommand.Dispatcher { suspend fun perform(action: BroadcastAction) = with(action) { println("Broadcasting to ${connections.size} connections") connections.mapNotNull { connection -> sendMessageAndReturnIdWhenFail(connection.connectionId, message) }.forEach { - execute(DisconnectPartyUserCommand(it)) + cannon.fire(DisconnectPartyUserCommand(it)) } } } diff --git a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ServerSavePairAssignmentDocumentCommandDispatcher.kt b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ServerSavePairAssignmentDocumentCommandDispatcher.kt index c84cda2993..5647bc341e 100644 --- a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ServerSavePairAssignmentDocumentCommandDispatcher.kt +++ b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ServerSavePairAssignmentDocumentCommandDispatcher.kt @@ -12,6 +12,8 @@ import com.zegreatrob.coupling.repository.slack.SlackAccessGet import com.zegreatrob.coupling.server.action.BroadcastAction import com.zegreatrob.coupling.server.action.CannonProvider import com.zegreatrob.coupling.server.action.connection.CouplingConnectionGetSyntax +import com.zegreatrob.coupling.server.action.connection.DisconnectPartyUserCommand +import com.zegreatrob.coupling.server.action.fire import com.zegreatrob.coupling.server.action.slack.SlackUpdateSpin interface ServerSavePairAssignmentDocumentCommandDispatcher : @@ -19,7 +21,8 @@ interface ServerSavePairAssignmentDocumentCommandDispatcher : PartyIdPairAssignmentDocumentSaveSyntax, CouplingConnectionGetSyntax, CannonProvider, - PartyIdLoadIntegrationSyntax where D : BroadcastAction.Dispatcher { + PartyIdLoadIntegrationSyntax + where D : DisconnectPartyUserCommand.Dispatcher, D : BroadcastAction.Dispatcher { val slackRepository: SlackUpdateSpin val slackAccessRepository: SlackAccessGet diff --git a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/SavePairAssignmentDocumentCommandTest.kt b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/SavePairAssignmentDocumentCommandTest.kt index 3759a4c4d3..ba4dab63e4 100644 --- a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/SavePairAssignmentDocumentCommandTest.kt +++ b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/SavePairAssignmentDocumentCommandTest.kt @@ -15,6 +15,7 @@ import com.zegreatrob.coupling.repository.memory.MemoryPartyRepository import com.zegreatrob.coupling.repository.pairassignmentdocument.PairAssignmentDocumentSave import com.zegreatrob.coupling.repository.slack.SlackAccessGet import com.zegreatrob.coupling.server.action.BroadcastAction +import com.zegreatrob.coupling.server.action.connection.DisconnectPartyUserCommand import com.zegreatrob.coupling.server.action.slack.SlackUpdateSpin import com.zegreatrob.coupling.stubmodel.stubPartyDetails import com.zegreatrob.coupling.stubmodel.stubPinnedCouplingPair @@ -32,7 +33,8 @@ import kotlin.test.Test class SavePairAssignmentDocumentCommandTest { interface SavePairAssignmentDocumentCommandTestDispatcher : ServerSavePairAssignmentDocumentCommandDispatcher, - BroadcastAction.Dispatcher + BroadcastAction.Dispatcher, + DisconnectPartyUserCommand.Dispatcher @Test fun willSendToRepository() = asyncSetup(object : SavePairAssignmentDocumentCommandTestDispatcher, ScopeMint() { diff --git a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/CommandDispatcher.kt b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/CommandDispatcher.kt index e04414133b..c4f19bc9d9 100644 --- a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/CommandDispatcher.kt +++ b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/CommandDispatcher.kt @@ -63,7 +63,6 @@ interface ICommandDispatcher : TraceIdProvider, AwsManagementApiSyntax, AwsSocketCommunicator, - BroadcastAction.Dispatcher, ConnectPartyUserCommand.Dispatcher, ConnectionsQuery.Dispatcher, CurrentPairAssignmentDocumentQuery.Dispatcher, @@ -89,7 +88,12 @@ class CommandDispatcher( override val scope: CoroutineScope, override val traceId: Uuid, override val managementApiClient: ApiGatewayManagementApiClient = apiGatewayManagementApiClient(), -) : ICommandDispatcher, RepositoryCatalog by repositoryCatalog, TraceIdProvider { +) : ICommandDispatcher, + RepositoryCatalog by repositoryCatalog, + TraceIdProvider, + BroadcastAction.Dispatcher { + override val cannon: ActionCannon = ActionCannon(this, LoggingActionPipe(traceId)) + override val slackRepository: SlackRepository by lazy { FetchSlackRepository() } private var authorizedPartyIdDispatcherJob: Deferred? = null @@ -126,6 +130,7 @@ class CurrentPartyDispatcher( AssignPinsAction.Dispatcher, NextPlayerAction.Dispatcher, PairAssignmentDispatcher, + BroadcastAction.Dispatcher, ServerSpinCommandDispatcher, ServerSaveSlackIntegrationCommandDispatcher, ServerCreateSecretCommandDispatcher,