use failure::Error;
use failure::_core::fmt::Debug;
use isahc::prelude::*;
+use log::debug;
use serde::Serialize;
fn populate_object_props(
A: Serialize + Debug,
{
let json = serde_json::to_string(&activity)?;
- println!("sending data {}", json);
+ debug!("Sending activitypub activity {}", json);
for t in to {
- println!("to: {}", t);
+ debug!("Sending activity to: {}", t);
let res = Request::post(t)
.header("Content-Type", "application/json")
.body(json.to_owned())?
.send()?;
- dbg!(res);
+ debug!("Result for activity send: {:?}", res);
}
Ok(())
}
use diesel::r2d2::{ConnectionManager, Pool};
use diesel::PgConnection;
use failure::Error;
+use log::debug;
+use serde::Deserialize;
use url::Url;
#[serde(untagged)]
-#[derive(serde::Deserialize)]
+#[derive(Deserialize, Debug)]
pub enum CommunityAcceptedObjects {
Follow(Follow),
}
+#[derive(Deserialize)]
+pub struct Params {
+ community_name: String,
+}
+
pub async fn community_inbox(
input: web::Json<CommunityAcceptedObjects>,
+ params: web::Query<Params>,
db: web::Data<Pool<ConnectionManager<PgConnection>>>,
) -> Result<HttpResponse, Error> {
let input = input.into_inner();
let conn = &db.get().unwrap();
+ debug!(
+ "Community {} received activity {:?}",
+ ¶ms.community_name, &input
+ );
match input {
CommunityAcceptedObjects::Follow(f) => handle_follow(&f, conn),
}
}
fn handle_follow(follow: &Follow, conn: &PgConnection) -> Result<HttpResponse, Error> {
- println!("received follow: {:?}", &follow);
-
// TODO: make sure this is a local community
let community_uri = follow
.follow_props
.unwrap()
.to_string();
let user = fetch_remote_user(&Url::parse(&user_uri)?, conn)?;
- // TODO: insert ID of the user into follows of the community
let community_follower_form = CommunityFollowerForm {
community_id: community.id,
user_id: user.id,
use diesel::r2d2::{ConnectionManager, Pool};
use diesel::PgConnection;
use failure::Error;
+use log::debug;
+use serde::Deserialize;
#[serde(untagged)]
-#[derive(serde::Deserialize)]
+#[derive(Deserialize, Debug)]
pub enum UserAcceptedObjects {
Create(Create),
Update(Update),
Accept(Accept),
}
+#[derive(Deserialize)]
+pub struct Params {
+ user_name: String,
+}
+
pub async fn user_inbox(
input: web::Json<UserAcceptedObjects>,
+ params: web::Query<Params>,
db: web::Data<Pool<ConnectionManager<PgConnection>>>,
) -> Result<HttpResponse, Error> {
let input = input.into_inner();
let conn = &db.get().unwrap();
+ debug!("User {} received activity: {:?}", ¶ms.user_name, &input);
+
match input {
UserAcceptedObjects::Create(c) => handle_create(&c, conn),
UserAcceptedObjects::Update(u) => handle_update(&u, conn),
Ok(HttpResponse::Ok().finish())
}
-fn handle_accept(accept: &Accept, _conn: &PgConnection) -> Result<HttpResponse, Error> {
- println!("received accept: {:?}", &accept);
+fn handle_accept(_accept: &Accept, _conn: &PgConnection) -> Result<HttpResponse, Error> {
+ // TODO: make sure that we actually requested a follow
// TODO: at this point, indicate to the user that they are following the community
Ok(HttpResponse::Ok().finish())
}
cfg
// TODO: check the user/community params for these
.route(
- "/federation/c/{_}/inbox",
+ "/federation/c/{community_name}/inbox",
web::post().to(apub::community_inbox::community_inbox),
)
.route(
- "/federation/u/{_}/inbox",
+ "/federation/u/{user_name}/inbox",
web::post().to(apub::user_inbox::user_inbox),
)
.route(