mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-03 00:31:25 -08:00
local only communities - do not federate
This commit is contained in:
parent
5b66fea4fe
commit
04a4abe9d5
4 changed files with 436 additions and 416 deletions
|
@ -589,6 +589,10 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
|
||||||
follow_id = request_json['id']
|
follow_id = request_json['id']
|
||||||
user = find_actor_or_create(user_ap_id)
|
user = find_actor_or_create(user_ap_id)
|
||||||
community = find_actor_or_create(community_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:
|
if user is not None and community is not None:
|
||||||
# check if user is banned from this community
|
# check if user is banned from this community
|
||||||
banned = CommunityBan.query.filter_by(user_id=user.id, community_id=community.id).first()
|
banned = CommunityBan.query.filter_by(user_id=user.id, community_id=community.id).first()
|
||||||
|
|
|
@ -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]:
|
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)
|
post_id, parent_comment_id, root_id = find_reply_parent(in_reply_to)
|
||||||
if post_id or parent_comment_id or root_id:
|
if post_id or parent_comment_id or root_id:
|
||||||
# set depth to +1 of the parent depth
|
# 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]:
|
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,
|
post = Post(user_id=user.id, community_id=community.id,
|
||||||
title=html.unescape(request_json['object']['name']),
|
title=html.unescape(request_json['object']['name']),
|
||||||
comments_enabled=request_json['object']['commentsEnabled'],
|
comments_enabled=request_json['object']['commentsEnabled'],
|
||||||
|
|
|
@ -376,6 +376,7 @@ def add_post(actor):
|
||||||
|
|
||||||
notify_about_post(post)
|
notify_about_post(post)
|
||||||
|
|
||||||
|
if not community.local_only:
|
||||||
page = {
|
page = {
|
||||||
'type': 'Page',
|
'type': 'Page',
|
||||||
'id': post.ap_id,
|
'id': post.ap_id,
|
||||||
|
|
|
@ -232,6 +232,7 @@ def post_vote(post_id: int, vote_direction):
|
||||||
post.author.reputation += effect
|
post.author.reputation += effect
|
||||||
db.session.add(vote)
|
db.session.add(vote)
|
||||||
|
|
||||||
|
if not post.community.local_only:
|
||||||
action_type = 'Like' if vote_direction == 'upvote' else 'Dislike'
|
action_type = 'Like' if vote_direction == 'upvote' else 'Dislike'
|
||||||
action_json = {
|
action_json = {
|
||||||
'actor': current_user.profile_id(),
|
'actor': current_user.profile_id(),
|
||||||
|
@ -325,6 +326,7 @@ def comment_vote(comment_id, vote_direction):
|
||||||
...
|
...
|
||||||
# todo: federate vote
|
# todo: federate vote
|
||||||
else:
|
else:
|
||||||
|
if not comment.community.local_only:
|
||||||
action_type = 'Like' if vote_direction == 'upvote' else 'Dislike'
|
action_type = 'Like' if vote_direction == 'upvote' else 'Dislike'
|
||||||
action_json = {
|
action_json = {
|
||||||
'actor': current_user.profile_id(),
|
'actor': current_user.profile_id(),
|
||||||
|
@ -438,6 +440,7 @@ def add_reply(post_id: int, comment_id: int):
|
||||||
post.flush_cache()
|
post.flush_cache()
|
||||||
|
|
||||||
# federation
|
# federation
|
||||||
|
if not post.community.local_only:
|
||||||
reply_json = {
|
reply_json = {
|
||||||
'type': 'Note',
|
'type': 'Note',
|
||||||
'id': reply.profile_id(),
|
'id': reply.profile_id(),
|
||||||
|
@ -566,6 +569,7 @@ def post_edit(post_id: int):
|
||||||
flash(_('Your changes have been saved.'), 'success')
|
flash(_('Your changes have been saved.'), 'success')
|
||||||
# federate edit
|
# federate edit
|
||||||
|
|
||||||
|
if not post.community.local_only:
|
||||||
page_json = {
|
page_json = {
|
||||||
'type': 'Page',
|
'type': 'Page',
|
||||||
'id': post.ap_id,
|
'id': post.ap_id,
|
||||||
|
@ -680,6 +684,7 @@ def post_delete(post_id: int):
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash(_('Post deleted.'))
|
flash(_('Post deleted.'))
|
||||||
|
|
||||||
|
if not community.local_only:
|
||||||
delete_json = {
|
delete_json = {
|
||||||
'id': f"https://{current_app.config['SERVER_NAME']}/activities/delete/{gibberish(15)}",
|
'id': f"https://{current_app.config['SERVER_NAME']}/activities/delete/{gibberish(15)}",
|
||||||
'type': 'Delete',
|
'type': 'Delete',
|
||||||
|
@ -919,6 +924,7 @@ def post_reply_edit(post_id: int, comment_id: int):
|
||||||
else:
|
else:
|
||||||
in_reply_to = post
|
in_reply_to = post
|
||||||
# federate edit
|
# federate edit
|
||||||
|
if not post.community.local_only:
|
||||||
reply_json = {
|
reply_json = {
|
||||||
'type': 'Note',
|
'type': 'Note',
|
||||||
'id': post_reply.profile_id(),
|
'id': post_reply.profile_id(),
|
||||||
|
@ -1014,6 +1020,7 @@ def post_reply_delete(post_id: int, comment_id: int):
|
||||||
post.flush_cache()
|
post.flush_cache()
|
||||||
flash(_('Comment deleted.'))
|
flash(_('Comment deleted.'))
|
||||||
# federate delete
|
# federate delete
|
||||||
|
if not post.community.local_only:
|
||||||
delete_json = {
|
delete_json = {
|
||||||
'id': f"https://{current_app.config['SERVER_NAME']}/activities/delete/{gibberish(15)}",
|
'id': f"https://{current_app.config['SERVER_NAME']}/activities/delete/{gibberish(15)}",
|
||||||
'type': 'Delete',
|
'type': 'Delete',
|
||||||
|
|
Loading…
Add table
Reference in a new issue