From b368ecc43b3b8a5b5f5e85c03e57f40f7ef1805e Mon Sep 17 00:00:00 2001 From: Kirill Date: Fri, 28 Nov 2025 12:57:07 +0300 Subject: [PATCH] Added context navigation logic --- modules/bot/front/include/handlers.hpp | 11 +++++++++++ modules/bot/front/src/handlers.cpp | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/modules/bot/front/include/handlers.hpp b/modules/bot/front/include/handlers.hpp index 558bd19..935de04 100644 --- a/modules/bot/front/include/handlers.hpp +++ b/modules/bot/front/include/handlers.hpp @@ -61,4 +61,15 @@ private: /// @param userId Идентификатор пользователя /// @return HandlerResult static HandlerResult returnMyTitles(int64_t userId); + + /// @brief Вход в новое состояние + /// @param ctx текущий контекст + /// @param newState новое состояние, добавляемое в стек + /// @param payload полезная нагрузка этого состояния + void pushState(UserContext& ctx, UserState newState, int64_t payload); + + /// @brief Возврат в предыдущее состояние + /// @param ctx Текущий контекст + /// @return true в случае успеха + bool popState(UserContext& ctx); }; diff --git a/modules/bot/front/src/handlers.cpp b/modules/bot/front/src/handlers.cpp index 977751e..426fa6b 100644 --- a/modules/bot/front/src/handlers.cpp +++ b/modules/bot/front/src/handlers.cpp @@ -136,3 +136,13 @@ std::pair BotHandlers::newStateNavigation(const TgBo return {result, newCtx}; } } + +void BotHandlers::pushState(UserContext& ctx, UserState newState, int64_t payload) { + ctx.history.push_back({newState, payload}); +} + +bool BotHandlers::popState(UserContext& ctx) { + if (ctx.history.size() <= 1) return false; // нельзя выйти из MAIN_MENU + ctx.history.pop_back(); + return true; +}