From 542e59bcaed256c88a9d974e6c6c3dc59f7ebbc9 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Tue, 12 Nov 2024 18:43:24 +0100 Subject: [PATCH] Fetch community mods synchronously (#5169) * Fetch community mods synchronously * fix * fix --------- Co-authored-by: Dessalines --- crates/apub/src/objects/community.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index efa2c5247..2a9abc939 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -194,10 +194,16 @@ impl Object for ApubCommunity { LanguageTag::to_language_id_multiple(group.language, &mut context.pool()).await?; let timestamp = group.updated.or(group.published).unwrap_or_else(naive_now); - let community = Community::insert_apub(&mut context.pool(), timestamp, &form).await?; + let community: ApubCommunity = Community::insert_apub(&mut context.pool(), timestamp, &form) + .await? + .into(); CommunityLanguage::update(&mut context.pool(), languages, community.id).await?; - let community: ApubCommunity = community.into(); + // Need to fetch mods synchronously, otherwise fetching a post in community with + // `posting_restricted_to_mods` can fail if mods havent been fetched yet. + if let Some(moderators) = group.attributed_to { + moderators.dereference(&community, context).await.ok(); + } // These collections are not necessary for Lemmy to work, so ignore errors. let community_ = community.clone(); @@ -210,9 +216,6 @@ impl Object for ApubCommunity { if let Some(featured) = group.featured { featured.dereference(&community_, &context_).await.ok(); } - if let Some(moderators) = group.attributed_to { - moderators.dereference(&community_, &context_).await.ok(); - } Ok(()) });