From 0d72fd638e001773f8108274773780bbeaab31c0 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 13 Oct 2019 02:39:44 +0300 Subject: [PATCH] Add Venue.{cpp,h}. GitOrigin-RevId: 19dd4da6d4792ecbb84fdba560e49affcfcf5bed --- CMakeLists.txt | 2 + td/telegram/InlineQueriesManager.cpp | 1 + td/telegram/Location.cpp | 117 ------------------------- td/telegram/Location.h | 73 ---------------- td/telegram/MessageContent.cpp | 1 + td/telegram/Td.cpp | 1 + td/telegram/Venue.cpp | 122 +++++++++++++++++++++++++++ td/telegram/Venue.h | 96 +++++++++++++++++++++ 8 files changed, 223 insertions(+), 190 deletions(-) create mode 100644 td/telegram/Venue.cpp create mode 100644 td/telegram/Venue.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ee2b31b7..f2fdaf00a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -459,6 +459,7 @@ set(TDLIB_SOURCE td/telegram/TermsOfService.cpp td/telegram/TopDialogManager.cpp td/telegram/UpdatesManager.cpp + td/telegram/Venue.cpp td/telegram/VideoNotesManager.cpp td/telegram/VideosManager.cpp td/telegram/VoiceNotesManager.cpp @@ -637,6 +638,7 @@ set(TDLIB_SOURCE td/telegram/UniqueId.h td/telegram/UpdatesManager.h td/telegram/UserId.h + td/telegram/Venue.h td/telegram/Version.h td/telegram/VideoNotesManager.h td/telegram/VideosManager.h diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index 68c1f128f..5a852c62b 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -34,6 +34,7 @@ #include "td/telegram/StickersManager.h" #include "td/telegram/Td.h" #include "td/telegram/TdDb.h" +#include "td/telegram/Venue.h" #include "td/telegram/VideosManager.h" #include "td/telegram/VoiceNotesManager.h" diff --git a/td/telegram/Location.cpp b/td/telegram/Location.cpp index 154121c08..3d3444303 100644 --- a/td/telegram/Location.cpp +++ b/td/telegram/Location.cpp @@ -6,14 +6,6 @@ // #include "td/telegram/Location.h" -#include "td/telegram/Global.h" -#include "td/telegram/misc.h" -#include "td/telegram/secret_api.h" -#include "td/telegram/td_api.h" -#include "td/telegram/telegram_api.h" - -#include "td/utils/common.h" - #include namespace td { @@ -114,82 +106,6 @@ StringBuilder &operator<<(StringBuilder &string_builder, const Location &locatio << "]"; } -Venue::Venue(const tl_object_ptr &geo_point_ptr, string title, string address, string provider, - string id, string type) - : location_(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 &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 Venue::get_venue_object() const { - return make_tl_object(location_.get_location_object(), title_, address_, provider_, id_, type_); -} - -tl_object_ptr Venue::get_input_media_venue() const { - return make_tl_object(location_.get_input_geo_point(), title_, address_, provider_, - id_, type_); -} - -SecretInputMedia Venue::get_secret_input_media_venue() const { - return SecretInputMedia{nullptr, - make_tl_object( - location_.get_latitude(), location_.get_longitude(), title_, address_, provider_, id_)}; -} - -tl_object_ptr Venue::get_input_bot_inline_message_media_venue( - int32 flags, tl_object_ptr &&reply_markup) const { - return make_tl_object( - flags, location_.get_input_geo_point(), title_, address_, provider_, id_, type_, std::move(reply_markup)); -} - -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> process_input_message_location( tl_object_ptr &&input_message_content) { CHECK(input_message_content != nullptr); @@ -212,37 +128,4 @@ Result> process_input_message_location( return std::make_pair(std::move(location), period); } -Result process_input_message_venue(tl_object_ptr &&input_message_content) { - CHECK(input_message_content != nullptr); - CHECK(input_message_content->get_id() == td_api::inputMessageVenue::ID); - auto venue = std::move(static_cast(input_message_content.get())->venue_); - - if (venue == nullptr) { - return Status::Error(400, "Venue can't be 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 diff --git a/td/telegram/Location.h b/td/telegram/Location.h index 9d7ecbec1..ddb6fa67a 100644 --- a/td/telegram/Location.h +++ b/td/telegram/Location.h @@ -8,7 +8,6 @@ #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" @@ -112,79 +111,7 @@ bool operator!=(const Location &lhs, const Location &rhs); StringBuilder &operator<<(StringBuilder &string_builder, const Location &location); -class Venue { - Location location_; - string title_; - string address_; - string provider_; - string id_; - string type_; - - friend bool operator==(const Venue &lhs, const Venue &rhs); - friend bool operator!=(const Venue &lhs, const Venue &rhs); - - friend StringBuilder &operator<<(StringBuilder &string_builder, const Venue &venue); - - public: - Venue() = default; - - Venue(const tl_object_ptr &geo_point_ptr, string title, string address, string provider, - string id, string type); - - Venue(Location location, string title, string address, string provider, string id, string type); - - explicit Venue(const tl_object_ptr &venue); - - bool empty() const; - - Location &location(); - - const Location &location() const; - - tl_object_ptr get_venue_object() const; - - tl_object_ptr get_input_media_venue() const; - - SecretInputMedia get_secret_input_media_venue() const; - - // TODO very strange function - tl_object_ptr get_input_bot_inline_message_media_venue( - int32 flags, tl_object_ptr &&reply_markup) const; - - template - void store(StorerT &storer) const { - using td::store; - store(location_, storer); - store(title_, storer); - store(address_, storer); - store(provider_, storer); - store(id_, storer); - store(type_, storer); - } - - template - void parse(ParserT &parser) { - using td::parse; - parse(location_, parser); - parse(title_, parser); - parse(address_, parser); - parse(provider_, parser); - parse(id_, parser); - if (parser.version() >= static_cast(Version::AddVenueType)) { - parse(type_, parser); - } - } -}; - -bool operator==(const Venue &lhs, const Venue &rhs); -bool operator!=(const Venue &lhs, const Venue &rhs); - -StringBuilder &operator<<(StringBuilder &string_builder, const Venue &venue); - Result> process_input_message_location( td_api::object_ptr &&input_message_content) TD_WARN_UNUSED_RESULT; -Result process_input_message_venue(td_api::object_ptr &&input_message_content) - TD_WARN_UNUSED_RESULT; - } // namespace td diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index cc73c97f1..8616bb9ac 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -50,6 +50,7 @@ #include "td/telegram/StickersManager.hpp" #include "td/telegram/Td.h" #include "td/telegram/UserId.h" +#include "td/telegram/Venue.h" #include "td/telegram/Version.h" #include "td/telegram/VideoNotesManager.h" #include "td/telegram/VideoNotesManager.hpp" diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 559a39bec..8bb77d3e0 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -38,6 +38,7 @@ #include "td/telegram/InlineQueriesManager.h" #include "td/telegram/JsonValue.h" #include "td/telegram/LanguagePackManager.h" +#include "td/telegram/Location.h" #include "td/telegram/Logging.h" #include "td/telegram/MessageEntity.h" #include "td/telegram/MessageId.h" diff --git a/td/telegram/Venue.cpp b/td/telegram/Venue.cpp new file mode 100644 index 000000000..3b2bec47b --- /dev/null +++ b/td/telegram/Venue.cpp @@ -0,0 +1,122 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019 +// +// 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" + +namespace td { + +Venue::Venue(const tl_object_ptr &geo_point_ptr, string title, string address, string provider, + string id, string type) + : location_(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 &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 Venue::get_venue_object() const { + return make_tl_object(location_.get_location_object(), title_, address_, provider_, id_, type_); +} + +tl_object_ptr Venue::get_input_media_venue() const { + return make_tl_object(location_.get_input_geo_point(), title_, address_, provider_, + id_, type_); +} + +SecretInputMedia Venue::get_secret_input_media_venue() const { + return SecretInputMedia{nullptr, + make_tl_object( + location_.get_latitude(), location_.get_longitude(), title_, address_, provider_, id_)}; +} + +tl_object_ptr Venue::get_input_bot_inline_message_media_venue( + int32 flags, tl_object_ptr &&reply_markup) const { + return make_tl_object( + flags, location_.get_input_geo_point(), title_, address_, provider_, id_, type_, std::move(reply_markup)); +} + +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 process_input_message_venue(tl_object_ptr &&input_message_content) { + CHECK(input_message_content != nullptr); + CHECK(input_message_content->get_id() == td_api::inputMessageVenue::ID); + auto venue = std::move(static_cast(input_message_content.get())->venue_); + + if (venue == nullptr) { + return Status::Error(400, "Venue can't be 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 diff --git a/td/telegram/Venue.h b/td/telegram/Venue.h new file mode 100644 index 000000000..8ff92e5e2 --- /dev/null +++ b/td/telegram/Venue.h @@ -0,0 +1,96 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019 +// +// 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 + +#include "td/telegram/Location.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/utils/common.h" +#include "td/utils/Status.h" +#include "td/utils/StringBuilder.h" +#include "td/utils/tl_helpers.h" + +namespace td { + +class Venue { + Location location_; + string title_; + string address_; + string provider_; + string id_; + string type_; + + friend bool operator==(const Venue &lhs, const Venue &rhs); + friend bool operator!=(const Venue &lhs, const Venue &rhs); + + friend StringBuilder &operator<<(StringBuilder &string_builder, const Venue &venue); + + public: + Venue() = default; + + Venue(const tl_object_ptr &geo_point_ptr, string title, string address, string provider, + string id, string type); + + Venue(Location location, string title, string address, string provider, string id, string type); + + explicit Venue(const tl_object_ptr &venue); + + bool empty() const; + + Location &location(); + + const Location &location() const; + + tl_object_ptr get_venue_object() const; + + tl_object_ptr get_input_media_venue() const; + + SecretInputMedia get_secret_input_media_venue() const; + + // TODO very strange function + tl_object_ptr get_input_bot_inline_message_media_venue( + int32 flags, tl_object_ptr &&reply_markup) const; + + template + void store(StorerT &storer) const { + using td::store; + store(location_, storer); + store(title_, storer); + store(address_, storer); + store(provider_, storer); + store(id_, storer); + store(type_, storer); + } + + template + void parse(ParserT &parser) { + using td::parse; + parse(location_, parser); + parse(title_, parser); + parse(address_, parser); + parse(provider_, parser); + parse(id_, parser); + if (parser.version() >= static_cast(Version::AddVenueType)) { + parse(type_, parser); + } + } +}; + +bool operator==(const Venue &lhs, const Venue &rhs); +bool operator!=(const Venue &lhs, const Venue &rhs); + +StringBuilder &operator<<(StringBuilder &string_builder, const Venue &venue); + +Result process_input_message_venue(td_api::object_ptr &&input_message_content) + TD_WARN_UNUSED_RESULT; + +} // namespace td