add data type and methods to send invite requests

This commit is contained in:
mycognosist 2022-02-04 10:06:36 +02:00 committed by adria0.eth
parent 2d9e948499
commit c8d86235c1
2 changed files with 43 additions and 1 deletions

View File

@ -189,3 +189,9 @@ pub struct FriendsHops {
#[serde(skip_serializing_if = "Option::is_none")]
pub start: Option<String>,
}
/// Optional parameter for defining the number of times an invite can be used.
#[derive(Debug, Serialize, Deserialize)]
pub struct InviteCreateOptions {
pub uses: u16,
}

View File

@ -1,6 +1,7 @@
use crate::{
api::dto::content::{
FriendsHops, RelationshipQuery, SubsetQuery, SubsetQueryOptions, TypedMessage,
FriendsHops, InviteCreateOptions, RelationshipQuery, SubsetQuery, SubsetQueryOptions,
TypedMessage,
},
feed::Message,
rpc::{Body, BodyType, RequestNo, RpcType, RpcWriter},
@ -13,6 +14,8 @@ const MAX_RPC_BODY_LEN: usize = 65536;
#[derive(Debug)]
pub enum ApiMethod {
InviteCreate,
InviteUse,
FriendsIsFollowing,
FriendsIsBlocking,
FriendsHops,
@ -31,6 +34,8 @@ impl ApiMethod {
pub fn selector(&self) -> &'static [&'static str] {
use ApiMethod::*;
match self {
InviteCreate => &["invite", "create"],
InviteUse => &["invite", "use"],
FriendsIsFollowing => &["friends", "isFollowing"],
FriendsIsBlocking => &["friends", "isBlocking"],
FriendsHops => &["friends", "hops"],
@ -48,6 +53,8 @@ impl ApiMethod {
pub fn from_selector(s: &[&str]) -> Option<Self> {
use ApiMethod::*;
match s {
["invite", "create"] => Some(InviteCreate),
["invite", "use"] => Some(InviteUse),
["friends", "isFollowing"] => Some(FriendsIsFollowing),
["friends", "isBlocking"] => Some(FriendsIsBlocking),
["friends", "hops"] => Some(FriendsHops),
@ -82,6 +89,35 @@ impl<W: Write + Unpin> ApiCaller<W> {
&mut self.rpc
}
/// Send ["invite", "create"] request.
pub async fn invite_create_req_send(&mut self, uses: u16) -> Result<RequestNo> {
let args = InviteCreateOptions { uses };
let req_no = self
.rpc
.send_request(
ApiMethod::InviteCreate.selector(),
RpcType::Async,
&args,
&None::<()>,
)
.await?;
Ok(req_no)
}
/// Send ["invite", "use"] request.
pub async fn invite_use_req_send(&mut self, invite_code: &str) -> Result<RequestNo> {
let req_no = self
.rpc
.send_request(
ApiMethod::InviteUse.selector(),
RpcType::Async,
&invite_code,
&None::<()>,
)
.await?;
Ok(req_no)
}
/// Send ["friends", "isFollowing"] request.
pub async fn friends_is_following_req_send(
&mut self,