Skip to content

Commit

Permalink
feat(mercury): Support a mediator in service uri field (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
FabioPinheiro committed Dec 16, 2022
1 parent 369aaaa commit 88ad415
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object MessagingService {
*
* TODO Move this method to another model
*/
def send(msg: Message): ZIO[DidComm & DIDResolver & HttpClient, SendMessageError, HttpResponseBody] = { // TODO create error for Throwable
def send(msg: Message): ZIO[DidComm & DIDResolver & HttpClient, SendMessageError, HttpResponseBody] = {
for {
didCommService <- ZIO.service[DidComm]
resolver <- ZIO.service[DIDResolver]
Expand Down Expand Up @@ -57,13 +57,15 @@ object MessagingService {
)
)
}

serviceEndpoint = didCommService.uri // TODO this is not safe

_ <- Console.printLine("Sending to" + serviceEndpoint)

serviceEndpoint <-
if (didCommService.uri.startsWith("did:"))
resolver
.didCommServices(DidId(didCommService.uri))
.map(_.toSeq.head.getServiceEndpoint()) // TODO this is not safe and also need to be recursive
else ZIO.succeed(didCommService.uri)

_ <- Console.printLine("Sending to " + serviceEndpoint)
res <- HttpClient.postDIDComm(serviceEndpoint, jsonString)

} yield (res)
}.catchAll { case ex =>
ZIO.fail(SendMessageError(ex))
Expand Down

0 comments on commit 88ad415

Please sign in to comment.