Broadcast activities to followers
This commit is contained in:
parent
03df88e186
commit
2f1f6a0295
@ -1,3 +1,4 @@
|
|||||||
|
use diesel::PgConnection;
|
||||||
use rocket::http::Status;
|
use rocket::http::Status;
|
||||||
use rocket::response::{Response, Responder};
|
use rocket::response::{Response, Responder};
|
||||||
use rocket::request::Request;
|
use rocket::request::Request;
|
||||||
@ -5,6 +6,8 @@ use serde_json;
|
|||||||
|
|
||||||
use activity_pub::{activity_pub, ActivityPub, context};
|
use activity_pub::{activity_pub, ActivityPub, context};
|
||||||
use activity_pub::activity::Activity;
|
use activity_pub::activity::Activity;
|
||||||
|
use activity_pub::actor::Actor;
|
||||||
|
use models::users::User;
|
||||||
|
|
||||||
pub struct Outbox {
|
pub struct Outbox {
|
||||||
id: String,
|
id: String,
|
||||||
@ -36,3 +39,9 @@ impl<'r> Responder<'r> for Outbox {
|
|||||||
self.serialize().respond_to(request)
|
self.serialize().respond_to(request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn broadcast(conn: &PgConnection, act: Activity, to: Vec<User>) {
|
||||||
|
for user in to {
|
||||||
|
user.send_to_inbox(conn, act.clone()); // TODO: run it in Sidekiq or something like that
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -34,6 +34,12 @@ impl Instance {
|
|||||||
.into_iter().nth(0)
|
.into_iter().nth(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_remotes(conn: &PgConnection) -> Vec<Instance> {
|
||||||
|
instances::table.filter(instances::local.eq(false))
|
||||||
|
.load::<Instance>(conn)
|
||||||
|
.expect("Error loading remote instances infos")
|
||||||
|
}
|
||||||
|
|
||||||
pub fn local_id(conn: &PgConnection) -> i32 {
|
pub fn local_id(conn: &PgConnection) -> i32 {
|
||||||
Instance::get_local(conn).unwrap().id
|
Instance::get_local(conn).unwrap().id
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ use rocket::response::Redirect;
|
|||||||
use rocket_contrib::Template;
|
use rocket_contrib::Template;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use activity_pub::activity::Activity;
|
||||||
|
use activity_pub::outbox::broadcast;
|
||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
use models::blogs::*;
|
use models::blogs::*;
|
||||||
use models::post_authors::*;
|
use models::post_authors::*;
|
||||||
@ -52,5 +54,9 @@ fn create(blog_name: String, data: Form<NewPostForm>, user: User, conn: DbConn)
|
|||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
author_id: user.id
|
author_id: user.id
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let act = Activity::create(&user, post, &*conn);
|
||||||
|
broadcast(&*conn, act, user.get_followers(&*conn));
|
||||||
|
|
||||||
Redirect::to(format!("/~/{}/{}", blog_name, slug).as_str())
|
Redirect::to(format!("/~/{}/{}", blog_name, slug).as_str())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user