From 983517179e55b132788377412eab2a71fb17d530 Mon Sep 17 00:00:00 2001 From: Ivan Reshetnikov Date: Wed, 14 Jun 2023 12:18:50 +0200 Subject: [PATCH] feat: batch receive methods for the client --- relay_client/src/http.rs | 13 ++++++++++++- relay_client/src/websocket.rs | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/relay_client/src/http.rs b/relay_client/src/http.rs index 799e4e8..c41aa6c 100644 --- a/relay_client/src/http.rs +++ b/relay_client/src/http.rs @@ -9,7 +9,7 @@ use { auth::ed25519_dalek::Keypair, domain::{DecodedClientId, SubscriptionId, Topic}, jwt::{self, JwtError, VerifyableClaims}, - rpc::{self, RequestPayload}, + rpc::{self, Receipt, RequestPayload}, }, std::{sync::Arc, time::Duration}, url::Url, @@ -247,6 +247,17 @@ impl Client { .await } + /// Acknowledge receipt of messages from a subscribed client. + pub async fn batch_receive( + &self, + receipts: impl Into>, + ) -> Response { + self.request(rpc::BatchReceiveMessages { + receipts: receipts.into(), + }) + .await + } + pub(crate) async fn request(&self, payload: T) -> Response where T: RequestPayload, diff --git a/relay_client/src/websocket.rs b/relay_client/src/websocket.rs index 3359a46..418a021 100644 --- a/relay_client/src/websocket.rs +++ b/relay_client/src/websocket.rs @@ -5,10 +5,12 @@ use { domain::{SubscriptionId, Topic}, rpc::{ BatchFetchMessages, + BatchReceiveMessages, BatchSubscribe, BatchUnsubscribe, FetchMessages, Publish, + Receipt, Subscribe, Subscription, Unsubscribe, @@ -231,6 +233,20 @@ impl Client { response } + /// Acknowledge receipt of messages from a subscribed client. + pub async fn batch_receive( + &self, + receipts: impl Into>, + ) -> ResponseFuture { + let (request, response) = create_request(BatchReceiveMessages { + receipts: receipts.into(), + }); + + self.request(request); + + response + } + /// Opens a connection to the Relay. pub async fn connect(&self, opts: &ConnectionOptions) -> Result<(), Error> { let (tx, rx) = oneshot::channel();