Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/tgbot/types/ReplyParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <vector>

Expand Down Expand Up @@ -60,7 +61,7 @@ class ReplyParameters {
*
* It can be specified instead of quoteParseMode.
*/
std::vector<MessageEntity::Ptr> quoteEntities;
std::optional<std::vector<MessageEntity::Ptr>> quoteEntities;

/**
* @brief Optional. Position of the quote in the original message in UTF-16 code units
Expand Down
14 changes: 12 additions & 2 deletions src/TgTypeParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ struct JsonWrapper {
}
data_[std::string(key)] = *value;
}
template <typename T,
std::enable_if_t<detail::is_vector_v<T>, bool> = true>
void put(const std::string_view key, std::optional<T> value) {
if (!value) {
return; // Skip empty optional
}
data_[std::string(key)] = TgBot::put(*value);
}

static void merge(nlohmann::json &thiz, const nlohmann::json &other) {
if (!thiz.is_object() || !other.is_object()) {
Expand Down Expand Up @@ -818,7 +826,9 @@ DECLARE_PARSER_FROM_JSON(ReplyParameters) {
&result->allowSendingWithoutReply);
parse(data, "quote", &result->quote);
parse(data, "quote_parse_mode", &result->quoteParseMode);
result->quoteEntities = parseArray<MessageEntity>(data, "quote_entities");
if (data.contains("quote_entities")) {
result->quoteEntities = parseArray<MessageEntity>(data, "quote_entities");
}
parse(data, "quote_position", &result->quotePosition);
return result;
}
Expand All @@ -833,7 +843,7 @@ DECLARE_PARSER_TO_JSON(ReplyParameters) {
object->allowSendingWithoutReply);
json.put("quote", object->quote);
json.put("quote_parse_mode", object->quoteParseMode);
json.put("quote_entities", put(object->quoteEntities));
json.put("quote_entities", object->quoteEntities);
json.put("quote_position", object->quotePosition);
}

Expand Down