功能变化: 优化websocket

pull/84/head
猿小天 2023-01-03 13:20:11 +08:00
parent 910b770784
commit b57d500e0c
2 changed files with 4 additions and 4 deletions

View File

@ -14,10 +14,10 @@ from channels.routing import ProtocolTypeRouter, URLRouter
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings')
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
from application.routing import websocket_urlpatterns
http_application = get_asgi_application()
from application.routing import websocket_urlpatterns
application = ProtocolTypeRouter({
"http":http_application,
'websocket': AuthMiddlewareStack(

View File

@ -138,8 +138,8 @@ class MessageCenterCreateSerializer(CustomModelSerializer):
targetuser_instance.save()
for user in users:
unread_count = MessageCenterTargetUser.objects.filter(users__id=user, is_read=False).count()
websocket_push(user, {"sender": 'system', "contentType": 'TEXT',
"content": {"model": 'message_center', "unread": unread_count}})
websocket_push(user, message={"sender": 'system', "contentType": 'SYSTEM',
"content": '您有一条新消息~', "unread": unread_count})
return data
class Meta: