feat: complete realtime challenge matchmaking

This commit is contained in:
2026-08-09 03:07:38 +08:00
parent b6fc2431ca
commit 821311f4ad
11 changed files with 767 additions and 31 deletions
+14 -1
View File
@@ -26,7 +26,11 @@ class MatchConsumer(AsyncJsonWebsocketConsumer):
await self.send_json({"type": "pong"})
return
if event_type == "progress":
answered_count = max(0, min(int(content.get("answered_count", 0)), 100))
try:
answered_count = max(0, min(int(content.get("answered_count", 0)), 100))
except (TypeError, ValueError):
await self.send_json({"type": "error", "message": "答题进度无效"})
return
await self.channel_layer.group_send(
self.group_name,
{
@@ -45,6 +49,15 @@ class MatchConsumer(AsyncJsonWebsocketConsumer):
}
)
async def match_state(self, event):
await self.send_json(
{
"type": "state",
"reason": event["reason"],
"match_id": str(self.match_id),
}
)
@database_sync_to_async
def _is_participant(self, user_id):
return RealtimeMatch.objects.filter(id=self.match_id).filter(