Use activitystreams to populate discovery view

This commit is contained in:
Mouse Reeve 2021-08-07 18:54:00 -07:00
parent 590338138c
commit c14bcf19cc
5 changed files with 142 additions and 119 deletions

View file

@ -56,7 +56,13 @@ class ActivityStream(RedisStore):
return (
models.Status.objects.select_subclasses()
.filter(id__in=statuses)
.select_related("user", "reply_parent")
.select_related(
"user",
"reply_parent",
"comment__book",
"review__book",
"quotation__book",
)
.prefetch_related("mention_books", "mention_users")
.order_by("-published_date")
)

View file

@ -1,9 +1,10 @@
{% load bookwyrm_tags %}
{% load i18n %}
{% load utilities %}
{% load status_display %}
{% if status %}
{% with book=status.book %}
{% if status.book or status.mention_books.exists %}
{% load_book status as book %}
<div class="columns is-gapless">
<div class="column is-6-tablet is-cover">
<a
@ -13,7 +14,7 @@
{% include 'snippets/stars.html' with rating=book|rating:request.user %}
<h3 class="title is-6">
<a href="{{ book.local_path }}">{{ book.title }}</a>
<a href="{{ book.local_path }}">{{ book|book_title }}</a>
</h3>
{% if book.authors %}
@ -69,5 +70,4 @@
</a>
</div>
</div>
{% endwith %}
{% endif %}

View file

@ -1,9 +1,10 @@
{% load bookwyrm_tags %}
{% load utilities %}
{% load i18n %}
{% load status_display %}
{% if status %}
{% with book=status.book %}
{% if status.book or status.mention_books.exists %}
{% load_book status as book %}
<a href="{{ book.local_path }}">
{% include 'snippets/book_cover.html' with cover_class='is-w-l-mobile is-w-auto align to-b to-l' %}
</a>
@ -46,9 +47,13 @@
{% endif %}
</div>
</div>
<div class="block">
<a href="{{ status.remote_id }}">
<span>{% trans "View status" %}</span>
<span class="icon icon-arrow-right" aria-hidden="true"></span>
</a>
</div>
<div class="block">
{% include 'snippets/follow_button.html' with user=status.user show_username=True minimal=True %}
</div>
{% endwith %}
{% endif %}

View file

@ -62,3 +62,9 @@ def get_published_date(date):
if delta.days:
return naturalday(date, "M j")
return naturaltime(date)
@register.simple_tag(takes_context=False)
def load_book(status):
"""how many users that you follow, follow them"""
return status.book if hasattr(status, "book") else status.mention_books.first()

View file

@ -6,8 +6,7 @@ from django.template.response import TemplateResponse
from django.utils.decorators import method_decorator
from django.views import View
from bookwyrm import models
from .helpers import privacy_filter
from bookwyrm import activitystreams
# pylint: disable= no-self-use
@ -17,21 +16,28 @@ class Discover(View):
def get(self, request):
"""tiled book activity page"""
activities = privacy_filter(
request.user,
models.Status.objects.select_subclasses().filter(
activities = (
activitystreams.streams["local"]
.get_activity_stream(request.user)
.filter(
Q(comment__isnull=False)
| Q(review__isnull=False)
| Q(quotation__isnull=False),
user__local=True,
),
privacy_levels=["public"],
| Q(quotation__isnull=False)
| Q(mention_books__isnull=False)
)
)
large_activities = Paginator(
activities.filter(~Q(content=None), ~Q(content="")), 6
activities.filter(mention_books__isnull=True)
.exclude(content=None, quotation__quote=None)
.exclude(content=""),
6,
)
small_activities = Paginator(
activities.filter(Q(content=None) | Q(content="")), 4
activities.filter(
Q(mention_books__isnull=False) | Q(content=None) | Q(content="")
),
4,
)
page = request.GET.get("page")