Bad variant of navigation handler (not working)
This commit is contained in:
parent
28a7d9e691
commit
e09b6658b2
1 changed files with 85 additions and 14 deletions
|
|
@ -32,23 +32,42 @@ HandlerResult BotHandlers::returnMyTitles(int64_t userId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BotHandlers::handleNavigation(TgBot::CallbackQuery::Ptr query) {
|
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;
|
const std::string& data = query->data;
|
||||||
if (data == BotConstants::Callback::MY_TITLES) {
|
|
||||||
auto [text, kb] = BotHandlers::returnMyTitles(321);
|
//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(
|
botApi.editMessageText(
|
||||||
text,
|
response.message,
|
||||||
query->message->chat->id,
|
query->message->chat->id,
|
||||||
query->message->messageId,
|
query->message->messageId,
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
nullptr,
|
nullptr,
|
||||||
kb
|
response.keyboard
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
botApi.sendMessage(query->message->chat->id, BotConstants::Text::SAD_ERROR, nullptr, nullptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BotHandlers::handleMessage(TgBot::Message::Ptr message) {
|
void BotHandlers::handleMessage(TgBot::Message::Ptr message) {
|
||||||
//TODO: просмотр состояния пользователя
|
//TODO: просмотр состояния пользователя
|
||||||
|
|
@ -65,3 +84,55 @@ void BotHandlers::processCallbackImpl(TgBot::CallbackQuery::Ptr query) {
|
||||||
botApi.sendMessage(query->message->chat->id, BotConstants::Text::SAD_ERROR, nullptr, nullptr);
|
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};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue