2023-08-01 14:17:50 +02:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
2023-08-01 14:17:50 +02: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/MediaArea.h"
|
|
|
|
#include "td/telegram/MediaAreaCoordinates.hpp"
|
|
|
|
|
|
|
|
#include "td/utils/tl_helpers.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2024-06-07 15:13:58 +02:00
|
|
|
template <class StorerT>
|
|
|
|
void MediaArea::GeoPointAddress::store(StorerT &storer) const {
|
|
|
|
bool has_country_iso2 = !country_iso2_.empty();
|
|
|
|
bool has_state = !state_.empty();
|
|
|
|
bool has_city = !city_.empty();
|
|
|
|
bool has_street = !street_.empty();
|
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(has_country_iso2);
|
|
|
|
STORE_FLAG(has_state);
|
|
|
|
STORE_FLAG(has_city);
|
|
|
|
STORE_FLAG(has_street);
|
|
|
|
END_STORE_FLAGS();
|
|
|
|
if (has_country_iso2) {
|
|
|
|
td::store(country_iso2_, storer);
|
|
|
|
}
|
|
|
|
if (has_state) {
|
|
|
|
td::store(state_, storer);
|
|
|
|
}
|
|
|
|
if (has_city) {
|
|
|
|
td::store(city_, storer);
|
|
|
|
}
|
|
|
|
if (has_street) {
|
|
|
|
td::store(street_, storer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void MediaArea::GeoPointAddress::parse(ParserT &parser) {
|
|
|
|
bool has_country_iso2;
|
|
|
|
bool has_state;
|
|
|
|
bool has_city;
|
|
|
|
bool has_street;
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(has_country_iso2);
|
|
|
|
PARSE_FLAG(has_state);
|
|
|
|
PARSE_FLAG(has_city);
|
|
|
|
PARSE_FLAG(has_street);
|
|
|
|
END_PARSE_FLAGS();
|
|
|
|
if (has_country_iso2) {
|
|
|
|
td::parse(country_iso2_, parser);
|
|
|
|
}
|
|
|
|
if (has_state) {
|
|
|
|
td::parse(state_, parser);
|
|
|
|
}
|
|
|
|
if (has_city) {
|
|
|
|
td::parse(city_, parser);
|
|
|
|
}
|
|
|
|
if (has_street) {
|
|
|
|
td::parse(street_, parser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-01 14:17:50 +02:00
|
|
|
template <class StorerT>
|
|
|
|
void MediaArea::store(StorerT &storer) const {
|
|
|
|
using td::store;
|
2023-08-01 17:11:30 +02:00
|
|
|
bool has_input_query_id = input_query_id_ != 0;
|
2024-06-07 15:13:58 +02:00
|
|
|
bool has_address = !address_.is_empty();
|
2023-08-01 14:17:50 +02:00
|
|
|
BEGIN_STORE_FLAGS();
|
2023-08-01 17:11:30 +02:00
|
|
|
STORE_FLAG(has_input_query_id);
|
2023-08-25 15:37:27 +02:00
|
|
|
STORE_FLAG(is_dark_);
|
|
|
|
STORE_FLAG(is_flipped_);
|
2023-12-18 12:40:11 +01:00
|
|
|
STORE_FLAG(is_old_message_);
|
2024-06-07 15:13:58 +02:00
|
|
|
STORE_FLAG(has_address);
|
2023-08-01 14:17:50 +02:00
|
|
|
END_STORE_FLAGS();
|
|
|
|
store(type_, storer);
|
|
|
|
store(coordinates_, storer);
|
|
|
|
switch (type_) {
|
|
|
|
case Type::Location:
|
|
|
|
store(location_, storer);
|
|
|
|
break;
|
|
|
|
case Type::Venue:
|
|
|
|
store(venue_, storer);
|
2023-08-01 17:11:30 +02:00
|
|
|
if (has_input_query_id) {
|
|
|
|
store(input_query_id_, storer);
|
|
|
|
store(input_result_id_, storer);
|
|
|
|
}
|
2023-08-01 14:17:50 +02:00
|
|
|
break;
|
2023-08-25 15:37:27 +02:00
|
|
|
case Type::Reaction:
|
|
|
|
store(reaction_type_, storer);
|
|
|
|
break;
|
2023-12-18 12:40:11 +01:00
|
|
|
case Type::Message:
|
|
|
|
store(message_full_id_, storer);
|
|
|
|
break;
|
2024-06-05 14:56:55 +02:00
|
|
|
case Type::Url:
|
|
|
|
store(url_, storer);
|
|
|
|
break;
|
2023-08-01 14:17:50 +02:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2024-06-07 15:13:58 +02:00
|
|
|
if (has_address) {
|
|
|
|
store(address_, storer);
|
|
|
|
}
|
2023-08-01 14:17:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void MediaArea::parse(ParserT &parser) {
|
|
|
|
using td::parse;
|
2023-08-01 17:11:30 +02:00
|
|
|
bool has_input_query_id;
|
2024-06-07 15:13:58 +02:00
|
|
|
bool has_address;
|
2023-08-01 14:17:50 +02:00
|
|
|
BEGIN_PARSE_FLAGS();
|
2023-08-01 17:11:30 +02:00
|
|
|
PARSE_FLAG(has_input_query_id);
|
2023-08-25 15:37:27 +02:00
|
|
|
PARSE_FLAG(is_dark_);
|
|
|
|
PARSE_FLAG(is_flipped_);
|
2023-12-18 12:40:11 +01:00
|
|
|
PARSE_FLAG(is_old_message_);
|
2024-06-07 15:13:58 +02:00
|
|
|
PARSE_FLAG(has_address);
|
2023-08-01 14:17:50 +02:00
|
|
|
END_PARSE_FLAGS();
|
|
|
|
parse(type_, parser);
|
|
|
|
parse(coordinates_, parser);
|
|
|
|
switch (type_) {
|
|
|
|
case Type::Location:
|
|
|
|
parse(location_, parser);
|
|
|
|
break;
|
|
|
|
case Type::Venue:
|
|
|
|
parse(venue_, parser);
|
2023-08-01 17:11:30 +02:00
|
|
|
if (has_input_query_id) {
|
|
|
|
parse(input_query_id_, parser);
|
|
|
|
parse(input_result_id_, parser);
|
|
|
|
}
|
2023-08-01 14:17:50 +02:00
|
|
|
break;
|
2023-08-25 15:37:27 +02:00
|
|
|
case Type::Reaction:
|
|
|
|
parse(reaction_type_, parser);
|
|
|
|
break;
|
2023-12-18 12:40:11 +01:00
|
|
|
case Type::Message:
|
|
|
|
parse(message_full_id_, parser);
|
|
|
|
break;
|
2024-06-05 14:56:55 +02:00
|
|
|
case Type::Url:
|
|
|
|
parse(url_, parser);
|
|
|
|
break;
|
2023-08-01 14:17:50 +02:00
|
|
|
default:
|
|
|
|
parser.set_error("Load invalid area type");
|
|
|
|
}
|
2024-06-07 15:13:58 +02:00
|
|
|
if (has_address) {
|
|
|
|
parse(address_, parser);
|
|
|
|
}
|
2023-08-01 14:17:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|