2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "td/telegram/ReplyMarkup.h"
|
2023-01-11 14:54:46 +01:00
|
|
|
#include "td/telegram/RequestedDialogType.hpp"
|
2021-09-03 11:27:59 +02:00
|
|
|
#include "td/telegram/Version.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
#include "td/utils/tl_helpers.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
template <class StorerT>
|
2023-01-11 14:54:46 +01:00
|
|
|
void store(const KeyboardButton &button, StorerT &storer) {
|
2022-03-27 00:20:26 +01:00
|
|
|
bool has_url = !button.url.empty();
|
2023-01-11 14:54:46 +01:00
|
|
|
bool has_requested_dialog_type = button.requested_dialog_type != nullptr;
|
2021-11-10 15:14:00 +01:00
|
|
|
BEGIN_STORE_FLAGS();
|
2022-03-27 00:20:26 +01:00
|
|
|
STORE_FLAG(has_url);
|
2023-01-11 14:54:46 +01:00
|
|
|
STORE_FLAG(has_requested_dialog_type);
|
2021-11-10 15:14:00 +01:00
|
|
|
END_STORE_FLAGS();
|
2018-12-31 20:04:05 +01:00
|
|
|
store(button.type, storer);
|
|
|
|
store(button.text, storer);
|
2022-03-27 00:20:26 +01:00
|
|
|
if (has_url) {
|
|
|
|
store(button.url, storer);
|
|
|
|
}
|
2023-01-11 14:54:46 +01:00
|
|
|
if (has_requested_dialog_type) {
|
|
|
|
store(button.requested_dialog_type, storer);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(KeyboardButton &button, ParserT &parser) {
|
2022-04-07 19:38:22 +02:00
|
|
|
bool has_url;
|
2023-01-11 14:54:46 +01:00
|
|
|
bool has_requested_dialog_type;
|
2021-11-10 15:14:00 +01:00
|
|
|
if (parser.version() >= static_cast<int32>(Version::AddKeyboardButtonFlags)) {
|
|
|
|
BEGIN_PARSE_FLAGS();
|
2022-03-27 00:20:26 +01:00
|
|
|
PARSE_FLAG(has_url);
|
2023-01-11 14:54:46 +01:00
|
|
|
PARSE_FLAG(has_requested_dialog_type);
|
2021-11-10 15:14:00 +01:00
|
|
|
END_PARSE_FLAGS();
|
2022-04-07 19:38:22 +02:00
|
|
|
} else {
|
|
|
|
has_url = false;
|
2023-01-11 14:54:46 +01:00
|
|
|
has_requested_dialog_type = false;
|
2021-11-10 15:14:00 +01:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
parse(button.type, parser);
|
|
|
|
parse(button.text, parser);
|
2022-03-27 00:20:26 +01:00
|
|
|
if (has_url) {
|
|
|
|
parse(button.url, parser);
|
|
|
|
}
|
2023-01-11 14:54:46 +01:00
|
|
|
if (has_requested_dialog_type) {
|
|
|
|
parse(button.requested_dialog_type, parser);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class StorerT>
|
2023-01-11 14:54:46 +01:00
|
|
|
void store(const InlineKeyboardButton &button, StorerT &storer) {
|
2021-11-10 15:14:00 +01:00
|
|
|
bool has_id = button.id != 0;
|
|
|
|
bool has_user_id = button.user_id.is_valid();
|
|
|
|
bool has_forward_text = !button.forward_text.empty();
|
|
|
|
bool has_data = !button.data.empty();
|
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(has_id);
|
|
|
|
STORE_FLAG(has_user_id);
|
|
|
|
STORE_FLAG(has_forward_text);
|
|
|
|
STORE_FLAG(has_data);
|
|
|
|
END_STORE_FLAGS();
|
2018-12-31 20:04:05 +01:00
|
|
|
store(button.type, storer);
|
2021-11-10 15:14:00 +01:00
|
|
|
if (has_id) {
|
2019-05-23 22:35:26 +02:00
|
|
|
store(button.id, storer);
|
|
|
|
}
|
2021-11-10 15:14:00 +01:00
|
|
|
if (has_user_id) {
|
|
|
|
store(button.user_id, storer);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
store(button.text, storer);
|
2021-11-10 15:14:00 +01:00
|
|
|
if (has_forward_text) {
|
|
|
|
store(button.forward_text, storer);
|
|
|
|
}
|
|
|
|
if (has_data) {
|
|
|
|
store(button.data, storer);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(InlineKeyboardButton &button, ParserT &parser) {
|
2021-11-10 15:14:00 +01:00
|
|
|
if (parser.version() >= static_cast<int32>(Version::AddKeyboardButtonFlags)) {
|
|
|
|
bool has_id;
|
|
|
|
bool has_user_id;
|
|
|
|
bool has_forward_text;
|
|
|
|
bool has_data;
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(has_id);
|
|
|
|
PARSE_FLAG(has_user_id);
|
|
|
|
PARSE_FLAG(has_forward_text);
|
|
|
|
PARSE_FLAG(has_data);
|
|
|
|
END_PARSE_FLAGS();
|
|
|
|
parse(button.type, parser);
|
|
|
|
if (has_id) {
|
2021-09-03 11:27:59 +02:00
|
|
|
parse(button.id, parser);
|
|
|
|
}
|
2021-11-10 15:14:00 +01:00
|
|
|
if (has_user_id) {
|
|
|
|
parse(button.user_id, parser);
|
|
|
|
}
|
|
|
|
parse(button.text, parser);
|
|
|
|
if (has_forward_text) {
|
|
|
|
parse(button.forward_text, parser);
|
|
|
|
}
|
|
|
|
if (has_data) {
|
|
|
|
parse(button.data, parser);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
parse(button.type, parser);
|
|
|
|
if (button.type == InlineKeyboardButton::Type::UrlAuth) {
|
|
|
|
if (parser.version() >= static_cast<int32>(Version::Support64BitIds)) {
|
|
|
|
parse(button.id, parser);
|
|
|
|
} else {
|
|
|
|
int32 old_id;
|
|
|
|
parse(old_id, parser);
|
|
|
|
button.id = old_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parse(button.text, parser);
|
|
|
|
parse(button.data, parser);
|
2019-05-23 22:35:26 +02:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(const ReplyMarkup &reply_markup, StorerT &storer) {
|
|
|
|
bool has_keyboard = !reply_markup.keyboard.empty();
|
|
|
|
bool has_inline_keyboard = !reply_markup.inline_keyboard.empty();
|
2021-06-22 17:34:39 +02:00
|
|
|
bool has_placeholder = !reply_markup.placeholder.empty();
|
2018-12-31 20:04:05 +01:00
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(reply_markup.is_personal);
|
|
|
|
STORE_FLAG(reply_markup.need_resize_keyboard);
|
|
|
|
STORE_FLAG(reply_markup.is_one_time_keyboard);
|
|
|
|
STORE_FLAG(has_keyboard);
|
|
|
|
STORE_FLAG(has_inline_keyboard);
|
2021-06-22 17:34:39 +02:00
|
|
|
STORE_FLAG(has_placeholder);
|
2022-12-15 12:59:12 +01:00
|
|
|
STORE_FLAG(reply_markup.is_persistent);
|
2018-12-31 20:04:05 +01:00
|
|
|
END_STORE_FLAGS();
|
|
|
|
store(reply_markup.type, storer);
|
|
|
|
if (has_keyboard) {
|
|
|
|
store(reply_markup.keyboard, storer);
|
|
|
|
}
|
|
|
|
if (has_inline_keyboard) {
|
|
|
|
store(reply_markup.inline_keyboard, storer);
|
|
|
|
}
|
2021-06-22 17:34:39 +02:00
|
|
|
if (has_placeholder) {
|
|
|
|
store(reply_markup.placeholder, storer);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ReplyMarkup &reply_markup, ParserT &parser) {
|
2020-09-15 18:45:45 +02:00
|
|
|
bool has_keyboard;
|
|
|
|
bool has_inline_keyboard;
|
2021-06-22 17:34:39 +02:00
|
|
|
bool has_placeholder;
|
2018-12-31 20:04:05 +01:00
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(reply_markup.is_personal);
|
|
|
|
PARSE_FLAG(reply_markup.need_resize_keyboard);
|
|
|
|
PARSE_FLAG(reply_markup.is_one_time_keyboard);
|
|
|
|
PARSE_FLAG(has_keyboard);
|
|
|
|
PARSE_FLAG(has_inline_keyboard);
|
2021-06-22 17:34:39 +02:00
|
|
|
PARSE_FLAG(has_placeholder);
|
2022-12-15 12:59:12 +01:00
|
|
|
PARSE_FLAG(reply_markup.is_persistent);
|
2018-12-31 20:04:05 +01:00
|
|
|
END_PARSE_FLAGS();
|
|
|
|
parse(reply_markup.type, parser);
|
|
|
|
if (has_keyboard) {
|
|
|
|
parse(reply_markup.keyboard, parser);
|
|
|
|
}
|
|
|
|
if (has_inline_keyboard) {
|
|
|
|
parse(reply_markup.inline_keyboard, parser);
|
|
|
|
}
|
2021-06-22 17:34:39 +02:00
|
|
|
if (has_placeholder) {
|
|
|
|
parse(reply_markup.placeholder, parser);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|