67 lines
2.2 KiB
Rust
67 lines
2.2 KiB
Rust
//! Publish Scuttlebutt private messages.
|
|
//!
|
|
//! Implements the following method:
|
|
//!
|
|
//! - [`Sbot::publish_private`]
|
|
|
|
use crate::{error::GolgiError, messages::SsbMessageContent, sbot::Sbot, utils};
|
|
|
|
impl Sbot {
|
|
/// Publish a private message.
|
|
///
|
|
/// # Arguments
|
|
///
|
|
/// * `msg` - A `PrivateMessage` `struct` whose fields include `text` and
|
|
/// `recipients`.
|
|
///
|
|
/// # Example
|
|
///
|
|
/// ```rust
|
|
/// use golgi::{Sbot, GolgiError, messages::SsbMessageContent, sbot::Keystore};
|
|
///
|
|
/// async fn publish_a_private_msg() -> Result<(), GolgiError> {
|
|
/// let mut sbot_client = Sbot::init(Keystore::Patchwork, None, None).await?;
|
|
///
|
|
/// let text = String::from("Hi friends, I have a super secrect message to share with you about the wonders of intra-cellular transport mechanics.");
|
|
///
|
|
/// // We must also include the local identity (public key) here if we wish
|
|
/// // to be able to read the message. Ie. the sender must be included in
|
|
/// // the list of recipients.
|
|
/// let recipients = vec![
|
|
/// String::from("@OKRij/n7Uu42A0Z75ty0JI0cZxcieD2NyjXrRdYKNOQ=.ed25519"),
|
|
/// String::from("@Sih4JGgs5oQPXehRyHS5qrYbx/0hQVUqChojX0LNtcQ=.ed25519"),
|
|
/// String::from("@BVA85B7a/a17v2ZVcLkMgPE+v7X5rQVAHEgQBbCaKMs=.ed25519"),
|
|
/// ];
|
|
///
|
|
/// let msg_ref = sbot_client.publish_private(text, recipients).await?;
|
|
///
|
|
/// println!("msg reference for the private msg: {}", msg_ref);
|
|
///
|
|
/// Ok(())
|
|
/// }
|
|
/// ```
|
|
pub async fn publish_private(
|
|
&mut self,
|
|
text: String,
|
|
recipients: Vec<String>,
|
|
) -> Result<String, GolgiError> {
|
|
let msg = SsbMessageContent::Post {
|
|
text: text.to_string(),
|
|
mentions: None,
|
|
};
|
|
|
|
let mut sbot_connection = self.get_sbot_connection().await?;
|
|
let req_id = sbot_connection
|
|
.client
|
|
.private_publish_req_send(msg, recipients)
|
|
.await?;
|
|
|
|
utils::get_async(
|
|
&mut sbot_connection.rpc_reader,
|
|
req_id,
|
|
utils::string_res_parse,
|
|
)
|
|
.await
|
|
}
|
|
}
|