Use the worker queue to send new articles to other instances
This commit is contained in:
parent
1e5ad2b086
commit
58d158238d
@ -1,11 +1,12 @@
|
|||||||
use activitypub::object::Article;
|
use activitypub::object::Article;
|
||||||
use heck::KebabCase;
|
use heck::KebabCase;
|
||||||
use rocket::request::LenientForm;
|
use rocket::{State, request::LenientForm};
|
||||||
use rocket::response::{Redirect, Flash};
|
use rocket::response::{Redirect, Flash};
|
||||||
use rocket_contrib::Template;
|
use rocket_contrib::Template;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use std::{collections::HashMap, borrow::Cow};
|
use std::{collections::HashMap, borrow::Cow};
|
||||||
use validator::{Validate, ValidationError, ValidationErrors};
|
use validator::{Validate, ValidationError, ValidationErrors};
|
||||||
|
use workerpool::{Pool, thunk::*};
|
||||||
|
|
||||||
use plume_common::activity_pub::{broadcast, ActivityStream, ApRequest};
|
use plume_common::activity_pub::{broadcast, ActivityStream, ApRequest};
|
||||||
use plume_common::utils;
|
use plume_common::utils;
|
||||||
@ -110,7 +111,7 @@ fn valid_slug(title: &str) -> Result<(), ValidationError> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[post("/~/<blog_name>/new", data = "<data>")]
|
#[post("/~/<blog_name>/new", data = "<data>")]
|
||||||
fn create(blog_name: String, data: LenientForm<NewPostForm>, user: User, conn: DbConn) -> Result<Redirect, Template> {
|
fn create(blog_name: String, data: LenientForm<NewPostForm>, user: User, conn: DbConn, worker: State<Pool<ThunkWorker<()>>>) -> Result<Redirect, Template> {
|
||||||
let blog = Blog::find_by_fqn(&*conn, blog_name.to_string()).unwrap();
|
let blog = Blog::find_by_fqn(&*conn, blog_name.to_string()).unwrap();
|
||||||
let form = data.get();
|
let form = data.get();
|
||||||
let slug = form.title.to_string().to_kebab_case();
|
let slug = form.title.to_string().to_kebab_case();
|
||||||
@ -154,7 +155,8 @@ fn create(blog_name: String, data: LenientForm<NewPostForm>, user: User, conn: D
|
|||||||
}
|
}
|
||||||
|
|
||||||
let act = post.create_activity(&*conn);
|
let act = post.create_activity(&*conn);
|
||||||
broadcast(&user, act, user.get_followers(&*conn));
|
let followers = user.get_followers(&*conn);
|
||||||
|
worker.execute(Thunk::of(move || broadcast(&user, act, followers)));
|
||||||
|
|
||||||
Ok(Redirect::to(uri!(details: blog = blog_name, slug = slug)))
|
Ok(Redirect::to(uri!(details: blog = blog_name, slug = slug)))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user