From 744c2825d97244dd27900cb1f777d2e638b49786 Mon Sep 17 00:00:00 2001 From: Christof Dorner Date: Fri, 12 May 2023 23:43:26 +0000 Subject: [PATCH] Show posts and boosts on an identity's profile view (#574) --- activities/services/timeline.py | 28 ++++++++++++++++++++++------ templates/identity/view.html | 17 +++++++++++++++-- users/views/identity.py | 7 ++++++- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/activities/services/timeline.py b/activities/services/timeline.py index a065b73..5e7015d 100644 --- a/activities/services/timeline.py +++ b/activities/services/timeline.py @@ -81,15 +81,31 @@ class TimelineService: .order_by("-created") ) - def identity_public(self, identity: Identity): + def identity_public(self, identity: Identity, include_boosts: bool = True): """ - Returns all publically visible posts for an identity + Returns timeline events with all of an identity's publicly visible posts + and their boosts """ + filter = models.Q( + type=TimelineEvent.Types.post, + subject_post__author=identity, + subject_post__visibility__in=[ + Post.Visibilities.public, + Post.Visibilities.local_only, + Post.Visibilities.unlisted, + ], + ) + if include_boosts: + filter = filter | models.Q( + type=TimelineEvent.Types.boost, subject_identity=identity + ) return ( - PostService.queryset() - .filter(author=identity) - .unlisted(include_replies=True) - .order_by("-id") + self.event_queryset() + .filter( + filter, + identity=identity, + ) + .order_by("-created") ) def likes(self) -> models.QuerySet[Post]: diff --git a/templates/identity/view.html b/templates/identity/view.html index 0c59723..16e31d0 100644 --- a/templates/identity/view.html +++ b/templates/identity/view.html @@ -1,4 +1,5 @@ {% extends "base.html" %} +{% load activity_tags %} {% block title %}{{ identity }}{% endblock %} @@ -90,8 +91,20 @@ {% block subcontent %}
- {% for post in page_obj %} - {% include "activities/_post.html" %} + {% for event in page_obj %} + {% if event.type == "post" %} + {% include "activities/_post.html" with post=event.subject_post %} + {% elif event.type == "boost" %} +
+ + {{ event.subject_identity.html_name_or_handle }} + boosted + +
+ {% include "activities/_post.html" with post=event.subject_post %} + {% endif %} {% empty %} {% if identity.local %} diff --git a/users/views/identity.py b/users/views/identity.py index a23177c..7de4064 100644 --- a/users/views/identity.py +++ b/users/views/identity.py @@ -164,7 +164,12 @@ class IdentityFeed(Feed): return {"image": image} def items(self, identity: Identity): - return TimelineService(None).identity_public(identity)[:20] + return [ + e.subject_post + for e in TimelineService(None).identity_public( + identity, include_boosts=False + )[:20] + ] def item_description(self, item: Post): return item.safe_content_remote()