summaryrefslogtreecommitdiffstats
path: root/users
diff options
context:
space:
mode:
Diffstat (limited to 'users')
-rw-r--r--users/models/follow.py4
-rw-r--r--users/views/follows.py33
-rw-r--r--users/views/identity.py14
3 files changed, 46 insertions, 5 deletions
diff --git a/users/models/follow.py b/users/models/follow.py
index d2ee493..e741c56 100644
--- a/users/models/follow.py
+++ b/users/models/follow.py
@@ -24,6 +24,10 @@ class FollowStates(StateGraph):
undone.transitions_to(undone_remotely)
@classmethod
+ def group_active(cls):
+ return [cls.unrequested, cls.local_requested, cls.accepted]
+
+ @classmethod
async def handle_unrequested(cls, instance: "Follow"):
"""
Follows that are unrequested need us to deliver the Follow object
diff --git a/users/views/follows.py b/users/views/follows.py
new file mode 100644
index 0000000..9030efe
--- /dev/null
+++ b/users/views/follows.py
@@ -0,0 +1,33 @@
+from django.utils.decorators import method_decorator
+from django.views.generic import TemplateView
+
+from users.decorators import identity_required
+from users.models import FollowStates
+
+
+@method_decorator(identity_required, name="dispatch")
+class FollowsPage(TemplateView):
+ """
+ Shows followers/follows.
+ """
+
+ template_name = "settings/follows.html"
+
+ def get_context_data(self):
+ # Gather all identities with a following relationship with us
+ identities = {}
+ for outbound_follow in self.request.identity.outbound_follows.filter(
+ state__in=FollowStates.group_active()
+ ):
+ identities.setdefault(outbound_follow.target, {})[
+ "outbound"
+ ] = outbound_follow
+ for inbound_follow in self.request.identity.inbound_follows.filter(
+ state__in=FollowStates.group_active()
+ ):
+ identities.setdefault(inbound_follow.source, {})["inbound"] = inbound_follow
+
+ return {
+ "section": "follows",
+ "identities": sorted(identities.items(), key=lambda i: i[0].username),
+ }
diff --git a/users/views/identity.py b/users/views/identity.py
index b83ba9a..ae8e5b0 100644
--- a/users/views/identity.py
+++ b/users/views/identity.py
@@ -28,18 +28,22 @@ class ViewIdentity(TemplateView):
if identity.data_age > Config.system.identity_max_age:
identity.transition_perform(IdentityStates.outdated)
follow = None
+ reverse_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,
- ]:
+ if follow and follow.state not in FollowStates.group_active():
follow = None
+ reverse_follow = Follow.maybe_get(identity, self.request.identity)
+ if (
+ reverse_follow
+ and reverse_follow.state not in FollowStates.group_active()
+ ):
+ reverse_follow = None
return {
"identity": identity,
"posts": posts,
"follow": follow,
+ "reverse_follow": reverse_follow,
}