mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-24 03:43:42 -08:00
oh boy, this sucks #194
This commit is contained in:
parent
c902f28137
commit
3203ac5506
14 changed files with 155 additions and 152 deletions
|
@ -255,7 +255,7 @@ def user_profile(actor):
|
||||||
server = current_app.config['SERVER_NAME']
|
server = current_app.config['SERVER_NAME']
|
||||||
actor_data = { "@context": default_context(),
|
actor_data = { "@context": default_context(),
|
||||||
"type": "Person" if not user.bot else "Service",
|
"type": "Person" if not user.bot else "Service",
|
||||||
"id": user.profile_id(),
|
"id": user.public_url(),
|
||||||
"preferredUsername": actor.lower(),
|
"preferredUsername": actor.lower(),
|
||||||
"name": user.title if user.title else user.user_name,
|
"name": user.title if user.title else user.user_name,
|
||||||
"inbox": f"https://{server}/u/{actor.lower()}/inbox",
|
"inbox": f"https://{server}/u/{actor.lower()}/inbox",
|
||||||
|
@ -264,8 +264,8 @@ def user_profile(actor):
|
||||||
"indexable": user.indexable,
|
"indexable": user.indexable,
|
||||||
"manuallyApprovesFollowers": False if not user.ap_manually_approves_followers else user.ap_manually_approves_followers,
|
"manuallyApprovesFollowers": False if not user.ap_manually_approves_followers else user.ap_manually_approves_followers,
|
||||||
"publicKey": {
|
"publicKey": {
|
||||||
"id": f"https://{server}/u/{actor.lower()}#main-key",
|
"id": f"{user.public_url()}#main-key",
|
||||||
"owner": f"https://{server}/u/{actor.lower()}",
|
"owner": user.public_url(),
|
||||||
"publicKeyPem": user.public_key # .replace("\n", "\\n") #LOOKSWRONG
|
"publicKeyPem": user.public_key # .replace("\n", "\\n") #LOOKSWRONG
|
||||||
},
|
},
|
||||||
"endpoints": {
|
"endpoints": {
|
||||||
|
@ -1187,13 +1187,13 @@ def announce_activity_to_followers(community, creator, activity):
|
||||||
|
|
||||||
announce_activity = {
|
announce_activity = {
|
||||||
'@context': default_context(),
|
'@context': default_context(),
|
||||||
"actor": community.profile_id(),
|
"actor": community.public_url(),
|
||||||
"to": [
|
"to": [
|
||||||
"https://www.w3.org/ns/activitystreams#Public"
|
"https://www.w3.org/ns/activitystreams#Public"
|
||||||
],
|
],
|
||||||
"object": activity,
|
"object": activity,
|
||||||
"cc": [
|
"cc": [
|
||||||
f"{community.profile_id()}/followers"
|
f"{community.public_url()}/followers"
|
||||||
],
|
],
|
||||||
"type": "Announce",
|
"type": "Announce",
|
||||||
"id": f"https://{current_app.config['SERVER_NAME']}/activities/announce/{gibberish(15)}"
|
"id": f"https://{current_app.config['SERVER_NAME']}/activities/announce/{gibberish(15)}"
|
||||||
|
@ -1390,7 +1390,7 @@ def process_user_follow_request(request_json, activitypublog_id, remote_user_id)
|
||||||
"type": "Accept",
|
"type": "Accept",
|
||||||
"id": f"https://{current_app.config['SERVER_NAME']}/activities/accept/" + gibberish(32)
|
"id": f"https://{current_app.config['SERVER_NAME']}/activities/accept/" + gibberish(32)
|
||||||
}
|
}
|
||||||
if post_request(remote_user.ap_inbox_url, accept, local_user.private_key, f"{local_user.profile_id()}#main-key"):
|
if post_request(remote_user.ap_inbox_url, accept, local_user.private_key, f"{local_user.public_url()}#main-key"):
|
||||||
activity_log.result = 'success'
|
activity_log.result = 'success'
|
||||||
else:
|
else:
|
||||||
activity_log.exception_message = 'Error sending Accept'
|
activity_log.exception_message = 'Error sending Accept'
|
||||||
|
@ -1461,21 +1461,21 @@ def comment_ap(comment_id):
|
||||||
"@context": default_context(),
|
"@context": default_context(),
|
||||||
"type": "Note",
|
"type": "Note",
|
||||||
"id": reply.ap_id,
|
"id": reply.ap_id,
|
||||||
"attributedTo": reply.author.profile_id(),
|
"attributedTo": reply.author.public_url(),
|
||||||
"inReplyTo": reply.in_reply_to(),
|
"inReplyTo": reply.in_reply_to(),
|
||||||
"to": [
|
"to": [
|
||||||
"https://www.w3.org/ns/activitystreams#Public",
|
"https://www.w3.org/ns/activitystreams#Public",
|
||||||
reply.to()
|
reply.to()
|
||||||
],
|
],
|
||||||
"cc": [
|
"cc": [
|
||||||
reply.community.profile_id(),
|
reply.community.public_url(),
|
||||||
reply.author.followers_url()
|
reply.author.followers_url()
|
||||||
],
|
],
|
||||||
'content': reply.body_html,
|
'content': reply.body_html,
|
||||||
'mediaType': 'text/html',
|
'mediaType': 'text/html',
|
||||||
'published': ap_datetime(reply.created_at),
|
'published': ap_datetime(reply.created_at),
|
||||||
'distinguished': False,
|
'distinguished': False,
|
||||||
'audience': reply.community.profile_id(),
|
'audience': reply.community.public_url(),
|
||||||
'language': {
|
'language': {
|
||||||
'identifier': reply.language_code(),
|
'identifier': reply.language_code(),
|
||||||
'name': reply.language_name()
|
'name': reply.language_name()
|
||||||
|
|
|
@ -133,14 +133,14 @@ def post_to_activity(post: Post, community: Community):
|
||||||
],
|
],
|
||||||
"object": {
|
"object": {
|
||||||
"id": create_id,
|
"id": create_id,
|
||||||
"actor": post.author.profile_id() if post.author.is_local() else post.author.ap_public_url,
|
"actor": post.author.public_url(),
|
||||||
"to": [
|
"to": [
|
||||||
"https://www.w3.org/ns/activitystreams#Public"
|
"https://www.w3.org/ns/activitystreams#Public"
|
||||||
],
|
],
|
||||||
"object": {
|
"object": {
|
||||||
"type": "Page",
|
"type": "Page",
|
||||||
"id": post.ap_id,
|
"id": post.ap_id,
|
||||||
"attributedTo": post.author.profile_id() if post.author.is_local() else post.author.ap_public_url,
|
"attributedTo": post.author.public_url(),
|
||||||
"to": [
|
"to": [
|
||||||
f"https://{current_app.config['SERVER_NAME']}/c/{community.name}",
|
f"https://{current_app.config['SERVER_NAME']}/c/{community.name}",
|
||||||
"https://www.w3.org/ns/activitystreams#Public"
|
"https://www.w3.org/ns/activitystreams#Public"
|
||||||
|
@ -2283,7 +2283,7 @@ def lemmy_site_data():
|
||||||
"banned": admin.banned,
|
"banned": admin.banned,
|
||||||
"published": admin.created.isoformat() + 'Z',
|
"published": admin.created.isoformat() + 'Z',
|
||||||
"updated": admin.created.isoformat() + 'Z',
|
"updated": admin.created.isoformat() + 'Z',
|
||||||
"actor_id": admin.profile_id(),
|
"actor_id": admin.public_url(),
|
||||||
"local": True,
|
"local": True,
|
||||||
"deleted": admin.deleted,
|
"deleted": admin.deleted,
|
||||||
"matrix_user_id": admin.matrix_user_id,
|
"matrix_user_id": admin.matrix_user_id,
|
||||||
|
@ -2571,8 +2571,8 @@ def inform_followers_of_post_update_task(post_id: int, sending_instance_id: int)
|
||||||
update_json = {
|
update_json = {
|
||||||
'id': f"https://{current_app.config['SERVER_NAME']}/activities/update/{gibberish(15)}",
|
'id': f"https://{current_app.config['SERVER_NAME']}/activities/update/{gibberish(15)}",
|
||||||
'type': 'Update',
|
'type': 'Update',
|
||||||
'actor': post.author.profile_id(),
|
'actor': post.author.public_url(),
|
||||||
'audience': post.community.profile_id(),
|
'audience': post.community.public_url(),
|
||||||
'to': ['https://www.w3.org/ns/activitystreams#Public'],
|
'to': ['https://www.w3.org/ns/activitystreams#Public'],
|
||||||
'published': ap_datetime(utcnow()),
|
'published': ap_datetime(utcnow()),
|
||||||
'cc': [
|
'cc': [
|
||||||
|
@ -2589,7 +2589,7 @@ def inform_followers_of_post_update_task(post_id: int, sending_instance_id: int)
|
||||||
for i in instances:
|
for i in instances:
|
||||||
if sending_instance_id != i.id:
|
if sending_instance_id != i.id:
|
||||||
try:
|
try:
|
||||||
post_request(i.inbox, update_json, post.author.private_key, post.author.profile_id() + '#main-key')
|
post_request(i.inbox, update_json, post.author.private_key, post.author.public_url() + '#main-key')
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -2600,6 +2600,6 @@ def inform_followers_of_post_update_task(post_id: int, sending_instance_id: int)
|
||||||
for i in instances:
|
for i in instances:
|
||||||
if sending_instance_id != i.id:
|
if sending_instance_id != i.id:
|
||||||
try:
|
try:
|
||||||
post_request(i.inbox, update_json, post.author.private_key, post.author.profile_id() + '#main-key')
|
post_request(i.inbox, update_json, post.author.private_key, post.author.public_url() + '#main-key')
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -34,9 +34,9 @@ def unsubscribe_from_everything_then_delete_task(user_id):
|
||||||
instances = Instance.query.filter(Instance.dormant == False).all()
|
instances = Instance.query.filter(Instance.dormant == False).all()
|
||||||
payload = {
|
payload = {
|
||||||
"@context": default_context(),
|
"@context": default_context(),
|
||||||
"actor": user.profile_id(),
|
"actor": user.public_url(),
|
||||||
"id": f"{user.profile_id()}#delete",
|
"id": f"{user.public_url()}#delete",
|
||||||
"object": user.profile_id(),
|
"object": user.public_url(),
|
||||||
"to": [
|
"to": [
|
||||||
"https://www.w3.org/ns/activitystreams#Public"
|
"https://www.w3.org/ns/activitystreams#Public"
|
||||||
],
|
],
|
||||||
|
@ -44,7 +44,7 @@ def unsubscribe_from_everything_then_delete_task(user_id):
|
||||||
}
|
}
|
||||||
for instance in instances:
|
for instance in instances:
|
||||||
if instance.inbox and instance.online() and instance.id != 1: # instance id 1 is always the current instance
|
if instance.inbox and instance.online() and instance.id != 1: # instance id 1 is always the current instance
|
||||||
post_request(instance.inbox, payload, user.private_key, f"{user.profile_id()}#main-key")
|
post_request(instance.inbox, payload, user.private_key, f"{user.public_url()}#main-key")
|
||||||
|
|
||||||
sleep(5)
|
sleep(5)
|
||||||
|
|
||||||
|
@ -57,15 +57,15 @@ def unsubscribe_from_everything_then_delete_task(user_id):
|
||||||
def unsubscribe_from_community(community, user):
|
def unsubscribe_from_community(community, user):
|
||||||
undo_id = f"https://{current_app.config['SERVER_NAME']}/activities/undo/" + gibberish(15)
|
undo_id = f"https://{current_app.config['SERVER_NAME']}/activities/undo/" + gibberish(15)
|
||||||
follow = {
|
follow = {
|
||||||
"actor": f"https://{current_app.config['SERVER_NAME']}/u/{user.user_name}",
|
"actor": user.public_url(),
|
||||||
"to": [community.ap_profile_id],
|
"to": [community.public_url()],
|
||||||
"object": community.ap_profile_id,
|
"object": community.public_url(),
|
||||||
"type": "Follow",
|
"type": "Follow",
|
||||||
"id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{gibberish(15)}"
|
"id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{gibberish(15)}"
|
||||||
}
|
}
|
||||||
undo = {
|
undo = {
|
||||||
'actor': user.profile_id(),
|
'actor': user.public_url(),
|
||||||
'to': [community.ap_profile_id],
|
'to': [community.public_url()],
|
||||||
'type': 'Undo',
|
'type': 'Undo',
|
||||||
'id': undo_id,
|
'id': undo_id,
|
||||||
'object': follow
|
'object': follow
|
||||||
|
@ -74,7 +74,7 @@ def unsubscribe_from_community(community, user):
|
||||||
activity_json=json.dumps(undo), result='processing')
|
activity_json=json.dumps(undo), result='processing')
|
||||||
db.session.add(activity)
|
db.session.add(activity)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
post_request(community.ap_inbox_url, undo, user.private_key, user.profile_id() + '#main-key')
|
post_request(community.ap_inbox_url, undo, user.private_key, user.public_url() + '#main-key')
|
||||||
activity.result = 'success'
|
activity.result = 'success'
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
|
@ -30,26 +30,26 @@ def send_message(message: str, conversation_id: int) -> ChatMessage:
|
||||||
else:
|
else:
|
||||||
# Federate reply
|
# Federate reply
|
||||||
reply_json = {
|
reply_json = {
|
||||||
"actor": current_user.profile_id(),
|
"actor": current_user.public_url(),
|
||||||
"id": f"https://{current_app.config['SERVER_NAME']}/activities/create/{gibberish(15)}",
|
"id": f"https://{current_app.config['SERVER_NAME']}/activities/create/{gibberish(15)}",
|
||||||
"object": {
|
"object": {
|
||||||
"attributedTo": current_user.profile_id(),
|
"attributedTo": current_user.public_url(),
|
||||||
"content": reply.body_html,
|
"content": reply.body_html,
|
||||||
"id": f"https://{current_app.config['SERVER_NAME']}/private_message/{reply.id}",
|
"id": f"https://{current_app.config['SERVER_NAME']}/private_message/{reply.id}",
|
||||||
"mediaType": "text/html",
|
"mediaType": "text/html",
|
||||||
"published": utcnow().isoformat() + 'Z', # Lemmy is inconsistent with the date format they use
|
"published": utcnow().isoformat() + 'Z', # Lemmy is inconsistent with the date format they use
|
||||||
"to": [
|
"to": [
|
||||||
recipient.profile_id()
|
recipient.public_url()
|
||||||
],
|
],
|
||||||
"type": "ChatMessage"
|
"type": "ChatMessage"
|
||||||
},
|
},
|
||||||
"to": [
|
"to": [
|
||||||
recipient.profile_id()
|
recipient.public_url()
|
||||||
],
|
],
|
||||||
"type": "Create"
|
"type": "Create"
|
||||||
}
|
}
|
||||||
success = post_request(recipient.ap_inbox_url, reply_json, current_user.private_key,
|
success = post_request(recipient.ap_inbox_url, reply_json, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
if not success:
|
if not success:
|
||||||
flash(_('Message failed to send to %(name)s.', name=recipient.link()), 'error')
|
flash(_('Message failed to send to %(name)s.', name=recipient.link()), 'error')
|
||||||
|
|
||||||
|
|
|
@ -386,14 +386,14 @@ def subscribe(actor):
|
||||||
db.session.add(join_request)
|
db.session.add(join_request)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
follow = {
|
follow = {
|
||||||
"actor": current_user.profile_id(),
|
"actor": current_user.public_url(),
|
||||||
"to": [community.ap_profile_id],
|
"to": [community.public_url()],
|
||||||
"object": community.ap_profile_id,
|
"object": community.public_url(),
|
||||||
"type": "Follow",
|
"type": "Follow",
|
||||||
"id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{join_request.id}"
|
"id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{join_request.id}"
|
||||||
}
|
}
|
||||||
success = post_request(community.ap_inbox_url, follow, current_user.private_key,
|
success = post_request(community.ap_inbox_url, follow, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
if not success:
|
if not success:
|
||||||
flash(_("There was a problem while trying to communicate with remote server. If other people have already joined this community it won't matter."), 'error')
|
flash(_("There was a problem while trying to communicate with remote server. If other people have already joined this community it won't matter."), 'error')
|
||||||
# for local communities, joining is instant
|
# for local communities, joining is instant
|
||||||
|
@ -426,21 +426,21 @@ def unsubscribe(actor):
|
||||||
if '@' in actor: # this is a remote community, so activitypub is needed
|
if '@' in actor: # this is a remote community, so activitypub is needed
|
||||||
undo_id = f"https://{current_app.config['SERVER_NAME']}/activities/undo/" + gibberish(15)
|
undo_id = f"https://{current_app.config['SERVER_NAME']}/activities/undo/" + gibberish(15)
|
||||||
follow = {
|
follow = {
|
||||||
"actor": current_user.profile_id(),
|
"actor": current_user.public_url(),
|
||||||
"to": [community.ap_profile_id],
|
"to": [community.public_url()],
|
||||||
"object": community.ap_profile_id,
|
"object": community.public_url(),
|
||||||
"type": "Follow",
|
"type": "Follow",
|
||||||
"id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{gibberish(15)}"
|
"id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{gibberish(15)}"
|
||||||
}
|
}
|
||||||
undo = {
|
undo = {
|
||||||
'actor': current_user.profile_id(),
|
'actor': current_user.public_url(),
|
||||||
'to': [community.ap_profile_id],
|
'to': [community.public_url()],
|
||||||
'type': 'Undo',
|
'type': 'Undo',
|
||||||
'id': undo_id,
|
'id': undo_id,
|
||||||
'object': follow
|
'object': follow
|
||||||
}
|
}
|
||||||
success = post_request(community.ap_inbox_url, undo, current_user.private_key,
|
success = post_request(community.ap_inbox_url, undo, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
if not success:
|
if not success:
|
||||||
flash('There was a problem while trying to unsubscribe', 'error')
|
flash('There was a problem while trying to unsubscribe', 'error')
|
||||||
|
|
||||||
|
@ -478,14 +478,14 @@ def join_then_add(actor):
|
||||||
db.session.add(join_request)
|
db.session.add(join_request)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
follow = {
|
follow = {
|
||||||
"actor": current_user.profile_id(),
|
"actor": current_user.public_url(),
|
||||||
"to": [community.ap_profile_id],
|
"to": [community.public_url()],
|
||||||
"object": community.ap_profile_id,
|
"object": community.public_url(),
|
||||||
"type": "Follow",
|
"type": "Follow",
|
||||||
"id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{join_request.id}"
|
"id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{join_request.id}"
|
||||||
}
|
}
|
||||||
success = post_request(community.ap_inbox_url, follow, current_user.private_key,
|
success = post_request(community.ap_inbox_url, follow, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
member = CommunityMember(user_id=current_user.id, community_id=community.id)
|
member = CommunityMember(user_id=current_user.id, community_id=community.id)
|
||||||
db.session.add(member)
|
db.session.add(member)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
@ -952,7 +952,7 @@ def federate_post(community, post):
|
||||||
page['oneOf' if poll.mode == 'single' else 'anyOf'] = choices
|
page['oneOf' if poll.mode == 'single' else 'anyOf'] = choices
|
||||||
if not community.is_local(): # this is a remote community - send the post to the instance that hosts it
|
if not community.is_local(): # this is a remote community - send the post to the instance that hosts it
|
||||||
success = post_request(community.ap_inbox_url, create, current_user.private_key,
|
success = post_request(community.ap_inbox_url, create, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
if success:
|
if success:
|
||||||
flash(_('Your post to %(name)s has been made.', name=community.title))
|
flash(_('Your post to %(name)s has been made.', name=community.title))
|
||||||
else:
|
else:
|
||||||
|
@ -1067,7 +1067,7 @@ def federate_post_to_user_followers(post):
|
||||||
instances = Instance.query.join(User, User.instance_id == Instance.id).join(UserFollower, UserFollower.remote_user_id == User.id)
|
instances = Instance.query.join(User, User.instance_id == Instance.id).join(UserFollower, UserFollower.remote_user_id == User.id)
|
||||||
instances = instances.filter(UserFollower.local_user_id == post.user_id).filter(Instance.gone_forever == False)
|
instances = instances.filter(UserFollower.local_user_id == post.user_id).filter(Instance.gone_forever == False)
|
||||||
for i in instances:
|
for i in instances:
|
||||||
post_request(i.inbox, create, current_user.private_key, current_user.profile_id() + '#main-key')
|
post_request(i.inbox, create, current_user.private_key, current_user.public_url() + '#main-key')
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/community/<int:community_id>/report', methods=['GET', 'POST'])
|
@bp.route('/community/<int:community_id>/report', methods=['GET', 'POST'])
|
||||||
|
|
|
@ -548,9 +548,9 @@ def delete_post_from_community_task(post_id):
|
||||||
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',
|
||||||
'actor': current_user.profile_id(),
|
'actor': current_user.public_url(),
|
||||||
'audience': post.community.profile_id(),
|
'audience': post.community.public_url(),
|
||||||
'to': [post.community.profile_id(), 'https://www.w3.org/ns/activitystreams#Public'],
|
'to': [post.community.public_url(), 'https://www.w3.org/ns/activitystreams#Public'],
|
||||||
'published': ap_datetime(utcnow()),
|
'published': ap_datetime(utcnow()),
|
||||||
'cc': [
|
'cc': [
|
||||||
current_user.followers_url()
|
current_user.followers_url()
|
||||||
|
@ -560,7 +560,7 @@ def delete_post_from_community_task(post_id):
|
||||||
|
|
||||||
if not post.community.is_local(): # this is a remote community, send it to the instance that hosts it
|
if not post.community.is_local(): # this is a remote community, send it to the instance that hosts it
|
||||||
success = post_request(post.community.ap_inbox_url, delete_json, current_user.private_key,
|
success = post_request(post.community.ap_inbox_url, delete_json, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
else: # local community - send it to followers on remote instances
|
else: # local community - send it to followers on remote instances
|
||||||
announce = {
|
announce = {
|
||||||
"id": f"https://{current_app.config['SERVER_NAME']}/activities/announce/{gibberish(15)}",
|
"id": f"https://{current_app.config['SERVER_NAME']}/activities/announce/{gibberish(15)}",
|
||||||
|
@ -608,9 +608,9 @@ def delete_post_reply_from_community_task(post_reply_id):
|
||||||
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',
|
||||||
'actor': current_user.profile_id(),
|
'actor': current_user.public_url(),
|
||||||
'audience': post.community.profile_id(),
|
'audience': post.community.public_url(),
|
||||||
'to': [post.community.profile_id(), 'https://www.w3.org/ns/activitystreams#Public'],
|
'to': [post.community.public_url(), 'https://www.w3.org/ns/activitystreams#Public'],
|
||||||
'published': ap_datetime(utcnow()),
|
'published': ap_datetime(utcnow()),
|
||||||
'cc': [
|
'cc': [
|
||||||
current_user.followers_url()
|
current_user.followers_url()
|
||||||
|
@ -620,7 +620,7 @@ def delete_post_reply_from_community_task(post_reply_id):
|
||||||
|
|
||||||
if not post.community.is_local(): # this is a remote community, send it to the instance that hosts it
|
if not post.community.is_local(): # this is a remote community, send it to the instance that hosts it
|
||||||
success = post_request(post.community.ap_inbox_url, delete_json, current_user.private_key,
|
success = post_request(post.community.ap_inbox_url, delete_json, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
|
|
||||||
else: # local community - send it to followers on remote instances
|
else: # local community - send it to followers on remote instances
|
||||||
announce = {
|
announce = {
|
||||||
|
|
|
@ -756,7 +756,7 @@ class User(UserMixin, db.Model):
|
||||||
if self.ap_followers_url:
|
if self.ap_followers_url:
|
||||||
return self.ap_followers_url
|
return self.ap_followers_url
|
||||||
else:
|
else:
|
||||||
return self.profile_id() + '/followers'
|
return self.public_url() + '/followers'
|
||||||
|
|
||||||
def get_reset_password_token(self, expires_in=600):
|
def get_reset_password_token(self, expires_in=600):
|
||||||
return jwt.encode(
|
return jwt.encode(
|
||||||
|
@ -1118,6 +1118,9 @@ class PostReply(db.Model):
|
||||||
else:
|
else:
|
||||||
return f"https://{current_app.config['SERVER_NAME']}/comment/{self.id}"
|
return f"https://{current_app.config['SERVER_NAME']}/comment/{self.id}"
|
||||||
|
|
||||||
|
def public_url(self):
|
||||||
|
return self.profile_id()
|
||||||
|
|
||||||
# the ap_id of the parent object, whether it's another PostReply or a Post
|
# the ap_id of the parent object, whether it's another PostReply or a Post
|
||||||
def in_reply_to(self):
|
def in_reply_to(self):
|
||||||
if self.parent_id is None:
|
if self.parent_id is None:
|
||||||
|
@ -1129,10 +1132,10 @@ class PostReply(db.Model):
|
||||||
# the AP profile of the person who wrote the parent object, which could be another PostReply or a Post
|
# the AP profile of the person who wrote the parent object, which could be another PostReply or a Post
|
||||||
def to(self):
|
def to(self):
|
||||||
if self.parent_id is None:
|
if self.parent_id is None:
|
||||||
return self.post.author.profile_id()
|
return self.post.author.public_url()
|
||||||
else:
|
else:
|
||||||
parent = PostReply.query.get(self.parent_id)
|
parent = PostReply.query.get(self.parent_id)
|
||||||
return parent.author.profile_id()
|
return parent.author.public_url()
|
||||||
|
|
||||||
def delete_dependencies(self):
|
def delete_dependencies(self):
|
||||||
for child_reply in self.child_replies():
|
for child_reply in self.child_replies():
|
||||||
|
|
|
@ -145,7 +145,7 @@ def show_post(post_id: int):
|
||||||
# federation
|
# federation
|
||||||
reply_json = {
|
reply_json = {
|
||||||
'type': 'Note',
|
'type': 'Note',
|
||||||
'id': reply.profile_id(),
|
'id': reply.public_url(),
|
||||||
'attributedTo': current_user.public_url(),
|
'attributedTo': current_user.public_url(),
|
||||||
'to': [
|
'to': [
|
||||||
'https://www.w3.org/ns/activitystreams#Public'
|
'https://www.w3.org/ns/activitystreams#Public'
|
||||||
|
@ -154,7 +154,7 @@ def show_post(post_id: int):
|
||||||
community.public_url(), post.author.public_url()
|
community.public_url(), post.author.public_url()
|
||||||
],
|
],
|
||||||
'content': reply.body_html,
|
'content': reply.body_html,
|
||||||
'inReplyTo': post.profile_id(),
|
'inReplyTo': post.public_url(),
|
||||||
'mediaType': 'text/html',
|
'mediaType': 'text/html',
|
||||||
'published': ap_datetime(utcnow()),
|
'published': ap_datetime(utcnow()),
|
||||||
'distinguished': False,
|
'distinguished': False,
|
||||||
|
@ -189,7 +189,7 @@ def show_post(post_id: int):
|
||||||
}
|
}
|
||||||
if not community.is_local(): # this is a remote community, send it to the instance that hosts it
|
if not community.is_local(): # this is a remote community, send it to the instance that hosts it
|
||||||
success = post_request(community.ap_inbox_url, create_json, current_user.private_key,
|
success = post_request(community.ap_inbox_url, create_json, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
if not success:
|
if not success:
|
||||||
flash('Failed to send to remote instance', 'error')
|
flash('Failed to send to remote instance', 'error')
|
||||||
else: # local community - send it to followers on remote instances
|
else: # local community - send it to followers on remote instances
|
||||||
|
@ -215,12 +215,12 @@ def show_post(post_id: int):
|
||||||
if not post.author.is_local() and post.author.ap_domain != community.ap_domain:
|
if not post.author.is_local() and post.author.ap_domain != community.ap_domain:
|
||||||
if not community.is_local() or (community.is_local and not community.has_followers_from_domain(post.author.ap_domain)):
|
if not community.is_local() or (community.is_local and not community.has_followers_from_domain(post.author.ap_domain)):
|
||||||
success = post_request(post.author.ap_inbox_url, create_json, current_user.private_key,
|
success = post_request(post.author.ap_inbox_url, create_json, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
if not success:
|
if not success:
|
||||||
# sending to shared inbox is good enough for Mastodon, but Lemmy will reject it the local community has no followers
|
# sending to shared inbox is good enough for Mastodon, but Lemmy will reject it the local community has no followers
|
||||||
personal_inbox = post.author.public_url() + '/inbox'
|
personal_inbox = post.author.public_url() + '/inbox'
|
||||||
post_request(personal_inbox, create_json, current_user.private_key,
|
post_request(personal_inbox, create_json, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
|
|
||||||
return redirect(url_for('activitypub.post_ap', post_id=post_id)) # redirect to current page to avoid refresh resubmitting the form
|
return redirect(url_for('activitypub.post_ap', post_id=post_id)) # redirect to current page to avoid refresh resubmitting the form
|
||||||
else:
|
else:
|
||||||
|
@ -387,26 +387,26 @@ def post_vote(post_id: int, vote_direction):
|
||||||
if not post.community.local_only:
|
if not post.community.local_only:
|
||||||
if undo:
|
if undo:
|
||||||
action_json = {
|
action_json = {
|
||||||
'actor': current_user.profile_id(),
|
'actor': current_user.public_url(),
|
||||||
'type': 'Undo',
|
'type': 'Undo',
|
||||||
'id': f"https://{current_app.config['SERVER_NAME']}/activities/undo/{gibberish(15)}",
|
'id': f"https://{current_app.config['SERVER_NAME']}/activities/undo/{gibberish(15)}",
|
||||||
'audience': post.community.profile_id(),
|
'audience': post.community.public_url(),
|
||||||
'object': {
|
'object': {
|
||||||
'actor': current_user.profile_id(),
|
'actor': current_user.public_url(),
|
||||||
'object': post.profile_id(),
|
'object': post.public_url(),
|
||||||
'type': undo,
|
'type': undo,
|
||||||
'id': f"https://{current_app.config['SERVER_NAME']}/activities/{undo.lower()}/{gibberish(15)}",
|
'id': f"https://{current_app.config['SERVER_NAME']}/activities/{undo.lower()}/{gibberish(15)}",
|
||||||
'audience': post.community.profile_id()
|
'audience': post.community.public_url()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
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.public_url(),
|
||||||
'object': post.profile_id(),
|
'object': post.public_url(),
|
||||||
'type': action_type,
|
'type': action_type,
|
||||||
'id': f"https://{current_app.config['SERVER_NAME']}/activities/{action_type.lower()}/{gibberish(15)}",
|
'id': f"https://{current_app.config['SERVER_NAME']}/activities/{action_type.lower()}/{gibberish(15)}",
|
||||||
'audience': post.community.profile_id()
|
'audience': post.community.public_url()
|
||||||
}
|
}
|
||||||
if post.community.is_local():
|
if post.community.is_local():
|
||||||
announce = {
|
announce = {
|
||||||
|
@ -415,7 +415,7 @@ def post_vote(post_id: int, vote_direction):
|
||||||
"to": [
|
"to": [
|
||||||
"https://www.w3.org/ns/activitystreams#Public"
|
"https://www.w3.org/ns/activitystreams#Public"
|
||||||
],
|
],
|
||||||
"actor": post.community.ap_profile_id,
|
"actor": post.community.public_url(),
|
||||||
"cc": [
|
"cc": [
|
||||||
post.community.ap_followers_url
|
post.community.ap_followers_url
|
||||||
],
|
],
|
||||||
|
@ -427,7 +427,7 @@ def post_vote(post_id: int, vote_direction):
|
||||||
send_to_remote_instance(instance.id, post.community.id, announce)
|
send_to_remote_instance(instance.id, post.community.id, announce)
|
||||||
else:
|
else:
|
||||||
success = post_request_in_background(post.community.ap_inbox_url, action_json, current_user.private_key,
|
success = post_request_in_background(post.community.ap_inbox_url, action_json, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
if not success:
|
if not success:
|
||||||
flash('Failed to send vote', 'warning')
|
flash('Failed to send vote', 'warning')
|
||||||
|
|
||||||
|
@ -499,26 +499,26 @@ def comment_vote(comment_id, vote_direction):
|
||||||
if not comment.community.local_only:
|
if not comment.community.local_only:
|
||||||
if undo:
|
if undo:
|
||||||
action_json = {
|
action_json = {
|
||||||
'actor': current_user.profile_id(),
|
'actor': current_user.public_url(),
|
||||||
'type': 'Undo',
|
'type': 'Undo',
|
||||||
'id': f"https://{current_app.config['SERVER_NAME']}/activities/undo/{gibberish(15)}",
|
'id': f"https://{current_app.config['SERVER_NAME']}/activities/undo/{gibberish(15)}",
|
||||||
'audience': comment.community.profile_id(),
|
'audience': comment.community.public_url(),
|
||||||
'object': {
|
'object': {
|
||||||
'actor': current_user.profile_id(),
|
'actor': current_user.public_url(),
|
||||||
'object': comment.profile_id(),
|
'object': comment.public_url(),
|
||||||
'type': undo,
|
'type': undo,
|
||||||
'id': f"https://{current_app.config['SERVER_NAME']}/activities/{undo.lower()}/{gibberish(15)}",
|
'id': f"https://{current_app.config['SERVER_NAME']}/activities/{undo.lower()}/{gibberish(15)}",
|
||||||
'audience': comment.community.profile_id()
|
'audience': comment.community.public_url()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
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.public_url(),
|
||||||
'object': comment.profile_id(),
|
'object': comment.public_url(),
|
||||||
'type': action_type,
|
'type': action_type,
|
||||||
'id': f"https://{current_app.config['SERVER_NAME']}/activities/{action_type.lower()}/{gibberish(15)}",
|
'id': f"https://{current_app.config['SERVER_NAME']}/activities/{action_type.lower()}/{gibberish(15)}",
|
||||||
'audience': comment.community.profile_id()
|
'audience': comment.community.public_url()
|
||||||
}
|
}
|
||||||
if comment.community.is_local():
|
if comment.community.is_local():
|
||||||
announce = {
|
announce = {
|
||||||
|
@ -539,7 +539,7 @@ def comment_vote(comment_id, vote_direction):
|
||||||
send_to_remote_instance(instance.id, comment.community.id, announce)
|
send_to_remote_instance(instance.id, comment.community.id, announce)
|
||||||
else:
|
else:
|
||||||
success = post_request_in_background(comment.community.ap_inbox_url, action_json, current_user.private_key,
|
success = post_request_in_background(comment.community.ap_inbox_url, action_json, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
if not success:
|
if not success:
|
||||||
flash('Failed to send vote', 'warning')
|
flash('Failed to send vote', 'warning')
|
||||||
|
|
||||||
|
@ -592,7 +592,7 @@ def poll_vote(post_id):
|
||||||
'object': {
|
'object': {
|
||||||
'attributedTo': current_user.public_url(),
|
'attributedTo': current_user.public_url(),
|
||||||
'id': f"https://{current_app.config['SERVER_NAME']}/activities/vote/{gibberish(15)}",
|
'id': f"https://{current_app.config['SERVER_NAME']}/activities/vote/{gibberish(15)}",
|
||||||
'inReplyTo': post.profile_id(),
|
'inReplyTo': post.public_url(),
|
||||||
'name': pv.choice_text,
|
'name': pv.choice_text,
|
||||||
'to': post.author.public_url(),
|
'to': post.author.public_url(),
|
||||||
'type': 'Note'
|
'type': 'Note'
|
||||||
|
@ -602,7 +602,7 @@ def poll_vote(post_id):
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
post_request(post.author.ap_inbox_url, pollvote_json, current_user.private_key,
|
post_request(post.author.ap_inbox_url, pollvote_json, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -741,7 +741,7 @@ def add_reply(post_id: int, comment_id: int):
|
||||||
if not post.community.local_only:
|
if not post.community.local_only:
|
||||||
reply_json = {
|
reply_json = {
|
||||||
'type': 'Note',
|
'type': 'Note',
|
||||||
'id': reply.profile_id(),
|
'id': reply.public_url(),
|
||||||
'attributedTo': current_user.public_url(),
|
'attributedTo': current_user.public_url(),
|
||||||
'to': [
|
'to': [
|
||||||
'https://www.w3.org/ns/activitystreams#Public'
|
'https://www.w3.org/ns/activitystreams#Public'
|
||||||
|
@ -751,8 +751,8 @@ def add_reply(post_id: int, comment_id: int):
|
||||||
in_reply_to.author.public_url()
|
in_reply_to.author.public_url()
|
||||||
],
|
],
|
||||||
'content': reply.body_html,
|
'content': reply.body_html,
|
||||||
'inReplyTo': in_reply_to.profile_id(),
|
'inReplyTo': in_reply_to.public_url(),
|
||||||
'url': reply.profile_id(),
|
'url': reply.public_url(),
|
||||||
'mediaType': 'text/html',
|
'mediaType': 'text/html',
|
||||||
'published': ap_datetime(utcnow()),
|
'published': ap_datetime(utcnow()),
|
||||||
'distinguished': False,
|
'distinguished': False,
|
||||||
|
@ -793,7 +793,7 @@ def add_reply(post_id: int, comment_id: int):
|
||||||
]
|
]
|
||||||
if not post.community.is_local(): # this is a remote community, send it to the instance that hosts it
|
if not post.community.is_local(): # this is a remote community, send it to the instance that hosts it
|
||||||
success = post_request(post.community.ap_inbox_url, create_json, current_user.private_key,
|
success = post_request(post.community.ap_inbox_url, create_json, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
if not success:
|
if not success:
|
||||||
flash('Failed to send reply', 'error')
|
flash('Failed to send reply', 'error')
|
||||||
else: # local community - send it to followers on remote instances
|
else: # local community - send it to followers on remote instances
|
||||||
|
@ -819,12 +819,12 @@ def add_reply(post_id: int, comment_id: int):
|
||||||
if not in_reply_to.author.is_local() and in_reply_to.author.ap_domain != reply.community.ap_domain:
|
if not in_reply_to.author.is_local() and in_reply_to.author.ap_domain != reply.community.ap_domain:
|
||||||
if not post.community.is_local() or (post.community.is_local and not post.community.has_followers_from_domain(in_reply_to.author.ap_domain)):
|
if not post.community.is_local() or (post.community.is_local and not post.community.has_followers_from_domain(in_reply_to.author.ap_domain)):
|
||||||
success = post_request(in_reply_to.author.ap_inbox_url, create_json, current_user.private_key,
|
success = post_request(in_reply_to.author.ap_inbox_url, create_json, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
if not success:
|
if not success:
|
||||||
# sending to shared inbox is good enough for Mastodon, but Lemmy will reject it the local community has no followers
|
# sending to shared inbox is good enough for Mastodon, but Lemmy will reject it the local community has no followers
|
||||||
personal_inbox = in_reply_to.author.public_url() + '/inbox'
|
personal_inbox = in_reply_to.author.public_url() + '/inbox'
|
||||||
post_request(personal_inbox, create_json, current_user.private_key,
|
post_request(personal_inbox, create_json, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
|
|
||||||
if reply.depth <= constants.THREAD_CUTOFF_DEPTH:
|
if reply.depth <= constants.THREAD_CUTOFF_DEPTH:
|
||||||
return redirect(url_for('activitypub.post_ap', post_id=post_id, _anchor=f'comment_{reply.id}'))
|
return redirect(url_for('activitypub.post_ap', post_id=post_id, _anchor=f'comment_{reply.id}'))
|
||||||
|
@ -1312,9 +1312,9 @@ def federate_post_update(post):
|
||||||
update_json = {
|
update_json = {
|
||||||
'id': f"https://{current_app.config['SERVER_NAME']}/activities/update/{gibberish(15)}",
|
'id': f"https://{current_app.config['SERVER_NAME']}/activities/update/{gibberish(15)}",
|
||||||
'type': 'Update',
|
'type': 'Update',
|
||||||
'actor': current_user.profile_id(),
|
'actor': current_user.public_url(),
|
||||||
'audience': post.community.profile_id(),
|
'audience': post.community.public_url(),
|
||||||
'to': [post.community.profile_id(), 'https://www.w3.org/ns/activitystreams#Public'],
|
'to': [post.community.public_url(), 'https://www.w3.org/ns/activitystreams#Public'],
|
||||||
'published': ap_datetime(utcnow()),
|
'published': ap_datetime(utcnow()),
|
||||||
'cc': [
|
'cc': [
|
||||||
current_user.followers_url()
|
current_user.followers_url()
|
||||||
|
@ -1356,7 +1356,7 @@ def federate_post_update(post):
|
||||||
|
|
||||||
if not post.community.is_local(): # this is a remote community, send it to the instance that hosts it
|
if not post.community.is_local(): # this is a remote community, send it to the instance that hosts it
|
||||||
success = post_request(post.community.ap_inbox_url, update_json, current_user.private_key,
|
success = post_request(post.community.ap_inbox_url, update_json, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
if not success:
|
if not success:
|
||||||
flash('Failed to send edit to remote server', 'error')
|
flash('Failed to send edit to remote server', 'error')
|
||||||
else: # local community - send it to followers on remote instances
|
else: # local community - send it to followers on remote instances
|
||||||
|
@ -1458,7 +1458,7 @@ def federate_post_edit_to_user_followers(post):
|
||||||
instances = Instance.query.join(User, User.instance_id == Instance.id).join(UserFollower, UserFollower.remote_user_id == User.id)
|
instances = Instance.query.join(User, User.instance_id == Instance.id).join(UserFollower, UserFollower.remote_user_id == User.id)
|
||||||
instances = instances.filter(UserFollower.local_user_id == post.user_id)
|
instances = instances.filter(UserFollower.local_user_id == post.user_id)
|
||||||
for i in instances:
|
for i in instances:
|
||||||
post_request(i.inbox, update, current_user.private_key, current_user.profile_id() + '#main-key')
|
post_request(i.inbox, update, current_user.private_key, current_user.public_url() + '#main-key')
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/post/<int:post_id>/delete', methods=['GET', 'POST'])
|
@bp.route('/post/<int:post_id>/delete', methods=['GET', 'POST'])
|
||||||
|
@ -1483,9 +1483,9 @@ def post_delete(post_id: int):
|
||||||
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',
|
||||||
'actor': current_user.profile_id(),
|
'actor': current_user.public_url(),
|
||||||
'audience': post.community.profile_id(),
|
'audience': post.community.public_url(),
|
||||||
'to': [post.community.profile_id(), 'https://www.w3.org/ns/activitystreams#Public'],
|
'to': [post.community.public_url(), 'https://www.w3.org/ns/activitystreams#Public'],
|
||||||
'published': ap_datetime(utcnow()),
|
'published': ap_datetime(utcnow()),
|
||||||
'cc': [
|
'cc': [
|
||||||
current_user.followers_url()
|
current_user.followers_url()
|
||||||
|
@ -1499,7 +1499,7 @@ def post_delete(post_id: int):
|
||||||
if not community.local_only:
|
if not community.local_only:
|
||||||
if not post.community.is_local(): # this is a remote community, send it to the instance that hosts it
|
if not post.community.is_local(): # this is a remote community, send it to the instance that hosts it
|
||||||
success = post_request(post.community.ap_inbox_url, delete_json, current_user.private_key,
|
success = post_request(post.community.ap_inbox_url, delete_json, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
if not success:
|
if not success:
|
||||||
flash('Failed to send delete to remote server', 'error')
|
flash('Failed to send delete to remote server', 'error')
|
||||||
else: # local community - send it to followers on remote instances
|
else: # local community - send it to followers on remote instances
|
||||||
|
@ -1527,7 +1527,7 @@ def post_delete(post_id: int):
|
||||||
instances = Instance.query.join(User, User.instance_id == Instance.id).join(UserFollower, UserFollower.remote_user_id == User.id)
|
instances = Instance.query.join(User, User.instance_id == Instance.id).join(UserFollower, UserFollower.remote_user_id == User.id)
|
||||||
instances = instances.filter(UserFollower.local_user_id == post.user_id)
|
instances = instances.filter(UserFollower.local_user_id == post.user_id)
|
||||||
for i in instances:
|
for i in instances:
|
||||||
post_request(i.inbox, delete_json, current_user.private_key, current_user.profile_id() + '#main-key')
|
post_request(i.inbox, delete_json, current_user.private_key, current_user.public_url() + '#main-key')
|
||||||
|
|
||||||
return redirect(url_for('activitypub.community_profile', actor=community.ap_id if community.ap_id is not None else community.name))
|
return redirect(url_for('activitypub.community_profile', actor=community.ap_id if community.ap_id is not None else community.name))
|
||||||
|
|
||||||
|
@ -1543,14 +1543,14 @@ def post_restore(post_id: int):
|
||||||
# Federate un-delete
|
# Federate un-delete
|
||||||
if post.is_local():
|
if post.is_local():
|
||||||
delete_json = {
|
delete_json = {
|
||||||
"actor": current_user.profile_id(),
|
"actor": current_user.public_url(),
|
||||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
"object": {
|
"object": {
|
||||||
'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',
|
||||||
'actor': current_user.profile_id(),
|
'actor': current_user.public_url(),
|
||||||
'audience': post.community.profile_id(),
|
'audience': post.community.public_url(),
|
||||||
'to': [post.community.profile_id(), 'https://www.w3.org/ns/activitystreams#Public'],
|
'to': [post.community.public_url(), 'https://www.w3.org/ns/activitystreams#Public'],
|
||||||
'published': ap_datetime(utcnow()),
|
'published': ap_datetime(utcnow()),
|
||||||
'cc': [
|
'cc': [
|
||||||
current_user.followers_url()
|
current_user.followers_url()
|
||||||
|
@ -1559,8 +1559,8 @@ def post_restore(post_id: int):
|
||||||
'uri': post.ap_id,
|
'uri': post.ap_id,
|
||||||
"summary": "bad post",
|
"summary": "bad post",
|
||||||
},
|
},
|
||||||
"cc": [post.community.profile_id()],
|
"cc": [post.community.public_url()],
|
||||||
"audience": post.author.profile_id(),
|
"audience": post.author.public_url(),
|
||||||
"type": "Undo",
|
"type": "Undo",
|
||||||
"id": f"https://{current_app.config['SERVER_NAME']}/activities/undo/{gibberish(15)}"
|
"id": f"https://{current_app.config['SERVER_NAME']}/activities/undo/{gibberish(15)}"
|
||||||
}
|
}
|
||||||
|
@ -1571,7 +1571,7 @@ def post_restore(post_id: int):
|
||||||
"to": [
|
"to": [
|
||||||
"https://www.w3.org/ns/activitystreams#Public"
|
"https://www.w3.org/ns/activitystreams#Public"
|
||||||
],
|
],
|
||||||
"actor": post.community.ap_profile_id,
|
"actor": post.community.public_url(),
|
||||||
"cc": [
|
"cc": [
|
||||||
post.community.ap_followers_url
|
post.community.ap_followers_url
|
||||||
],
|
],
|
||||||
|
@ -1626,21 +1626,21 @@ def post_report(post_id: int):
|
||||||
if form.description.data:
|
if form.description.data:
|
||||||
summary += ' - ' + form.description.data
|
summary += ' - ' + form.description.data
|
||||||
report_json = {
|
report_json = {
|
||||||
"actor": current_user.profile_id(),
|
"actor": current_user.public_url(),
|
||||||
"audience": post.community.profile_id(),
|
"audience": post.community.public_url(),
|
||||||
"content": None,
|
"content": None,
|
||||||
"id": f"https://{current_app.config['SERVER_NAME']}/activities/flag/{gibberish(15)}",
|
"id": f"https://{current_app.config['SERVER_NAME']}/activities/flag/{gibberish(15)}",
|
||||||
"object": post.ap_id,
|
"object": post.ap_id,
|
||||||
"summary": summary,
|
"summary": summary,
|
||||||
"to": [
|
"to": [
|
||||||
post.community.profile_id()
|
post.community.public_url()
|
||||||
],
|
],
|
||||||
"type": "Flag"
|
"type": "Flag"
|
||||||
}
|
}
|
||||||
instance = Instance.query.get(post.community.instance_id)
|
instance = Instance.query.get(post.community.instance_id)
|
||||||
if post.community.ap_inbox_url and not current_user.has_blocked_instance(instance.id) and not instance_banned(instance.domain):
|
if post.community.ap_inbox_url and not current_user.has_blocked_instance(instance.id) and not instance_banned(instance.domain):
|
||||||
success = post_request(post.community.ap_inbox_url, report_json, current_user.private_key,
|
success = post_request(post.community.ap_inbox_url, report_json, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
if not success:
|
if not success:
|
||||||
flash('Failed to send report to remote server', 'error')
|
flash('Failed to send report to remote server', 'error')
|
||||||
|
|
||||||
|
@ -1762,14 +1762,14 @@ def post_reply_report(post_id: int, comment_id: int):
|
||||||
if form.description.data:
|
if form.description.data:
|
||||||
summary += ' - ' + form.description.data
|
summary += ' - ' + form.description.data
|
||||||
report_json = {
|
report_json = {
|
||||||
"actor": current_user.profile_id(),
|
"actor": current_user.public_url(),
|
||||||
"audience": post.community.profile_id(),
|
"audience": post.community.public_url(),
|
||||||
"content": None,
|
"content": None,
|
||||||
"id": f"https://{current_app.config['SERVER_NAME']}/activities/flag/{gibberish(15)}",
|
"id": f"https://{current_app.config['SERVER_NAME']}/activities/flag/{gibberish(15)}",
|
||||||
"object": post_reply.ap_id,
|
"object": post_reply.ap_id,
|
||||||
"summary": summary,
|
"summary": summary,
|
||||||
"to": [
|
"to": [
|
||||||
post.community.profile_id()
|
post.community.public_url()
|
||||||
],
|
],
|
||||||
"type": "Flag"
|
"type": "Flag"
|
||||||
}
|
}
|
||||||
|
@ -1777,7 +1777,7 @@ def post_reply_report(post_id: int, comment_id: int):
|
||||||
if post.community.ap_inbox_url and not current_user.has_blocked_instance(
|
if post.community.ap_inbox_url and not current_user.has_blocked_instance(
|
||||||
instance.id) and not instance_banned(instance.domain):
|
instance.id) and not instance_banned(instance.domain):
|
||||||
success = post_request(post.community.ap_inbox_url, report_json, current_user.private_key,
|
success = post_request(post.community.ap_inbox_url, report_json, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
if not success:
|
if not success:
|
||||||
flash('Failed to send report to remote server', 'error')
|
flash('Failed to send report to remote server', 'error')
|
||||||
|
|
||||||
|
@ -1852,7 +1852,7 @@ def post_reply_edit(post_id: int, comment_id: int):
|
||||||
if not post.community.local_only:
|
if not post.community.local_only:
|
||||||
reply_json = {
|
reply_json = {
|
||||||
'type': 'Note',
|
'type': 'Note',
|
||||||
'id': post_reply.profile_id(),
|
'id': post_reply.public_url(),
|
||||||
'attributedTo': current_user.public_url(),
|
'attributedTo': current_user.public_url(),
|
||||||
'to': [
|
'to': [
|
||||||
'https://www.w3.org/ns/activitystreams#Public'
|
'https://www.w3.org/ns/activitystreams#Public'
|
||||||
|
@ -1862,8 +1862,8 @@ def post_reply_edit(post_id: int, comment_id: int):
|
||||||
in_reply_to.author.public_url()
|
in_reply_to.author.public_url()
|
||||||
],
|
],
|
||||||
'content': post_reply.body_html,
|
'content': post_reply.body_html,
|
||||||
'inReplyTo': in_reply_to.profile_id(),
|
'inReplyTo': in_reply_to.public_url(),
|
||||||
'url': post_reply.profile_id(),
|
'url': post_reply.public_url(),
|
||||||
'mediaType': 'text/html',
|
'mediaType': 'text/html',
|
||||||
'published': ap_datetime(post_reply.posted_at),
|
'published': ap_datetime(post_reply.posted_at),
|
||||||
'updated': ap_datetime(post_reply.edited_at),
|
'updated': ap_datetime(post_reply.edited_at),
|
||||||
|
@ -1909,7 +1909,7 @@ def post_reply_edit(post_id: int, comment_id: int):
|
||||||
]
|
]
|
||||||
if not post.community.is_local(): # this is a remote community, send it to the instance that hosts it
|
if not post.community.is_local(): # this is a remote community, send it to the instance that hosts it
|
||||||
success = post_request(post.community.ap_inbox_url, update_json, current_user.private_key,
|
success = post_request(post.community.ap_inbox_url, update_json, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
if not success:
|
if not success:
|
||||||
flash('Failed to send send edit to remote server', 'error')
|
flash('Failed to send send edit to remote server', 'error')
|
||||||
else: # local community - send it to followers on remote instances
|
else: # local community - send it to followers on remote instances
|
||||||
|
@ -1935,12 +1935,12 @@ def post_reply_edit(post_id: int, comment_id: int):
|
||||||
if not in_reply_to.author.is_local() and in_reply_to.author.ap_domain != post_reply.community.ap_domain:
|
if not in_reply_to.author.is_local() and in_reply_to.author.ap_domain != post_reply.community.ap_domain:
|
||||||
if not post.community.is_local() or (post.community.is_local and not post.community.has_followers_from_domain(in_reply_to.author.ap_domain)):
|
if not post.community.is_local() or (post.community.is_local and not post.community.has_followers_from_domain(in_reply_to.author.ap_domain)):
|
||||||
success = post_request(in_reply_to.author.ap_inbox_url, update_json, current_user.private_key,
|
success = post_request(in_reply_to.author.ap_inbox_url, update_json, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
if not success:
|
if not success:
|
||||||
# sending to shared inbox is good enough for Mastodon, but Lemmy will reject it the local community has no followers
|
# sending to shared inbox is good enough for Mastodon, but Lemmy will reject it the local community has no followers
|
||||||
personal_inbox = in_reply_to.author.public_url() + '/inbox'
|
personal_inbox = in_reply_to.author.public_url() + '/inbox'
|
||||||
post_request(personal_inbox, update_json, current_user.private_key,
|
post_request(personal_inbox, update_json, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
|
|
||||||
return redirect(url_for('activitypub.post_ap', post_id=post.id))
|
return redirect(url_for('activitypub.post_ap', post_id=post.id))
|
||||||
else:
|
else:
|
||||||
|
@ -1978,9 +1978,9 @@ def post_reply_delete(post_id: int, comment_id: int):
|
||||||
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',
|
||||||
'actor': current_user.profile_id(),
|
'actor': current_user.public_url(),
|
||||||
'audience': post.community.profile_id(),
|
'audience': post.community.public_url(),
|
||||||
'to': [post.community.profile_id(), 'https://www.w3.org/ns/activitystreams#Public'],
|
'to': [post.community.public_url(), 'https://www.w3.org/ns/activitystreams#Public'],
|
||||||
'published': ap_datetime(utcnow()),
|
'published': ap_datetime(utcnow()),
|
||||||
'cc': [
|
'cc': [
|
||||||
current_user.followers_url()
|
current_user.followers_url()
|
||||||
|
@ -1992,7 +1992,7 @@ def post_reply_delete(post_id: int, comment_id: int):
|
||||||
|
|
||||||
if not post.community.is_local(): # this is a remote community, send it to the instance that hosts it
|
if not post.community.is_local(): # this is a remote community, send it to the instance that hosts it
|
||||||
success = post_request(post.community.ap_inbox_url, delete_json, current_user.private_key,
|
success = post_request(post.community.ap_inbox_url, delete_json, current_user.private_key,
|
||||||
current_user.profile_id() + '#main-key')
|
current_user.public_url() + '#main-key')
|
||||||
if not success:
|
if not success:
|
||||||
flash('Failed to send delete to remote server', 'error')
|
flash('Failed to send delete to remote server', 'error')
|
||||||
else: # local community - send it to followers on remote instances
|
else: # local community - send it to followers on remote instances
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
</form>
|
</form>
|
||||||
<p class="mt-4">
|
<p class="mt-4">
|
||||||
{% if not user.is_local() %}
|
{% if not user.is_local() %}
|
||||||
<a href="{{ user.profile_id() }}" class="btn btn-primary">View original profile</a>
|
<a href="{{ user.public_url() }}" class="btn btn-primary">View original profile</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -149,7 +149,7 @@
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
{% if not community.is_local() -%}
|
{% if not community.is_local() -%}
|
||||||
<ul>
|
<ul>
|
||||||
<li><p><a href="{{ community.profile_id() }}">{{ _('View community on original server') }}</a></p></li>
|
<li><p><a href="{{ community.public_url() }}">{{ _('View community on original server') }}</a></p></li>
|
||||||
<li><p><a href="{{ url_for('community.retrieve_remote_post', community_id=community.id) }}">{{ _('Retrieve a post from the original server') }}</a></p></li>
|
<li><p><a href="{{ url_for('community.retrieve_remote_post', community_id=community.id) }}">{{ _('Retrieve a post from the original server') }}</a></p></li>
|
||||||
</ul>
|
</ul>
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
<div class="col-12 col-md-8 position-relative add_reply main_pane">
|
<div class="col-12 col-md-8 position-relative add_reply main_pane">
|
||||||
<fieldset class="coolfieldset mt-4"><legend class="w-auto">Original post</legend>
|
<fieldset class="coolfieldset mt-4"><legend class="w-auto">Original post</legend>
|
||||||
<h3>{{ post.title }}</h3>
|
<h3>{{ post.title }}</h3>
|
||||||
{{ post.body_html | safe }}
|
{{ post.body_html|safe if post.body_html }}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
{% if comment %}
|
{% if comment %}
|
||||||
<fieldset class="coolfieldset mt-4"><legend class="w-auto">Comment you are replying to</legend>
|
<fieldset class="coolfieldset mt-4"><legend class="w-auto">Comment you are replying to</legend>
|
||||||
|
|
|
@ -273,11 +273,11 @@ def send_community_follow(community_id, join_request_id, user_id):
|
||||||
user = User.query.get(user_id)
|
user = User.query.get(user_id)
|
||||||
community = Community.query.get(community_id)
|
community = Community.query.get(community_id)
|
||||||
follow = {
|
follow = {
|
||||||
"actor": current_user.profile_id(),
|
"actor": current_user.public_url(),
|
||||||
"to": [community.ap_profile_id],
|
"to": [community.public_url()],
|
||||||
"object": community.ap_profile_id,
|
"object": community.public_url(),
|
||||||
"type": "Follow",
|
"type": "Follow",
|
||||||
"id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{join_request_id}"
|
"id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{join_request_id}"
|
||||||
}
|
}
|
||||||
success = post_request(community.ap_inbox_url, follow, user.private_key,
|
success = post_request(community.ap_inbox_url, follow, user.private_key,
|
||||||
user.profile_id() + '#main-key')
|
user.public_url() + '#main-key')
|
||||||
|
|
|
@ -560,9 +560,9 @@ def send_deletion_requests(user_id):
|
||||||
instances = Instance.query.filter(Instance.dormant == False).all()
|
instances = Instance.query.filter(Instance.dormant == False).all()
|
||||||
payload = {
|
payload = {
|
||||||
"@context": default_context(),
|
"@context": default_context(),
|
||||||
"actor": user.profile_id(),
|
"actor": user.public_url(),
|
||||||
"id": f"{user.profile_id()}#delete",
|
"id": f"{user.public_url()}#delete",
|
||||||
"object": user.profile_id(),
|
"object": user.public_url(),
|
||||||
"to": [
|
"to": [
|
||||||
"https://www.w3.org/ns/activitystreams#Public"
|
"https://www.w3.org/ns/activitystreams#Public"
|
||||||
],
|
],
|
||||||
|
@ -570,7 +570,7 @@ def send_deletion_requests(user_id):
|
||||||
}
|
}
|
||||||
for instance in instances:
|
for instance in instances:
|
||||||
if instance.inbox and instance.online() and instance.id != 1: # instance id 1 is always the current instance
|
if instance.inbox and instance.online() and instance.id != 1: # instance id 1 is always the current instance
|
||||||
post_request(instance.inbox, payload, user.private_key, f"{user.profile_id()}#main-key")
|
post_request(instance.inbox, payload, user.private_key, f"{user.public_url()}#main-key")
|
||||||
|
|
||||||
sleep(5)
|
sleep(5)
|
||||||
|
|
||||||
|
@ -704,14 +704,14 @@ def import_settings_task(user_id, filename):
|
||||||
db.session.add(join_request)
|
db.session.add(join_request)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
follow = {
|
follow = {
|
||||||
"actor": current_user.profile_id(),
|
"actor": current_user.public_url(),
|
||||||
"to": [community.ap_profile_id],
|
"to": [community.public_url()],
|
||||||
"object": community.ap_profile_id,
|
"object": community.public_url(),
|
||||||
"type": "Follow",
|
"type": "Follow",
|
||||||
"id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{join_request.id}"
|
"id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{join_request.id}"
|
||||||
}
|
}
|
||||||
success = post_request(community.ap_inbox_url, follow, user.private_key,
|
success = post_request(community.ap_inbox_url, follow, user.private_key,
|
||||||
user.profile_id() + '#main-key')
|
user.public_url() + '#main-key')
|
||||||
if not success:
|
if not success:
|
||||||
sleep(5) # give them a rest
|
sleep(5) # give them a rest
|
||||||
else: # for local communities, joining is instant
|
else: # for local communities, joining is instant
|
||||||
|
|
|
@ -27,9 +27,9 @@ def purge_user_then_delete_task(user_id):
|
||||||
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',
|
||||||
'actor': user.profile_id(),
|
'actor': user.public_url(),
|
||||||
'audience': post.community.profile_id(),
|
'audience': post.community.public_url(),
|
||||||
'to': [post.community.profile_id(), 'https://www.w3.org/ns/activitystreams#Public'],
|
'to': [post.community.public_url(), 'https://www.w3.org/ns/activitystreams#Public'],
|
||||||
'published': ap_datetime(utcnow()),
|
'published': ap_datetime(utcnow()),
|
||||||
'cc': [
|
'cc': [
|
||||||
user.followers_url()
|
user.followers_url()
|
||||||
|
@ -39,7 +39,7 @@ def purge_user_then_delete_task(user_id):
|
||||||
|
|
||||||
if not post.community.is_local(): # this is a remote community, send it to the instance that hosts it
|
if not post.community.is_local(): # this is a remote community, send it to the instance that hosts it
|
||||||
success = post_request(post.community.ap_inbox_url, delete_json, user.private_key,
|
success = post_request(post.community.ap_inbox_url, delete_json, user.private_key,
|
||||||
user.profile_id() + '#main-key')
|
user.public_url() + '#main-key')
|
||||||
|
|
||||||
else: # local community - send it to followers on remote instances, using Announce
|
else: # local community - send it to followers on remote instances, using Announce
|
||||||
announce = {
|
announce = {
|
||||||
|
@ -81,7 +81,7 @@ def purge_user_then_delete_task(user_id):
|
||||||
}
|
}
|
||||||
for instance in instances:
|
for instance in instances:
|
||||||
if instance.inbox and instance.id != 1:
|
if instance.inbox and instance.id != 1:
|
||||||
post_request(instance.inbox, payload, user.private_key, user.profile_id() + '#main-key')
|
post_request(instance.inbox, payload, user.private_key, user.public_url() + '#main-key')
|
||||||
|
|
||||||
sleep(100) # wait a while for any related activitypub traffic to die down.
|
sleep(100) # wait a while for any related activitypub traffic to die down.
|
||||||
user.deleted = True
|
user.deleted = True
|
||||||
|
@ -93,15 +93,15 @@ def purge_user_then_delete_task(user_id):
|
||||||
def unsubscribe_from_community(community, user):
|
def unsubscribe_from_community(community, user):
|
||||||
undo_id = f"https://{current_app.config['SERVER_NAME']}/activities/undo/" + gibberish(15)
|
undo_id = f"https://{current_app.config['SERVER_NAME']}/activities/undo/" + gibberish(15)
|
||||||
follow = {
|
follow = {
|
||||||
"actor": user.profile_id(),
|
"actor": user.public_url(),
|
||||||
"to": [community.ap_profile_id],
|
"to": [community.public_url()],
|
||||||
"object": community.ap_profile_id,
|
"object": community.public_url(),
|
||||||
"type": "Follow",
|
"type": "Follow",
|
||||||
"id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{gibberish(15)}"
|
"id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{gibberish(15)}"
|
||||||
}
|
}
|
||||||
undo = {
|
undo = {
|
||||||
'actor': user.profile_id(),
|
'actor': user.public_url(),
|
||||||
'to': [community.ap_profile_id],
|
'to': [community.public_url()],
|
||||||
'type': 'Undo',
|
'type': 'Undo',
|
||||||
'id': undo_id,
|
'id': undo_id,
|
||||||
'object': follow
|
'object': follow
|
||||||
|
@ -110,7 +110,7 @@ def unsubscribe_from_community(community, user):
|
||||||
activity_json=json.dumps(undo), result='processing')
|
activity_json=json.dumps(undo), result='processing')
|
||||||
db.session.add(activity)
|
db.session.add(activity)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
post_request(community.ap_inbox_url, undo, user.private_key, user.profile_id() + '#main-key')
|
post_request(community.ap_inbox_url, undo, user.private_key, user.public_url() + '#main-key')
|
||||||
activity.result = 'success'
|
activity.result = 'success'
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue