Follow endpoint

This commit is contained in:
Bat
2018-05-01 20:57:30 +01:00
parent 2e71912941
commit 9fdfb2b25e
3 changed files with 24 additions and 3 deletions
+13
View File
@@ -5,10 +5,12 @@ use serde_json;
use std::collections::HashMap;
use activity_pub::ActivityPub;
use activity_pub::activity::Activity;
use activity_pub::actor::Actor;
use activity_pub::inbox::Inbox;
use activity_pub::outbox::Outbox;
use db_conn::DbConn;
use models::follows::*;
use models::instance::Instance;
use models::users::*;
@@ -25,6 +27,17 @@ fn details(name: String, conn: DbConn) -> Template {
}))
}
#[get("/@/<name>/follow")]
fn follow(name: String, conn: DbConn, user: User) -> Redirect {
let target = User::find_by_fqn(&*conn, name.clone()).unwrap();
Follow::insert(&*conn, NewFollow {
follower_id: user.id,
following_id: target.id
});
target.send_to_inbox(&*conn, Activity::follow(&user, &target, &*conn));
Redirect::to(format!("/@/{}", name).as_ref())
}
#[get("/@/<name>", format = "application/activity+json", rank = 1)]
fn activity_details(name: String, conn: DbConn) -> ActivityPub {
let user = User::find_local(&*conn, name).unwrap();