From 35b9d56c640c10f2653e66f99c3ce3a82cb1850f Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 13 Oct 2019 02:21:37 +0300 Subject: [PATCH] Add DialogLocation, td_api::chatLocation and td_api::chatEventLocationChanged. GitOrigin-RevId: 5bd47788c58065b0b79119d7d84c1d851a400417 --- CMakeLists.txt | 2 + td/generate/scheme/td_api.tl | 7 ++++ td/generate/scheme/td_api.tlo | Bin 161136 -> 161452 bytes td/telegram/DialogLocation.cpp | 63 ++++++++++++++++++++++++++++++++ td/telegram/DialogLocation.h | 63 ++++++++++++++++++++++++++++++++ td/telegram/MessagesManager.cpp | 8 ++++ 6 files changed, 143 insertions(+) create mode 100644 td/telegram/DialogLocation.cpp create mode 100644 td/telegram/DialogLocation.h 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 e9c255dca536d8448c0a30afd118a8d10371c38d..e20857f8194b4e21b0aaefad34c6a158b04705cc 100644 GIT binary patch delta 683 zcmezHigV3dPTohe^{p77;L}Fla#m6HYYW!%J7*-8xR#~nl{hAsWaj6IPJYNPK6wM{ z9Ztpm*^78UvXc{ql{fdW87MP;*t}Qsu{sM#-{d8MHW0>>zz7J#AxHzvm>$5)XaEsf zfFU#~7(-D)u#N=C$eYK6d_e9ia%R)vux&dCu_jmpx8##x72J{vAyAtZ%w)8gY!E5} zbrMWC;5?(wy z6_|)c1k{|A2&g#+U?OiKpaH292{k7sG6Q1riAZQT{)x1Jh*(5H)nr6vxPk%*7Nb|? zxMKYNo_#Kn42w^n{NzMXi~^%DFFiE{s1O#&OhC5uv-_Gn`8g@^(?7mp6czJ}z%GO79`cL=(+v(V a@=PuW<6r>^H?N3qUlGr^eMLOe2~hyV-UWXE delta 518 zcmZ4Umh;0aPTohe^{p77;NwQ#a#m4K?OYFj=ZwS>*Rs^S6366{%=|o&$${+RlQ*#5 z*}Q|zK$-E~=9ij})mcC)CtnD(fiMJuA|Q;MAPq2MdO-`L0YvBwrjSlBhN_-m9SM+` zH;)PVfSgq1%%;O(+jbCQPp}4VNr4a*+>$;aP@5h+V$_*zU?ns8KnMraT`(yJRVJOu z7eaj?!X=?P5FellD}+G|n(Pw>_3DZ+h{DM?!V(}_ZNi}wW3v8a2WO}YBO;;Zbwp-BZ1@ssfKWVrVj+_;L_8%5s&YycROOUt f3y9Q(XcsVJvqVe`OY?_>_74e++dm{Q?GXh4Gp(jQ 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;