diff --git a/Cargo.lock b/Cargo.lock index c5f984783..99fcd4e24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -397,15 +397,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "ansi_term" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -dependencies = [ - "winapi 0.3.9", -] - [[package]] name = "anyhow" version = "1.0.33" @@ -777,21 +768,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "clap" -version = "2.33.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" -dependencies = [ - "ansi_term", - "atty", - "bitflags 1.2.1", - "strsim 0.8.0", - "textwrap", - "unicode-width", - "vec_map", -] - [[package]] name = "cloudabi" version = "0.1.0" @@ -813,7 +789,6 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d325e4f2ffff52ca77d995bb675494d5364aa332499d5f7c7fbb28c25e671f6" dependencies = [ - "clap", "entities", "lazy_static", "pest", @@ -980,7 +955,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim 0.9.3", + "strsim", "syn", ] @@ -3166,12 +3141,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" -[[package]] -name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - [[package]] name = "strsim" version = "0.9.3" @@ -3230,15 +3199,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - [[package]] name = "thiserror" version = "1.0.21" @@ -3565,12 +3525,6 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" -[[package]] -name = "unicode-width" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" - [[package]] name = "unicode-xid" version = "0.2.1" @@ -3649,12 +3603,6 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "version_check" version = "0.1.5" diff --git a/lemmy_apub/src/fetcher.rs b/lemmy_apub/src/fetcher.rs index b4598ea37..e66ad7fd7 100644 --- a/lemmy_apub/src/fetcher.rs +++ b/lemmy_apub/src/fetcher.rs @@ -136,6 +136,22 @@ pub async fn search_by_apub_id( Url::parse(&query)? }; + let recursion_counter = &mut 0; + let search_result = + fetch_remote_object::(context.client(), &query_url, recursion_counter) + .await?; + let response = match_search_result(context, search_result, query_url, recursion_counter).await?; + + Ok(response) +} + +async fn match_search_result( + context: &LemmyContext, + search_result: SearchAcceptedObjects, + query_url: Url, + recursion_counter: &mut i32, +) -> Result { + let domain = query_url.domain().context("url has no domain")?; let mut response = SearchResponse { type_: SearchType::All.to_string(), comments: vec![], @@ -144,15 +160,7 @@ pub async fn search_by_apub_id( users: vec![], }; - let domain = query_url.domain().context("url has no domain")?; - let recursion_counter = &mut 0; - let response = match fetch_remote_object::( - context.client(), - &query_url, - recursion_counter, - ) - .await? - { + match search_result { SearchAcceptedObjects::Person(p) => { let user_uri = p.inner.id(domain)?.context("person has no id")?; @@ -164,8 +172,6 @@ pub async fn search_by_apub_id( }) .await??, ]; - - response } SearchAcceptedObjects::Group(g) => { let community_uri = g.inner.id(domain)?.context("group has no id")?; @@ -179,8 +185,6 @@ pub async fn search_by_apub_id( }) .await??, ]; - - response } SearchAcceptedObjects::Page(p) => { let post_form = PostForm::from_apub(&p, context, Some(query_url), recursion_counter).await?; @@ -188,8 +192,6 @@ pub async fn search_by_apub_id( let p = blocking(context.pool(), move |conn| Post::upsert(conn, &post_form)).await??; response.posts = vec![blocking(context.pool(), move |conn| PostView::read(conn, p.id, None)).await??]; - - response } SearchAcceptedObjects::Comment(c) => { let comment_form = @@ -205,8 +207,6 @@ pub async fn search_by_apub_id( }) .await??, ]; - - response } }; @@ -391,7 +391,17 @@ async fn fetch_remote_community( .await??; } - // fetch outbox (maybe make this conditional) + // maybe make this conditional + fetch_community_outbox(context, &community, recursion_counter).await?; + + Ok(community) +} + +async fn fetch_community_outbox( + context: &LemmyContext, + community: &Community, + recursion_counter: &mut i32, +) -> Result<(), LemmyError> { let outbox = fetch_remote_object::( context.client(), &community.get_outbox_url()?, @@ -425,7 +435,7 @@ async fn fetch_remote_community( // TODO: we need to send a websocket update here } - Ok(community) + Ok(()) } /// Gets a post by its apub ID. If it exists locally, it is returned directly. Otherwise it is diff --git a/lemmy_utils/Cargo.toml b/lemmy_utils/Cargo.toml index 1d5a6b0d9..b0a0f3e6b 100644 --- a/lemmy_utils/Cargo.toml +++ b/lemmy_utils/Cargo.toml @@ -19,7 +19,7 @@ percent-encoding = "2.1" serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0", features = ["preserve_order"]} thiserror = "1.0" -comrak = "0.8" +comrak = { version = "0.8", default-features = false } lazy_static = "1.3" openssl = "0.10" url = { version = "2.1", features = ["serde"] }