From 18667084ad4e61da77b4c5a6653571d54010f540 Mon Sep 17 00:00:00 2001 From: notplants Date: Sun, 16 Jan 2022 09:51:54 -0500 Subject: [PATCH] Add methods for invites --- examples/ssb-invite.rs | 32 ++++++++++++++++++++++++++++++++ src/sbot.rs | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 examples/ssb-invite.rs diff --git a/examples/ssb-invite.rs b/examples/ssb-invite.rs new file mode 100644 index 0000000..8b823a2 --- /dev/null +++ b/examples/ssb-invite.rs @@ -0,0 +1,32 @@ +use async_std::stream::StreamExt; +use futures::pin_mut; +use std::process; + +use golgi::error::GolgiError; +use golgi::messages::SsbMessageContent; +use golgi::sbot::Sbot; +use golgi::sbot::{FriendsHopsOpts, SubsetQuery, SubsetQueryOptions}; + +async fn run() -> Result<(), GolgiError> { + let mut sbot_client = Sbot::init(None, None).await?; + + let id = sbot_client.whoami().await?; + println!("whoami: {}", id); + + let invite_link = sbot_client.invite_create(100).await?; + println!("invite: {:?}", invite_link); + + let test_invite = "net:ssbroom2.commoninternet.net:8009~shs:wm8a1zHWjtESv4XSKMWU/rPRhnAoAiSAe4hQSY0UF5A="; + let mref = sbot_client.invite_use(test_invite).await?; + println!("mref: {:?}", mref); + + Ok(()) +} + +#[async_std::main] +async fn main() { + if let Err(e) = run().await { + eprintln!("Application error: {}", e); + process::exit(1); + } +} diff --git a/src/sbot.rs b/src/sbot.rs index 52c2797..ee38fbb 100644 --- a/src/sbot.rs +++ b/src/sbot.rs @@ -314,6 +314,44 @@ impl Sbot { .await } + /// Call the `invite create` RPC method and return the created invite + pub async fn invite_create( + &mut self, + uses: i32, + ) -> Result { + let mut sbot_connection = self.get_sbot_connection().await?; + let req_id = sbot_connection + .client + .invite_create_req_send(uses) + .await?; + + utils::get_async( + &mut sbot_connection.rpc_reader, + req_id, + utils::string_res_parse, + ) + .await + } + + /// Call the `invite use` RPC method and return a reference to the message. + pub async fn invite_use( + &mut self, + invite_link: &str, + ) -> Result { + let mut sbot_connection = self.get_sbot_connection().await?; + let req_id = sbot_connection + .client + .invite_use_req_send(invite_link) + .await?; + + utils::get_async( + &mut sbot_connection.rpc_reader, + req_id, + utils::string_res_parse, + ) + .await + } + /// Wrapper for publish which constructs and publishes a post message appropriately from a string. /// /// # Arguments -- 2.54.0