diff --git a/CMakeLists.txt b/CMakeLists.txt index e9b173e46..0ee2b31b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -375,6 +375,7 @@ set(TDLIB_SOURCE td/telegram/DhCache.cpp td/telegram/DialogDb.cpp td/telegram/DialogId.cpp + td/telegram/DialogLocation.cpp td/telegram/DialogParticipant.cpp td/telegram/Document.cpp td/telegram/DocumentsManager.cpp @@ -519,6 +520,7 @@ set(TDLIB_SOURCE td/telegram/DialogDate.h td/telegram/DialogDb.h td/telegram/DialogId.h + td/telegram/DialogLocation.h td/telegram/DialogParticipant.h td/telegram/Document.h td/telegram/DocumentsManager.h diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index b011cdfb9..be20a9136 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -288,6 +288,10 @@ botCommand command:string description:string = BotCommand; botInfo description:string commands:vector = BotInfo; +//@description Represents a location of a chat @location The location @address Location address; as defined by the chat creator +chatLocation location:location address:string = ChatLocation; + + //@description Represents a user @id User identifier @first_name First name of the user @last_name Last name of the user @username Username of the user //@phone_number Phone number of the user @status Current online status of the user @profile_photo Profile photo of the user; may be null //@is_contact The user is a contact of the current user @@ -1937,6 +1941,9 @@ chatEventSignMessagesToggled sign_messages:Bool = ChatEventAction; //@description The supergroup sticker set was changed @old_sticker_set_id Previous identifier of the chat sticker set; 0 if none @new_sticker_set_id New identifier of the chat sticker set; 0 if none chatEventStickerSetChanged old_sticker_set_id:int64 new_sticker_set_id:int64 = ChatEventAction; +//@description The supergroup location was changed @old_location Previous location; may be null @new_location New location; may be null +chatEventLocationChanged old_location:chatLocation new_location:chatLocation = ChatEventAction; + //@description The is_all_history_available setting of a supergroup was toggled @is_all_history_available New value of is_all_history_available chatEventIsAllHistoryAvailableToggled is_all_history_available:Bool = ChatEventAction; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index e9c255dca..e20857f81 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/DialogLocation.cpp b/td/telegram/DialogLocation.cpp new file mode 100644 index 000000000..9c42c4017 --- /dev/null +++ b/td/telegram/DialogLocation.cpp @@ -0,0 +1,63 @@ +// +// 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/DialogLocation.h" + +#include "td/telegram/misc.h" + +namespace td { + +DialogLocation::DialogLocation(telegram_api::object_ptr &&channel_location_ptr) { + if (channel_location_ptr != nullptr && channel_location_ptr->get_id() == telegram_api::channelLocation::ID) { + auto channel_location = static_cast(channel_location_ptr.get()); + location_ = Location(channel_location->geo_point_); + address_ = std::move(channel_location->address_); + } +} + +DialogLocation::DialogLocation(td_api::object_ptr &&chat_location) { + if (chat_location != nullptr) { + location_ = Location(chat_location->location_); + address_ = std::move(chat_location->address_); + if (!clean_input_string(address_)) { + address_.clear(); + } + } +} + +bool DialogLocation::empty() const { + return location_.empty(); +} + +td_api::object_ptr DialogLocation::get_chat_location_object() const { + if (empty()) { + return nullptr; + } + return td_api::make_object(location_.get_location_object(), address_); +} + +telegram_api::object_ptr 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 diff --git a/td/telegram/DialogLocation.h b/td/telegram/DialogLocation.h new file mode 100644 index 000000000..ea0d917ba --- /dev/null +++ b/td/telegram/DialogLocation.h @@ -0,0 +1,63 @@ +// +// 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/td_api.h" +#include "td/telegram/telegram_api.h" + +#include "td/utils/common.h" +#include "td/utils/StringBuilder.h" +#include "td/utils/tl_helpers.h" + +namespace td { + +class DialogLocation { + Location location_; + string address_; + + friend bool operator==(const DialogLocation &lhs, const DialogLocation &rhs); + friend bool operator!=(const DialogLocation &lhs, const DialogLocation &rhs); + + friend StringBuilder &operator<<(StringBuilder &string_builder, const DialogLocation &location); + + public: + DialogLocation() = default; + + DialogLocation(telegram_api::object_ptr &&channel_location_ptr); + + explicit DialogLocation(td_api::object_ptr &&chat_location); + + bool empty() const; + + td_api::object_ptr get_chat_location_object() const; + + telegram_api::object_ptr get_input_geo_point() const; + + const string &get_address() const; + + template + void store(StorerT &storer) const { + using td::store; + store(location_, storer); + store(address_, storer); + } + + template + void parse(ParserT &parser) { + using td::parse; + parse(location_, parser); + parse(address_, parser); + } +}; + +bool operator==(const DialogLocation &lhs, const DialogLocation &rhs); +bool operator!=(const DialogLocation &lhs, const DialogLocation &rhs); + +StringBuilder &operator<<(StringBuilder &string_builder, const DialogLocation &location); + +} // namespace td diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 873a098cd..c1d1118b0 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -11,6 +11,7 @@ #include "td/telegram/ConfigShared.h" #include "td/telegram/ContactsManager.h" #include "td/telegram/DialogDb.h" +#include "td/telegram/DialogLocation.h" #include "td/telegram/DraftMessage.h" #include "td/telegram/DraftMessage.hpp" #include "td/telegram/FileReferenceManager.h" @@ -23879,6 +23880,13 @@ tl_object_ptr MessagesManager::get_chat_event_action_ob } return make_tl_object(old_linked_dialog_id.get(), new_linked_dialog_id.get()); } + case telegram_api::channelAdminLogEventActionChangeLocation::ID: { + auto action = move_tl_object_as(action_ptr); + auto old_location = DialogLocation(std::move(action->prev_value_)); + auto new_location = DialogLocation(std::move(action->new_value_)); + return make_tl_object(old_location.get_chat_location_object(), + new_location.get_chat_location_object()); + } default: UNREACHABLE(); return nullptr;