make comments work (more or less)

This commit is contained in:
Felix Ableitner 2020-05-28 20:09:37 +02:00
parent 8f9bd1fef7
commit d6e2119277
3 changed files with 16 additions and 3 deletions

View file

@ -34,6 +34,9 @@ use diesel::{
use failure::Error; use failure::Error;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::str::FromStr; use std::str::FromStr;
use crate::apub::get_apub_protocol_string;
use crate::db::community::Community;
use url::Url;
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct CreatePost { pub struct CreatePost {
@ -190,7 +193,17 @@ impl Perform for Oper<CreatePost> {
} }
}; };
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, Ok(post) => post,
Err(_e) => return Err(APIError::err("couldnt_create_post").into()), Err(_e) => return Err(APIError::err("couldnt_create_post").into()),
}; };

View file

@ -124,7 +124,7 @@ fn post_updates_2020_04_03(conn: &PgConnection) -> Result<(), Error> {
.load::<Post>(conn)?; .load::<Post>(conn)?;
for cpost in &incorrect_posts { 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()); info!("{} post rows updated.", incorrect_posts.len());

View file

@ -75,7 +75,7 @@ impl Post {
post.filter(ap_id.eq(object_id)).first::<Self>(conn) post.filter(ap_id.eq(object_id)).first::<Self>(conn)
} }
pub fn update_ap_id(conn: &PgConnection, post_id: i32) -> Result<Self, Error> { pub fn update_ap_id(conn: &PgConnection, post_id: i32, ap_id: &str) -> Result<Self, Error> {
use crate::schema::post::dsl::*; use crate::schema::post::dsl::*;
let apid = make_apub_endpoint(EndpointType::Post, &post_id.to_string()).to_string(); let apid = make_apub_endpoint(EndpointType::Post, &post_id.to_string()).to_string();