Merge branch 'main' into bookwyrm-groups
This commit is contained in:
@ -172,6 +172,7 @@ def add_description(request, book_id):
|
||||
return redirect("book", book.id)
|
||||
|
||||
|
||||
@login_required
|
||||
@require_POST
|
||||
def resolve_book(request):
|
||||
"""figure out the local path to a book from a remote_id"""
|
||||
|
@ -10,8 +10,7 @@ from django.utils.datastructures import MultiValueDictKeyError
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views import View
|
||||
|
||||
from bookwyrm import forms, models
|
||||
from bookwyrm.connectors import connector_manager
|
||||
from bookwyrm import book_search, forms, models
|
||||
from bookwyrm.views.helpers import get_edition
|
||||
from .books import set_cover_from_url
|
||||
|
||||
@ -73,10 +72,9 @@ class EditBook(View):
|
||||
if not book:
|
||||
# check if this is an edition of an existing work
|
||||
author_text = book.author_text if book else add_author
|
||||
data["book_matches"] = connector_manager.local_search(
|
||||
data["book_matches"] = book_search.search(
|
||||
f'{form.cleaned_data.get("title")} {author_text}',
|
||||
min_confidence=0.5,
|
||||
raw=True,
|
||||
)[:5]
|
||||
|
||||
# either of the above cases requires additional confirmation
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
),
|
||||
|
@ -14,7 +14,7 @@ class Block(View):
|
||||
"""blocking users"""
|
||||
|
||||
def get(self, request):
|
||||
"""list of blocked users?"""
|
||||
"""list of blocked users"""
|
||||
return TemplateResponse(request, "preferences/blocks.html")
|
||||
|
||||
def post(self, request, user_id):
|
||||
|
@ -67,11 +67,11 @@ class Search(View):
|
||||
return TemplateResponse(request, f"search/{search_type}.html", data)
|
||||
|
||||
|
||||
def book_search(query, _, min_confidence, search_remote=False):
|
||||
def book_search(query, user, min_confidence, search_remote=False):
|
||||
"""the real business is elsewhere"""
|
||||
# try a local-only search
|
||||
results = [{"results": search(query, min_confidence=min_confidence)}]
|
||||
if results and not search_remote:
|
||||
if not user.is_authenticated or (results[0]["results"] and not search_remote):
|
||||
return results, False
|
||||
|
||||
# if there were no local results, or the request was for remote, search all sources
|
||||
@ -101,7 +101,7 @@ def user_search(query, viewer, *_):
|
||||
.filter(
|
||||
similarity__gt=0.5,
|
||||
)
|
||||
.order_by("-similarity")[:10]
|
||||
.order_by("-similarity")
|
||||
), None
|
||||
|
||||
|
||||
@ -122,5 +122,5 @@ def list_search(query, viewer, *_):
|
||||
.filter(
|
||||
similarity__gt=0.1,
|
||||
)
|
||||
.order_by("-similarity")[:10]
|
||||
.order_by("-similarity")
|
||||
), None
|
||||
|
Reference in New Issue
Block a user