fix: 站内信未读信息计数不准

This commit is contained in:
xinwen
2021-06-09 20:51:31 +08:00
committed by 老广
parent 891a5157a7
commit 7dddf0c3c2
3 changed files with 19 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ from rest_framework.response import Response
from rest_framework.mixins import ListModelMixin, RetrieveModelMixin
from rest_framework.decorators import action
from common.http import is_true
from common.permissions import IsValidUser
from common.const.http import GET, PATCH, POST
from common.drf.api import JmsGenericViewSet
@@ -26,13 +27,18 @@ class SiteMessageViewSet(ListModelMixin, RetrieveModelMixin, JmsGenericViewSet):
def get_queryset(self):
user = self.request.user
msgs = SiteMessage.get_user_all_msgs(user.id)
has_read = self.request.query_params.get('has_read')
if has_read is None:
msgs = SiteMessage.get_user_all_msgs(user.id)
else:
msgs = SiteMessage.filter_user_msgs(user.id, has_read=is_true(has_read))
return msgs
@action(methods=[GET], detail=False, url_path='unread-total')
def unread_total(self, request, **kwargs):
user = request.user
msgs = SiteMessage.get_user_unread_msgs(user.id)
msgs = SiteMessage.filter_user_msgs(user.id, has_read=False)
return Response(data={'total': msgs.count()})
@action(methods=[PATCH], detail=False, url_path='mark-as-read')