2021-03-08 11:49:10 -05:00
|
|
|
""" endpoints for getting updates about activity """
|
2021-01-18 19:32:02 -05:00
|
|
|
from django.contrib.auth.decorators import login_required
|
2021-12-09 21:16:34 -05:00
|
|
|
from django.http import Http404, JsonResponse
|
2021-01-18 19:32:02 -05:00
|
|
|
|
2021-03-23 15:52:38 -04:00
|
|
|
from bookwyrm import activitystreams
|
2021-03-08 11:49:10 -05:00
|
|
|
|
2021-03-23 16:07:29 -04:00
|
|
|
|
2021-03-23 15:52:38 -04:00
|
|
|
@login_required
|
|
|
|
def get_notification_count(request):
|
2021-04-26 12:15:42 -04:00
|
|
|
"""any notifications waiting?"""
|
2021-03-23 16:07:29 -04:00
|
|
|
return JsonResponse(
|
|
|
|
{
|
2021-04-30 10:49:34 -04:00
|
|
|
"count": request.user.unread_notification_count,
|
|
|
|
"has_mentions": request.user.has_unread_mentions,
|
2021-03-23 16:07:29 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2021-03-23 15:52:38 -04:00
|
|
|
|
|
|
|
@login_required
|
2021-03-23 16:28:05 -04:00
|
|
|
def get_unread_status_count(request, stream="home"):
|
2021-04-26 12:15:42 -04:00
|
|
|
"""any unread statuses for this feed?"""
|
2021-03-23 15:52:38 -04:00
|
|
|
stream = activitystreams.streams.get(stream)
|
|
|
|
if not stream:
|
2021-12-09 21:16:34 -05:00
|
|
|
raise Http404
|
2021-11-24 13:00:30 -05:00
|
|
|
return JsonResponse(
|
|
|
|
{
|
|
|
|
"count": stream.get_unread_count(request.user),
|
|
|
|
"count_by_type": stream.get_unread_count_by_status_type(request.user),
|
|
|
|
}
|
|
|
|
)
|