mirror of
https://github.com/Nutomic/ibis.git
synced 2024-11-22 18:31:10 +00:00
change follow response
This commit is contained in:
parent
688ead9217
commit
f9f83974d3
3 changed files with 22 additions and 25 deletions
|
@ -1,6 +1,9 @@
|
|||
use crate::{
|
||||
backend::{database::IbisData, error::MyResult, federation::activities::follow::Follow},
|
||||
common::{DbInstance, FollowInstance, GetInstance, InstanceView, LocalUserView, ResolveObject},
|
||||
common::{
|
||||
DbInstance, FollowInstance, FollowInstanceResponse, GetInstance, InstanceView,
|
||||
LocalUserView, ResolveObject,
|
||||
},
|
||||
};
|
||||
use activitypub_federation::{config::Data, fetch::object_id::ObjectId};
|
||||
use axum::{extract::Query, Extension, Form, Json};
|
||||
|
@ -23,13 +26,13 @@ pub(in crate::backend::api) async fn follow_instance(
|
|||
Extension(user): Extension<LocalUserView>,
|
||||
data: Data<IbisData>,
|
||||
Form(query): Form<FollowInstance>,
|
||||
) -> MyResult<()> {
|
||||
) -> MyResult<Json<FollowInstanceResponse>> {
|
||||
let target = DbInstance::read(query.id, &data)?;
|
||||
let pending = !target.local;
|
||||
DbInstance::follow(&user.person, &target, pending, &data)?;
|
||||
let instance = DbInstance::read(query.id, &data)?;
|
||||
Follow::send(user.person, &instance, &data).await?;
|
||||
Ok(())
|
||||
Ok(Json(FollowInstanceResponse { success: true }))
|
||||
}
|
||||
|
||||
/// Fetch a remote instance actor. This automatically synchronizes the remote articles collection to
|
||||
|
|
|
@ -244,6 +244,11 @@ pub struct FollowInstance {
|
|||
pub id: InstanceId,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
pub struct FollowInstanceResponse {
|
||||
pub success: bool
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Clone, Debug)]
|
||||
pub struct SearchArticleForm {
|
||||
pub query: String,
|
||||
|
|
|
@ -3,10 +3,10 @@ use crate::{
|
|||
newtypes::{ArticleId, ConflictId},
|
||||
utils::http_protocol_str,
|
||||
ApiConflict, ApproveArticleForm, ArticleView, CreateArticleForm, DbArticle, DbInstance,
|
||||
DbPerson, DeleteConflictForm, EditArticleForm, FollowInstance, ForkArticleForm,
|
||||
GetArticleForm, GetInstance, GetUserForm, InstanceView, ListArticlesForm, LocalUserView,
|
||||
LoginUserForm, Notification, ProtectArticleForm, RegisterUserForm, ResolveObject,
|
||||
SearchArticleForm, SiteView,
|
||||
DbPerson, DeleteConflictForm, EditArticleForm, FollowInstance, FollowInstanceResponse,
|
||||
ForkArticleForm, GetArticleForm, GetInstance, GetUserForm, InstanceView, ListArticlesForm,
|
||||
LocalUserView, LoginUserForm, Notification, ProtectArticleForm, RegisterUserForm,
|
||||
ResolveObject, SearchArticleForm, SiteView,
|
||||
},
|
||||
frontend::error::MyResult,
|
||||
};
|
||||
|
@ -164,22 +164,12 @@ impl ApiClient {
|
|||
Ok(instance_resolved)
|
||||
}
|
||||
|
||||
pub async fn follow_instance(&self, follow_form: FollowInstance) -> MyResult<()> {
|
||||
todo!();
|
||||
/*
|
||||
// cant use post helper because follow doesnt return json
|
||||
let res = self
|
||||
.client
|
||||
.post(self.request_endpoint("/api/v1/instance/follow"))
|
||||
.form(&follow_form)
|
||||
.send()
|
||||
.await?;
|
||||
if res.status() == StatusCode::OK {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!("API error: {}", res.text().await?).into())
|
||||
}
|
||||
*/
|
||||
pub async fn follow_instance(
|
||||
&self,
|
||||
follow_form: FollowInstance,
|
||||
) -> MyResult<FollowInstanceResponse> {
|
||||
self.post("/api/v1/instance/follow", Some(follow_form))
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn site(&self) -> MyResult<SiteView> {
|
||||
|
@ -268,8 +258,7 @@ impl ApiClient {
|
|||
use gloo_net::http::*;
|
||||
use leptos::prelude::on_cleanup;
|
||||
use send_wrapper::SendWrapper;
|
||||
use std::collections::HashMap;
|
||||
use web_sys::{RequestCredentials, UrlSearchParams};
|
||||
use web_sys::RequestCredentials;
|
||||
|
||||
SendWrapper::new(async move {
|
||||
let abort_controller = SendWrapper::new(web_sys::AbortController::new().ok());
|
||||
|
|
Loading…
Reference in a new issue