diff --git a/README.md b/README.md index 635805d3..adca457f 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ The mediator is especially useful when the edge entities are not always online, - [DONE] `MediatorCoordination 2.0` - https://didcomm.org/mediator-coordination/2.0 - See [link for the protocol specs](/Coordinate-Mediation-Protocol.md) - [TODO] `MediatorCoordination 3.0` - https://didcomm.org/mediator-coordination/3.0 -- [DONE] `Pickup 3` - https://didcomm.org/pickup/3.0 [ with exclusion of When the delivery request (https://didcomm.org/messagepickup/3.0/delivery-request) is made, but there are no messages currently available to be sent, No status message is sent immediately, Instead you can check the the status of message using the status request https://didcomm.org/messagepickup/3.0/status-request] +- [DONE] `Pickup 3` - https://didcomm.org/pickup/3.0 - [DONE] `TrustPing 2.0` - https://didcomm.org/trust-ping/2.0/ - [DONE] `Report Problem 2.0` https://didcomm.org/report-problem/2.0/ diff --git a/mediator/src/main/scala/io/iohk/atala/mediator/protocols/PickupExecuter.scala b/mediator/src/main/scala/io/iohk/atala/mediator/protocols/PickupExecuter.scala index 0c7f4ffa..6f560cee 100644 --- a/mediator/src/main/scala/io/iohk/atala/mediator/protocols/PickupExecuter.scala +++ b/mediator/src/main/scala/io/iohk/atala/mediator/protocols/PickupExecuter.scala @@ -113,24 +113,40 @@ object PickupExecuter ) case Some(didAccount) => val msgHash = didAccount.messagesRef.filter(_.state == false).map(_.hash) - for { - allMessagesFor <- repoMessageItem.findByIds(msgHash) - messagesToReturn = - if (m.recipient_did.isEmpty) allMessagesFor - else { - allMessagesFor.filterNot( - _.msg.recipientsSubject - .map(_.did) - .forall(e => !m.recipient_did.map(_.toDID.did).contains(e)) - ) - } - } yield MessageDelivery( - thid = m.id, - from = m.to.asFROM, - to = m.from.asTO, - recipient_did = m.recipient_did, - attachments = messagesToReturn.map(m => (m._id, m.msg)).toMap, - ).toPlaintextMessage + if (msgHash.isEmpty) { + ZIO.succeed(Status( + thid = m.id, + from = m.to.asFROM, + to = m.from.asTO, + recipient_did = m.recipient_did, + message_count = msgHash.size, + longest_waited_seconds = None, // TODO + newest_received_time = None, // TODO + oldest_received_time = None, // TODO + total_bytes = None, // TODO + live_delivery = None, // TODO + ).toPlaintextMessage) + } else { + for { + allMessagesFor <- repoMessageItem.findByIds(msgHash) + messagesToReturn = + if (m.recipient_did.isEmpty) allMessagesFor + else { + allMessagesFor.filterNot( + _.msg.recipientsSubject + .map(_.did) + .forall(e => !m.recipient_did.map(_.toDID.did).contains(e)) + ) + } + } yield MessageDelivery( + thid = m.id, + from = m.to.asFROM, + to = m.from.asTO, + recipient_did = m.recipient_did, + attachments = messagesToReturn.map(m => (m._id, m.msg)).toMap, + ).toPlaintextMessage + } + } yield SyncReplyOnly(ret) case m: MessageDelivery => ZIO.logInfo("MessageDelivery") *> diff --git a/mediator/src/test/scala/io/iohk/atala/mediator/protocols/PickupExecuterSpec.scala b/mediator/src/test/scala/io/iohk/atala/mediator/protocols/PickupExecuterSpec.scala index 47b562f8..fb124a27 100644 --- a/mediator/src/test/scala/io/iohk/atala/mediator/protocols/PickupExecuterSpec.scala +++ b/mediator/src/test/scala/io/iohk/atala/mediator/protocols/PickupExecuterSpec.scala @@ -113,6 +113,27 @@ object PickupExecuterSpec extends ZIOSpecDefault with DidAccountStubSetup with M assertTrue(plainText.`type` == MessageDelivery.piuri) && assertTrue(plainText.attachments.nonEmpty) } } @@ TestAspect.before(setupAndClean), + test("Delivery Request message for Pickup returns a Status Message when there are no messages available") { + val pickupExecuter = PickupExecuter + for { + mediatorAgent <- ZIO.service[MediatorAgent] + userAccount <- ZIO.service[UserAccountRepo] + _ <- userAccount.createOrFindDidAccount(DIDSubject(aliceAgent.id.did)) + _ <- userAccount.addAlias( + owner = DIDSubject(aliceAgent.id.did), + newAlias = DIDSubject(aliceAgent.id.did) + ) + msg <- ZIO.fromEither( + plaintextDeliveryRequestMessage(aliceAgent.id.did, mediatorAgent.id.did, aliceAgent.id.did) + ) + result <- pickupExecuter.execute(msg) + message <- ZIO.fromOption(result) + decryptedMessage <- authDecrypt(message.asInstanceOf[EncryptedMessage]).provideSomeLayer(aliceAgentLayer) + } yield { + val plainText = decryptedMessage.asInstanceOf[PlaintextMessage] + assertTrue(plainText.`type` == Status.piuri) + } + } @@ TestAspect.before(setupAndClean), test("Messages Received message should clear the messages from the queue") { val executer = PickupExecuter val forwardMessageExecuter = ForwardMessageExecuter