Merge pull request 'Add publish_post method' (#3) from publish into main

Reviewed-on: #3
This commit is contained in:
notplants 2021-12-26 17:49:47 +00:00
commit 187d279d7b
3 changed files with 44 additions and 12 deletions

View File

@ -33,6 +33,9 @@ async fn run() -> Result<(), GolgiError> {
let post_msg_ref = sbot_client.publish(post).await?;
println!("{}", post_msg_ref);
let post_msg_ref = sbot_client.publish_description("this is a description").await?;
println!("description: {}", post_msg_ref);
Ok(())
}

View File

@ -39,19 +39,18 @@ impl Sbot {
/// for the sbot, then retrieve the public key, private key (secret) and identity from the
/// `.ssb-go/secret` file. Open a TCP stream to the sbot and perform the secret handshake. If successful, create a box stream and split it into a writer and reader. Return RPC handles to the sbot as part of the `struct` output.
pub async fn init(ip_port: Option<String>, net_id: Option<String>) -> Result<Sbot, GolgiError> {
let address;
if ip_port.is_none() {
address = "127.0.0.1:8008".to_string();
} else {
address = ip_port.unwrap();
}
let network_id;
if net_id.is_none() {
network_id = discovery::ssb_net_id();
let address = if ip_port.is_none() {
"127.0.0.1:8008".to_string()
} else {
network_id = auth::Key::from_slice(&hex::decode(net_id.unwrap()).unwrap()).unwrap();
}
ip_port.unwrap()
};
let network_id = if net_id.is_none() {
discovery::ssb_net_id()
} else {
auth::Key::from_slice(&hex::decode(net_id.unwrap()).unwrap()).unwrap()
};
let OwnedIdentity { pk, sk, id } = keystore::from_gosbot_local()
.await
@ -113,6 +112,36 @@ impl Sbot {
utils::get_async(&mut self.rpc_reader, req_id, utils::publish_res_parse).await
}
/// Wrapper for publish which constructs and publishes a post message appropriately from a string.
///
/// # Arguments
///
/// * `text` - A reference to a string slice which represents the text to be published in the post
pub async fn publish_post(&mut self, text: &str) -> Result<String, GolgiError> {
let msg = TypedMessage::Post{ text: text.to_string(), mentions: None};
self.publish(msg).await
}
/// Wrapper for publish which constructs and publishes an about description message appropriately from a string.
///
/// # Arguments
///
/// * `description` - A reference to a string slice which represents the text to be published as an about description.
pub async fn publish_description(&mut self, description: &str) -> Result<String, GolgiError> {
let msg = TypedMessage::About {
about: self.id.to_string(),
name: None,
title: None,
branch: None,
image: None,
description: Some(description.to_string()),
location: None,
start_datetime: None,
};
self.publish(msg).await
}
/*
pub async fn publish_post(&mut self, post: Post) -> Result<String, GolgiError> {
let req_id = self.client.publish_req_send(post).await?;

View File

@ -10,7 +10,7 @@ use std::fmt::Debug;
use async_std::io::Read;
use kuska_ssb::api::dto::{PublishOut, WhoAmIOut};
use kuska_ssb::api::dto::{WhoAmIOut};
use kuska_ssb::feed::Feed;
use kuska_ssb::rpc::{RecvMsg, RequestNo, RpcReader};