Follow endpoint
This commit is contained in:
parent
2e71912941
commit
9fdfb2b25e
@ -8,7 +8,8 @@ use activity_pub::object::Object;
|
||||
#[derive(Clone)]
|
||||
pub enum Activity {
|
||||
Create(Payload),
|
||||
Accept(Payload)
|
||||
Accept(Payload),
|
||||
Follow(Payload)
|
||||
}
|
||||
impl Activity {
|
||||
pub fn serialize(&self) -> serde_json::Value {
|
||||
@ -23,14 +24,16 @@ impl Activity {
|
||||
pub fn get_type(&self) -> String {
|
||||
match self {
|
||||
Activity::Accept(_) => String::from("Accept"),
|
||||
Activity::Create(_) => String::from("Create")
|
||||
Activity::Create(_) => String::from("Create"),
|
||||
Activity::Follow(_) => String::from("Follow")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn payload(&self) -> Payload {
|
||||
match self {
|
||||
Activity::Accept(p) => p.clone(),
|
||||
Activity::Create(p) => p.clone()
|
||||
Activity::Create(p) => p.clone(),
|
||||
Activity::Follow(p) => p.clone()
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,6 +44,10 @@ impl Activity {
|
||||
pub fn accept<A: Actor>(by: &A, what: String, conn: &PgConnection) -> Activity {
|
||||
Activity::Accept(Payload::new(serde_json::Value::String(by.compute_id(conn)), serde_json::Value::String(what)))
|
||||
}
|
||||
|
||||
pub fn follow<A: Actor, B: Actor>(by: &A, obj: &B, conn: &PgConnection) -> Activity {
|
||||
Activity::Follow(Payload::new(serde_json::Value::String(by.compute_id(conn)), serde_json::Value::String(obj.compute_id(conn))))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -56,6 +56,7 @@ fn main() {
|
||||
|
||||
routes::user::me,
|
||||
routes::user::details,
|
||||
routes::user::follow,
|
||||
routes::user::activity_details,
|
||||
routes::user::outbox,
|
||||
routes::user::inbox,
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user