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
|
2021-12-10 02:16:34 +00:00
|
|
|
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(
|
|
|
|
{
|
2021-04-30 14:49:34 +00:00
|
|
|
"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:
|
2021-12-10 02:16:34 +00:00
|
|
|
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),
|
|
|
|
}
|
|
|
|
)
|