add method to publish image msg
This commit is contained in:
parent
6ece486103
commit
e6c3a8e993
|
@ -4,9 +4,12 @@
|
|||
//!
|
||||
//! - [`Sbot::publish`]
|
||||
//! - [`Sbot::publish_description`]
|
||||
//! - [`Sbot::publish_image`]
|
||||
//! - [`Sbot::publish_name`]
|
||||
//! - [`Sbot::publish_post`]
|
||||
|
||||
use kuska_ssb::api::dto::content::Image;
|
||||
|
||||
use crate::{error::GolgiError, messages::SsbMessageContent, sbot::Sbot, utils};
|
||||
|
||||
impl Sbot {
|
||||
|
@ -116,6 +119,45 @@ impl Sbot {
|
|||
self.publish(msg).await
|
||||
}
|
||||
|
||||
/// Publish an image for the local identity.
|
||||
///
|
||||
/// Requires the image to have been added to the local blobstore. The
|
||||
/// ID of the blob (sigil-link in the form `&...=.sha256`) must be provided.
|
||||
///
|
||||
/// Convenient wrapper around the `publish` method which constructs and
|
||||
/// publishes an `about` type name message appropriately from a string.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// use golgi::{Sbot, GolgiError};
|
||||
///
|
||||
/// async fn publish_an_image() -> Result<(), GolgiError> {
|
||||
/// let mut sbot_client = Sbot::init(None, None).await?;
|
||||
///
|
||||
/// let blob_id = "&JlJHc9yeG1EpZA9fIPGLzUKDH0FeR39Ai57euhKT1G8=.sha256";
|
||||
///
|
||||
/// let msg_ref = sbot_client.publish_image(blob_id).await?;
|
||||
///
|
||||
/// println!("msg reference: {}", msg_ref);
|
||||
///
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
pub async fn publish_image(&mut self, blob_id: &str) -> Result<String, GolgiError> {
|
||||
let msg = SsbMessageContent::About {
|
||||
about: self.id.to_string(),
|
||||
name: None,
|
||||
title: None,
|
||||
branch: None,
|
||||
image: Some(Image::OnlyLink(blob_id.to_string())),
|
||||
description: None,
|
||||
location: None,
|
||||
start_datetime: None,
|
||||
};
|
||||
self.publish(msg).await
|
||||
}
|
||||
|
||||
/// Publish a name for the local identity.
|
||||
///
|
||||
/// Convenient wrapper around the `publish` method which constructs and
|
||||
|
|
Loading…
Reference in New Issue