working invites

This commit is contained in:
glyph 2022-02-04 10:16:45 +02:00
parent ed923abc2f
commit 2689824126
2 changed files with 32 additions and 21 deletions

View File

@ -2,21 +2,39 @@ use async_std::stream::StreamExt;
use futures::pin_mut;
use std::process;
use kuska_ssb::api::dto::content::PubAddress;
use golgi::error::GolgiError;
use golgi::messages::SsbMessageContent;
use golgi::sbot::Sbot;
use golgi::sbot::{FriendsHopsOpts, SubsetQuery, SubsetQueryOptions};
use golgi::sbot::{SubsetQuery, SubsetQueryOptions};
async fn run() -> Result<(), GolgiError> {
let mut sbot_client = Sbot::init(None, None).await?;
let mut sbot_client = Sbot::init(Some("127.0.0.1:8009".to_string()), None).await?;
let id = sbot_client.whoami().await?;
println!("whoami: {}", id);
let invite_link = sbot_client.invite_create(100).await?;
println!("invite: {:?}", invite_link);
// publish a pub address message (in order to test accepting invite from other client)
let pub_address_msg = SsbMessageContent::Pub {
address: Some(PubAddress {
host: Some("127.0.0.1".to_string()),
port: 8009,
key: id,
}),
};
let test_invite = "net:ssbroom2.commoninternet.net:8009~shs:wm8a1zHWjtESv4XSKMWU/rPRhnAoAiSAe4hQSY0UF5A=";
let pub_msg_ref = sbot_client.publish(pub_address_msg).await?;
println!("pub_msg_ref: {}", pub_msg_ref);
let invite_code = sbot_client.invite_create(1).await?;
println!("invite (1 use): {:?}", invite_code);
let invite_code_2 = sbot_client.invite_create(7).await?;
println!("invite (7 uses): {:?}", invite_code_2);
let test_invite =
"net:ssbroom2.commoninternet.net:8009~shs:wm8a1zHWjtESv4XSKMWU/rPRhnAoAiSAe4hQSY0UF5A=";
let mref = sbot_client.invite_use(test_invite).await?;
println!("mref: {:?}", mref);

View File

@ -21,7 +21,7 @@ use crate::utils;
use crate::utils::get_source_stream;
// re-export types from kuska
pub use kuska_ssb::api::dto::content::{FriendsHopsOpts, SubsetQuery, SubsetQueryOptions};
pub use kuska_ssb::api::dto::content::{FriendsHops, SubsetQuery, SubsetQueryOptions};
/// A struct representing a connection with a running sbot.
/// A client and an rpc_reader can together be used to make requests to the sbot
@ -210,6 +210,7 @@ impl Sbot {
self.publish(msg).await
}
/*
/// Call the `friends isfollowing` RPC method and return a message reference.
/// returns true if src_id is following dest_id and false otherwise
pub async fn friends_is_following(
@ -290,35 +291,27 @@ impl Sbot {
)
.await
}
*/
/// Call the `invite create` RPC method and return the created invite
pub async fn invite_create(
&mut self,
uses: i32,
) -> Result<String, GolgiError> {
pub async fn invite_create(&mut self, uses: u16) -> Result<String, GolgiError> {
let mut sbot_connection = self.get_sbot_connection().await?;
let req_id = sbot_connection
.client
.invite_create_req_send(uses)
.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
.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<String, GolgiError> {
pub async fn invite_use(&mut self, invite_code: &str) -> Result<String, GolgiError> {
let mut sbot_connection = self.get_sbot_connection().await?;
let req_id = sbot_connection
.client
.invite_use_req_send(invite_link)
.invite_use_req_send(invite_code)
.await?;
utils::get_async(
@ -326,7 +319,7 @@ impl Sbot {
req_id,
utils::string_res_parse,
)
.await
.await
}
/// Wrapper for publish which constructs and publishes a post message appropriately from a string.