Explicitly pass Td to Location constructor and don't register locations for bots.

This commit is contained in:
levlam 2023-06-28 19:01:00 +03:00
parent 40d11e7935
commit 3a3ae9eabf
12 changed files with 51 additions and 39 deletions

View File

@ -13117,7 +13117,7 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
} }
on_update_channel_full_linked_channel_id(channel_full, channel_id, linked_channel_id); on_update_channel_full_linked_channel_id(channel_full, channel_id, linked_channel_id);
on_update_channel_full_location(channel_full, channel_id, DialogLocation(std::move(channel->location_))); on_update_channel_full_location(channel_full, channel_id, DialogLocation(td_, std::move(channel->location_)));
if (c->is_megagroup) { if (c->is_megagroup) {
on_update_channel_full_slow_mode_delay(channel_full, channel_id, channel->slowmode_seconds_, on_update_channel_full_slow_mode_delay(channel_full, channel_id, channel->slowmode_seconds_,

View File

@ -249,8 +249,8 @@ static td_api::object_ptr<td_api::ChatEventAction> get_chat_event_action_object(
} }
case telegram_api::channelAdminLogEventActionChangeLocation::ID: { case telegram_api::channelAdminLogEventActionChangeLocation::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionChangeLocation>(action_ptr); auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionChangeLocation>(action_ptr);
auto old_location = DialogLocation(std::move(action->prev_value_)); auto old_location = DialogLocation(td, std::move(action->prev_value_));
auto new_location = DialogLocation(std::move(action->new_value_)); auto new_location = DialogLocation(td, std::move(action->new_value_));
return td_api::make_object<td_api::chatEventLocationChanged>(old_location.get_chat_location_object(), return td_api::make_object<td_api::chatEventLocationChanged>(old_location.get_chat_location_object(),
new_location.get_chat_location_object()); new_location.get_chat_location_object());
} }

View File

@ -10,10 +10,10 @@
namespace td { namespace td {
DialogLocation::DialogLocation(telegram_api::object_ptr<telegram_api::ChannelLocation> &&channel_location_ptr) { 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) { 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()); auto channel_location = static_cast<telegram_api::channelLocation *>(channel_location_ptr.get());
location_ = Location(channel_location->geo_point_); location_ = Location(td, channel_location->geo_point_);
address_ = std::move(channel_location->address_); address_ = std::move(channel_location->address_);
} }
} }

View File

@ -16,6 +16,8 @@
namespace td { namespace td {
class Td;
class DialogLocation { class DialogLocation {
Location location_; Location location_;
string address_; string address_;
@ -28,7 +30,7 @@ class DialogLocation {
public: public:
DialogLocation() = default; DialogLocation() = default;
explicit DialogLocation(telegram_api::object_ptr<telegram_api::ChannelLocation> &&channel_location_ptr); DialogLocation(Td *td, telegram_api::object_ptr<telegram_api::ChannelLocation> &&channel_location_ptr);
explicit DialogLocation(td_api::object_ptr<td_api::chatLocation> &&chat_location); explicit DialogLocation(td_api::object_ptr<td_api::chatLocation> &&chat_location);

View File

@ -1778,11 +1778,11 @@ void InlineQueriesManager::on_get_inline_query_results(DialogId dialog_id, UserI
if (result->send_message_->get_id() == telegram_api::botInlineMessageMediaGeo::ID) { if (result->send_message_->get_id() == telegram_api::botInlineMessageMediaGeo::ID) {
auto inline_message_geo = auto inline_message_geo =
static_cast<const telegram_api::botInlineMessageMediaGeo *>(result->send_message_.get()); static_cast<const telegram_api::botInlineMessageMediaGeo *>(result->send_message_.get());
Location l(inline_message_geo->geo_); Location l(td_, inline_message_geo->geo_);
location->location_ = l.get_location_object(); location->location_ = l.get_location_object();
} else { } else {
auto latitude_longitude = split(Slice(result->description_)); auto latitude_longitude = split(Slice(result->description_));
Location l(to_double(latitude_longitude.first), to_double(latitude_longitude.second), 0.0, 0); Location l(td_, to_double(latitude_longitude.first), to_double(latitude_longitude.second), 0.0, 0);
location->location_ = l.get_location_object(); location->location_ = l.get_location_object();
} }
location->thumbnail_ = register_thumbnail(std::move(result->thumb_)); location->thumbnail_ = register_thumbnail(std::move(result->thumb_));
@ -1798,18 +1798,19 @@ void InlineQueriesManager::on_get_inline_query_results(DialogId dialog_id, UserI
if (result->send_message_->get_id() == telegram_api::botInlineMessageMediaVenue::ID) { if (result->send_message_->get_id() == telegram_api::botInlineMessageMediaVenue::ID) {
auto inline_message_venue = auto inline_message_venue =
static_cast<const telegram_api::botInlineMessageMediaVenue *>(result->send_message_.get()); static_cast<const telegram_api::botInlineMessageMediaVenue *>(result->send_message_.get());
Venue v(inline_message_venue->geo_, inline_message_venue->title_, inline_message_venue->address_, Venue v(td_, inline_message_venue->geo_, inline_message_venue->title_, inline_message_venue->address_,
inline_message_venue->provider_, inline_message_venue->venue_id_, inline_message_venue->provider_, inline_message_venue->venue_id_,
inline_message_venue->venue_type_); inline_message_venue->venue_type_);
venue->venue_ = v.get_venue_object(); venue->venue_ = v.get_venue_object();
} else if (result->send_message_->get_id() == telegram_api::botInlineMessageMediaGeo::ID) { } else if (result->send_message_->get_id() == telegram_api::botInlineMessageMediaGeo::ID) {
auto inline_message_geo = auto inline_message_geo =
static_cast<const telegram_api::botInlineMessageMediaGeo *>(result->send_message_.get()); static_cast<const telegram_api::botInlineMessageMediaGeo *>(result->send_message_.get());
Venue v(inline_message_geo->geo_, std::move(result->title_), std::move(result->description_), string(), Venue v(td_, inline_message_geo->geo_, std::move(result->title_), std::move(result->description_), string(),
string(), string()); string(), string());
venue->venue_ = v.get_venue_object(); venue->venue_ = v.get_venue_object();
} else { } else {
Venue v(nullptr, std::move(result->title_), std::move(result->description_), string(), string(), string()); Venue v(td_, nullptr, std::move(result->title_), std::move(result->description_), string(), string(),
string());
venue->venue_ = v.get_venue_object(); venue->venue_ = v.get_venue_object();
} }
venue->thumbnail_ = register_thumbnail(std::move(result->thumb_)); venue->thumbnail_ = register_thumbnail(std::move(result->thumb_));

View File

@ -6,6 +6,9 @@
// //
#include "td/telegram/Location.h" #include "td/telegram/Location.h"
#include "td/telegram/AuthManager.h"
#include "td/telegram/Td.h"
#include <cmath> #include <cmath>
namespace td { namespace td {
@ -20,26 +23,28 @@ double Location::fix_accuracy(double accuracy) {
return accuracy; return accuracy;
} }
void Location::init(double latitude, double longitude, double horizontal_accuracy, int64 access_hash) { void Location::init(Td *td, double latitude, double longitude, double horizontal_accuracy, int64 access_hash) {
if (std::isfinite(latitude) && std::isfinite(longitude) && std::abs(latitude) <= 90 && std::abs(longitude) <= 180) { if (std::isfinite(latitude) && std::isfinite(longitude) && std::abs(latitude) <= 90 && std::abs(longitude) <= 180) {
is_empty_ = false; is_empty_ = false;
latitude_ = latitude; latitude_ = latitude;
longitude_ = longitude; longitude_ = longitude;
horizontal_accuracy_ = fix_accuracy(horizontal_accuracy); horizontal_accuracy_ = fix_accuracy(horizontal_accuracy);
access_hash_ = access_hash; access_hash_ = access_hash;
G()->add_location_access_hash(latitude_, longitude_, access_hash_); if (td != nullptr && !td->auth_manager_->is_bot()) {
G()->add_location_access_hash(latitude_, longitude_, access_hash_);
}
} }
} }
Location::Location(double latitude, double longitude, double horizontal_accuracy, int64 access_hash) { Location::Location(Td *td, double latitude, double longitude, double horizontal_accuracy, int64 access_hash) {
init(latitude, longitude, horizontal_accuracy, access_hash); init(td, latitude, longitude, horizontal_accuracy, access_hash);
} }
Location::Location(const tl_object_ptr<secret_api::decryptedMessageMediaGeoPoint> &geo_point) Location::Location(const tl_object_ptr<secret_api::decryptedMessageMediaGeoPoint> &geo_point)
: Location(geo_point->lat_, geo_point->long_, 0.0, 0) { : Location(nullptr, geo_point->lat_, geo_point->long_, 0.0, 0) {
} }
Location::Location(const tl_object_ptr<telegram_api::GeoPoint> &geo_point_ptr) { Location::Location(Td *td, const tl_object_ptr<telegram_api::GeoPoint> &geo_point_ptr) {
if (geo_point_ptr == nullptr) { if (geo_point_ptr == nullptr) {
return; return;
} }
@ -48,7 +53,7 @@ Location::Location(const tl_object_ptr<telegram_api::GeoPoint> &geo_point_ptr) {
break; break;
case telegram_api::geoPoint::ID: { case telegram_api::geoPoint::ID: {
auto geo_point = static_cast<const telegram_api::geoPoint *>(geo_point_ptr.get()); auto geo_point = static_cast<const telegram_api::geoPoint *>(geo_point_ptr.get());
init(geo_point->lat_, geo_point->long_, geo_point->accuracy_radius_, geo_point->access_hash_); init(td, geo_point->lat_, geo_point->long_, geo_point->accuracy_radius_, geo_point->access_hash_);
break; break;
} }
default: default:
@ -62,7 +67,7 @@ Location::Location(const tl_object_ptr<td_api::location> &location) {
return; return;
} }
init(location->latitude_, location->longitude_, location->horizontal_accuracy_, 0); init(nullptr, location->latitude_, location->longitude_, location->horizontal_accuracy_, 0);
} }
bool Location::empty() const { bool Location::empty() const {

View File

@ -19,6 +19,8 @@
namespace td { namespace td {
class Td;
class Location { class Location {
bool is_empty_ = true; bool is_empty_ = true;
double latitude_ = 0.0; double latitude_ = 0.0;
@ -31,18 +33,18 @@ class Location {
friend StringBuilder &operator<<(StringBuilder &string_builder, const Location &location); friend StringBuilder &operator<<(StringBuilder &string_builder, const Location &location);
void init(double latitude, double longitude, double horizontal_accuracy, int64 access_hash); void init(Td *td, double latitude, double longitude, double horizontal_accuracy, int64 access_hash);
static double fix_accuracy(double accuracy); static double fix_accuracy(double accuracy);
public: public:
Location() = default; Location() = default;
Location(double latitude, double longitude, double horizontal_accuracy, int64 access_hash); Location(Td *td, double latitude, double longitude, double horizontal_accuracy, int64 access_hash);
explicit Location(const tl_object_ptr<secret_api::decryptedMessageMediaGeoPoint> &geo_point); explicit Location(const tl_object_ptr<secret_api::decryptedMessageMediaGeoPoint> &geo_point);
explicit Location(const tl_object_ptr<telegram_api::GeoPoint> &geo_point_ptr); Location(Td *td, const tl_object_ptr<telegram_api::GeoPoint> &geo_point_ptr);
explicit Location(const tl_object_ptr<td_api::location> &location); explicit Location(const tl_object_ptr<td_api::location> &location);

View File

@ -1934,10 +1934,10 @@ InlineMessageContent create_inline_message_content(Td *td, FileId file_id,
auto inline_message = move_tl_object_as<telegram_api::botInlineMessageMediaGeo>(bot_inline_message); auto inline_message = move_tl_object_as<telegram_api::botInlineMessageMediaGeo>(bot_inline_message);
if (inline_message->period_ > 0) { if (inline_message->period_ > 0) {
result.message_content = result.message_content =
make_unique<MessageLiveLocation>(Location(inline_message->geo_), inline_message->period_, make_unique<MessageLiveLocation>(Location(td, inline_message->geo_), inline_message->period_,
inline_message->heading_, inline_message->proximity_notification_radius_); inline_message->heading_, inline_message->proximity_notification_radius_);
} else { } else {
result.message_content = make_unique<MessageLocation>(Location(inline_message->geo_)); result.message_content = make_unique<MessageLocation>(Location(td, inline_message->geo_));
} }
reply_markup = std::move(inline_message->reply_markup_); reply_markup = std::move(inline_message->reply_markup_);
break; break;
@ -1945,7 +1945,7 @@ InlineMessageContent create_inline_message_content(Td *td, FileId file_id,
case telegram_api::botInlineMessageMediaVenue::ID: { case telegram_api::botInlineMessageMediaVenue::ID: {
auto inline_message = move_tl_object_as<telegram_api::botInlineMessageMediaVenue>(bot_inline_message); auto inline_message = move_tl_object_as<telegram_api::botInlineMessageMediaVenue>(bot_inline_message);
result.message_content = make_unique<MessageVenue>( result.message_content = make_unique<MessageVenue>(
Venue(inline_message->geo_, std::move(inline_message->title_), std::move(inline_message->address_), Venue(td, inline_message->geo_, std::move(inline_message->title_), std::move(inline_message->address_),
std::move(inline_message->provider_), std::move(inline_message->venue_id_), std::move(inline_message->provider_), std::move(inline_message->venue_id_),
std::move(inline_message->venue_type_))); std::move(inline_message->venue_type_)));
reply_markup = std::move(inline_message->reply_markup_); reply_markup = std::move(inline_message->reply_markup_);
@ -4749,9 +4749,9 @@ unique_ptr<MessageContent> get_secret_message_content(
media->venue_id_.clear(); media->venue_id_.clear();
} }
auto m = make_unique<MessageVenue>(Venue(Location(media->lat_, media->long_, 0.0, 0), std::move(media->title_), auto m = make_unique<MessageVenue>(Venue(Location(td, media->lat_, media->long_, 0.0, 0),
std::move(media->address_), std::move(media->provider_), std::move(media->title_), std::move(media->address_),
std::move(media->venue_id_), string())); std::move(media->provider_), std::move(media->venue_id_), string()));
if (m->venue.empty()) { if (m->venue.empty()) {
is_media_empty = true; is_media_empty = true;
break; break;
@ -4907,7 +4907,7 @@ unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message,
case telegram_api::messageMediaGeo::ID: { case telegram_api::messageMediaGeo::ID: {
auto media = move_tl_object_as<telegram_api::messageMediaGeo>(media_ptr); auto media = move_tl_object_as<telegram_api::messageMediaGeo>(media_ptr);
auto m = make_unique<MessageLocation>(Location(media->geo_)); auto m = make_unique<MessageLocation>(Location(td, media->geo_));
if (m->location.empty()) { if (m->location.empty()) {
break; break;
} }
@ -4916,7 +4916,7 @@ unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message,
} }
case telegram_api::messageMediaGeoLive::ID: { case telegram_api::messageMediaGeoLive::ID: {
auto media = move_tl_object_as<telegram_api::messageMediaGeoLive>(media_ptr); auto media = move_tl_object_as<telegram_api::messageMediaGeoLive>(media_ptr);
auto location = Location(media->geo_); auto location = Location(td, media->geo_);
if (location.empty()) { if (location.empty()) {
break; break;
} }
@ -4931,7 +4931,7 @@ unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message,
} }
case telegram_api::messageMediaVenue::ID: { case telegram_api::messageMediaVenue::ID: {
auto media = move_tl_object_as<telegram_api::messageMediaVenue>(media_ptr); auto media = move_tl_object_as<telegram_api::messageMediaVenue>(media_ptr);
auto m = make_unique<MessageVenue>(Venue(media->geo_, std::move(media->title_), std::move(media->address_), auto m = make_unique<MessageVenue>(Venue(td, media->geo_, std::move(media->title_), std::move(media->address_),
std::move(media->provider_), std::move(media->venue_id_), std::move(media->provider_), std::move(media->venue_id_),
std::move(media->venue_type_))); std::move(media->venue_type_)));
if (m->venue.empty()) { if (m->venue.empty()) {

View File

@ -3881,13 +3881,13 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDcOptions> upda
} }
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotInlineQuery> update, Promise<Unit> &&promise) { void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotInlineQuery> update, Promise<Unit> &&promise) {
td_->inline_queries_manager_->on_new_query(update->query_id_, UserId(update->user_id_), Location(update->geo_), td_->inline_queries_manager_->on_new_query(update->query_id_, UserId(update->user_id_), Location(td_, update->geo_),
std::move(update->peer_type_), update->query_, update->offset_); std::move(update->peer_type_), update->query_, update->offset_);
promise.set_value(Unit()); promise.set_value(Unit());
} }
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotInlineSend> update, Promise<Unit> &&promise) { void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBotInlineSend> update, Promise<Unit> &&promise) {
td_->inline_queries_manager_->on_chosen_result(UserId(update->user_id_), Location(update->geo_), update->query_, td_->inline_queries_manager_->on_chosen_result(UserId(update->user_id_), Location(td_, update->geo_), update->query_,
update->id_, std::move(update->msg_id_)); update->id_, std::move(update->msg_id_));
promise.set_value(Unit()); promise.set_value(Unit());
} }

View File

@ -11,9 +11,9 @@
namespace td { namespace td {
Venue::Venue(const tl_object_ptr<telegram_api::GeoPoint> &geo_point_ptr, string title, string address, string provider, Venue::Venue(Td *td, const tl_object_ptr<telegram_api::GeoPoint> &geo_point_ptr, string title, string address,
string id, string type) string provider, string id, string type)
: location_(geo_point_ptr) : location_(td, geo_point_ptr)
, title_(std::move(title)) , title_(std::move(title))
, address_(std::move(address)) , address_(std::move(address))
, provider_(std::move(provider)) , provider_(std::move(provider))

View File

@ -19,6 +19,8 @@
namespace td { namespace td {
class Td;
class Venue { class Venue {
Location location_; Location location_;
string title_; string title_;
@ -34,8 +36,8 @@ class Venue {
public: public:
Venue() = default; Venue() = default;
Venue(const tl_object_ptr<telegram_api::GeoPoint> &geo_point_ptr, string title, string address, string provider, Venue(Td *td, const tl_object_ptr<telegram_api::GeoPoint> &geo_point_ptr, string title, string address,
string id, string type); string provider, string id, string type);
Venue(Location location, string title, string address, string provider, string id, string type); Venue(Location location, string title, string address, string provider, string id, string type);

View File

@ -2242,7 +2242,7 @@ unique_ptr<WebPageBlock> get_web_page_block(Td *td, tl_object_ptr<telegram_api::
} }
case telegram_api::pageBlockMap::ID: { case telegram_api::pageBlockMap::ID: {
auto page_block = move_tl_object_as<telegram_api::pageBlockMap>(page_block_ptr); auto page_block = move_tl_object_as<telegram_api::pageBlockMap>(page_block_ptr);
Location location(page_block->geo_); Location location(td, page_block->geo_);
auto zoom = page_block->zoom_; auto zoom = page_block->zoom_;
Dimensions dimensions = get_dimensions(page_block->w_, page_block->h_, "pageBlockMap"); Dimensions dimensions = get_dimensions(page_block->w_, page_block->h_, "pageBlockMap");
if (location.empty()) { if (location.empty()) {