Use Location access hashes.
GitOrigin-RevId: 1f018d5e42e1c657492f2e1da74700632825c8f9
This commit is contained in:
parent
c6bc8f7c3f
commit
8d5c17036a
@ -3277,7 +3277,7 @@ setStickerPositionInSet sticker:InputFile position:int32 = Ok;
|
||||
removeStickerFromSet sticker:InputFile = Ok;
|
||||
|
||||
|
||||
//@description Returns information about a file with a map thumbnail @location Location of the map center @zoom Map zoom level; 13-20 @width Map width in pixels before applying scale; 16-1024 @height Map height in pixels before applying scale; 16-1024 @scale Map scale; 1-3 @chat_id Identifier of a chat, in which the thumbnail will be shown. Use 0 if unknown
|
||||
//@description Returns information about a file with a map thumbnail in PNG format @location Location of the map center @zoom Map zoom level; 13-20 @width Map width in pixels before applying scale; 16-1024 @height Map height in pixels before applying scale; 16-1024 @scale Map scale; 1-3 @chat_id Identifier of a chat, in which the thumbnail will be shown. Use 0 if unknown
|
||||
getMapThumbnailFile location:location zoom:int32 width:int32 height:int32 scale:int32 chat_id:int53 = File;
|
||||
|
||||
|
||||
|
@ -21,6 +21,8 @@
|
||||
#include "td/utils/port/Clocks.h"
|
||||
#include "td/utils/tl_helpers.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace td {
|
||||
|
||||
Global::Global() = default;
|
||||
@ -120,4 +122,37 @@ void Global::set_shared_config(std::unique_ptr<ConfigShared> shared_config) {
|
||||
shared_config_ = std::move(shared_config);
|
||||
}
|
||||
|
||||
int64 Global::get_location_key(double latitude, double longitude) {
|
||||
const double PI = 3.14159265358979323846;
|
||||
latitude *= PI / 180;
|
||||
longitude *= PI / 180;
|
||||
|
||||
int64 key = 0;
|
||||
if (latitude < 0) {
|
||||
latitude = -latitude;
|
||||
key = 65536;
|
||||
}
|
||||
|
||||
double f = std::tan(PI / 4 - latitude / 2);
|
||||
key += static_cast<int64>(f * std::cos(longitude) * 128) * 256;
|
||||
key += static_cast<int64>(f * std::sin(longitude) * 128);
|
||||
return key;
|
||||
}
|
||||
|
||||
int64 Global::get_location_access_hash(double latitude, double longitude) {
|
||||
auto it = location_access_hashes_.find(get_location_key(latitude, longitude));
|
||||
if (it == location_access_hashes_.end()) {
|
||||
return 0;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void Global::add_location_access_hash(double latitude, double longitude, int64 access_hash) {
|
||||
if (access_hash == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
location_access_hashes_[get_location_key(latitude, longitude)] = access_hash;
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace td {
|
||||
class AnimationsManager;
|
||||
@ -301,6 +302,10 @@ class Global : public ActorContext {
|
||||
net_stats_file_callbacks_ = std::move(callbacks);
|
||||
}
|
||||
|
||||
int64 get_location_access_hash(double latitude, double longitude);
|
||||
|
||||
void add_location_access_hash(double latitude, double longitude, int64 access_hash);
|
||||
|
||||
private:
|
||||
std::shared_ptr<DhConfig> dh_config_;
|
||||
|
||||
@ -346,6 +351,10 @@ class Global : public ActorContext {
|
||||
|
||||
int32 my_id_ = 0; // hack
|
||||
|
||||
static int64 get_location_key(double latitude, double longitude);
|
||||
|
||||
std::unordered_map<int64, int64> location_access_hashes_;
|
||||
|
||||
void do_close(Promise<> on_finish, bool destroy_flag);
|
||||
};
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
//
|
||||
#include "td/telegram/Location.h"
|
||||
|
||||
#include "td/telegram/Global.h"
|
||||
#include "td/telegram/secret_api.h"
|
||||
#include "td/telegram/td_api.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
@ -23,6 +24,7 @@ void Location::init(double latitude, double longitude, int64 access_hash) {
|
||||
latitude_ = latitude;
|
||||
longitude_ = longitude;
|
||||
access_hash_ = access_hash;
|
||||
G()->add_location_access_hash(latitude_, longitude_, access_hash_);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,16 +6,17 @@
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/StringBuilder.h"
|
||||
#include "td/utils/tl_helpers.h"
|
||||
#include "td/telegram/Global.h"
|
||||
#include "td/telegram/SecretInputMedia.h"
|
||||
#include "td/telegram/Version.h"
|
||||
|
||||
#include "td/telegram/secret_api.h"
|
||||
#include "td/telegram/td_api.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
|
||||
#include "td/telegram/SecretInputMedia.h"
|
||||
#include "td/telegram/Version.h"
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/StringBuilder.h"
|
||||
#include "td/utils/tl_helpers.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
@ -98,6 +99,7 @@ class Location {
|
||||
parse(longitude_, parser);
|
||||
if (has_access_hash) {
|
||||
parse(access_hash_, parser);
|
||||
G()->add_location_access_hash(latitude_, longitude_, access_hash_);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -152,7 +152,6 @@ class MapDownloadGenerateActor : public FileGenerateActor {
|
||||
TRY_RESULT(width, to_integer_safe<int32>(parts[5]));
|
||||
TRY_RESULT(height, to_integer_safe<int32>(parts[6]));
|
||||
TRY_RESULT(scale, to_integer_safe<int32>(parts[7]));
|
||||
int64 access_hash = 0;
|
||||
|
||||
if (zoom < 13 || zoom > 20) {
|
||||
return Status::Error("Wrong zoom");
|
||||
@ -171,12 +170,13 @@ class MapDownloadGenerateActor : public FileGenerateActor {
|
||||
return Status::Error("Wrong scale");
|
||||
}
|
||||
|
||||
file_name_ = PSTRING() << "map_" << zoom << "_" << x << "_" << y << ".jpg";
|
||||
file_name_ = PSTRING() << "map_" << zoom << "_" << x << "_" << y << ".png";
|
||||
|
||||
const double PI = 3.14159265358979323846;
|
||||
double longitude = (x + 0.1) * 360.0 / size - 180;
|
||||
double latitude = 90 - 360 * std::atan(std::exp(((y + 0.1) / size - 0.5) * 2 * PI)) / PI;
|
||||
|
||||
int64 access_hash = G()->get_location_access_hash(latitude, longitude);
|
||||
return make_tl_object<telegram_api::inputWebFileGeoPointLocation>(
|
||||
make_tl_object<telegram_api::inputGeoPoint>(latitude, longitude), access_hash, width, height, zoom, scale);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user