mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-01-08 11:11:37 +00:00
Fix handling of apub downvote (fixes #4545)
This commit is contained in:
parent
0f77951e05
commit
6192dd31e8
1 changed files with 18 additions and 13 deletions
|
@ -2,7 +2,7 @@ use crate::{
|
||||||
activities::{
|
activities::{
|
||||||
generate_activity_id,
|
generate_activity_id,
|
||||||
verify_person_in_community,
|
verify_person_in_community,
|
||||||
voting::{vote_comment, vote_post},
|
voting::{undo_vote_comment, undo_vote_post, vote_comment, vote_post},
|
||||||
},
|
},
|
||||||
insert_received_activity,
|
insert_received_activity,
|
||||||
objects::{community::ApubCommunity, person::ApubPerson},
|
objects::{community::ApubCommunity, person::ApubPerson},
|
||||||
|
@ -58,15 +58,7 @@ impl ActivityHandler for Vote {
|
||||||
async fn verify(&self, context: &Data<LemmyContext>) -> Result<(), LemmyError> {
|
async fn verify(&self, context: &Data<LemmyContext>) -> Result<(), LemmyError> {
|
||||||
let community = self.community(context).await?;
|
let community = self.community(context).await?;
|
||||||
verify_person_in_community(&self.actor, &community, context).await?;
|
verify_person_in_community(&self.actor, &community, context).await?;
|
||||||
let enable_downvotes = LocalSite::read(&mut context.pool())
|
Ok(())
|
||||||
.await
|
|
||||||
.map(|l| l.enable_downvotes)
|
|
||||||
.unwrap_or(true);
|
|
||||||
if self.kind == VoteType::Dislike && !enable_downvotes {
|
|
||||||
Err(anyhow!("Downvotes disabled").into())
|
|
||||||
} else {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
|
@ -77,9 +69,22 @@ impl ActivityHandler for Vote {
|
||||||
|
|
||||||
check_bot_account(&actor.0)?;
|
check_bot_account(&actor.0)?;
|
||||||
|
|
||||||
match object {
|
let enable_downvotes = LocalSite::read(&mut context.pool())
|
||||||
PostOrComment::Post(p) => vote_post(&self.kind, actor, &p, context).await,
|
.await
|
||||||
PostOrComment::Comment(c) => vote_comment(&self.kind, actor, &c, context).await,
|
.map(|l| l.enable_downvotes)
|
||||||
|
.unwrap_or(true);
|
||||||
|
if self.kind == VoteType::Dislike && !enable_downvotes {
|
||||||
|
// If this is a downvote but downvotes are ignored, only undo any existing vote
|
||||||
|
match object {
|
||||||
|
PostOrComment::Post(p) => undo_vote_post(actor, &p, context).await,
|
||||||
|
PostOrComment::Comment(c) => undo_vote_comment(actor, &c, context).await,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Otherwise apply the vote normally
|
||||||
|
match object {
|
||||||
|
PostOrComment::Post(p) => vote_post(&self.kind, actor, &p, context).await,
|
||||||
|
PostOrComment::Comment(c) => vote_comment(&self.kind, actor, &c, context).await,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue