From e09b6658b297c8f23379382ea9a6f3af2986dc2f Mon Sep 17 00:00:00 2001 From: Kirill Date: Fri, 28 Nov 2025 12:30:34 +0300 Subject: [PATCH] Bad variant of navigation handler (not working) --- modules/bot/front/src/handlers.cpp | 99 +++++++++++++++++++++++++----- 1 file changed, 85 insertions(+), 14 deletions(-) diff --git a/modules/bot/front/src/handlers.cpp b/modules/bot/front/src/handlers.cpp index 4ae1040..977751e 100644 --- a/modules/bot/front/src/handlers.cpp +++ b/modules/bot/front/src/handlers.cpp @@ -32,22 +32,41 @@ HandlerResult BotHandlers::returnMyTitles(int64_t userId) { } void BotHandlers::handleNavigation(TgBot::CallbackQuery::Ptr query) { + int64_t userId = query->from->id; + auto it = userContexts.find(userId); + if (it == userContexts.end()) { + botApi.sendMessage(query->message->chat->id, BotConstants::Text::SAD_ERROR); + return; + } + + UserContext& ctx = it->second; const std::string& data = query->data; - if (data == BotConstants::Callback::MY_TITLES) { - auto [text, kb] = BotHandlers::returnMyTitles(321); - botApi.editMessageText( - text, - query->message->chat->id, - query->message->messageId, - "", - "", - nullptr, - kb - ); - } - else { - botApi.sendMessage(query->message->chat->id, BotConstants::Text::SAD_ERROR, nullptr, nullptr); + + //HandlerResult response; + //UserContext newCtx; + + auto [response, newCtx] = newStateNavigation(query, ctx); + switch (ctx.state) { + case UserState::VIEWING_MY_TITLES: + response = BotHandlers::returnMyTitles(ctx.cursor); + break; + case UserState::VIEWING_REVIEW_LIST: + response = BotHandlers::returnReviewList(ctx.cursor); + break; + default: + botApi.sendMessage(query->message->chat->id, BotConstants::Text::SAD_ERROR); + return; } + + botApi.editMessageText( + response.message, + query->message->chat->id, + query->message->messageId, + "", + "", + nullptr, + response.keyboard + ); } void BotHandlers::handleMessage(TgBot::Message::Ptr message) { @@ -65,3 +84,55 @@ void BotHandlers::processCallbackImpl(TgBot::CallbackQuery::Ptr query) { botApi.sendMessage(query->message->chat->id, BotConstants::Text::SAD_ERROR, nullptr, nullptr); } } + +std::pair BotHandlers::newStateNavigation(const TgBot::CallbackQuery::Ptr& query, const UserContext& ctx) { + const std::string& data = query->data; + switch (ctx.state) { + case UserState::MAIN_MENU: + if(data == BotConstants::Callback::MY_TITLES) { + UserContext newCtx{.state = UserState::VIEWING_MY_TITLES, .cursor = BotConstants::CURSOR_NOT_INIT}; + HandlerResult result = returnMyTitles(query->from->id); + + return {result, newCtx}; + } + case UserState::VIEWING_MY_TITLES: + if(data == BotConstants::Callback::LIST_PREV) { + + } + else if (data == BotConstants::Callback::LIST_NEXT) { + + } + case UserState::AWAITING_TITLE_NAME: + if(data == BotConstants::Callback::LIST_PREV) { + + } + case UserState::VIEWING_TITLE_PAGE: + if(data == BotConstants::Callback::LIST_PREV) { + + } + case UserState::AWAITING_REVIEW: + if(data == BotConstants::Callback::LIST_PREV) { + + } + case UserState::VIEWING_REVIEW_LIST: + if(data == BotConstants::Callback::LIST_PREV) { + + } + else if (data == BotConstants::Callback::LIST_NEXT) { + + } + case UserState::VIEWING_REVIEW: + if(data == BotConstants::Callback::LIST_PREV) { + + } + case UserState::VIEWING_DESCRIPTION: + if(data == BotConstants::Callback::LIST_PREV) { + + } + default: + UserContext newCtx{.state = UserState::ERROR, .cursor = BotConstants::CURSOR_NOT_INIT}; + HandlerResult result = {"", nullptr}; + + return {result, newCtx}; + } +}