mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-02 16:21:32 -08:00
accept mastodon replies
This commit is contained in:
parent
474ff8c194
commit
d0cc79f8ad
6 changed files with 21 additions and 8 deletions
|
@ -572,14 +572,16 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
|
|||
db.session.commit()
|
||||
return
|
||||
user = find_actor_or_create(user_ap_id)
|
||||
if (user and not user.is_local()) and community:
|
||||
user.last_seen = community.last_active = site.last_active = utcnow()
|
||||
|
||||
if user and not user.is_local():
|
||||
if community:
|
||||
user.last_seen = community.last_active = site.last_active = utcnow()
|
||||
else:
|
||||
user.last_seen = site.last_active = utcnow()
|
||||
object_type = request_json['object']['type']
|
||||
new_content_types = ['Page', 'Article', 'Link', 'Note', 'Question']
|
||||
if object_type in new_content_types: # create or update a post
|
||||
in_reply_to = request_json['object']['inReplyTo'] if 'inReplyTo' in request_json['object'] else None
|
||||
if not in_reply_to:
|
||||
if not in_reply_to: # Creating a new post
|
||||
post = Post.query.filter_by(ap_id=request_json['object']['id']).first()
|
||||
if post:
|
||||
if request_json['type'] == 'Create':
|
||||
|
@ -607,7 +609,7 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
|
|||
post = None
|
||||
else:
|
||||
post = None
|
||||
else:
|
||||
else: # Creating a reply / comment
|
||||
reply = PostReply.query.filter_by(ap_id=request_json['object']['id']).first()
|
||||
if reply:
|
||||
if request_json['type'] == 'Create':
|
||||
|
@ -624,6 +626,12 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
|
|||
else:
|
||||
activity_log.exception_message = 'Edit attempt denied'
|
||||
else:
|
||||
if community is None: # Mastodon: replies do not specify the community they're in. Attempt to find out the community by looking at the parent object
|
||||
parent_post_id, parent_comment_id, _ = find_reply_parent(in_reply_to)
|
||||
if parent_comment_id:
|
||||
community = PostReply.query.get(parent_comment_id).community
|
||||
else:
|
||||
community = Post.query.get(parent_post_id).community
|
||||
if can_create_post_reply(user, community):
|
||||
try:
|
||||
post_reply = create_post_reply(activity_log, community, in_reply_to, request_json, user)
|
||||
|
|
|
@ -326,6 +326,8 @@ def find_actor_or_create(actor: str, create_if_not_found=True, community_only=Fa
|
|||
elif isinstance(user, Community):
|
||||
refresh_community_profile(user.id)
|
||||
# refresh_instance_profile(user.instance_id) # disable in favour of cron job - see app.cli.daily_maintenance()
|
||||
if community_only and not isinstance(user, Community):
|
||||
return None
|
||||
return user
|
||||
else: # User does not exist in the DB, it's going to need to be created from it's remote home instance
|
||||
if create_if_not_found:
|
||||
|
|
|
@ -263,7 +263,7 @@ def register(app):
|
|||
db.session.commit()
|
||||
|
||||
# retrieve list of Admins from /api/v3/site, update InstanceRole
|
||||
if not instance.dormant and (instance.software == 'lemmy' or instance.software == 'piefed'):
|
||||
if instance.online() and (instance.software == 'lemmy' or instance.software == 'piefed'):
|
||||
try:
|
||||
response = get_request(f'https://{instance.domain}/api/v3/site')
|
||||
except:
|
||||
|
|
|
@ -713,7 +713,7 @@ def send_to_remote_instance_task(instance_id: int, community_id: int, payload):
|
|||
community = Community.query.get(community_id)
|
||||
if community:
|
||||
instance = Instance.query.get(instance_id)
|
||||
if instance.inbox and not instance.dormant:
|
||||
if instance.inbox and instance.online():
|
||||
if post_request(instance.inbox, payload, community.private_key, community.ap_profile_id + '#main-key'):
|
||||
instance.last_successful_send = utcnow()
|
||||
instance.failures = 0
|
||||
|
|
|
@ -1257,7 +1257,7 @@ def post_delete_post(community: Community, post: Post, user_id: int, federate_al
|
|||
UserFollower.remote_user_id == User.id)
|
||||
instances = instances.filter(UserFollower.local_user_id == post.user_id)
|
||||
for instance in instances:
|
||||
if instance.inbox and not user.has_blocked_instance(instance.id) and not instance_banned(instance.domain) and not instance.dormant:
|
||||
if instance.inbox and not user.has_blocked_instance(instance.id) and not instance_banned(instance.domain) and instance.online():
|
||||
post_request_in_background(instance.inbox, delete_json, user.private_key, user.public_url() + '#main-key')
|
||||
|
||||
if post.user_id != user.id:
|
||||
|
|
|
@ -626,6 +626,9 @@ def can_upvote(user, community: Community) -> bool:
|
|||
|
||||
|
||||
def can_create_post(user, content: Community) -> bool:
|
||||
if community is None:
|
||||
return False
|
||||
|
||||
if user is None or content is None or user.banned:
|
||||
return False
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue