This commit is contained in:
aprilthepink 2024-08-03 08:05:17 +02:00
parent 01ba54328e
commit f7be000097
2 changed files with 26 additions and 6 deletions

View file

@ -230,6 +230,29 @@ pub async fn lysand_url_to_user_and_model(
let db = DB.get().unwrap();
let data = FEDERATION_CONFIG.get().unwrap();
let opt_model = prelude::User::find()
.filter(user::Column::Url.eq(url.as_str()))
.one(db)
.await?;
let target;
if let Some(model) = opt_model {
target = model;
} else {
target = ObjectId::<user::Model>::from(url)
.dereference(&data.to_request_data())
.await
.unwrap();
}
Ok((lysand_user_from_db(target.clone()).await?, target))
}
pub async fn main_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();
let opt_model = prelude::User::find()
.filter(user::Column::Url.eq(url.as_str()))
.one(db)

View file

@ -1,12 +1,9 @@
use crate::{
activities::follow::Follow,
entities::{
activities::follow::Follow, entities::{
self, follow_relation,
prelude::{self, FollowRelation},
user,
},
utils::generate_follow_req_id,
DB, FEDERATION_CONFIG,
}, lysand::http::main_lysand_url_to_user_and_model, utils::generate_follow_req_id, DB, FEDERATION_CONFIG
};
use activitypub_federation::{
activity_sending::SendActivityTask, fetch::object_id::ObjectId, protocol::context::WithContext,
@ -75,7 +72,7 @@ async fn follow_request(follow: super::objects::Follow) -> Result<()> {
));
}
let data = FEDERATION_CONFIG.get().unwrap();
let author = lysand_url_to_user_and_model(follow.author.into()).await?;
let author = main_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(),