mirror of
https://github.com/versia-pub/activitypub.git
synced 2025-12-06 06:38:20 +01:00
fmt: codebase
This commit is contained in:
parent
12dc5e89d0
commit
b666d339f2
|
|
@ -172,6 +172,5 @@ async fn save_follow(
|
|||
// modify db entry
|
||||
let res = prelude::FollowRelation::update(query.unwrap());
|
||||
|
||||
|
||||
Ok(model)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,8 +88,6 @@ async fn lysand_inbox(
|
|||
body: web::Bytes,
|
||||
state: web::Data<State>,
|
||||
) -> actix_web::Result<HttpResponse, error::Error> {
|
||||
|
||||
|
||||
Ok(HttpResponse::Created().finish())
|
||||
}
|
||||
|
||||
|
|
@ -212,13 +210,16 @@ pub async fn lysand_url_to_user(url: Url) -> anyhow::Result<super::objects::User
|
|||
} else {
|
||||
target = ObjectId::<user::Model>::from(url)
|
||||
.dereference(&data.to_request_data())
|
||||
.await.unwrap();
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
Ok(lysand_user_from_db(target).await?)
|
||||
}
|
||||
|
||||
pub async fn lysand_url_to_user_and_model(url: Url) -> anyhow::Result<(super::objects::User, user::Model)> {
|
||||
pub async fn lysand_url_to_user_and_model(
|
||||
url: Url,
|
||||
) -> anyhow::Result<(super::objects::User, user::Model)> {
|
||||
let db = DB.get().unwrap();
|
||||
let data = FEDERATION_CONFIG.get().unwrap();
|
||||
|
||||
|
|
@ -232,7 +233,8 @@ pub async fn lysand_url_to_user_and_model(url: Url) -> anyhow::Result<(super::ob
|
|||
} else {
|
||||
target = ObjectId::<user::Model>::from(url)
|
||||
.dereference(&data.to_request_data())
|
||||
.await.unwrap();
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
Ok((lysand_user_from_db(target.clone()).await?, target))
|
||||
|
|
|
|||
|
|
@ -1,13 +1,27 @@
|
|||
|
||||
use activitypub_federation::{activity_sending::SendActivityTask, fetch::object_id::ObjectId, protocol::context::WithContext};
|
||||
use crate::{
|
||||
activities::follow::Follow,
|
||||
entities::{
|
||||
self, follow_relation,
|
||||
prelude::{self, FollowRelation},
|
||||
user,
|
||||
},
|
||||
utils::generate_follow_req_id,
|
||||
DB, FEDERATION_CONFIG,
|
||||
};
|
||||
use activitypub_federation::{
|
||||
activity_sending::SendActivityTask, fetch::object_id::ObjectId, protocol::context::WithContext,
|
||||
};
|
||||
use activitystreams_kinds::activity::FollowType;
|
||||
use anyhow::Result;
|
||||
use sea_orm::{ActiveModelTrait, ColumnTrait, EntityOrSelect, EntityTrait, QueryFilter, Set};
|
||||
use serde::Deserialize;
|
||||
use url::Url;
|
||||
use crate::{activities::follow::Follow, entities::{self, follow_relation, prelude::{self, FollowRelation}, user}, utils::generate_follow_req_id, DB, FEDERATION_CONFIG};
|
||||
|
||||
use super::{conversion::lysand_user_from_db, http::{lysand_url_to_user, lysand_url_to_user_and_model}, objects::LysandType};
|
||||
use super::{
|
||||
conversion::lysand_user_from_db,
|
||||
http::{lysand_url_to_user, lysand_url_to_user_and_model},
|
||||
objects::LysandType,
|
||||
};
|
||||
|
||||
pub async fn inbox_entry(json: &str) -> Result<()> {
|
||||
// Deserialize the JSON string into a dynamic value
|
||||
|
|
@ -19,27 +33,25 @@ pub async fn inbox_entry(json: &str) -> Result<()> {
|
|||
match json_type.as_str() {
|
||||
Some("Note") => {
|
||||
let note: super::objects::Note = serde_json::from_str(json)?;
|
||||
|
||||
}
|
||||
Some("Patch") => {
|
||||
let patch: super::objects::Patch = serde_json::from_str(json)?;
|
||||
|
||||
}
|
||||
Some("Follow") => {
|
||||
let follow_req: super::objects::Follow = serde_json::from_str(json)?;
|
||||
|
||||
}
|
||||
Some("FollowAccept") => {
|
||||
let follow_accept: super::objects::FollowResult = serde_json::from_str(json)?;
|
||||
|
||||
}
|
||||
Some("FollowReject") => {
|
||||
let follow_rej: super::objects::FollowResult = serde_json::from_str(json)?;
|
||||
|
||||
}
|
||||
// Add more cases for other types as needed
|
||||
_ => {
|
||||
return Err(anyhow::anyhow!("Unknown 'type' field in JSON, it is {}", json_type));
|
||||
return Err(anyhow::anyhow!(
|
||||
"Unknown 'type' field in JSON, it is {}",
|
||||
json_type
|
||||
));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -57,20 +69,29 @@ async fn follow_request(follow: super::objects::Follow) -> Result<()> {
|
|||
.one(db)
|
||||
.await?;
|
||||
if query.is_some() {
|
||||
return Err(anyhow::anyhow!("User is already follow requesting / following the followee"));
|
||||
return Err(anyhow::anyhow!(
|
||||
"User is already follow requesting / following the followee"
|
||||
));
|
||||
}
|
||||
let data = FEDERATION_CONFIG.get().unwrap();
|
||||
let author = lysand_url_to_user_and_model(follow.author.into()).await?;
|
||||
let followee = lysand_url_to_user_and_model(follow.followee.into()).await?;
|
||||
let serial_ap_author = serde_json::from_str::<crate::objects::person::Person>(&(author.1.ap_json.clone()).unwrap())?;
|
||||
let serial_ap_followee = serde_json::from_str::<crate::objects::person::Person>(&(followee.1.ap_json.clone()).unwrap())?;
|
||||
let serial_ap_author = serde_json::from_str::<crate::objects::person::Person>(
|
||||
&(author.1.ap_json.clone()).unwrap(),
|
||||
)?;
|
||||
let serial_ap_followee = serde_json::from_str::<crate::objects::person::Person>(
|
||||
&(followee.1.ap_json.clone()).unwrap(),
|
||||
)?;
|
||||
|
||||
let id = uuid::Uuid::now_v7().to_string();
|
||||
|
||||
let followee_object: ObjectId<user::Model> = serial_ap_followee.url.into();
|
||||
let localuser_object: ObjectId<user::Model> = serial_ap_author.url.into();
|
||||
|
||||
println!("Sending follow request to {}", &followee.0.display_name.unwrap_or(followee.0.username));
|
||||
println!(
|
||||
"Sending follow request to {}",
|
||||
&followee.0.display_name.unwrap_or(followee.0.username)
|
||||
);
|
||||
let create = Follow {
|
||||
actor: localuser_object.clone(),
|
||||
object: followee_object.clone(),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
pub mod conversion;
|
||||
pub mod funcs;
|
||||
pub mod http;
|
||||
pub mod inbox;
|
||||
pub mod objects;
|
||||
pub mod superx;
|
||||
pub mod test;
|
||||
pub mod inbox;
|
||||
|
|
@ -289,7 +289,10 @@ async fn main() -> actix_web::Result<(), anyhow::Error> {
|
|||
.service(follow_manually)
|
||||
.route("/{user}", web::get().to(http_get_user))
|
||||
.route("/{user}/inbox", web::post().to(http_post_user_inbox))
|
||||
.route("/apbridge/{user}/inbox", web::post().to(http_post_user_inbox))
|
||||
.route(
|
||||
"/apbridge/{user}/inbox",
|
||||
web::post().to(http_post_user_inbox),
|
||||
)
|
||||
.route("/.well-known/webfinger", web::get().to(webfinger))
|
||||
.service(index)
|
||||
.service(fetch_post)
|
||||
|
|
|
|||
Loading…
Reference in a new issue