mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-09-03 03:33:50 +00:00
parent
7e55a39677
commit
cc61b70b29
5 changed files with 41 additions and 15 deletions
|
@ -91,7 +91,8 @@ pub async fn like_comment(
|
|||
object_id: orig_comment.comment.ap_id,
|
||||
actor: local_user_view.person.clone(),
|
||||
community: orig_comment.community,
|
||||
score: data.score,
|
||||
previous_score: orig_comment.comment_actions.and_then(|a| a.like_score),
|
||||
new_score: data.score,
|
||||
},
|
||||
&context,
|
||||
)?;
|
||||
|
|
|
@ -41,9 +41,10 @@ pub async fn like_post(
|
|||
check_bot_account(&local_user_view.person)?;
|
||||
|
||||
// Check for a community ban
|
||||
let post = PostView::read(&mut context.pool(), post_id, None, local_instance_id, false).await?;
|
||||
let orig_post =
|
||||
PostView::read(&mut context.pool(), post_id, None, local_instance_id, false).await?;
|
||||
|
||||
check_community_user_action(&local_user_view, &post.community, &mut context.pool()).await?;
|
||||
check_community_user_action(&local_user_view, &orig_post.community, &mut context.pool()).await?;
|
||||
|
||||
let mut like_form = PostLikeForm::new(data.post_id, local_user_view.person.id, data.score);
|
||||
|
||||
|
@ -67,13 +68,20 @@ pub async fn like_post(
|
|||
|
||||
ActivityChannel::submit_activity(
|
||||
SendActivityData::LikePostOrComment {
|
||||
object_id: post.post.ap_id,
|
||||
object_id: orig_post.post.ap_id,
|
||||
actor: local_user_view.person.clone(),
|
||||
community: post.community.clone(),
|
||||
score: data.score,
|
||||
community: orig_post.community.clone(),
|
||||
previous_score: orig_post.post_actions.and_then(|a| a.like_score),
|
||||
new_score: data.score,
|
||||
},
|
||||
&context,
|
||||
)?;
|
||||
|
||||
build_post_response(context.deref(), post.community.id, local_user_view, post_id).await
|
||||
build_post_response(
|
||||
context.deref(),
|
||||
orig_post.community.id,
|
||||
local_user_view,
|
||||
post_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
|
|
@ -61,7 +61,8 @@ pub enum SendActivityData {
|
|||
object_id: DbUrl,
|
||||
actor: Person,
|
||||
community: Community,
|
||||
score: i16,
|
||||
previous_score: Option<i16>,
|
||||
new_score: i16,
|
||||
},
|
||||
FollowCommunity(Community, Person, bool),
|
||||
FollowMultiCommunity(MultiCommunity, Person, bool),
|
||||
|
|
|
@ -256,8 +256,19 @@ pub async fn match_outgoing_activities(
|
|||
object_id,
|
||||
actor,
|
||||
community,
|
||||
score,
|
||||
} => send_like_activity(object_id, actor, community, score, context).await,
|
||||
previous_score,
|
||||
new_score,
|
||||
} => {
|
||||
send_like_activity(
|
||||
object_id,
|
||||
actor,
|
||||
community,
|
||||
previous_score,
|
||||
new_score,
|
||||
context,
|
||||
)
|
||||
.await
|
||||
}
|
||||
FollowCommunity(community, person, follow) => {
|
||||
send_follow(Either::Left(community.into()), person, follow, &context).await
|
||||
}
|
||||
|
|
|
@ -38,7 +38,8 @@ pub(crate) async fn send_like_activity(
|
|||
object_id: DbUrl,
|
||||
actor: Person,
|
||||
community: Community,
|
||||
score: i16,
|
||||
previous_score: Option<i16>,
|
||||
new_score: i16,
|
||||
context: Data<LemmyContext>,
|
||||
) -> LemmyResult<()> {
|
||||
let object_id: ObjectId<PostOrComment> = object_id.into();
|
||||
|
@ -47,13 +48,17 @@ pub(crate) async fn send_like_activity(
|
|||
|
||||
let empty = ActivitySendTargets::empty();
|
||||
// score of 1 means upvote, -1 downvote, 0 undo a previous vote
|
||||
if score != 0 {
|
||||
let vote = Vote::new(object_id, &actor, score.try_into()?, &context)?;
|
||||
if new_score != 0 {
|
||||
let vote = Vote::new(object_id, &actor, new_score.try_into()?, &context)?;
|
||||
let activity = AnnouncableActivities::Vote(vote);
|
||||
send_activity_in_community(activity, &actor, &community, empty, false, &context).await
|
||||
} else {
|
||||
// Lemmy API doesn't distinguish between Undo/Like and Undo/Dislike, so we hardcode it here.
|
||||
let vote = Vote::new(object_id, &actor, VoteType::Like, &context)?;
|
||||
let previous_vote_type = if previous_score.unwrap_or_default() > 0 {
|
||||
VoteType::Like
|
||||
} else {
|
||||
VoteType::Dislike
|
||||
};
|
||||
let vote = Vote::new(object_id, &actor, previous_vote_type, &context)?;
|
||||
let undo_vote = UndoVote::new(vote, &actor, &context)?;
|
||||
let activity = AnnouncableActivities::UndoVote(undo_vote);
|
||||
send_activity_in_community(activity, &actor, &community, empty, false, &context).await
|
||||
|
|
Loading…
Reference in a new issue