From 574e3ae215f135e1cc220cf7ef3f8436d1ff8b45 Mon Sep 17 00:00:00 2001 From: freamon Date: Sun, 24 Nov 2024 16:31:20 +0000 Subject: [PATCH] apf part 26: Announce / Add mods or sticky --- app/activitypub/routes.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/app/activitypub/routes.py b/app/activitypub/routes.py index 9cdf0391..a0b197e3 100644 --- a/app/activitypub/routes.py +++ b/app/activitypub/routes.py @@ -962,6 +962,36 @@ def process_inbox_request(request_json, store_ap_json): log_incoming_ap(request_json['id'], APLOG_LOCK, APLOG_FAILURE, request_json if store_ap_json else None, 'Lock: post not found') return + if request_json['object']['type'] == 'Add': # Announce of adding mods or stickying a post + target = request_json['object']['target'] + featured_url = community.ap_featured_url + moderators_url = community.ap_moderators_url + if target == featured_url: + post = Post.query.filter_by(ap_id=request_json['object']['object']).first() + if post: + post.sticky = True + db.session.commit() + log_incoming_ap(request_json['id'], APLOG_ADD, APLOG_SUCCESS, request_json if store_ap_json else None) + else: + log_incoming_ap(request_json['id'], APLOG_ADD, APLOG_FAILURE, request_json if store_ap_json else None, 'Cannot find: ' + request_json['object']['object']) + return + if target == moderators_url: + user = find_actor_or_create(request_json['object']['object']) + if user: + existing_membership = CommunityMember.query.filter_by(community_id=community.id, user_id=user.id).first() + if existing_membership: + existing_membership.is_moderator = True + else: + new_membership = CommunityMember(community_id=community.id, user_id=user.id, is_moderator=True) + db.session.add(new_membership) + db.session.commit() + log_incoming_ap(request_json['id'], APLOG_ADD, APLOG_SUCCESS, request_json if store_ap_json else None) + else: + log_incoming_ap(request_json['id'], APLOG_ADD, APLOG_FAILURE, request_json if store_ap_json else None, 'Cannot find: ' + request_json['object']['object']) + return + log_incoming_ap(request_json['id'], APLOG_ADD, APLOG_FAILURE, request_json if store_ap_json else None, 'Unknown target for Add') + return + # -- below this point is code that will be incrementally replaced to use log_incoming_ap() instead --