mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-02 16:21:32 -08:00
apf part 19: Undo / Like requests
This commit is contained in:
parent
e533603f4d
commit
30dba0acf2
2 changed files with 18 additions and 16 deletions
|
@ -841,6 +841,17 @@ def process_inbox_request(request_json, store_ap_json):
|
|||
log_incoming_ap(request_json['id'], APLOG_UNDO_DELETE, APLOG_FAILURE, request_json if store_ap_json else None, 'Undo delete: cannot find ' + ap_id)
|
||||
return
|
||||
|
||||
if request_json['object']['type'] == 'Like' or request_json['object']['type'] == 'Dislike': # Undoing an upvote or downvote
|
||||
post = comment = None
|
||||
target_ap_id = request_json['object']['object']
|
||||
post_or_comment = undo_vote(comment, post, target_ap_id, user)
|
||||
if post_or_comment:
|
||||
log_incoming_ap(request_json['id'], APLOG_UNDO_VOTE, APLOG_SUCCESS, request_json if store_ap_json else None)
|
||||
announce_activity_to_followers(post_or_comment.community, user, request_json)
|
||||
else:
|
||||
log_incoming_ap(request_json['id'], APLOG_UNDO_VOTE, APLOG_FAILURE, request_json if store_ap_json else None, 'Unfound object ' + target_ap_id)
|
||||
return
|
||||
|
||||
|
||||
# -- below this point is code that will be incrementally replaced to use log_incoming_ap() instead --
|
||||
|
||||
|
|
|
@ -1969,11 +1969,10 @@ def undo_downvote(activity_log, comment, post, target_ap_id, user):
|
|||
return post
|
||||
|
||||
|
||||
def undo_vote(activity_log, comment, post, target_ap_id, user):
|
||||
def undo_vote(comment, post, target_ap_id, user):
|
||||
voted_on = find_liked_object(target_ap_id)
|
||||
if (user and not user.is_local()) and isinstance(voted_on, Post):
|
||||
if isinstance(voted_on, Post):
|
||||
post = voted_on
|
||||
user.last_seen = utcnow()
|
||||
existing_vote = PostVote.query.filter_by(user_id=user.id, post_id=post.id).first()
|
||||
if existing_vote:
|
||||
post.author.reputation -= existing_vote.effect
|
||||
|
@ -1983,8 +1982,9 @@ def undo_vote(activity_log, comment, post, target_ap_id, user):
|
|||
post.up_votes -= 1
|
||||
post.score -= existing_vote.effect
|
||||
db.session.delete(existing_vote)
|
||||
activity_log.result = 'success'
|
||||
if (user and not user.is_local()) and isinstance(voted_on, PostReply):
|
||||
db.session.commit()
|
||||
return post
|
||||
if isinstance(voted_on, PostReply):
|
||||
comment = voted_on
|
||||
existing_vote = PostReplyVote.query.filter_by(user_id=user.id, post_reply_id=comment.id).first()
|
||||
if existing_vote:
|
||||
|
@ -1995,18 +1995,9 @@ def undo_vote(activity_log, comment, post, target_ap_id, user):
|
|||
comment.up_votes -= 1
|
||||
comment.score -= existing_vote.effect
|
||||
db.session.delete(existing_vote)
|
||||
activity_log.result = 'success'
|
||||
|
||||
if user is None or (post is None and comment is None):
|
||||
activity_log.exception_message = 'Blocked or unfound user or comment'
|
||||
if user and user.is_local():
|
||||
activity_log.exception_message = 'Activity about local content which is already present'
|
||||
activity_log.result = 'ignored'
|
||||
|
||||
if post:
|
||||
return post
|
||||
if comment:
|
||||
db.session.commit()
|
||||
return comment
|
||||
|
||||
return None
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue