mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-05 20:15:01 +00:00
Minor code cleanup
This commit is contained in:
parent
f7330bf062
commit
d9657b24a7
4 changed files with 14 additions and 9 deletions
|
@ -107,7 +107,8 @@ impl Perform<PostResponse> for Oper<CreatePost> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for a site ban
|
// 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());
|
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()),
|
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
|
// They like their own post by default
|
||||||
let like_form = PostLikeForm {
|
let like_form = PostLikeForm {
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
use crate::apub::{get_apub_protocol_string, get_following_instances};
|
use crate::apub::{get_apub_protocol_string, get_following_instances};
|
||||||
use crate::db::post::Post;
|
use crate::db::post::Post;
|
||||||
use crate::db::user::User_;
|
use crate::db::user::User_;
|
||||||
use crate::db::Crud;
|
|
||||||
use activitystreams::activity::Create;
|
use activitystreams::activity::Create;
|
||||||
use activitystreams::context;
|
use activitystreams::context;
|
||||||
use diesel::PgConnection;
|
use diesel::PgConnection;
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use isahc::prelude::*;
|
use isahc::prelude::*;
|
||||||
|
|
||||||
pub fn post_create(post: &Post, conn: &PgConnection) -> Result<(), Error> {
|
pub fn post_create(post: &Post, creator: &User_, conn: &PgConnection) -> Result<(), Error> {
|
||||||
let user = User_::read(conn, post.creator_id)?;
|
|
||||||
let page = post.as_page(conn)?;
|
let page = post.as_page(conn)?;
|
||||||
let mut create = Create::new();
|
let mut create = Create::new();
|
||||||
create.object_props.set_context_xsd_any_uri(context())?;
|
create.object_props.set_context_xsd_any_uri(context())?;
|
||||||
|
@ -17,7 +15,9 @@ pub fn post_create(post: &Post, conn: &PgConnection) -> Result<(), Error> {
|
||||||
create
|
create
|
||||||
.object_props
|
.object_props
|
||||||
.set_id(page.object_props.get_id().unwrap().to_string())?;
|
.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)?;
|
create.create_props.set_object_base_box(page)?;
|
||||||
let json = serde_json::to_string(&create)?;
|
let json = serde_json::to_string(&create)?;
|
||||||
for i in get_following_instances() {
|
for i in get_following_instances() {
|
||||||
|
|
|
@ -7,7 +7,9 @@ use diesel::r2d2::{ConnectionManager, Pool};
|
||||||
use diesel::PgConnection;
|
use diesel::PgConnection;
|
||||||
use failure::Error;
|
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>,
|
create: web::Json<Create>,
|
||||||
db: web::Data<Pool<ConnectionManager<PgConnection>>>,
|
db: web::Data<Pool<ConnectionManager<PgConnection>>>,
|
||||||
) -> Result<HttpResponse, Error> {
|
) -> Result<HttpResponse, Error> {
|
||||||
|
|
|
@ -10,8 +10,10 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
"/federation/communities",
|
"/federation/communities",
|
||||||
web::get().to(apub::community::get_apub_community_list),
|
web::get().to(apub::community::get_apub_community_list),
|
||||||
)
|
)
|
||||||
// TODO: need a proper actor that has this inbox
|
.route(
|
||||||
.route("/federation/inbox", web::post().to(apub::inbox::inbox))
|
"/federation/inbox",
|
||||||
|
web::post().to(apub::inbox::create_inbox),
|
||||||
|
)
|
||||||
.route(
|
.route(
|
||||||
"/federation/c/{community_name}",
|
"/federation/c/{community_name}",
|
||||||
web::get().to(apub::community::get_apub_community_http),
|
web::get().to(apub::community::get_apub_community_http),
|
||||||
|
|
Loading…
Reference in a new issue