From 3203ac5506067b45b38d5d9acd50c2dd2838c3bc Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Wed, 5 Jun 2024 13:21:41 +1200 Subject: [PATCH] oh boy, this sucks #194 --- app/activitypub/routes.py | 18 ++-- app/activitypub/util.py | 14 +-- app/admin/util.py | 20 ++-- app/chat/util.py | 10 +- app/community/routes.py | 32 +++--- app/community/util.py | 16 +-- app/models.py | 9 +- app/post/routes.py | 134 ++++++++++++------------ app/templates/admin/edit_user.html | 2 +- app/templates/community/community.html | 2 +- app/templates/post/post_reply_edit.html | 4 +- app/topic/routes.py | 8 +- app/user/routes.py | 16 +-- app/user/utils.py | 22 ++-- 14 files changed, 155 insertions(+), 152 deletions(-) diff --git a/app/activitypub/routes.py b/app/activitypub/routes.py index a6cb5d55..68bf24f1 100644 --- a/app/activitypub/routes.py +++ b/app/activitypub/routes.py @@ -255,7 +255,7 @@ def user_profile(actor): server = current_app.config['SERVER_NAME'] actor_data = { "@context": default_context(), "type": "Person" if not user.bot else "Service", - "id": user.profile_id(), + "id": user.public_url(), "preferredUsername": actor.lower(), "name": user.title if user.title else user.user_name, "inbox": f"https://{server}/u/{actor.lower()}/inbox", @@ -264,8 +264,8 @@ def user_profile(actor): "indexable": user.indexable, "manuallyApprovesFollowers": False if not user.ap_manually_approves_followers else user.ap_manually_approves_followers, "publicKey": { - "id": f"https://{server}/u/{actor.lower()}#main-key", - "owner": f"https://{server}/u/{actor.lower()}", + "id": f"{user.public_url()}#main-key", + "owner": user.public_url(), "publicKeyPem": user.public_key # .replace("\n", "\\n") #LOOKSWRONG }, "endpoints": { @@ -1187,13 +1187,13 @@ def announce_activity_to_followers(community, creator, activity): announce_activity = { '@context': default_context(), - "actor": community.profile_id(), + "actor": community.public_url(), "to": [ "https://www.w3.org/ns/activitystreams#Public" ], "object": activity, "cc": [ - f"{community.profile_id()}/followers" + f"{community.public_url()}/followers" ], "type": "Announce", "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", "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' else: activity_log.exception_message = 'Error sending Accept' @@ -1461,21 +1461,21 @@ def comment_ap(comment_id): "@context": default_context(), "type": "Note", "id": reply.ap_id, - "attributedTo": reply.author.profile_id(), + "attributedTo": reply.author.public_url(), "inReplyTo": reply.in_reply_to(), "to": [ "https://www.w3.org/ns/activitystreams#Public", reply.to() ], "cc": [ - reply.community.profile_id(), + reply.community.public_url(), reply.author.followers_url() ], 'content': reply.body_html, 'mediaType': 'text/html', 'published': ap_datetime(reply.created_at), 'distinguished': False, - 'audience': reply.community.profile_id(), + 'audience': reply.community.public_url(), 'language': { 'identifier': reply.language_code(), 'name': reply.language_name() diff --git a/app/activitypub/util.py b/app/activitypub/util.py index 966233db..ccff4f7b 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -133,14 +133,14 @@ def post_to_activity(post: Post, community: Community): ], "object": { "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": [ "https://www.w3.org/ns/activitystreams#Public" ], "object": { "type": "Page", "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": [ f"https://{current_app.config['SERVER_NAME']}/c/{community.name}", "https://www.w3.org/ns/activitystreams#Public" @@ -2283,7 +2283,7 @@ def lemmy_site_data(): "banned": admin.banned, "published": admin.created.isoformat() + 'Z', "updated": admin.created.isoformat() + 'Z', - "actor_id": admin.profile_id(), + "actor_id": admin.public_url(), "local": True, "deleted": admin.deleted, "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 = { 'id': f"https://{current_app.config['SERVER_NAME']}/activities/update/{gibberish(15)}", 'type': 'Update', - 'actor': post.author.profile_id(), - 'audience': post.community.profile_id(), + 'actor': post.author.public_url(), + 'audience': post.community.public_url(), 'to': ['https://www.w3.org/ns/activitystreams#Public'], 'published': ap_datetime(utcnow()), 'cc': [ @@ -2589,7 +2589,7 @@ def inform_followers_of_post_update_task(post_id: int, sending_instance_id: int) for i in instances: if sending_instance_id != i.id: 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: pass @@ -2600,6 +2600,6 @@ def inform_followers_of_post_update_task(post_id: int, sending_instance_id: int) for i in instances: if sending_instance_id != i.id: 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: pass diff --git a/app/admin/util.py b/app/admin/util.py index 6871eea8..b22684d1 100644 --- a/app/admin/util.py +++ b/app/admin/util.py @@ -34,9 +34,9 @@ def unsubscribe_from_everything_then_delete_task(user_id): instances = Instance.query.filter(Instance.dormant == False).all() payload = { "@context": default_context(), - "actor": user.profile_id(), - "id": f"{user.profile_id()}#delete", - "object": user.profile_id(), + "actor": user.public_url(), + "id": f"{user.public_url()}#delete", + "object": user.public_url(), "to": [ "https://www.w3.org/ns/activitystreams#Public" ], @@ -44,7 +44,7 @@ def unsubscribe_from_everything_then_delete_task(user_id): } for instance in instances: 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) @@ -57,15 +57,15 @@ def unsubscribe_from_everything_then_delete_task(user_id): def unsubscribe_from_community(community, user): undo_id = f"https://{current_app.config['SERVER_NAME']}/activities/undo/" + gibberish(15) follow = { - "actor": f"https://{current_app.config['SERVER_NAME']}/u/{user.user_name}", - "to": [community.ap_profile_id], - "object": community.ap_profile_id, + "actor": user.public_url(), + "to": [community.public_url()], + "object": community.public_url(), "type": "Follow", "id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{gibberish(15)}" } undo = { - 'actor': user.profile_id(), - 'to': [community.ap_profile_id], + 'actor': user.public_url(), + 'to': [community.public_url()], 'type': 'Undo', 'id': undo_id, 'object': follow @@ -74,7 +74,7 @@ def unsubscribe_from_community(community, user): activity_json=json.dumps(undo), result='processing') db.session.add(activity) 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' db.session.commit() diff --git a/app/chat/util.py b/app/chat/util.py index 9b6083f3..8d63a3c1 100644 --- a/app/chat/util.py +++ b/app/chat/util.py @@ -30,26 +30,26 @@ def send_message(message: str, conversation_id: int) -> ChatMessage: else: # Federate reply reply_json = { - "actor": current_user.profile_id(), + "actor": current_user.public_url(), "id": f"https://{current_app.config['SERVER_NAME']}/activities/create/{gibberish(15)}", "object": { - "attributedTo": current_user.profile_id(), + "attributedTo": current_user.public_url(), "content": reply.body_html, "id": f"https://{current_app.config['SERVER_NAME']}/private_message/{reply.id}", "mediaType": "text/html", "published": utcnow().isoformat() + 'Z', # Lemmy is inconsistent with the date format they use "to": [ - recipient.profile_id() + recipient.public_url() ], "type": "ChatMessage" }, "to": [ - recipient.profile_id() + recipient.public_url() ], "type": "Create" } 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: flash(_('Message failed to send to %(name)s.', name=recipient.link()), 'error') diff --git a/app/community/routes.py b/app/community/routes.py index 1f729771..98407e87 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -386,14 +386,14 @@ def subscribe(actor): db.session.add(join_request) db.session.commit() follow = { - "actor": current_user.profile_id(), - "to": [community.ap_profile_id], - "object": community.ap_profile_id, + "actor": current_user.public_url(), + "to": [community.public_url()], + "object": community.public_url(), "type": "Follow", "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, - current_user.profile_id() + '#main-key') + current_user.public_url() + '#main-key') 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') # 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 undo_id = f"https://{current_app.config['SERVER_NAME']}/activities/undo/" + gibberish(15) follow = { - "actor": current_user.profile_id(), - "to": [community.ap_profile_id], - "object": community.ap_profile_id, + "actor": current_user.public_url(), + "to": [community.public_url()], + "object": community.public_url(), "type": "Follow", "id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{gibberish(15)}" } undo = { - 'actor': current_user.profile_id(), - 'to': [community.ap_profile_id], + 'actor': current_user.public_url(), + 'to': [community.public_url()], 'type': 'Undo', 'id': undo_id, 'object': follow } 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: 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.commit() follow = { - "actor": current_user.profile_id(), - "to": [community.ap_profile_id], - "object": community.ap_profile_id, + "actor": current_user.public_url(), + "to": [community.public_url()], + "object": community.public_url(), "type": "Follow", "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, - current_user.profile_id() + '#main-key') + current_user.public_url() + '#main-key') member = CommunityMember(user_id=current_user.id, community_id=community.id) db.session.add(member) db.session.commit() @@ -952,7 +952,7 @@ def federate_post(community, post): 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 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: flash(_('Your post to %(name)s has been made.', name=community.title)) 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 = instances.filter(UserFollower.local_user_id == post.user_id).filter(Instance.gone_forever == False) 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//report', methods=['GET', 'POST']) diff --git a/app/community/util.py b/app/community/util.py index e6b3b672..decfe47b 100644 --- a/app/community/util.py +++ b/app/community/util.py @@ -548,9 +548,9 @@ def delete_post_from_community_task(post_id): delete_json = { 'id': f"https://{current_app.config['SERVER_NAME']}/activities/delete/{gibberish(15)}", 'type': 'Delete', - 'actor': current_user.profile_id(), - 'audience': post.community.profile_id(), - 'to': [post.community.profile_id(), 'https://www.w3.org/ns/activitystreams#Public'], + 'actor': current_user.public_url(), + 'audience': post.community.public_url(), + 'to': [post.community.public_url(), 'https://www.w3.org/ns/activitystreams#Public'], 'published': ap_datetime(utcnow()), 'cc': [ 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 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 announce = { "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 = { 'id': f"https://{current_app.config['SERVER_NAME']}/activities/delete/{gibberish(15)}", 'type': 'Delete', - 'actor': current_user.profile_id(), - 'audience': post.community.profile_id(), - 'to': [post.community.profile_id(), 'https://www.w3.org/ns/activitystreams#Public'], + 'actor': current_user.public_url(), + 'audience': post.community.public_url(), + 'to': [post.community.public_url(), 'https://www.w3.org/ns/activitystreams#Public'], 'published': ap_datetime(utcnow()), 'cc': [ 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 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 announce = { diff --git a/app/models.py b/app/models.py index 4242e785..5192a5db 100644 --- a/app/models.py +++ b/app/models.py @@ -756,7 +756,7 @@ class User(UserMixin, db.Model): if self.ap_followers_url: return self.ap_followers_url else: - return self.profile_id() + '/followers' + return self.public_url() + '/followers' def get_reset_password_token(self, expires_in=600): return jwt.encode( @@ -1118,6 +1118,9 @@ class PostReply(db.Model): else: 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 def in_reply_to(self): 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 def to(self): if self.parent_id is None: - return self.post.author.profile_id() + return self.post.author.public_url() else: parent = PostReply.query.get(self.parent_id) - return parent.author.profile_id() + return parent.author.public_url() def delete_dependencies(self): for child_reply in self.child_replies(): diff --git a/app/post/routes.py b/app/post/routes.py index 57c9eabb..ae260853 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -145,7 +145,7 @@ def show_post(post_id: int): # federation reply_json = { 'type': 'Note', - 'id': reply.profile_id(), + 'id': reply.public_url(), 'attributedTo': current_user.public_url(), 'to': [ 'https://www.w3.org/ns/activitystreams#Public' @@ -154,7 +154,7 @@ def show_post(post_id: int): community.public_url(), post.author.public_url() ], 'content': reply.body_html, - 'inReplyTo': post.profile_id(), + 'inReplyTo': post.public_url(), 'mediaType': 'text/html', 'published': ap_datetime(utcnow()), '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 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: flash('Failed to send to remote instance', 'error') 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 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, - current_user.profile_id() + '#main-key') + current_user.public_url() + '#main-key') if not success: # 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' 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 else: @@ -387,26 +387,26 @@ def post_vote(post_id: int, vote_direction): if not post.community.local_only: if undo: action_json = { - 'actor': current_user.profile_id(), + 'actor': current_user.public_url(), 'type': 'Undo', 'id': f"https://{current_app.config['SERVER_NAME']}/activities/undo/{gibberish(15)}", - 'audience': post.community.profile_id(), + 'audience': post.community.public_url(), 'object': { - 'actor': current_user.profile_id(), - 'object': post.profile_id(), + 'actor': current_user.public_url(), + 'object': post.public_url(), 'type': undo, 'id': f"https://{current_app.config['SERVER_NAME']}/activities/{undo.lower()}/{gibberish(15)}", - 'audience': post.community.profile_id() + 'audience': post.community.public_url() } } else: action_type = 'Like' if vote_direction == 'upvote' else 'Dislike' action_json = { - 'actor': current_user.profile_id(), - 'object': post.profile_id(), + 'actor': current_user.public_url(), + 'object': post.public_url(), 'type': action_type, '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(): announce = { @@ -415,7 +415,7 @@ def post_vote(post_id: int, vote_direction): "to": [ "https://www.w3.org/ns/activitystreams#Public" ], - "actor": post.community.ap_profile_id, + "actor": post.community.public_url(), "cc": [ 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) else: 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: flash('Failed to send vote', 'warning') @@ -499,26 +499,26 @@ def comment_vote(comment_id, vote_direction): if not comment.community.local_only: if undo: action_json = { - 'actor': current_user.profile_id(), + 'actor': current_user.public_url(), 'type': 'Undo', 'id': f"https://{current_app.config['SERVER_NAME']}/activities/undo/{gibberish(15)}", - 'audience': comment.community.profile_id(), + 'audience': comment.community.public_url(), 'object': { - 'actor': current_user.profile_id(), - 'object': comment.profile_id(), + 'actor': current_user.public_url(), + 'object': comment.public_url(), 'type': undo, 'id': f"https://{current_app.config['SERVER_NAME']}/activities/{undo.lower()}/{gibberish(15)}", - 'audience': comment.community.profile_id() + 'audience': comment.community.public_url() } } else: action_type = 'Like' if vote_direction == 'upvote' else 'Dislike' action_json = { - 'actor': current_user.profile_id(), - 'object': comment.profile_id(), + 'actor': current_user.public_url(), + 'object': comment.public_url(), 'type': action_type, '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(): announce = { @@ -539,7 +539,7 @@ def comment_vote(comment_id, vote_direction): send_to_remote_instance(instance.id, comment.community.id, announce) else: 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: flash('Failed to send vote', 'warning') @@ -592,7 +592,7 @@ def poll_vote(post_id): 'object': { 'attributedTo': current_user.public_url(), 'id': f"https://{current_app.config['SERVER_NAME']}/activities/vote/{gibberish(15)}", - 'inReplyTo': post.profile_id(), + 'inReplyTo': post.public_url(), 'name': pv.choice_text, 'to': post.author.public_url(), 'type': 'Note' @@ -602,7 +602,7 @@ def poll_vote(post_id): } try: 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: pass @@ -741,7 +741,7 @@ def add_reply(post_id: int, comment_id: int): if not post.community.local_only: reply_json = { 'type': 'Note', - 'id': reply.profile_id(), + 'id': reply.public_url(), 'attributedTo': current_user.public_url(), 'to': [ '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() ], 'content': reply.body_html, - 'inReplyTo': in_reply_to.profile_id(), - 'url': reply.profile_id(), + 'inReplyTo': in_reply_to.public_url(), + 'url': reply.public_url(), 'mediaType': 'text/html', 'published': ap_datetime(utcnow()), '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 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: flash('Failed to send reply', 'error') 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 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, - current_user.profile_id() + '#main-key') + current_user.public_url() + '#main-key') if not success: # 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' 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: 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 = { 'id': f"https://{current_app.config['SERVER_NAME']}/activities/update/{gibberish(15)}", 'type': 'Update', - 'actor': current_user.profile_id(), - 'audience': post.community.profile_id(), - 'to': [post.community.profile_id(), 'https://www.w3.org/ns/activitystreams#Public'], + 'actor': current_user.public_url(), + 'audience': post.community.public_url(), + 'to': [post.community.public_url(), 'https://www.w3.org/ns/activitystreams#Public'], 'published': ap_datetime(utcnow()), 'cc': [ 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 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: flash('Failed to send edit to remote server', 'error') 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 = instances.filter(UserFollower.local_user_id == post.user_id) 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//delete', methods=['GET', 'POST']) @@ -1483,9 +1483,9 @@ def post_delete(post_id: int): delete_json = { 'id': f"https://{current_app.config['SERVER_NAME']}/activities/delete/{gibberish(15)}", 'type': 'Delete', - 'actor': current_user.profile_id(), - 'audience': post.community.profile_id(), - 'to': [post.community.profile_id(), 'https://www.w3.org/ns/activitystreams#Public'], + 'actor': current_user.public_url(), + 'audience': post.community.public_url(), + 'to': [post.community.public_url(), 'https://www.w3.org/ns/activitystreams#Public'], 'published': ap_datetime(utcnow()), 'cc': [ current_user.followers_url() @@ -1499,7 +1499,7 @@ def post_delete(post_id: int): if not community.local_only: 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, - current_user.profile_id() + '#main-key') + current_user.public_url() + '#main-key') if not success: flash('Failed to send delete to remote server', 'error') 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 = instances.filter(UserFollower.local_user_id == post.user_id) 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)) @@ -1543,14 +1543,14 @@ def post_restore(post_id: int): # Federate un-delete if post.is_local(): delete_json = { - "actor": current_user.profile_id(), + "actor": current_user.public_url(), "to": ["https://www.w3.org/ns/activitystreams#Public"], "object": { 'id': f"https://{current_app.config['SERVER_NAME']}/activities/delete/{gibberish(15)}", 'type': 'Delete', - 'actor': current_user.profile_id(), - 'audience': post.community.profile_id(), - 'to': [post.community.profile_id(), 'https://www.w3.org/ns/activitystreams#Public'], + 'actor': current_user.public_url(), + 'audience': post.community.public_url(), + 'to': [post.community.public_url(), 'https://www.w3.org/ns/activitystreams#Public'], 'published': ap_datetime(utcnow()), 'cc': [ current_user.followers_url() @@ -1559,8 +1559,8 @@ def post_restore(post_id: int): 'uri': post.ap_id, "summary": "bad post", }, - "cc": [post.community.profile_id()], - "audience": post.author.profile_id(), + "cc": [post.community.public_url()], + "audience": post.author.public_url(), "type": "Undo", "id": f"https://{current_app.config['SERVER_NAME']}/activities/undo/{gibberish(15)}" } @@ -1571,7 +1571,7 @@ def post_restore(post_id: int): "to": [ "https://www.w3.org/ns/activitystreams#Public" ], - "actor": post.community.ap_profile_id, + "actor": post.community.public_url(), "cc": [ post.community.ap_followers_url ], @@ -1626,21 +1626,21 @@ def post_report(post_id: int): if form.description.data: summary += ' - ' + form.description.data report_json = { - "actor": current_user.profile_id(), - "audience": post.community.profile_id(), + "actor": current_user.public_url(), + "audience": post.community.public_url(), "content": None, "id": f"https://{current_app.config['SERVER_NAME']}/activities/flag/{gibberish(15)}", "object": post.ap_id, "summary": summary, "to": [ - post.community.profile_id() + post.community.public_url() ], "type": "Flag" } 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): 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: 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: summary += ' - ' + form.description.data report_json = { - "actor": current_user.profile_id(), - "audience": post.community.profile_id(), + "actor": current_user.public_url(), + "audience": post.community.public_url(), "content": None, "id": f"https://{current_app.config['SERVER_NAME']}/activities/flag/{gibberish(15)}", "object": post_reply.ap_id, "summary": summary, "to": [ - post.community.profile_id() + post.community.public_url() ], "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( instance.id) and not instance_banned(instance.domain): 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: 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: reply_json = { 'type': 'Note', - 'id': post_reply.profile_id(), + 'id': post_reply.public_url(), 'attributedTo': current_user.public_url(), 'to': [ '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() ], 'content': post_reply.body_html, - 'inReplyTo': in_reply_to.profile_id(), - 'url': post_reply.profile_id(), + 'inReplyTo': in_reply_to.public_url(), + 'url': post_reply.public_url(), 'mediaType': 'text/html', 'published': ap_datetime(post_reply.posted_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 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: flash('Failed to send send edit to remote server', 'error') 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 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, - current_user.profile_id() + '#main-key') + current_user.public_url() + '#main-key') if not success: # 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' 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)) else: @@ -1978,9 +1978,9 @@ def post_reply_delete(post_id: int, comment_id: int): delete_json = { 'id': f"https://{current_app.config['SERVER_NAME']}/activities/delete/{gibberish(15)}", 'type': 'Delete', - 'actor': current_user.profile_id(), - 'audience': post.community.profile_id(), - 'to': [post.community.profile_id(), 'https://www.w3.org/ns/activitystreams#Public'], + 'actor': current_user.public_url(), + 'audience': post.community.public_url(), + 'to': [post.community.public_url(), 'https://www.w3.org/ns/activitystreams#Public'], 'published': ap_datetime(utcnow()), 'cc': [ 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 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: flash('Failed to send delete to remote server', 'error') else: # local community - send it to followers on remote instances diff --git a/app/templates/admin/edit_user.html b/app/templates/admin/edit_user.html index 2070ed91..91d87942 100644 --- a/app/templates/admin/edit_user.html +++ b/app/templates/admin/edit_user.html @@ -38,7 +38,7 @@

{% if not user.is_local() %} - View original profile + View original profile {% endif %}

diff --git a/app/templates/community/community.html b/app/templates/community/community.html index 4d29cb3f..28cb16cf 100644 --- a/app/templates/community/community.html +++ b/app/templates/community/community.html @@ -149,7 +149,7 @@ {% endif -%} {% if not community.is_local() -%} {% endif -%} diff --git a/app/templates/post/post_reply_edit.html b/app/templates/post/post_reply_edit.html index af2afcd6..64f3e54b 100644 --- a/app/templates/post/post_reply_edit.html +++ b/app/templates/post/post_reply_edit.html @@ -11,11 +11,11 @@
Original post

{{ post.title }}

- {{ post.body_html | safe }} + {{ post.body_html|safe if post.body_html }}
{% if comment %}
Comment you are replying to - {{ comment.body_html | safe}} + {{ comment.body_html|safe }}
{% endif %}
diff --git a/app/topic/routes.py b/app/topic/routes.py index e03ef8ce..7dcfaa1f 100644 --- a/app/topic/routes.py +++ b/app/topic/routes.py @@ -273,11 +273,11 @@ def send_community_follow(community_id, join_request_id, user_id): user = User.query.get(user_id) community = Community.query.get(community_id) follow = { - "actor": current_user.profile_id(), - "to": [community.ap_profile_id], - "object": community.ap_profile_id, + "actor": current_user.public_url(), + "to": [community.public_url()], + "object": community.public_url(), "type": "Follow", "id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{join_request_id}" } success = post_request(community.ap_inbox_url, follow, user.private_key, - user.profile_id() + '#main-key') + user.public_url() + '#main-key') diff --git a/app/user/routes.py b/app/user/routes.py index bc988cc6..4ce7eef5 100644 --- a/app/user/routes.py +++ b/app/user/routes.py @@ -560,9 +560,9 @@ def send_deletion_requests(user_id): instances = Instance.query.filter(Instance.dormant == False).all() payload = { "@context": default_context(), - "actor": user.profile_id(), - "id": f"{user.profile_id()}#delete", - "object": user.profile_id(), + "actor": user.public_url(), + "id": f"{user.public_url()}#delete", + "object": user.public_url(), "to": [ "https://www.w3.org/ns/activitystreams#Public" ], @@ -570,7 +570,7 @@ def send_deletion_requests(user_id): } for instance in instances: 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) @@ -704,14 +704,14 @@ def import_settings_task(user_id, filename): db.session.add(join_request) db.session.commit() follow = { - "actor": current_user.profile_id(), - "to": [community.ap_profile_id], - "object": community.ap_profile_id, + "actor": current_user.public_url(), + "to": [community.public_url()], + "object": community.public_url(), "type": "Follow", "id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{join_request.id}" } success = post_request(community.ap_inbox_url, follow, user.private_key, - user.profile_id() + '#main-key') + user.public_url() + '#main-key') if not success: sleep(5) # give them a rest else: # for local communities, joining is instant diff --git a/app/user/utils.py b/app/user/utils.py index 42c4d8f3..01aa9bcf 100644 --- a/app/user/utils.py +++ b/app/user/utils.py @@ -27,9 +27,9 @@ def purge_user_then_delete_task(user_id): delete_json = { 'id': f"https://{current_app.config['SERVER_NAME']}/activities/delete/{gibberish(15)}", 'type': 'Delete', - 'actor': user.profile_id(), - 'audience': post.community.profile_id(), - 'to': [post.community.profile_id(), 'https://www.w3.org/ns/activitystreams#Public'], + 'actor': user.public_url(), + 'audience': post.community.public_url(), + 'to': [post.community.public_url(), 'https://www.w3.org/ns/activitystreams#Public'], 'published': ap_datetime(utcnow()), 'cc': [ 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 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 announce = { @@ -81,7 +81,7 @@ def purge_user_then_delete_task(user_id): } for instance in instances: 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. user.deleted = True @@ -93,15 +93,15 @@ def purge_user_then_delete_task(user_id): def unsubscribe_from_community(community, user): undo_id = f"https://{current_app.config['SERVER_NAME']}/activities/undo/" + gibberish(15) follow = { - "actor": user.profile_id(), - "to": [community.ap_profile_id], - "object": community.ap_profile_id, + "actor": user.public_url(), + "to": [community.public_url()], + "object": community.public_url(), "type": "Follow", "id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{gibberish(15)}" } undo = { - 'actor': user.profile_id(), - 'to': [community.ap_profile_id], + 'actor': user.public_url(), + 'to': [community.public_url()], 'type': 'Undo', 'id': undo_id, 'object': follow @@ -110,7 +110,7 @@ def unsubscribe_from_community(community, user): activity_json=json.dumps(undo), result='processing') db.session.add(activity) 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' db.session.commit()