Merge pull request #1865 from bookwyrm-social/unread-status-translation
Calculate and translate unread status counts in view
This commit is contained in:
@ -114,7 +114,7 @@ from .rss_feed import RssFeed
|
||||
from .search import Search
|
||||
from .status import CreateStatus, EditStatus, DeleteStatus, update_progress
|
||||
from .status import edit_readthrough
|
||||
from .updates import get_notification_count, get_unread_status_count
|
||||
from .updates import get_notification_count, get_unread_status_string
|
||||
from .user import User, Followers, Following, hide_suggestions, user_redirect
|
||||
from .wellknown import *
|
||||
from .annual_summary import (
|
||||
|
@ -62,7 +62,6 @@ class Feed(View):
|
||||
"streams": STREAMS,
|
||||
"goal_form": forms.GoalForm(),
|
||||
"feed_status_types_options": FeedFilterChoices,
|
||||
"allowed_status_types": request.user.feed_status_types,
|
||||
"filters_applied": filters_applied,
|
||||
"path": f"/{tab['key']}",
|
||||
"annual_summary_year": get_annual_summary_year(),
|
||||
|
@ -1,6 +1,7 @@
|
||||
""" endpoints for getting updates about activity """
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import Http404, JsonResponse
|
||||
from django.utils.translation import ngettext
|
||||
|
||||
from bookwyrm import activitystreams
|
||||
|
||||
@ -17,14 +18,31 @@ def get_notification_count(request):
|
||||
|
||||
|
||||
@login_required
|
||||
def get_unread_status_count(request, stream="home"):
|
||||
def get_unread_status_string(request, stream="home"):
|
||||
"""any unread statuses for this feed?"""
|
||||
stream = activitystreams.streams.get(stream)
|
||||
if not stream:
|
||||
raise Http404
|
||||
return JsonResponse(
|
||||
{
|
||||
"count": stream.get_unread_count(request.user),
|
||||
"count_by_type": stream.get_unread_count_by_status_type(request.user),
|
||||
}
|
||||
)
|
||||
|
||||
counts_by_type = stream.get_unread_count_by_status_type(request.user).items()
|
||||
if counts_by_type == {}:
|
||||
count = stream.get_unread_count(request.user)
|
||||
else:
|
||||
# only consider the types that are visible in the feed
|
||||
allowed_status_types = request.user.feed_status_types
|
||||
count = sum(c for (k, c) in counts_by_type if k in allowed_status_types)
|
||||
# if "everything else" is allowed, add other types to the sum
|
||||
count += sum(
|
||||
c
|
||||
for (k, c) in counts_by_type
|
||||
if k not in ["review", "comment", "quotation"]
|
||||
)
|
||||
|
||||
if not count:
|
||||
return JsonResponse({})
|
||||
|
||||
translation_string = lambda c: ngettext(
|
||||
"Load %(count)d unread status", "Load %(count)d unread statuses", c
|
||||
) % {"count": c}
|
||||
|
||||
return JsonResponse({"count": translation_string(count)})
|
||||
|
Reference in New Issue
Block a user