diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-04-28 21:23:23 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-04-28 21:23:23 +0200 |
commit | 5062a7541a3c8263aeb3f5ab32978d48d27e75bc (patch) | |
tree | 31594d1c2e49da36a3def15af356b12ad82349c2 | |
parent | ed056a56353554a4ad1766ab2487f08039e7854f (diff) |
Add App::new_post() method
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | src/app.rs | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -3,6 +3,7 @@ use std::collections::BTreeMap; use failure::Error; use crate::types::util::IPFSHash; +use crate::types::util::MimeType; use crate::types::util::IPNSHash; use crate::types::block::Block; use crate::repository::repository::Repository; @@ -39,6 +40,34 @@ impl App { Ok(App { repo, device_name, publishing_key: publishing_key.to_string() }) } + pub async fn new_post(&self, + content: Vec<u8>, + mime: MimeType, + reply_to: Option<IPFSHash>, + comments_will_be_propagated: Option<bool>, + comments_propagated_until: Option<Timestamp>) + -> Result<(), Error> + { + let content_hash = self.repo.put_raw_bytes(content).await?; + + let payload = Payload::Post { + content_format: mime, + content: content_hash, + reply_to, + comments_will_be_propagated, + comments_propagated_until, + }; + let timestamp = Timestamp::now(); + let content = Content::new(vec![], Some(timestamp), payload); + + let content_hash = self.repo.put_content(content).await?; + + let head = self.repo.put_block(Block::new(protocol_version(), vec![], content_hash)).await?; + let device_name = self.repo.publish(&self.publishing_key, &head).await?; + + Ok(()) + } + } |