diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2022-11-09 15:35:17 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2022-11-09 15:35:38 -0800 |
commit | 7af51292ddfc81d55dd5beff07c557757bb0075f (patch) | |
tree | 6601cc2c73adab784f791f650e08fd9dc92aa65b /adenosine-pds/src/db.rs | |
parent | b8eea211866766aabde8c5e55d1061deb799ddc6 (diff) | |
download | adenosine-7af51292ddfc81d55dd5beff07c557757bb0075f.tar.gz adenosine-7af51292ddfc81d55dd5beff07c557757bb0075f.zip |
pds: more bsky posts/feeds/follow/like progress
Diffstat (limited to 'adenosine-pds/src/db.rs')
-rw-r--r-- | adenosine-pds/src/db.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/adenosine-pds/src/db.rs b/adenosine-pds/src/db.rs index 384b498..051588d 100644 --- a/adenosine-pds/src/db.rs +++ b/adenosine-pds/src/db.rs @@ -1,6 +1,6 @@ use crate::models::{FollowRecord, Post, RefRecord}; /// ATP database (as distinct from blockstore) -use crate::{ipld_into_json_value, AtpSession, Did, KeyPair, Tid}; +use crate::{created_at_now, ipld_into_json_value, AtpSession, Did, KeyPair, Tid}; use anyhow::{anyhow, Result}; use lazy_static::lazy_static; use libipld::cbor::DagCborCodec; @@ -167,15 +167,21 @@ impl AtpDatabase { let block = Block::<DefaultParams>::encode(DagCborCodec, Code::Sha2_256, &val)?; let cid = *block.cid(); let post: Post = serde_json::from_value(ipld_into_json_value(val))?; + let (reply_to_parent_uri, reply_to_root_uri) = match post.reply { + Some(ref reply) => (Some(reply.parent.uri.clone()), Some(reply.root.uri.clone())), + None => (None, None), + }; let mut stmt = self .conn - .prepare_cached("INSERT INTO bsky_post (did, tid, cid, record_json, created_at) VALUES (?1, ?2, ?3, ?4, ?5)")?; + .prepare_cached("INSERT INTO bsky_post (did, tid, cid, reply_to_parent_uri, reply_to_root_uri, record_json, created_at) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)")?; stmt.execute(params!( did.to_string(), tid.to_string(), cid.to_string(), + reply_to_parent_uri, + reply_to_root_uri, serde_json::to_string(&post)?, - post.createdAt + post.createdAt.unwrap_or_else(|| created_at_now()) ))?; } else { let mut stmt = self |