Minor code cleanup

This commit is contained in:
Felix 2020-04-09 21:26:22 +02:00
parent f7330bf062
commit d9657b24a7
4 changed files with 14 additions and 9 deletions

View file

@ -107,7 +107,8 @@ impl Perform<PostResponse> for Oper<CreatePost> {
}
// Check for a site ban
if UserView::read(&conn, user_id)?.banned {
let user = User_::read(&conn, user_id)?;
if user.banned {
return Err(APIError::err("site_ban").into());
}
@ -154,7 +155,7 @@ impl Perform<PostResponse> for Oper<CreatePost> {
Err(_e) => return Err(APIError::err("couldnt_create_post").into()),
};
post_create(&inserted_post, conn)?;
post_create(&inserted_post, &user, conn)?;
// They like their own post by default
let like_form = PostLikeForm {

View file

@ -1,15 +1,13 @@
use crate::apub::{get_apub_protocol_string, get_following_instances};
use crate::db::post::Post;
use crate::db::user::User_;
use crate::db::Crud;
use activitystreams::activity::Create;
use activitystreams::context;
use diesel::PgConnection;
use failure::Error;
use isahc::prelude::*;
pub fn post_create(post: &Post, conn: &PgConnection) -> Result<(), Error> {
let user = User_::read(conn, post.creator_id)?;
pub fn post_create(post: &Post, creator: &User_, conn: &PgConnection) -> Result<(), Error> {
let page = post.as_page(conn)?;
let mut create = Create::new();
create.object_props.set_context_xsd_any_uri(context())?;
@ -17,7 +15,9 @@ pub fn post_create(post: &Post, conn: &PgConnection) -> Result<(), Error> {
create
.object_props
.set_id(page.object_props.get_id().unwrap().to_string())?;
create.create_props.set_actor_xsd_any_uri(user.actor_id)?;
create
.create_props
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?;
create.create_props.set_object_base_box(page)?;
let json = serde_json::to_string(&create)?;
for i in get_following_instances() {

View file

@ -7,7 +7,9 @@ use diesel::r2d2::{ConnectionManager, Pool};
use diesel::PgConnection;
use failure::Error;
pub async fn inbox(
// TODO: need a proper actor that has this inbox
pub async fn create_inbox(
create: web::Json<Create>,
db: web::Data<Pool<ConnectionManager<PgConnection>>>,
) -> Result<HttpResponse, Error> {

View file

@ -10,8 +10,10 @@ pub fn config(cfg: &mut web::ServiceConfig) {
"/federation/communities",
web::get().to(apub::community::get_apub_community_list),
)
// TODO: need a proper actor that has this inbox
.route("/federation/inbox", web::post().to(apub::inbox::inbox))
.route(
"/federation/inbox",
web::post().to(apub::inbox::create_inbox),
)
.route(
"/federation/c/{community_name}",
web::get().to(apub::community::get_apub_community_http),