Added context navigation logic
This commit is contained in:
parent
a8dd448c95
commit
b368ecc43b
2 changed files with 21 additions and 0 deletions
|
|
@ -61,4 +61,15 @@ private:
|
||||||
/// @param userId Идентификатор пользователя
|
/// @param userId Идентификатор пользователя
|
||||||
/// @return HandlerResult
|
/// @return HandlerResult
|
||||||
static HandlerResult returnMyTitles(int64_t userId);
|
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);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -136,3 +136,13 @@ std::pair<HandlerResult, UserContext> BotHandlers::newStateNavigation(const TgBo
|
||||||
return {result, newCtx};
|
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;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue