Merge remote-tracking branch 'origin/main'

This commit is contained in:
rimu 2024-06-06 13:12:16 +12:00
commit 99633772ec
2 changed files with 20 additions and 74 deletions

View file

@ -256,10 +256,10 @@ def user_profile(actor):
actor_data = { "@context": default_context(),
"type": "Person" if not user.bot else "Service",
"id": user.public_url(),
"preferredUsername": actor.lower(),
"preferredUsername": actor,
"name": user.title if user.title else user.user_name,
"inbox": f"https://{server}/u/{actor.lower()}/inbox",
"outbox": f"https://{server}/u/{actor.lower()}/outbox",
"inbox": f"{user.public_url()}/inbox",
"outbox": f"{user.public_url()}/outbox",
"discoverable": user.searchable,
"indexable": user.indexable,
"manuallyApprovesFollowers": False if not user.ap_manually_approves_followers else user.ap_manually_approves_followers,
@ -844,14 +844,14 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
# send reject message to deny the follow
reject = {
"@context": default_context(),
"actor": community.ap_profile_id,
"actor": community.public_url(),
"to": [
user.ap_profile_id
user.public_url()
],
"object": {
"actor": user.ap_profile_id,
"actor": user.public_url(),
"to": None,
"object": community.ap_profile_id,
"object": community.public_url(),
"type": "Follow",
"id": follow_id
},
@ -874,14 +874,14 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
# send accept message to acknowledge the follow
accept = {
"@context": default_context(),
"actor": community.ap_profile_id,
"actor": community.public_url(),
"to": [
user.ap_profile_id
user.public_url()
],
"object": {
"actor": user.ap_profile_id,
"actor": user.public_url(),
"to": None,
"object": community.ap_profile_id,
"object": community.public_url(),
"type": "Follow",
"id": follow_id
},
@ -1476,8 +1476,7 @@ def post_ap2(post_id):
def post_ap(post_id):
if request.method == 'GET' and is_activitypub_request():
post = Post.query.get_or_404(post_id)
post_data = post_to_activity(post, post.community)
post_data = post_data['object']['object']
post_data = post_to_page(post)
post_data['@context'] = default_context()
resp = jsonify(post_data)
resp.content_type = 'application/activity+json'

View file

@ -137,31 +137,7 @@ def post_to_activity(post: Post, community: Community):
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
"object": {
"type": "Page",
"id": post.ap_id,
"attributedTo": post.author.public_url(),
"to": [
community.public_url(),
"https://www.w3.org/ns/activitystreams#Public"
],
"name": post.title,
"cc": [],
"content": post.body_html if post.body_html else '',
"mediaType": "text/html",
"attachment": [],
"commentsEnabled": post.comments_enabled,
"sensitive": post.nsfw or post.nsfl,
"published": ap_datetime(post.created_at),
"stickied": post.sticky,
"audience": community.public_url(),
'language': {
'identifier': post.language_code(),
'name': post.language_name()
},
'tag': post.tags_for_activitypub(),
'replies': post_replies_for_ap(post.id)
},
"object": post_to_page(post),
"cc": [
community.public_url()
],
@ -174,31 +150,6 @@ def post_to_activity(post: Post, community: Community):
"type": "Announce",
"id": announce_id
}
if post.edited_at is not None:
activity_data["object"]["object"]["updated"] = ap_datetime(post.edited_at)
if (post.type == POST_TYPE_LINK or post.type == POST_TYPE_VIDEO) and post.url is not None:
activity_data["object"]["object"]["attachment"] = [{"href": post.url, "type": "Link"}]
if post.image_id is not None:
activity_data["object"]["object"]["image"] = {"url": post.image.view_url(), "type": "Image"}
if post.image.alt_text:
activity_data["object"]["object"]["image"]['name'] = post.image.alt_text
if post.type == POST_TYPE_POLL:
poll = Poll.query.filter_by(post_id=post.id).first()
activity_data["object"]["object"]['type'] = 'Question'
mode = 'oneOf' if poll.mode == 'single' else 'anyOf'
choices = []
for choice in PollChoice.query.filter_by(post_id=post.id).order_by(PollChoice.sort_order).all():
choices.append({
"type": "Note",
"name": choice.choice_text,
"replies": {
"type": "Collection",
"totalItems": choice.num_votes
}
})
activity_data["object"]["object"][mode] = choices
activity_data["object"]["object"]['endTime'] = ap_datetime(poll.end_poll)
activity_data["object"]["object"]['votersCount'] = poll.total_votes()
return activity_data
@ -209,7 +160,7 @@ def post_to_page(post: Post):
"id": post.ap_id,
"attributedTo": post.author.ap_public_url,
"to": [
f"https://{current_app.config['SERVER_NAME']}/c/{post.community.name}",
post.community.public_url(),
"https://www.w3.org/ns/activitystreams#Public"
],
"name": post.title,
@ -221,11 +172,12 @@ def post_to_page(post: Post):
"sensitive": post.nsfw or post.nsfl,
"published": ap_datetime(post.created_at),
"stickied": post.sticky,
"audience": f"https://{current_app.config['SERVER_NAME']}/c/{post.community.name}",
"audience": post.community.public_url(),
"tag": post.tags_for_activitypub(),
'language': {
'identifier': post.language_code(),
'name': post.language_name()
"replies": post_replies_for_ap(post.id),
"language": {
"identifier": post.language_code(),
"name": post.language_name()
},
}
if post.edited_at is not None:
@ -294,11 +246,6 @@ def comment_model_to_json(reply: PostReply) -> dict:
}
if reply.edited_at:
reply_data['updated'] = ap_datetime(reply.edited_at)
if reply.body.strip():
reply_data['source'] = {
'content': reply.body,
'mediaType': 'text/markdown'
}
return reply_data
@ -543,7 +490,7 @@ def refresh_user_profile_task(user_id):
{'user_id': user.id,
'indexable': new_indexable})
user.user_name = activity_json['preferredUsername'].lower()
user.user_name = activity_json['preferredUsername']
if 'name' in activity_json:
user.title = activity_json['name']
user.about_html = parse_summary(activity_json)