@@ -80,12 +80,17 @@ async def join_ranked_queue(self, *, actor_user: User) -> QueueJoinResponse:
8080 refreshed = await self .repository .get_entry_by_id (entry .id )
8181 if refreshed is None :
8282 raise LookupError ("Queue entry not found after join." )
83+ opponent_username = await self ._resolve_opponent_username (
84+ actor_user_id = actor_user .id ,
85+ game_id = refreshed .matched_game_id ,
86+ )
8387 return QueueJoinResponse (
8488 queue_id = refreshed .id ,
8589 status = self ._status_value (refreshed .status ),
8690 season_id = refreshed .season_id ,
8791 game_id = game_id ,
8892 matched_with = matched_with ,
93+ opponent_username = opponent_username ,
8994 created_at = refreshed .created_at ,
9095 updated_at = refreshed .updated_at ,
9196 )
@@ -115,13 +120,24 @@ async def get_status(self, *, actor_user: User) -> QueueStatusResponse:
115120 refreshed = await self .repository .get_entry_by_id (entry .id )
116121 if refreshed is not None :
117122 entry = refreshed
123+ elif entry .status == QueueEntryStatus .MATCHED :
124+ matched_with = await self ._resolve_matched_with (
125+ actor_user_id = actor_user .id ,
126+ game_id = entry .matched_game_id ,
127+ )
128+
129+ opponent_username = await self ._resolve_opponent_username (
130+ actor_user_id = actor_user .id ,
131+ game_id = entry .matched_game_id ,
132+ )
118133
119134 return QueueStatusResponse (
120135 queue_id = entry .id ,
121136 status = self ._status_value (entry .status ),
122137 season_id = entry .season_id ,
123138 game_id = entry .matched_game_id ,
124139 matched_with = matched_with ,
140+ opponent_username = opponent_username ,
125141 created_at = entry .created_at ,
126142 updated_at = entry .updated_at ,
127143 )
@@ -326,3 +342,53 @@ def _select_bot_candidate(
326342 if roll <= cumulative :
327343 return bot_user
328344 return candidates [- 1 ][0 ]
345+
346+ async def _resolve_opponent_username (
347+ self ,
348+ * ,
349+ actor_user_id : UUID ,
350+ game_id : UUID | None ,
351+ ) -> str | None :
352+ if game_id is None :
353+ return None
354+ game = await self .repository .get_game (game_id )
355+ if game is None :
356+ return None
357+
358+ opponent_user_id : UUID | None = None
359+ if game .player1_id == actor_user_id :
360+ opponent_user_id = game .player2_id
361+ elif game .player2_id == actor_user_id :
362+ opponent_user_id = game .player1_id
363+ if opponent_user_id is None :
364+ return None
365+
366+ opponent_user = await self .repository .get_user (opponent_user_id )
367+ if opponent_user is None :
368+ return None
369+ return opponent_user .username
370+
371+ async def _resolve_matched_with (
372+ self ,
373+ * ,
374+ actor_user_id : UUID ,
375+ game_id : UUID | None ,
376+ ) -> MatchedWith | None :
377+ if game_id is None :
378+ return None
379+ game = await self .repository .get_game (game_id )
380+ if game is None :
381+ return None
382+
383+ opponent_user_id : UUID | None = None
384+ if game .player1_id == actor_user_id :
385+ opponent_user_id = game .player2_id
386+ elif game .player2_id == actor_user_id :
387+ opponent_user_id = game .player1_id
388+ if opponent_user_id is None :
389+ return None
390+
391+ opponent_user = await self .repository .get_user (opponent_user_id )
392+ if opponent_user is None :
393+ return None
394+ return "bot" if opponent_user .is_bot else "human"
0 commit comments