This commit is contained in:
Felix Ableitner 2024-05-02 16:28:12 +02:00
parent 3bc61dd40d
commit 3fefc89a2e
2 changed files with 6 additions and 9 deletions

View file

@ -233,6 +233,10 @@ impl ActivityHandler for Page {
#[async_trait::async_trait] #[async_trait::async_trait]
impl InCommunity for Page { impl InCommunity for Page {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> { async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
if let Some(audience) = &self.audience {
return audience.dereference(context).await;
}
let community = match &self.attributed_to { let community = match &self.attributed_to {
AttributedTo::Lemmy(_) => { AttributedTo::Lemmy(_) => {
let mut iter = self.to.iter().merge(self.cc.iter()); let mut iter = self.to.iter().merge(self.cc.iter());
@ -243,11 +247,7 @@ impl InCommunity for Page {
break c; break c;
} }
} else { } else {
let audience = self Err(LemmyErrorType::CouldntFindCommunity)?;
.audience
.clone()
.ok_or(LemmyErrorType::NoCommunityFoundInCc)?;
break audience.dereference(context).await?;
} }
} }
} }
@ -255,13 +255,12 @@ impl InCommunity for Page {
p.iter() p.iter()
.find(|a| a.kind == PersonOrGroupType::Group) .find(|a| a.kind == PersonOrGroupType::Group)
.map(|a| ObjectId::<ApubCommunity>::from(a.id.clone().into_inner())) .map(|a| ObjectId::<ApubCommunity>::from(a.id.clone().into_inner()))
.ok_or(LemmyErrorType::PageDoesNotSpecifyGroup)? .ok_or(LemmyErrorType::CouldntFindCommunity)?
.dereference(context) .dereference(context)
.await? .await?
} }
}; };
// TODO: doesnt make sense to do this here as were checking audience against itself
if let Some(audience) = &self.audience { if let Some(audience) = &self.audience {
verify_community_matches(audience, community.actor_id.clone())?; verify_community_matches(audience, community.actor_id.clone())?;
} }

View file

@ -99,8 +99,6 @@ pub enum LemmyErrorType {
PersonIsBannedFromSite(String), PersonIsBannedFromSite(String),
InvalidVoteValue, InvalidVoteValue,
PageDoesNotSpecifyCreator, PageDoesNotSpecifyCreator,
PageDoesNotSpecifyGroup,
NoCommunityFoundInCc,
NoEmailSetup, NoEmailSetup,
LocalSiteNotSetup, LocalSiteNotSetup,
EmailSmtpServerNeedsAPort, EmailSmtpServerNeedsAPort,