Skip to content

Commit

Permalink
fix: awa
Browse files Browse the repository at this point in the history
  • Loading branch information
CutestNekoAqua committed Aug 3, 2024
1 parent 01ba543 commit f7be000
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
23 changes: 23 additions & 0 deletions src/lysand/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 3 additions & 6 deletions src/lysand/inbox.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit f7be000

Please sign in to comment.