2018-12-31 20:04:05 +01:00
|
|
|
//
|
2020-01-01 02:23:48 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2020
|
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
|
|
|
|
|
2018-08-14 01:11:49 +02:00
|
|
|
#include "td/telegram/Global.h"
|
|
|
|
#include "td/telegram/SecretInputMedia.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
#include "td/telegram/secret_api.h"
|
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
#include "td/telegram/telegram_api.h"
|
|
|
|
|
2018-08-14 01:11:49 +02:00
|
|
|
#include "td/utils/common.h"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/utils/Status.h"
|
2018-08-14 01:11:49 +02:00
|
|
|
#include "td/utils/StringBuilder.h"
|
|
|
|
#include "td/utils/tl_helpers.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
class Location {
|
|
|
|
bool is_empty_ = true;
|
|
|
|
double latitude_ = 0.0;
|
|
|
|
double longitude_ = 0.0;
|
2020-10-17 21:47:47 +02:00
|
|
|
double horizontal_accuracy_ = 0.0;
|
2019-02-19 16:52:09 +01:00
|
|
|
mutable int64 access_hash_ = 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
friend bool operator==(const Location &lhs, const Location &rhs);
|
|
|
|
friend bool operator!=(const Location &lhs, const Location &rhs);
|
|
|
|
|
|
|
|
friend StringBuilder &operator<<(StringBuilder &string_builder, const Location &location);
|
|
|
|
|
2020-10-17 21:47:47 +02:00
|
|
|
void init(double latitude, double longitude, double horizontal_accuracy, int64 access_hash);
|
|
|
|
|
|
|
|
double fix_accuracy(double accuracy);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
Location() = default;
|
|
|
|
|
2020-10-17 21:47:47 +02:00
|
|
|
Location(double latitude, double longitude, double horizontal_accuracy, int64 access_hash);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
explicit Location(const tl_object_ptr<secret_api::decryptedMessageMediaGeoPoint> &geo_point);
|
|
|
|
|
|
|
|
explicit Location(const tl_object_ptr<telegram_api::GeoPoint> &geo_point_ptr);
|
|
|
|
|
|
|
|
explicit Location(const tl_object_ptr<td_api::location> &location);
|
|
|
|
|
|
|
|
bool empty() const;
|
|
|
|
|
2018-08-13 22:18:27 +02:00
|
|
|
bool is_valid_map_point() const;
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
tl_object_ptr<td_api::location> get_location_object() const;
|
|
|
|
|
|
|
|
tl_object_ptr<telegram_api::InputGeoPoint> get_input_geo_point() const;
|
|
|
|
|
|
|
|
tl_object_ptr<telegram_api::inputMediaGeoPoint> get_input_media_geo_point() const;
|
|
|
|
|
|
|
|
double get_latitude() const {
|
|
|
|
return latitude_;
|
|
|
|
}
|
2018-06-25 23:10:53 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
double get_longitude() const {
|
|
|
|
return longitude_;
|
|
|
|
}
|
2018-06-25 23:10:53 +02:00
|
|
|
|
|
|
|
int64 get_access_hash() const {
|
|
|
|
return access_hash_;
|
|
|
|
}
|
|
|
|
|
2019-02-19 16:52:09 +01:00
|
|
|
void set_access_hash(int64 access_hash) const {
|
2018-06-25 23:10:53 +02:00
|
|
|
access_hash_ = access_hash;
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
SecretInputMedia get_secret_input_media_geo_point() const;
|
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const {
|
|
|
|
using td::store;
|
2018-06-25 23:10:53 +02:00
|
|
|
bool has_access_hash = access_hash_ != 0;
|
2020-10-17 21:47:47 +02:00
|
|
|
bool has_horizontal_accuracy = horizontal_accuracy_ > 0.0;
|
2018-12-31 20:04:05 +01:00
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(is_empty_);
|
2018-06-25 23:10:53 +02:00
|
|
|
STORE_FLAG(has_access_hash);
|
2020-10-17 21:47:47 +02:00
|
|
|
STORE_FLAG(has_horizontal_accuracy);
|
2018-12-31 20:04:05 +01:00
|
|
|
END_STORE_FLAGS();
|
|
|
|
store(latitude_, storer);
|
|
|
|
store(longitude_, storer);
|
2018-06-25 23:10:53 +02:00
|
|
|
if (has_access_hash) {
|
|
|
|
store(access_hash_, storer);
|
|
|
|
}
|
2020-10-17 21:47:47 +02:00
|
|
|
if (has_horizontal_accuracy) {
|
|
|
|
store(horizontal_accuracy_, storer);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser) {
|
|
|
|
using td::parse;
|
2018-06-25 23:10:53 +02:00
|
|
|
bool has_access_hash;
|
2020-10-17 21:47:47 +02:00
|
|
|
bool has_horizontal_accuracy;
|
2018-12-31 20:04:05 +01:00
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(is_empty_);
|
2018-06-25 23:10:53 +02:00
|
|
|
PARSE_FLAG(has_access_hash);
|
2020-10-17 21:47:47 +02:00
|
|
|
PARSE_FLAG(has_horizontal_accuracy);
|
2018-12-31 20:04:05 +01:00
|
|
|
END_PARSE_FLAGS();
|
|
|
|
parse(latitude_, parser);
|
|
|
|
parse(longitude_, parser);
|
2018-06-25 23:10:53 +02:00
|
|
|
if (has_access_hash) {
|
|
|
|
parse(access_hash_, parser);
|
2018-08-14 01:11:49 +02:00
|
|
|
G()->add_location_access_hash(latitude_, longitude_, access_hash_);
|
2018-06-25 23:10:53 +02:00
|
|
|
}
|
2020-10-17 21:47:47 +02:00
|
|
|
if (has_horizontal_accuracy) {
|
|
|
|
parse(horizontal_accuracy_, parser);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
bool operator==(const Location &lhs, const Location &rhs);
|
|
|
|
bool operator!=(const Location &lhs, const Location &rhs);
|
|
|
|
|
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const Location &location);
|
|
|
|
|
2020-10-16 22:08:28 +02:00
|
|
|
struct InputMessageLocation {
|
|
|
|
Location location;
|
|
|
|
int32 live_period;
|
|
|
|
int32 heading;
|
|
|
|
};
|
|
|
|
Result<InputMessageLocation> process_input_message_location(
|
2018-09-28 22:57:34 +02:00
|
|
|
td_api::object_ptr<td_api::InputMessageContent> &&input_message_content) TD_WARN_UNUSED_RESULT;
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace td
|