diff options
author | Andrew Godwin | 2022-11-16 22:23:32 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-11-16 22:23:32 -0700 |
commit | b13c239213147b7acae4060aff35640d625b5169 (patch) | |
tree | 16c76dc20b3cc28403371c4b7817f636e22b13c1 /users/views | |
parent | 5b34ea46c3f458a174c5443714ade43c21defdac (diff) | |
download | takahe-b13c239213147b7acae4060aff35640d625b5169.tar.gz takahe-b13c239213147b7acae4060aff35640d625b5169.tar.bz2 takahe-b13c239213147b7acae4060aff35640d625b5169.zip |
Handle post edits, follow undos
Diffstat (limited to 'users/views')
-rw-r--r-- | users/views/activitypub.py | 4 | ||||
-rw-r--r-- | users/views/identity.py | 24 |
2 files changed, 22 insertions, 6 deletions
diff --git a/users/views/activitypub.py b/users/views/activitypub.py index f1abb06..4660d7a 100644 --- a/users/views/activitypub.py +++ b/users/views/activitypub.py @@ -52,13 +52,13 @@ class Webfinger(View): { "subject": f"acct:{identity.handle}", "aliases": [ - identity.view_url, + str(identity.urls.view_nice), ], "links": [ { "rel": "http://webfinger.net/rel/profile-page", "type": "text/html", - "href": identity.view_url, + "href": str(identity.urls.view_nice), }, { "rel": "self", diff --git a/users/views/identity.py b/users/views/identity.py index 4b92e14..b9298b7 100644 --- a/users/views/identity.py +++ b/users/views/identity.py @@ -9,7 +9,7 @@ from django.views.generic import FormView, TemplateView, View from core.models import Config from users.decorators import identity_required -from users.models import Domain, Follow, Identity, IdentityStates +from users.models import Domain, Follow, FollowStates, Identity, IdentityStates from users.shortcuts import by_handle_or_404 @@ -27,12 +27,19 @@ class ViewIdentity(TemplateView): posts = identity.posts.all()[:100] if identity.data_age > Config.system.identity_max_age: identity.transition_perform(IdentityStates.outdated) + follow = None + if self.request.identity: + follow = Follow.maybe_get(self.request.identity, identity) + if follow and follow.state not in [ + FollowStates.unrequested, + FollowStates.local_requested, + FollowStates.accepted, + ]: + follow = None return { "identity": identity, "posts": posts, - "follow": Follow.maybe_get(self.request.identity, identity) - if self.request.identity - else None, + "follow": follow, } @@ -46,6 +53,15 @@ class ActionIdentity(View): existing_follow = Follow.maybe_get(self.request.identity, identity) if not existing_follow: Follow.create_local(self.request.identity, identity) + elif existing_follow.state in [ + FollowStates.undone, + FollowStates.undone_remotely, + ]: + existing_follow.transition_perform(FollowStates.unrequested) + elif action == "unfollow": + existing_follow = Follow.maybe_get(self.request.identity, identity) + if existing_follow: + existing_follow.transition_perform(FollowStates.undone) else: raise ValueError(f"Cannot handle identity action {action}") return redirect(identity.urls.view) |