2024-01-03 12:29:25 +00:00
|
|
|
use crate::backend::database::instance::{DbInstance, InstanceView};
|
|
|
|
use crate::backend::database::user::LocalUserView;
|
|
|
|
use crate::backend::database::MyDataHandle;
|
|
|
|
use crate::backend::error::MyResult;
|
|
|
|
use crate::backend::federation::activities::follow::Follow;
|
2023-12-13 12:32:44 +00:00
|
|
|
use activitypub_federation::config::Data;
|
2023-12-14 16:06:44 +00:00
|
|
|
use axum::Extension;
|
2023-12-13 12:32:44 +00:00
|
|
|
use axum::{Form, Json};
|
|
|
|
use axum_macros::debug_handler;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
/// Retrieve the local instance info.
|
|
|
|
#[debug_handler]
|
2024-01-03 12:29:25 +00:00
|
|
|
pub(in crate::backend::api) async fn get_local_instance(
|
2023-12-13 12:32:44 +00:00
|
|
|
data: Data<MyDataHandle>,
|
|
|
|
) -> MyResult<Json<InstanceView>> {
|
|
|
|
let local_instance = DbInstance::read_local_view(&data.db_connection)?;
|
|
|
|
Ok(Json(local_instance))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize, Debug)]
|
|
|
|
pub struct FollowInstance {
|
|
|
|
pub id: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Make the local instance follow a given remote instance, to receive activities about new and
|
|
|
|
/// updated articles.
|
|
|
|
#[debug_handler]
|
2024-01-03 12:29:25 +00:00
|
|
|
pub(in crate::backend::api) async fn follow_instance(
|
2023-12-14 16:06:44 +00:00
|
|
|
Extension(user): Extension<LocalUserView>,
|
2023-12-13 12:32:44 +00:00
|
|
|
data: Data<MyDataHandle>,
|
|
|
|
Form(query): Form<FollowInstance>,
|
|
|
|
) -> MyResult<()> {
|
|
|
|
let target = DbInstance::read(query.id, &data.db_connection)?;
|
|
|
|
let pending = !target.local;
|
2023-12-14 16:06:44 +00:00
|
|
|
DbInstance::follow(&user.person, &target, pending, &data)?;
|
2023-12-13 12:32:44 +00:00
|
|
|
let instance = DbInstance::read(query.id, &data.db_connection)?;
|
2023-12-14 16:06:44 +00:00
|
|
|
Follow::send(user.person, instance, &data).await?;
|
2023-12-13 12:32:44 +00:00
|
|
|
Ok(())
|
|
|
|
}
|