1+ from dataclasses import dataclass
2+ from typing import Any
3+
14from aiogram .types import CallbackQuery
5+ from aiogram .types .user import User
26from aiogram_dialog import DialogManager , Window
37from aiogram_dialog .widgets .kbd import (
48 Button ,
1014from dishka .integrations .aiogram_dialog import inject
1115from magic_filter import F
1216
17+ from ttt .application .user .game .dont_wait_for_matchmaking import (
18+ DontWaitForMatchmaking ,
19+ )
20+ from ttt .application .user .game .view_matchmaking import ViewMatchmaking
1321from ttt .application .user .game .wait_for_matchmaking import WaitForMatchmaking
22+ from ttt .presentation .aiogram_dialog .common .data import EncodableToWindowData
1423from ttt .presentation .aiogram_dialog .common .wigets .hint import hint
1524from ttt .presentation .aiogram_dialog .common .wigets .one_time_key import (
1625 OneTimekey ,
1726)
1827from ttt .presentation .aiogram_dialog .main_dialog .common import MainDialogState
28+ from ttt .presentation .result_buffer import ResultBuffer
29+
30+
31+ @dataclass (frozen = True )
32+ class GameStartView (EncodableToWindowData ):
33+ is_user_waiting_for_matchmaking : bool
1934
2035
2136@inject
22- async def on_matchmaking_clicked (
37+ async def on_wait_for_matchmaking_clicked (
2338 callback : CallbackQuery ,
2439 _ : Button ,
2540 __ : DialogManager ,
@@ -28,14 +43,45 @@ async def on_matchmaking_clicked(
2843 await wait_for_matchmaking (callback .from_user .id )
2944
3045
46+ @inject
47+ async def on_dont_wait_for_matchmaking_clicked (
48+ callback : CallbackQuery ,
49+ _ : Button ,
50+ __ : DialogManager ,
51+ dont_wait_for_matchmaking : FromDishka [DontWaitForMatchmaking ],
52+ ) -> None :
53+ await dont_wait_for_matchmaking (callback .from_user .id )
54+
55+
56+ @inject
57+ async def getter (
58+ * ,
59+ event_from_user : User ,
60+ view_matchmaking : FromDishka [ViewMatchmaking ],
61+ result_buffer : FromDishka [ResultBuffer ],
62+ ** _ : Any , # noqa: ANN401
63+ ) -> dict [str , Any ]:
64+ await view_matchmaking (event_from_user .id )
65+ view = result_buffer (GameStartView )
66+
67+ return view .window_data ()
68+
69+
3170game_start_window = Window (
3271 Const ("⚔️ Выберите режим" , when = ~ F ["start_data" ]["hint" ]),
3372 hint (key = "hint" ),
3473 Row (
3574 Button (
3675 Const ("🗡 Подбор игр" ),
37- id = "matchmaking" ,
38- on_click = on_matchmaking_clicked ,
76+ id = "wait_for_matchmaking" ,
77+ on_click = on_wait_for_matchmaking_clicked ,
78+ when = ~ F ["main" ]["is_user_waiting_for_matchmaking" ],
79+ ),
80+ Button (
81+ Const ("🗡❌ Отменить" ),
82+ id = "dont_wait_for_matchmaking" ,
83+ on_click = on_dont_wait_for_matchmaking_clicked ,
84+ when = F ["main" ]["is_user_waiting_for_matchmaking" ],
3985 ),
4086 SwitchTo (
4187 Const ("🤖 Играть с ИИ" ),
@@ -54,4 +100,5 @@ async def on_matchmaking_clicked(
54100
55101 OneTimekey ("hint" ),
56102 state = MainDialogState .game_mode_to_start_game ,
103+ getter = getter ,
57104)
0 commit comments