From d6e21192772a5631968fe5ddb51049287c34eba7 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 28 May 2020 20:09:37 +0200 Subject: [PATCH] make comments work (more or less) --- server/src/api/post.rs | 15 ++++++++++++++- server/src/db/code_migrations.rs | 2 +- server/src/db/post.rs | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/server/src/api/post.rs b/server/src/api/post.rs index 9bbde791..aee60732 100644 --- a/server/src/api/post.rs +++ b/server/src/api/post.rs @@ -34,6 +34,9 @@ use diesel::{ use failure::Error; use serde::{Deserialize, Serialize}; use std::str::FromStr; +use crate::apub::get_apub_protocol_string; +use crate::db::community::Community; +use url::Url; #[derive(Serialize, Deserialize, Debug)] pub struct CreatePost { @@ -190,7 +193,17 @@ impl Perform for Oper { } }; - let updated_post = match Post::update_ap_id(&conn, inserted_post.id) { + // TODO: we should be able to remove Post::update_ap_id with this + let community = Url::parse(&Community::read(&conn, data.community_id)?.actor_id)?; + let apub_id = + format!( + "{}://{}/{}/{}", + get_apub_protocol_string(), + community.domain().ok_or(format_err!("community has invalid domain"))?, + "post", + inserted_post.id + ); + let updated_post = match Post::update_ap_id(&conn, inserted_post.id, &apub_id) { Ok(post) => post, Err(_e) => return Err(APIError::err("couldnt_create_post").into()), }; diff --git a/server/src/db/code_migrations.rs b/server/src/db/code_migrations.rs index 204bfe79..11c8ba1f 100644 --- a/server/src/db/code_migrations.rs +++ b/server/src/db/code_migrations.rs @@ -124,7 +124,7 @@ fn post_updates_2020_04_03(conn: &PgConnection) -> Result<(), Error> { .load::(conn)?; for cpost in &incorrect_posts { - Post::update_ap_id(&conn, cpost.id)?; + Post::update_ap_id(&conn, cpost.id, todo!())?; } info!("{} post rows updated.", incorrect_posts.len()); diff --git a/server/src/db/post.rs b/server/src/db/post.rs index d12f98d8..ff3af55d 100644 --- a/server/src/db/post.rs +++ b/server/src/db/post.rs @@ -75,7 +75,7 @@ impl Post { post.filter(ap_id.eq(object_id)).first::(conn) } - pub fn update_ap_id(conn: &PgConnection, post_id: i32) -> Result { + pub fn update_ap_id(conn: &PgConnection, post_id: i32, ap_id: &str) -> Result { use crate::schema::post::dsl::*; let apid = make_apub_endpoint(EndpointType::Post, &post_id.to_string()).to_string(); -- 2.44.1