moviewyrm/bookwyrm/views/updates.py
2021-04-26 09:15:42 -07:00

24 lines
698 B
Python

""" endpoints for getting updates about activity """
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
from bookwyrm import activitystreams
@login_required
def get_notification_count(request):
"""any notifications waiting?"""
return JsonResponse(
{
"count": request.user.notification_set.filter(read=False).count(),
}
)
@login_required
def get_unread_status_count(request, stream="home"):
"""any unread statuses for this feed?"""
stream = activitystreams.streams.get(stream)
if not stream:
return JsonResponse({})
return JsonResponse({"count": stream.get_unread_count(request.user)})