announce undo vote

This commit is contained in:
rimu 2024-01-05 09:39:20 +13:00
parent ca5bd607f2
commit 7ee6139068
2 changed files with 17 additions and 8 deletions

View file

@ -555,6 +555,16 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
activity_log.result = 'success'
else:
activity_log.exception_message = 'PostReply not found'
elif request_json['object']['type'] == 'Undo':
if request_json['object']['object']['type'] == 'Like':
activity_log.activity_type = request_json['object']['object']['type']
user_ap_id = request_json['object']['actor']
user = find_actor_or_create(user_ap_id)
post = None
comment = None
target_ap_id = request_json['object']['object']['object'] # object object object!
post = undo_vote(activity_log, comment, post, target_ap_id, user)
activity_log.result = 'success'
else:
activity_log.exception_message = 'Invalid type for Announce'
@ -641,7 +651,7 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
comment = None
target_ap_id = request_json['object']['object']
post = undo_vote(activity_log, comment, post, target_ap_id, user)
activity_log.result = 'success'
elif request_json['object']['type'] == 'Dislike': # Undoing a downvote - probably unused
activity_log.activity_type = request_json['object']['type']
user_ap_id = request_json['actor']
@ -650,7 +660,7 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
comment = None
target_ap_id = request_json['object']['object']
post = undo_downvote(activity_log, comment, post, target_ap_id, user)
activity_log.result = 'success'
elif request_json['type'] == 'Update':
activity_log.activity_type = 'Update'
if request_json['object']['type'] == 'Page': # Editing a post

View file

@ -1052,11 +1052,9 @@ def undo_downvote(activity_log, comment, post, target_ap_id, user):
def undo_vote(activity_log, comment, post, target_ap_id, user):
if '/comment/' in target_ap_id:
comment = PostReply.query.filter_by(ap_id=target_ap_id).first()
if '/post/' in target_ap_id:
post = Post.query.filter_by(ap_id=target_ap_id).first()
if (user and not user.is_local()) and post:
voted_on = find_liked_object(target_ap_id)
if (user and not user.is_local()) and 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:
@ -1068,7 +1066,8 @@ def undo_vote(activity_log, comment, post, target_ap_id, user):
post.score -= existing_vote.effect
db.session.delete(existing_vote)
activity_log.result = 'success'
if (user and not user.is_local()) and comment:
if (user and not user.is_local()) and 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:
comment.author.reputation -= existing_vote.effect