Merge branch 'main' into new-shelf-fix

This commit is contained in:
Hugh Rundle 2021-10-03 19:47:15 +11:00
commit c59194f808
6 changed files with 87 additions and 37 deletions

View file

@ -17,7 +17,7 @@ def infer_format(app_registry, schema_editor):
for edition in editions:
free_format = edition.physical_format_detail.lower()
edition.physical_format = infer_physical_format(free_format)
edition.save()
edition.save(broadcast=False, update_fields=["physical_format"])
def reverse(app_registry, schema_editor):

View file

@ -1,5 +1,6 @@
{% extends 'feed/layout.html' %}
{% load i18n %}
{% load bookwyrm_tags %}
{% block panel %}
<header class="block">
@ -9,7 +10,26 @@
</a>
</header>
{% include 'feed/thread.html' with status=status depth=0 max_depth=6 is_root=True direction=0 %}
<div class="thread-parent is-relative block">
<div class="thread">
{% for parent in ancestors %}
{% if parent.id %}
<div class="block">
{% include 'snippets/status/status.html' with status=parent|load_subclass %}
</div>
{% endif %}
{% endfor %}
<div class="is-main block" id="anchor-{{ status.id }}">
{% include 'snippets/status/status.html' with status=status main=True %}
</div>
{% for child in children %}
<div class="block">
{% include 'snippets/status/status.html' with status=child %}
</div>
{% endfor %}
</div>
</div>
{% endblock %}

View file

@ -1,25 +0,0 @@
{% load status_display %}
<div class="thread-parent is-relative block">
<div class="thread">
{% with depth=depth|add:1 %}
{% if depth <= max_depth and status.reply_parent and direction <= 0 %}
{% with direction=-1 %}
{% include 'feed/thread.html' with status=status|parent is_root=False %}
{% endwith %}
{% endif %}
<div{% if is_root %} class="block mt-5 is-main"{% endif %}>
{% include 'snippets/status/status.html' with status=status main=is_root %}
</div>
{% if depth <= max_depth and direction >= 0 %}
{% for reply in status|replies %}
{% with direction=1 %}
{% include 'feed/thread.html' with status=reply is_root=False %}
{% endwith %}
{% endfor %}
{% endif %}
{% endwith %}
</div>
</div>

View file

@ -53,18 +53,24 @@ def get_next_shelf(current_shelf):
return "to-read"
@register.filter(name="load_subclass")
def load_subclass(status):
"""sometimes you didn't select_subclass"""
if hasattr(status, "quotation"):
return status.quotation
if hasattr(status, "review"):
return status.review
if hasattr(status, "comment"):
return status.comment
return status
@register.simple_tag(takes_context=False)
def related_status(notification):
"""for notifications"""
if not notification.related_status:
return None
if hasattr(notification.related_status, "quotation"):
return notification.related_status.quotation
if hasattr(notification.related_status, "review"):
return notification.related_status.review
if hasattr(notification.related_status, "comment"):
return notification.related_status.comment
return notification.related_status
return load_subclass(notification.related_status)
@register.simple_tag(takes_context=True)

View file

@ -109,10 +109,60 @@ class Status(View):
status.to_activity(pure=not is_bookwyrm_request(request))
)
visible_thread = privacy_filter(
request.user, models.Status.objects.filter(thread_id=status.thread_id)
).values_list("id", flat=True)
visible_thread = list(visible_thread)
ancestors = models.Status.objects.select_subclasses().raw(
"""
WITH RECURSIVE get_thread(depth, id, path) AS (
SELECT 1, st.id, ARRAY[st.id]
FROM bookwyrm_status st
WHERE id = '%s' AND id = ANY(%s)
UNION
SELECT (gt.depth + 1), st.reply_parent_id, path || st.id
FROM get_thread gt, bookwyrm_status st
WHERE st.id = gt.id AND depth < 5 AND st.id = ANY(%s)
)
SELECT * FROM get_thread ORDER BY path DESC;
""",
params=[status.reply_parent_id or 0, visible_thread, visible_thread],
)
children = models.Status.objects.select_subclasses().raw(
"""
WITH RECURSIVE get_thread(depth, id, path) AS (
SELECT 1, st.id, ARRAY[st.id]
FROM bookwyrm_status st
WHERE reply_parent_id = '%s' AND id = ANY(%s)
UNION
SELECT (gt.depth + 1), st.id, path || st.id
FROM get_thread gt, bookwyrm_status st
WHERE st.reply_parent_id = gt.id AND depth < 5 AND st.id = ANY(%s)
)
SELECT * FROM get_thread ORDER BY path;
""",
params=[status.id, visible_thread, visible_thread],
)
data = {
**feed_page_data(request.user),
**{
"status": status,
"children": children,
"ancestors": ancestors,
},
}
return TemplateResponse(request, "feed/status.html", data)

View file

@ -61,8 +61,7 @@ def privacy_filter(viewer, queryset, privacy_levels=None, following_only=False):
# exclude blocks from both directions
if not viewer.is_anonymous:
blocked = models.User.objects.filter(id__in=viewer.blocks.all()).all()
queryset = queryset.exclude(Q(user__in=blocked) | Q(user__blocks=viewer))
queryset = queryset.exclude(Q(user__blocked_by=viewer) | Q(user__blocks=viewer))
# you can't see followers only or direct messages if you're not logged in
if viewer.is_anonymous:
@ -75,7 +74,7 @@ def privacy_filter(viewer, queryset, privacy_levels=None, following_only=False):
if following_only:
queryset = queryset.exclude(
~Q( # remove everythign except
Q(user__in=viewer.following.all())
Q(user__followers=viewer)
| Q(user=viewer) # user following
| Q(mention_users=viewer) # is self # mentions user
),