blob: 88f9d437856406330f9112b7af5edc961d10c370 (
plain)
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
|
//
// 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/DialogLocation.h"
#include "td/telegram/misc.h"
namespace td {
DialogLocation::DialogLocation(Td *td, telegram_api::object_ptr<telegram_api::ChannelLocation> &&channel_location_ptr) {
if (channel_location_ptr != nullptr && channel_location_ptr->get_id() == telegram_api::channelLocation::ID) {
auto channel_location = static_cast<telegram_api::channelLocation *>(channel_location_ptr.get());
location_ = Location(td, channel_location->geo_point_);
address_ = std::move(channel_location->address_);
}
}
DialogLocation::DialogLocation(Td *td, telegram_api::object_ptr<telegram_api::businessLocation> &&business_location) {
if (business_location != nullptr) {
location_ = Location(td, business_location->geo_point_);
address_ = std::move(business_location->address_);
}
}
DialogLocation::DialogLocation(td_api::object_ptr<td_api::chatLocation> &&chat_location) {
if (chat_location != nullptr) {
location_ = Location(chat_location->location_);
address_ = std::move(chat_location->address_);
if (!clean_input_string(address_)) {
address_.clear();
}
}
}
DialogLocation::DialogLocation(td_api::object_ptr<td_api::businessLocation> &&business_location) {
if (business_location != nullptr) {
location_ = Location(business_location->location_);
address_ = std::move(business_location->address_);
if (!clean_input_string(address_)) {
address_.clear();
}
}
}
bool DialogLocation::empty() const {
return location_.empty();
}
td_api::object_ptr<td_api::chatLocation> DialogLocation::get_chat_location_object() const {
if (empty()) {
return nullptr;
}
return td_api::make_object<td_api::chatLocation>(location_.get_location_object(), address_);
}
td_api::object_ptr<td_api::businessLocation> DialogLocation::get_business_location_object() const {
if (empty() && address_.empty()) {
return nullptr;
}
return td_api::make_object<td_api::businessLocation>(location_.get_location_object(), address_);
}
telegram_api::object_ptr<telegram_api::InputGeoPoint> DialogLocation::get_input_geo_point() const {
return location_.get_input_geo_point();
}
const string &DialogLocation::get_address() const {
return address_;
}
bool operator==(const DialogLocation &lhs, const DialogLocation &rhs) {
return lhs.location_ == rhs.location_ && lhs.address_ == rhs.address_;
}
bool operator!=(const DialogLocation &lhs, const DialogLocation &rhs) {
return !(lhs == rhs);
}
StringBuilder &operator<<(StringBuilder &string_builder, const DialogLocation &location) {
return string_builder << "DialogLocation[location = " << location.location_ << ", address = " << location.address_
<< "]";
}
} // namespace td
|