use rocket::request::Form; use rocket::response::Redirect; use rocket_contrib::Template; use serde_json; use activity_pub::{activity, activity_pub, ActivityPub, context}; use activity_pub::actor::Actor; use activity_pub::inbox::Inbox; use activity_pub::object::Object; use activity_pub::outbox::Outbox; use db_conn::DbConn; use models::follows::*; use models::instance::Instance; use models::posts::Post; use models::users::*; #[get("/me")] fn me(user: User) -> Redirect { Redirect::to(format!("/@/{}", user.username).as_ref()) } #[get("/@/", rank = 2)] fn details(name: String, conn: DbConn, account: Option) -> Template { let user = User::find_by_fqn(&*conn, name).unwrap(); let recents = Post::get_recents_for_author(&*conn, &user, 5); let user_id = user.id.clone(); Template::render("users/details", json!({ "user": serde_json::to_value(user).unwrap(), "account": account, "recents": recents.into_iter().map(|p| { json!({ "post": p, "author": p.get_authors(&*conn)[0], "url": p.compute_id(&*conn), "date": p.creation_date.timestamp() }) }).collect::>(), "is_self": account.map(|a| a.id == user_id).unwrap_or(false) })) } #[get("/@//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, &user, activity::Follow::new(&user, &target, &*conn)); Redirect::to(format!("/@/{}", name).as_ref()) } #[get("/@/", format = "application/activity+json", rank = 1)] fn activity_details(name: String, conn: DbConn) -> ActivityPub { let user = User::find_local(&*conn, name).unwrap(); user.as_activity_pub(&*conn) } #[get("/users/new")] fn new(user: Option) -> Template { Template::render("users/new", json!({ "account": user })) } #[get("/@//edit")] fn edit(name: String, user: User) -> Option