Skip to content

Commit

Permalink
fix: send status message on delivery request If no messages are avail… (
Browse files Browse the repository at this point in the history
#139)

* fix: send status message on delivery request If no messages are available to be sent, a status message MUST be sent immediately

Signed-off-by: mineme0110 <[email protected]>

* readme updated to match the protocol behaviour

Signed-off-by: mineme0110 <[email protected]>

---------

Signed-off-by: mineme0110 <[email protected]>
Signed-off-by: Shailesh <Patil>
  • Loading branch information
mineme0110 authored and Shailesh committed Apr 30, 2024
1 parent 4ea9b6d commit 6514117
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") *>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6514117

Please sign in to comment.