mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-13 10:51:03 +00:00
Drive user timeline and RSS off a single service
This commit is contained in:
parent
a058140d11
commit
af6ddcf8f1
2 changed files with 28 additions and 16 deletions
|
@ -9,7 +9,7 @@ class TimelineService:
|
|||
Timelines and stuff!
|
||||
"""
|
||||
|
||||
def __init__(self, identity: Identity):
|
||||
def __init__(self, identity: Identity | None):
|
||||
self.identity = identity
|
||||
|
||||
def home(self) -> models.QuerySet[TimelineEvent]:
|
||||
|
@ -145,3 +145,27 @@ class TimelineService:
|
|||
),
|
||||
)
|
||||
)
|
||||
|
||||
def identity_public(self, identity: Identity):
|
||||
"""
|
||||
Returns all publically visible posts for an identity
|
||||
"""
|
||||
return (
|
||||
identity.posts.not_hidden()
|
||||
.unlisted(include_replies=True)
|
||||
.select_related("author")
|
||||
.prefetch_related("attachments")
|
||||
.select_related("author", "author__domain")
|
||||
.prefetch_related("attachments", "mentions")
|
||||
.annotate(
|
||||
like_count=models.Count(
|
||||
"interactions",
|
||||
filter=models.Q(interactions__type=PostInteraction.Types.like),
|
||||
),
|
||||
boost_count=models.Count(
|
||||
"interactions",
|
||||
filter=models.Q(interactions__type=PostInteraction.Types.boost),
|
||||
),
|
||||
)
|
||||
.order_by("-created")
|
||||
)
|
||||
|
|
|
@ -11,6 +11,7 @@ from django.views.decorators.vary import vary_on_headers
|
|||
from django.views.generic import FormView, ListView, TemplateView, View
|
||||
|
||||
from activities.models import Post, PostInteraction
|
||||
from activities.services import TimelineService
|
||||
from core.decorators import cache_page, cache_page_by_ap_json
|
||||
from core.ld import canonicalise
|
||||
from core.models import Config
|
||||
|
@ -62,13 +63,7 @@ class ViewIdentity(ListView):
|
|||
)
|
||||
|
||||
def get_queryset(self):
|
||||
return (
|
||||
self.identity.posts.not_hidden()
|
||||
.unlisted(include_replies=True)
|
||||
.select_related("author")
|
||||
.prefetch_related("attachments")
|
||||
.order_by("-created")
|
||||
)
|
||||
return TimelineService(self.request.identity).identity_public(self.identity)
|
||||
|
||||
def get_context_data(self):
|
||||
context = super().get_context_data()
|
||||
|
@ -121,14 +116,7 @@ class IdentityFeed(Feed):
|
|||
return identity.absolute_profile_uri()
|
||||
|
||||
def items(self, identity: Identity):
|
||||
return (
|
||||
identity.posts.filter(
|
||||
visibility=Post.Visibilities.public,
|
||||
)
|
||||
.select_related("author")
|
||||
.prefetch_related("attachments")
|
||||
.order_by("-created")
|
||||
)
|
||||
return TimelineService(None).identity_public(identity)[:20]
|
||||
|
||||
def item_description(self, item: Post):
|
||||
return item.safe_content_remote()
|
||||
|
|
Loading…
Reference in a new issue