refactor(tgbot-front): change editMessage args
This commit is contained in:
parent
19164b8d9d
commit
7e0222d6f1
4 changed files with 33 additions and 25 deletions
|
|
@ -6,6 +6,8 @@
|
|||
void BotHandlers::handleNavigation(TgBot::CallbackQuery::Ptr query, UserContext& ctx) {
|
||||
const auto& current = ctx.history.back(); // текущий экран
|
||||
const std::string& data = query->data;
|
||||
int64_t chatId = query->message->chat->id;
|
||||
int64_t messageId = query->message->messageId;
|
||||
|
||||
// Пагинация (в списках)
|
||||
if ((data == BotConstants::Callback::LIST_PREV || data == BotConstants::Callback::LIST_NEXT)
|
||||
|
|
@ -30,54 +32,56 @@ void BotHandlers::handleNavigation(TgBot::CallbackQuery::Ptr query, UserContext&
|
|||
|
||||
auto result = renderCurrent(query, ctx);
|
||||
if(result.message == "meow") return; // TODO: убрать
|
||||
editMessage(query, result);
|
||||
editMessage(chatId, messageId, result);
|
||||
return;
|
||||
}
|
||||
|
||||
// Обработка back по интерфейсу
|
||||
if (data == BotConstants::Callback::NAV_BACK) {
|
||||
if (!popState(ctx)) {
|
||||
sendError(query, BotConstants::Text::SAD_ERROR);
|
||||
sendError(chatId, messageId, BotConstants::Text::SAD_ERROR);
|
||||
return;
|
||||
}
|
||||
auto result = renderCurrent(query, ctx);
|
||||
if(result.message == "meow") return; // TODO: убрать
|
||||
editMessage(query, result);
|
||||
editMessage(chatId, messageId, result);
|
||||
return;
|
||||
}
|
||||
|
||||
// Переходы вперёд (push)
|
||||
// Переходы вперёд (pyush)
|
||||
auto newStepOpt = computeNextStep(query, current);
|
||||
if (!newStepOpt.has_value()) {
|
||||
sendError(query, BotConstants::Text::SAD_ERROR);
|
||||
sendError(chatId, messageId, BotConstants::Text::SAD_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.history.push_back(*newStepOpt);
|
||||
auto result = renderCurrent(query, ctx);
|
||||
if(result.message == "meow") return; // TODO: убрать
|
||||
editMessage(query, result);
|
||||
editMessage(chatId, messageId, result);
|
||||
}
|
||||
|
||||
HandlerResult BotHandlers::renderCurrent(TgBot::CallbackQuery::Ptr query, const UserContext& ctx) {
|
||||
const auto& step = ctx.history.back();
|
||||
int64_t userId = query->from->id;
|
||||
//int64_t userId = query->from->id;
|
||||
int64_t chatId = query->message->chat->id;
|
||||
int64_t messageId = query->message->messageId;
|
||||
switch (step.state) {
|
||||
case UserState::MAIN_MENU:
|
||||
return showMainMenu();
|
||||
case UserState::VIEWING_MY_TITLES:
|
||||
server_.fetchUserTitlesAsync(std::to_string(2)) // ALARM: тестовое значение вместо userId
|
||||
.then([this, query](pplx::task<std::vector<BotStructs::Title>> t) {
|
||||
.then([this, chatId, messageId](pplx::task<std::vector<BotStructs::Title>> t) {
|
||||
try {
|
||||
auto titles = t.get();
|
||||
|
||||
std::string message = formatTitlesList(titles);
|
||||
auto keyboard = KeyboardFactory::createMyTitles(titles);
|
||||
|
||||
editMessage(query, {message, keyboard});
|
||||
editMessage(chatId, messageId, {message, keyboard});
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
sendError(query, BotConstants::Text::SERVER_ERROR);
|
||||
sendError(chatId, messageId, BotConstants::Text::SERVER_ERROR);
|
||||
// Логирование ошибки (например, в cerr)
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue