local only communities - do not federate

This commit is contained in:
rimu 2024-01-27 12:22:35 +13:00
parent 5b66fea4fe
commit 04a4abe9d5
4 changed files with 436 additions and 416 deletions

View file

@ -589,6 +589,10 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
follow_id = request_json['id']
user = find_actor_or_create(user_ap_id)
community = find_actor_or_create(community_ap_id)
if community and community.local_only:
# todo: send Deny activity
activity_log.exception_message = 'Local only cannot be followed by remote users'
else:
if user is not None and community is not None:
# check if user is banned from this community
banned = CommunityBan.query.filter_by(user_id=user.id, community_id=community.id).first()

View file

@ -917,6 +917,10 @@ def delete_post_or_comment_task(user_ap_id, community_ap_id, to_be_deleted_ap_id
def create_post_reply(activity_log: ActivityPubLog, community: Community, in_reply_to, request_json: dict, user: User, announce_id=None) -> Union[Post, None]:
if community.local_only:
activity_log.exception_message = 'Community is local only, reply discarded'
activity_log.result = 'ignored'
return None
post_id, parent_comment_id, root_id = find_reply_parent(in_reply_to)
if post_id or parent_comment_id or root_id:
# set depth to +1 of the parent depth
@ -1006,6 +1010,10 @@ def create_post_reply(activity_log: ActivityPubLog, community: Community, in_rep
def create_post(activity_log: ActivityPubLog, community: Community, request_json: dict, user: User, announce_id=None) -> Union[Post, None]:
if community.local_only:
activity_log.exception_message = 'Community is local only, post discarded'
activity_log.result = 'ignored'
return None
post = Post(user_id=user.id, community_id=community.id,
title=html.unescape(request_json['object']['name']),
comments_enabled=request_json['object']['commentsEnabled'],

View file

@ -376,6 +376,7 @@ def add_post(actor):
notify_about_post(post)
if not community.local_only:
page = {
'type': 'Page',
'id': post.ap_id,

View file

@ -232,6 +232,7 @@ def post_vote(post_id: int, vote_direction):
post.author.reputation += effect
db.session.add(vote)
if not post.community.local_only:
action_type = 'Like' if vote_direction == 'upvote' else 'Dislike'
action_json = {
'actor': current_user.profile_id(),
@ -325,6 +326,7 @@ def comment_vote(comment_id, vote_direction):
...
# todo: federate vote
else:
if not comment.community.local_only:
action_type = 'Like' if vote_direction == 'upvote' else 'Dislike'
action_json = {
'actor': current_user.profile_id(),
@ -438,6 +440,7 @@ def add_reply(post_id: int, comment_id: int):
post.flush_cache()
# federation
if not post.community.local_only:
reply_json = {
'type': 'Note',
'id': reply.profile_id(),
@ -566,6 +569,7 @@ def post_edit(post_id: int):
flash(_('Your changes have been saved.'), 'success')
# federate edit
if not post.community.local_only:
page_json = {
'type': 'Page',
'id': post.ap_id,
@ -680,6 +684,7 @@ def post_delete(post_id: int):
db.session.commit()
flash(_('Post deleted.'))
if not community.local_only:
delete_json = {
'id': f"https://{current_app.config['SERVER_NAME']}/activities/delete/{gibberish(15)}",
'type': 'Delete',
@ -919,6 +924,7 @@ def post_reply_edit(post_id: int, comment_id: int):
else:
in_reply_to = post
# federate edit
if not post.community.local_only:
reply_json = {
'type': 'Note',
'id': post_reply.profile_id(),
@ -1014,6 +1020,7 @@ def post_reply_delete(post_id: int, comment_id: int):
post.flush_cache()
flash(_('Comment deleted.'))
# federate delete
if not post.community.local_only:
delete_json = {
'id': f"https://{current_app.config['SERVER_NAME']}/activities/delete/{gibberish(15)}",
'type': 'Delete',