moviewyrm/bookwyrm/views/updates.py

25 lines
698 B
Python
Raw Normal View History

2021-03-08 16:49:10 +00:00
""" endpoints for getting updates about activity """
2021-01-19 00:32:02 +00:00
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
2021-03-23 19:52:38 +00:00
from bookwyrm import activitystreams
2021-03-08 16:49:10 +00:00
2021-03-23 20:07:29 +00:00
2021-03-23 19:52:38 +00:00
@login_required
def get_notification_count(request):
2021-04-26 16:15:42 +00:00
"""any notifications waiting?"""
2021-03-23 20:07:29 +00:00
return JsonResponse(
{
"count": request.user.notification_set.filter(read=False).count(),
}
)
2021-03-23 19:52:38 +00:00
@login_required
2021-03-23 20:28:05 +00:00
def get_unread_status_count(request, stream="home"):
2021-04-26 16:15:42 +00:00
"""any unread statuses for this feed?"""
2021-03-23 19:52:38 +00:00
stream = activitystreams.streams.get(stream)
if not stream:
return JsonResponse({})
2021-03-23 20:07:29 +00:00
return JsonResponse({"count": stream.get_unread_count(request.user)})