Store IDs of incoming Note objects

This commit is contained in:
silverpill 2021-10-08 22:39:40 +00:00
parent 8c18a0ab86
commit 8610719bd0
7 changed files with 12 additions and 1 deletions

View file

@ -0,0 +1 @@
ALTER TABLE post ADD COLUMN object_id VARCHAR(200) UNIQUE;

View file

@ -35,6 +35,7 @@ CREATE TABLE post (
content TEXT NOT NULL,
in_reply_to_id UUID REFERENCES post (id) ON DELETE CASCADE,
reply_count INTEGER NOT NULL CHECK (reply_count >= 0) DEFAULT 0,
object_id VARCHAR(200) UNIQUE,
ipfs_cid VARCHAR(200),
token_id INTEGER,
token_tx_id VARCHAR(200),

View file

@ -127,7 +127,7 @@ pub fn create_note(
let post = in_reply_to.unwrap();
assert_eq!(post.id, in_reply_to_id);
match post.author.is_local() {
false => None, // TODO: store object ID for remote posts
false => post.object_id.clone(),
true => Some(get_object_url(&config.instance_url(), &post.id)),
}
},

View file

@ -125,6 +125,7 @@ pub async fn receive_activity(
// TODO: parse inReplyTo field
in_reply_to_id: None,
attachments: attachments,
object_id: Some(object.id),
created_at: object.published,
};
create_post(db_client, &author.id, post_data).await?;

View file

@ -62,6 +62,7 @@ impl From<StatusData> for PostCreateData {
content: value.status,
in_reply_to_id: value.in_reply_to_id,
attachments: value.media_ids.unwrap_or(vec![]),
object_id: None,
created_at: None,
}
}

View file

@ -133,6 +133,7 @@ pub async fn create_post(
in_reply_to_id: db_post.in_reply_to_id,
reply_count: db_post.reply_count,
attachments: db_attachments,
object_id: db_post.object_id,
ipfs_cid: db_post.ipfs_cid,
token_id: db_post.token_id,
token_tx_id: db_post.token_tx_id,

View file

@ -18,6 +18,7 @@ pub struct DbPost {
pub content: String,
pub in_reply_to_id: Option<Uuid>,
pub reply_count: i32,
pub object_id: Option<String>,
pub ipfs_cid: Option<String>,
pub token_id: Option<i32>,
pub token_tx_id: Option<String>,
@ -32,6 +33,7 @@ pub struct Post {
pub in_reply_to_id: Option<Uuid>,
pub reply_count: i32,
pub attachments: Vec<DbMediaAttachment>,
pub object_id: Option<String>,
pub ipfs_cid: Option<String>,
pub token_id: Option<i32>,
pub token_tx_id: Option<String>,
@ -53,6 +55,7 @@ impl TryFrom<&Row> for Post {
in_reply_to_id: db_post.in_reply_to_id,
reply_count: db_post.reply_count,
attachments: db_attachments,
object_id: db_post.object_id,
ipfs_cid: db_post.ipfs_cid,
token_id: db_post.token_id,
token_tx_id: db_post.token_tx_id,
@ -66,6 +69,7 @@ pub struct PostCreateData {
pub content: String,
pub in_reply_to_id: Option<Uuid>,
pub attachments: Vec<Uuid>,
pub object_id: Option<String>,
pub created_at: Option<DateTime<Utc>>,
}
@ -92,6 +96,7 @@ mod tests {
content: " ".to_string(),
in_reply_to_id: None,
attachments: vec![],
object_id: None,
created_at: None,
};
assert_eq!(post_data_1.validate().is_ok(), false);
@ -103,6 +108,7 @@ mod tests {
content: "test ".to_string(),
in_reply_to_id: None,
attachments: vec![],
object_id: None,
created_at: None,
};
assert_eq!(post_data_2.validate().is_ok(), true);