mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 03:21:05 +00:00
Adds books stream
This commit is contained in:
parent
a8d6dbd8a6
commit
5a9dbc50da
4 changed files with 44 additions and 8 deletions
|
@ -173,6 +173,7 @@ class FederatedStream(ActivityStream):
|
||||||
privacy_levels=["public"],
|
privacy_levels=["public"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class BooksStream(ActivityStream):
|
class BooksStream(ActivityStream):
|
||||||
"""books on your shelves"""
|
"""books on your shelves"""
|
||||||
|
|
||||||
|
@ -182,30 +183,46 @@ class BooksStream(ActivityStream):
|
||||||
"""anyone with the mentioned book on their shelves"""
|
"""anyone with the mentioned book on their shelves"""
|
||||||
# only show public statuses on the books feed,
|
# only show public statuses on the books feed,
|
||||||
# and only statuses that mention books
|
# and only statuses that mention books
|
||||||
if status.privacy != "public" or not (status.mention_books.exists() or hasattr(status, "book")):
|
if status.privacy != "public" or not (
|
||||||
|
status.mention_books.exists() or hasattr(status, "book")
|
||||||
|
):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
work = status.book.parent_work if hasattr(status, "book") else status.mention_books.first().parent_work
|
work = (
|
||||||
|
status.book.parent_work
|
||||||
|
if hasattr(status, "book")
|
||||||
|
else status.mention_books.first().parent_work
|
||||||
|
)
|
||||||
|
|
||||||
audience = super().get_audience(status)
|
audience = super().get_audience(status)
|
||||||
if not audience:
|
if not audience:
|
||||||
return []
|
return []
|
||||||
return audience.filter(
|
return audience.filter(shelfbook__book__parent_work=work).distinct()
|
||||||
shelfbook__book__parent_work=work
|
|
||||||
).distinct()
|
|
||||||
|
|
||||||
def get_statuses_for_user(self, user):
|
def get_statuses_for_user(self, user):
|
||||||
"""any public status that mentions their books"""
|
"""any public status that mentions their books"""
|
||||||
|
books = user.shelfbook_set.values_list(
|
||||||
|
"book__parent_work__id", flat=True
|
||||||
|
).distinct()
|
||||||
return privacy_filter(
|
return privacy_filter(
|
||||||
user,
|
user,
|
||||||
models.Status.objects.select_subclasses().filter(,
|
models.Status.objects.select_subclasses()
|
||||||
|
.filter(
|
||||||
|
Q(comment__book__parent_work__id__in=books)
|
||||||
|
| Q(quotation__book__parent_work__id__in=books)
|
||||||
|
| Q(review__book__parent_work__id__in=books)
|
||||||
|
| Q(mention_books__parent_work__id__in=books)
|
||||||
|
)
|
||||||
|
.distinct(),
|
||||||
privacy_levels=["public"],
|
privacy_levels=["public"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
streams = {
|
streams = {
|
||||||
"home": HomeStream(),
|
"home": HomeStream(),
|
||||||
"local": LocalStream(),
|
"local": LocalStream(),
|
||||||
"federated": FederatedStream(),
|
"federated": FederatedStream(),
|
||||||
|
"books": BooksStream(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
17
bookwyrm/migrations/0080_alter_shelfbook_options.py
Normal file
17
bookwyrm/migrations/0080_alter_shelfbook_options.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
# Generated by Django 3.2.4 on 2021-08-05 00:00
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("bookwyrm", "0079_merge_20210804_1746"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name="shelfbook",
|
||||||
|
options={"ordering": ("-shelved_date", "-created_date", "-updated_date")},
|
||||||
|
),
|
||||||
|
]
|
|
@ -118,7 +118,7 @@ REDIS_ACTIVITY_PORT = env("REDIS_ACTIVITY_PORT", 6379)
|
||||||
REDIS_ACTIVITY_PASSWORD = env("REDIS_ACTIVITY_PASSWORD", None)
|
REDIS_ACTIVITY_PASSWORD = env("REDIS_ACTIVITY_PASSWORD", None)
|
||||||
|
|
||||||
MAX_STREAM_LENGTH = int(env("MAX_STREAM_LENGTH", 200))
|
MAX_STREAM_LENGTH = int(env("MAX_STREAM_LENGTH", 200))
|
||||||
STREAMS = ["home", "local", "federated"]
|
STREAMS = ["home", "books"]
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
|
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
|
||||||
|
|
|
@ -23,6 +23,8 @@ STATUS_PATH = r"%s/(%s)/(?P<status_id>\d+)" % (USER_PATH, "|".join(status_types)
|
||||||
|
|
||||||
BOOK_PATH = r"^book/(?P<book_id>\d+)"
|
BOOK_PATH = r"^book/(?P<book_id>\d+)"
|
||||||
|
|
||||||
|
STREAMS = "|".join(settings.STREAMS)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("admin/", admin.site.urls),
|
path("admin/", admin.site.urls),
|
||||||
path(
|
path(
|
||||||
|
@ -177,7 +179,7 @@ urlpatterns = [
|
||||||
name="get-started-users",
|
name="get-started-users",
|
||||||
),
|
),
|
||||||
# feeds
|
# feeds
|
||||||
re_path(r"^(?P<tab>home|local|federated)/?$", views.Feed.as_view()),
|
re_path(r"^(?P<tab>{:s})/?$".format(STREAMS), views.Feed.as_view()),
|
||||||
re_path(
|
re_path(
|
||||||
r"^direct-messages/?$", views.DirectMessage.as_view(), name="direct-messages"
|
r"^direct-messages/?$", views.DirectMessage.as_view(), name="direct-messages"
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in a new issue