1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2026
//
// 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)
//
#include "td/telegram/Venue.h"
#include "td/telegram/misc.h"
#include "td/telegram/secret_api.h"
namespace td {
Venue::Venue(Td *td, const tl_object_ptr<telegram_api::GeoPoint> &geo_point_ptr, string title, string address,
string provider, string id, string type)
: location_(td, geo_point_ptr)
, title_(std::move(title))
, address_(std::move(address))
, provider_(std::move(provider))
, id_(std::move(id))
, type_(std::move(type)) {
}
Venue::Venue(Location location, string title, string address, string provider, string id, string type)
: location_(location)
, title_(std::move(title))
, address_(std::move(address))
, provider_(std::move(provider))
, id_(std::move(id))
, type_(std::move(type)) {
}
Venue::Venue(const tl_object_ptr<td_api::venue> &venue)
: location_(venue->location_)
, title_(venue->title_)
, address_(venue->address_)
, provider_(venue->provider_)
, id_(venue->id_)
, type_(venue->type_) {
}
bool Venue::empty() const {
return location_.empty();
}
Location &Venue::location() {
return location_;
}
const Location &Venue::location() const {
return location_;
}
tl_object_ptr<td_api::venue> Venue::get_venue_object() const {
return make_tl_object<td_api::venue>(location_.get_location_object(), title_, address_, provider_, id_, type_);
}
tl_object_ptr<telegram_api::inputMediaVenue> Venue::get_input_media_venue() const {
return make_tl_object<telegram_api::inputMediaVenue>(location_.get_input_geo_point(), title_, address_, provider_,
id_, type_);
}
SecretInputMedia Venue::get_secret_input_media_venue() const {
return SecretInputMedia{nullptr,
make_tl_object<secret_api::decryptedMessageMediaVenue>(
location_.get_latitude(), location_.get_longitude(), title_, address_, provider_, id_)};
}
tl_object_ptr<telegram_api::inputBotInlineMessageMediaVenue> Venue::get_input_bot_inline_message_media_venue(
tl_object_ptr<telegram_api::ReplyMarkup> &&reply_markup) const {
int32 flags = 0;
if (reply_markup != nullptr) {
flags |= telegram_api::inputBotInlineMessageMediaVenue::REPLY_MARKUP_MASK;
}
return make_tl_object<telegram_api::inputBotInlineMessageMediaVenue>(
flags, location_.get_input_geo_point(), title_, address_, provider_, id_, type_, std::move(reply_markup));
}
telegram_api::object_ptr<telegram_api::mediaAreaVenue> Venue::get_input_media_area_venue(
telegram_api::object_ptr<telegram_api::mediaAreaCoordinates> &&coordinates) const {
return telegram_api::make_object<telegram_api::mediaAreaVenue>(std::move(coordinates), location_.get_fake_geo_point(),
title_, address_, provider_, id_, type_);
}
bool operator==(const Venue &lhs, const Venue &rhs) {
return lhs.location_ == rhs.location_ && lhs.title_ == rhs.title_ && lhs.address_ == rhs.address_ &&
lhs.provider_ == rhs.provider_ && lhs.id_ == rhs.id_ && lhs.type_ == rhs.type_;
}
bool operator!=(const Venue &lhs, const Venue &rhs) {
return !(lhs == rhs);
}
StringBuilder &operator<<(StringBuilder &string_builder, const Venue &venue) {
return string_builder << "Venue[location = " << venue.location_ << ", title = " << venue.title_
<< ", address = " << venue.address_ << ", provider = " << venue.provider_
<< ", ID = " << venue.id_ << ", type = " << venue.type_ << "]";
}
Result<Venue> process_input_message_venue(tl_object_ptr<td_api::InputMessageContent> &&input_message_content) {
CHECK(input_message_content != nullptr);
CHECK(input_message_content->get_id() == td_api::inputMessageVenue::ID);
auto venue = std::move(static_cast<td_api::inputMessageVenue *>(input_message_content.get())->venue_);
if (venue == nullptr) {
return Status::Error(400, "Venue must be non-empty");
}
if (!clean_input_string(venue->title_)) {
return Status::Error(400, "Venue title must be encoded in UTF-8");
}
if (!clean_input_string(venue->address_)) {
return Status::Error(400, "Venue address must be encoded in UTF-8");
}
if (!clean_input_string(venue->provider_)) {
return Status::Error(400, "Venue provider must be encoded in UTF-8");
}
if (!clean_input_string(venue->id_)) {
return Status::Error(400, "Venue identifier must be encoded in UTF-8");
}
if (!clean_input_string(venue->type_)) {
return Status::Error(400, "Venue type must be encoded in UTF-8");
}
Venue result(venue);
if (result.empty()) {
return Status::Error(400, "Wrong venue location specified");
}
return result;
}
} // namespace td
|