Sent activities in other threads
This commit is contained in:
parent
58d158238d
commit
a9f95c91e2
@ -1,10 +1,12 @@
|
||||
use rocket::{
|
||||
State,
|
||||
request::LenientForm,
|
||||
response::Redirect
|
||||
};
|
||||
use rocket_contrib::Template;
|
||||
use serde_json;
|
||||
use validator::Validate;
|
||||
use workerpool::{Pool, thunk::*};
|
||||
|
||||
use plume_common::activity_pub::broadcast;
|
||||
use plume_models::{
|
||||
@ -25,7 +27,7 @@ struct NewCommentForm {
|
||||
}
|
||||
|
||||
#[post("/~/<blog_name>/<slug>/comment", data = "<data>")]
|
||||
fn create(blog_name: String, slug: String, data: LenientForm<NewCommentForm>, user: User, conn: DbConn) -> Result<Redirect, Template> {
|
||||
fn create(blog_name: String, slug: String, data: LenientForm<NewCommentForm>, user: User, conn: DbConn, worker: State<Pool<ThunkWorker<()>>>) -> Result<Redirect, Template> {
|
||||
let blog = Blog::find_by_fqn(&*conn, blog_name.clone()).unwrap();
|
||||
let post = Post::find_by_slug(&*conn, slug.clone(), blog.id).unwrap();
|
||||
let form = data.get();
|
||||
@ -41,7 +43,9 @@ fn create(blog_name: String, slug: String, data: LenientForm<NewCommentForm>, us
|
||||
let instance = Instance::get_local(&*conn).unwrap();
|
||||
instance.received(&*conn, serde_json::to_value(new_comment.clone()).expect("JSON serialization error"))
|
||||
.expect("We are not compatible with ourselve: local broadcast failed (new comment)");
|
||||
broadcast(&user, new_comment, user.get_followers(&*conn));
|
||||
let followers = user.get_followers(&*conn);
|
||||
let user_clone = user.clone();
|
||||
worker.execute(Thunk::of(move || broadcast(&user_clone, new_comment, followers)));
|
||||
|
||||
Redirect::to(format!("/~/{}/{}/#comment-{}", blog_name, slug, id))
|
||||
})
|
||||
|
@ -1,4 +1,5 @@
|
||||
use rocket::response::{Redirect, Flash};
|
||||
use rocket::{State, response::{Redirect, Flash}};
|
||||
use workerpool::{Pool, thunk::*};
|
||||
|
||||
use plume_common::activity_pub::{broadcast, inbox::Notify};
|
||||
use plume_common::utils;
|
||||
@ -11,7 +12,7 @@ use plume_models::{
|
||||
};
|
||||
|
||||
#[post("/~/<blog>/<slug>/like")]
|
||||
fn create(blog: String, slug: String, user: User, conn: DbConn) -> Redirect {
|
||||
fn create(blog: String, slug: String, user: User, conn: DbConn, worker: State<Pool<ThunkWorker<()>>>) -> Redirect {
|
||||
let b = Blog::find_by_fqn(&*conn, blog.clone()).unwrap();
|
||||
let post = Post::find_by_slug(&*conn, slug.clone(), b.id).unwrap();
|
||||
|
||||
@ -24,11 +25,14 @@ fn create(blog: String, slug: String, user: User, conn: DbConn) -> Redirect {
|
||||
like.update_ap_url(&*conn);
|
||||
like.notify(&*conn);
|
||||
|
||||
broadcast(&user, like.into_activity(&*conn), user.get_followers(&*conn));
|
||||
let followers = user.get_followers(&*conn);
|
||||
let act = like.into_activity(&*conn);
|
||||
worker.execute(Thunk::of(move || broadcast(&user, act, followers)));
|
||||
} else {
|
||||
let like = likes::Like::find_by_user_on_post(&*conn, user.id, post.id).unwrap();
|
||||
let delete_act = like.delete(&*conn);
|
||||
broadcast(&user, delete_act, user.get_followers(&*conn));
|
||||
let followers = user.get_followers(&*conn);
|
||||
worker.execute(Thunk::of(move || broadcast(&user, delete_act, followers)));
|
||||
}
|
||||
|
||||
Redirect::to(uri!(super::posts::details: blog = blog, slug = slug))
|
||||
|
@ -1,4 +1,5 @@
|
||||
use rocket::response::{Redirect, Flash};
|
||||
use rocket::{State, response::{Redirect, Flash}};
|
||||
use workerpool::{Pool, thunk::*};
|
||||
|
||||
use plume_common::activity_pub::{broadcast, inbox::Notify};
|
||||
use plume_common::utils;
|
||||
@ -11,7 +12,7 @@ use plume_models::{
|
||||
};
|
||||
|
||||
#[post("/~/<blog>/<slug>/reshare")]
|
||||
fn create(blog: String, slug: String, user: User, conn: DbConn) -> Redirect {
|
||||
fn create(blog: String, slug: String, user: User, conn: DbConn, worker: State<Pool<ThunkWorker<()>>>) -> Redirect {
|
||||
let b = Blog::find_by_fqn(&*conn, blog.clone()).unwrap();
|
||||
let post = Post::find_by_slug(&*conn, slug.clone(), b.id).unwrap();
|
||||
|
||||
@ -24,11 +25,14 @@ fn create(blog: String, slug: String, user: User, conn: DbConn) -> Redirect {
|
||||
reshare.update_ap_url(&*conn);
|
||||
reshare.notify(&*conn);
|
||||
|
||||
broadcast(&user, reshare.into_activity(&*conn), user.get_followers(&*conn));
|
||||
let followers = user.get_followers(&*conn);
|
||||
let act = reshare.into_activity(&*conn);
|
||||
worker.execute(Thunk::of(move || broadcast(&user, act, followers)));
|
||||
} else {
|
||||
let reshare = Reshare::find_by_user_on_post(&*conn, user.id, post.id).unwrap();
|
||||
let delete_act = reshare.delete(&*conn);
|
||||
broadcast(&user, delete_act, user.get_followers(&*conn));
|
||||
let followers = user.get_followers(&*conn);
|
||||
worker.execute(Thunk::of(move || broadcast(&user, delete_act, followers)));
|
||||
}
|
||||
|
||||
Redirect::to(uri!(super::posts::details: blog = blog, slug = slug))
|
||||
|
@ -2,12 +2,15 @@ use activitypub::{
|
||||
activity::Follow,
|
||||
collection::OrderedCollection
|
||||
};
|
||||
use rocket::{request::LenientForm,
|
||||
use rocket::{
|
||||
State,
|
||||
request::LenientForm,
|
||||
response::{Redirect, Flash}
|
||||
};
|
||||
use rocket_contrib::Template;
|
||||
use serde_json;
|
||||
use validator::{Validate, ValidationError};
|
||||
use workerpool::{Pool, thunk::*};
|
||||
|
||||
use plume_common::activity_pub::{
|
||||
ActivityStream, broadcast, Id, IntoId, ApRequest,
|
||||
@ -71,7 +74,7 @@ fn dashboard_auth() -> Flash<Redirect> {
|
||||
}
|
||||
|
||||
#[get("/@/<name>/follow")]
|
||||
fn follow(name: String, conn: DbConn, user: User) -> Redirect {
|
||||
fn follow(name: String, conn: DbConn, user: User, worker: State<Pool<ThunkWorker<()>>>) -> Redirect {
|
||||
let target = User::find_by_fqn(&*conn, name.clone()).unwrap();
|
||||
let f = follows::Follow::insert(&*conn, follows::NewFollow {
|
||||
follower_id: user.id,
|
||||
@ -86,7 +89,7 @@ fn follow(name: String, conn: DbConn, user: User) -> Redirect {
|
||||
act.object_props.set_to_link(target.clone().into_id()).expect("New Follow error while setting 'to'");
|
||||
act.object_props.set_cc_link_vec::<Id>(vec![]).expect("New Follow error while setting 'cc'");
|
||||
|
||||
broadcast(&user, act, vec![target]);
|
||||
worker.execute(Thunk::of(move || broadcast(&user, act, vec![target])));
|
||||
Redirect::to(uri!(details: name = name))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user