Some checks failed
lint / lint (push) Has been cancelled
test / unit (push) Has been cancelled
test / integration (push) Has been cancelled
lint / lint (pull_request) Failing after 9m33s
test / unit (pull_request) Successful in 16m24s
test / integration (pull_request) Failing after 16m52s
98 lines
2.9 KiB
Rust
98 lines
2.9 KiB
Rust
use crate::{errors::ApiError, extractors::AuthUser, state::AppState};
|
|
use api_types::responses::{ProfileField, RemoteActorResponse};
|
|
use application::use_cases::federation_management::{
|
|
accept_follow_request, list_pending_requests, list_remote_followers, list_remote_following,
|
|
reject_follow_request, remove_remote_following,
|
|
};
|
|
use axum::{extract::State, http::StatusCode, Json};
|
|
use serde::Deserialize;
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct ActorUrlBody {
|
|
pub actor_url: String,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct HandleBody {
|
|
pub handle: String,
|
|
}
|
|
|
|
fn to_response(a: domain::models::remote_actor::RemoteActor) -> RemoteActorResponse {
|
|
RemoteActorResponse {
|
|
handle: a.handle,
|
|
display_name: a.display_name,
|
|
avatar_url: a.avatar_url,
|
|
url: a.url,
|
|
bio: a.bio,
|
|
banner_url: a.banner_url,
|
|
also_known_as: a.also_known_as,
|
|
outbox_url: a.outbox_url,
|
|
followers_url: a.followers_url,
|
|
following_url: a.following_url,
|
|
attachment: a
|
|
.attachment
|
|
.into_iter()
|
|
.map(|(name, value)| ProfileField { name, value })
|
|
.collect(),
|
|
}
|
|
}
|
|
|
|
pub async fn get_pending_requests(
|
|
State(s): State<AppState>,
|
|
AuthUser(uid): AuthUser,
|
|
) -> Result<Json<Vec<RemoteActorResponse>>, ApiError> {
|
|
let actors = list_pending_requests(&*s.federation, &uid).await?;
|
|
Ok(Json(actors.into_iter().map(to_response).collect()))
|
|
}
|
|
|
|
pub async fn post_accept_request(
|
|
State(s): State<AppState>,
|
|
AuthUser(uid): AuthUser,
|
|
Json(body): Json<ActorUrlBody>,
|
|
) -> Result<StatusCode, ApiError> {
|
|
accept_follow_request(&*s.federation, &uid, &body.actor_url).await?;
|
|
Ok(StatusCode::NO_CONTENT)
|
|
}
|
|
|
|
pub async fn delete_follower(
|
|
State(s): State<AppState>,
|
|
AuthUser(uid): AuthUser,
|
|
Json(body): Json<ActorUrlBody>,
|
|
) -> Result<StatusCode, ApiError> {
|
|
reject_follow_request(&*s.federation, &uid, &body.actor_url).await?;
|
|
Ok(StatusCode::NO_CONTENT)
|
|
}
|
|
|
|
pub async fn get_remote_followers(
|
|
State(s): State<AppState>,
|
|
AuthUser(uid): AuthUser,
|
|
) -> Result<Json<Vec<RemoteActorResponse>>, ApiError> {
|
|
let actors = list_remote_followers(&*s.federation, &uid).await?;
|
|
Ok(Json(actors.into_iter().map(to_response).collect()))
|
|
}
|
|
|
|
pub async fn get_remote_following(
|
|
State(s): State<AppState>,
|
|
AuthUser(uid): AuthUser,
|
|
) -> Result<Json<Vec<RemoteActorResponse>>, ApiError> {
|
|
let actors = list_remote_following(&*s.federation, &uid).await?;
|
|
Ok(Json(actors.into_iter().map(to_response).collect()))
|
|
}
|
|
|
|
pub async fn delete_following(
|
|
State(s): State<AppState>,
|
|
AuthUser(uid): AuthUser,
|
|
Json(body): Json<HandleBody>,
|
|
) -> Result<StatusCode, ApiError> {
|
|
remove_remote_following(
|
|
&*s.follows,
|
|
&*s.users,
|
|
&*s.federation,
|
|
&*s.events,
|
|
&uid,
|
|
&body.handle,
|
|
)
|
|
.await?;
|
|
Ok(StatusCode::NO_CONTENT)
|
|
}
|