Bad variant of navigation handler (not working)

This commit is contained in:
Kirill 2025-11-28 12:30:34 +03:00
parent 28a7d9e691
commit e09b6658b2

View file

@ -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<HandlerResult, UserContext> 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};
}
}