moviewyrm/bookwyrm/views/updates.py

31 lines
861 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 Http404, JsonResponse
2021-01-19 00:32:02 +00:00
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.unread_notification_count,
"has_mentions": request.user.has_unread_mentions,
2021-03-23 20:07:29 +00:00
}
)
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:
raise Http404
2021-11-24 18:00:30 +00:00
return JsonResponse(
{
"count": stream.get_unread_count(request.user),
"count_by_type": stream.get_unread_count_by_status_type(request.user),
}
)