From 4498067221def243227faf5d40f18d349fa2456c Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 28 Apr 2020 16:25:56 +0300 Subject: [PATCH] Update layer to 113. Replace chat.is_sponsored with chat.source. GitOrigin-RevId: 777a646b9639ed14d2ee1c304c6f0574c1d5ce5e --- CMakeLists.txt | 2 + td/generate/scheme/td_api.tl | 19 +++-- td/generate/scheme/td_api.tlo | Bin 171440 -> 171664 bytes td/generate/scheme/telegram_api.tl | 11 +-- td/generate/scheme/telegram_api.tlo | Bin 206572 -> 206868 bytes td/telegram/DialogSource.cpp | 97 ++++++++++++++++++++++++++ td/telegram/DialogSource.h | 41 +++++++++++ td/telegram/MessagesManager.cpp | 93 ++++++++++++++---------- td/telegram/MessagesManager.h | 16 +++-- td/telegram/Version.h | 2 +- td/telegram/net/ConnectionCreator.cpp | 45 ++++++------ td/telegram/net/ConnectionCreator.h | 2 +- td/telegram/net/NetQuery.cpp | 3 +- 13 files changed, 253 insertions(+), 78 deletions(-) create mode 100644 td/telegram/DialogSource.cpp create mode 100644 td/telegram/DialogSource.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d8f31145..acc677027 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -398,6 +398,7 @@ set(TDLIB_SOURCE td/telegram/DialogId.cpp td/telegram/DialogLocation.cpp td/telegram/DialogParticipant.cpp + td/telegram/DialogSource.cpp td/telegram/Document.cpp td/telegram/DocumentsManager.cpp td/telegram/DraftMessage.cpp @@ -549,6 +550,7 @@ set(TDLIB_SOURCE td/telegram/DialogId.h td/telegram/DialogLocation.h td/telegram/DialogParticipant.h + td/telegram/DialogSource.h td/telegram/Document.h td/telegram/DocumentsManager.h td/telegram/DraftMessage.h diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index be8b8bcd4..61c9c1183 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -649,6 +649,15 @@ chatListMain = ChatList; chatListArchive = ChatList; +//@class ChatSource @description Describes a reason why the chat is shown in a chat list + +//@description The chat is sponsored by the user's MTProxy server +chatSourceMtprotoProxy = ChatSource; + +//@description The chat contains a public service announcement @type The type of the announcement @text The text of the announcement +chatSourcePublicServiceAnnouncement type:string text:string = ChatSource; + + //@description A chat. (Can be a private chat, basic group, supergroup, or secret chat) //@id Chat unique identifier //@type Type of the chat @@ -658,9 +667,9 @@ chatListArchive = ChatList; //@permissions Actions that non-administrator chat members are allowed to take in the chat //@last_message Last message in the chat; may be null //@order Descending parameter by which chats are sorted in the main chat list. If the order number of two chats is the same, they must be sorted in descending order by ID. If 0, the position of the chat in the list is undetermined +//@source Source of the chat in a chat list; may be null //@is_pinned True, if the chat is pinned //@is_marked_as_unread True, if the chat is marked as unread -//@is_sponsored True, if the chat is sponsored by the user's MTProxy server //@has_scheduled_messages True, if the chat has scheduled messages //@can_be_deleted_only_for_self True, if the chat messages can be deleted only for the current user while other users will continue to see the messages //@can_be_deleted_for_all_users True, if the chat messages can be deleted for all users @@ -676,7 +685,7 @@ chatListArchive = ChatList; //@reply_markup_message_id Identifier of the message from which reply markup needs to be used; 0 if there is no default custom reply markup in the chat //@draft_message A draft of a message in the chat; may be null //@client_data Contains client-specific data associated with the chat. (For example, the chat position or local chat notification settings can be stored here.) Persistent if the message database is used -chat id:int53 type:ChatType chat_list:ChatList title:string photo:chatPhoto permissions:chatPermissions last_message:message order:int64 is_pinned:Bool is_marked_as_unread:Bool is_sponsored:Bool has_scheduled_messages:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users:Bool can_be_reported:Bool default_disable_notification:Bool unread_count:int32 last_read_inbox_message_id:int53 last_read_outbox_message_id:int53 unread_mention_count:int32 notification_settings:chatNotificationSettings action_bar:ChatActionBar pinned_message_id:int53 reply_markup_message_id:int53 draft_message:draftMessage client_data:string = Chat; +chat id:int53 type:ChatType chat_list:ChatList title:string photo:chatPhoto permissions:chatPermissions last_message:message order:int64 source:ChatSource is_pinned:Bool is_marked_as_unread:Bool has_scheduled_messages:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users:Bool can_be_reported:Bool default_disable_notification:Bool unread_count:int32 last_read_inbox_message_id:int53 last_read_outbox_message_id:int53 unread_mention_count:int32 notification_settings:chatNotificationSettings action_bar:ChatActionBar pinned_message_id:int53 reply_markup_message_id:int53 draft_message:draftMessage client_data:string = Chat; //@description Represents a list of chats @chat_ids List of chat identifiers chats chat_ids:vector = Chats; @@ -2875,7 +2884,7 @@ updateChatPermissions chat_id:int53 permissions:chatPermissions = Update; //@description The last message of a chat was changed. If last_message is null, then the last message in the chat became unknown. Some new unknown messages might be added to the chat in this case @chat_id Chat identifier @last_message The new last message in the chat; may be null @order New value of the chat order updateChatLastMessage chat_id:int53 last_message:message order:int64 = Update; -//@description The order of the chat in the chat list has changed. Instead of this update updateChatLastMessage, updateChatIsPinned, updateChatDraftMessage, or updateChatIsSponsored might be sent @chat_id Chat identifier @order New value of the order +//@description The order of the chat in the chat list has changed. Instead of this update updateChatLastMessage, updateChatIsPinned, updateChatDraftMessage, or updateChatSource might be sent @chat_id Chat identifier @order New value of the order updateChatOrder chat_id:int53 order:int64 = Update; //@description A chat was pinned or unpinned @chat_id Chat identifier @is_pinned New value of is_pinned @order New value of the chat order @@ -2884,8 +2893,8 @@ updateChatIsPinned chat_id:int53 is_pinned:Bool order:int64 = Update; //@description A chat was marked as unread or was read @chat_id Chat identifier @is_marked_as_unread New value of is_marked_as_unread updateChatIsMarkedAsUnread chat_id:int53 is_marked_as_unread:Bool = Update; -//@description A chat's is_sponsored field has changed @chat_id Chat identifier @is_sponsored New value of is_sponsored @order New value of chat order -updateChatIsSponsored chat_id:int53 is_sponsored:Bool order:int64 = Update; +//@description A chat's source in the chat list has changed @chat_id Chat identifier @source New chat's source; may be null @order New value of chat order +updateChatSource chat_id:int53 source:ChatSource order:int64 = Update; //@description A chat's has_scheduled_messages field has changed @chat_id Chat identifier @has_scheduled_messages New value of has_scheduled_messages updateChatHasScheduledMessages chat_id:int53 has_scheduled_messages:Bool = Update; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 377f0ce8eb73f5ede1a84f0573b4b5d30b34acdf..b60c6a11b4d4215e6183e98db4fb24d60c218eb7 100644 GIT binary patch delta 2453 zcmZWrZ%k8H6z{pTt`dlKA*0MjI>CYA5o$sLF>J%Z2eWlr}u<1Z+7a4 z*hKQ9?$w#X+zsQqAFtZuKG@`O>b5KJiA|O)D2Vn5g&RyVg}zy8l!z6&`R!()%T-`9 z$ecPlycfzu#}R{=>nMvhIueAb7Vpw;{4C3SJpUEBnW?_#aksa5+8pg|-eWqs`?u+r z?Xuzax>bVljgwOfBcI@x_1XKo4}G*)w9@bB_`r3zd6%>OuF)_op?)pD!soY0*?cvtj4GqR*L2&F8t2O-3wB^9&wfR|x`963+PpYvxDR{h`_NzUMGaOi9@w#t`Y!^XK5!AIk9bMBczj1;&T}Hxe#|>^K%m}! zurqHn{aRL9FaSj?Q9FRPl#cjbu!_ERgQg-qfQMtc1p5Vf7(Sm)UZ21E|1L9iD4VTW zeVtAjI`|qXr%$S24d3J30jOZQ=F9vjMfXw3=w+y6c;qrvE0Kbmui)-9TtT0{E6~Mi zO<_K*Tr0+R+E&&i6xPz4LP%e86>rde6&e}Mf`n=IZSz)AL~VoI26YXhu(TWHbZQVv zSli;DMxE9VA+dKzi_Z_Cv@!DB-84qdDPjly3M{^7G2M`p_eZgF@5N>!h$#I-xhsPQH|WU@;) z@!fWPi6pK`Jf7}J95ywH#OVg&X1(qNV!;G%^Zf+gv~dbttj;^7F(8dL1$8WukrFJj z+`?sb-9pm9EnL=R6%%elfOVv9WACHecp^d)v4$jGUowfqEGAK-<_^ci+S7cU!*{SX zJp&GUUm)E4nQ6_v7{s6dsi4c#Xd-ZzcZrTIr8ILF#+bSA3|f-dW;k{aYZGsqY33gI z8GhnNjlfIdQD4!w(@;wFv)DL4i`JHBk=B+%vS6?I>wS6DkpVLeB1%&!zAxhaCpM;I zox_9JHiz$WVGis@{J^EQ5@Lzf{{&{6^6gI>pF#tR;!h#Sv1ii3%HKgW^-SVZBHt;( zIPH~EGFsFqW%gyqjFaB7Ov6%1;>D0eSzW5zUX8i|gTeGhK delta 2326 zcmZ8jUr1YL6!(0I5+$;9SQ^?e!*r|C8_a_bVRI0s4;{^Dx)yPp(8%oOK-#Q2nBYTT z;v9r7aG77$%8a)4Pt9sHaaSATZme4EuFi+D=G> zo!|NMo$ubna%HJ(S^1wg>fR{gKbR@MQEYv@G^V7J#VeL{ytGhhy_hKLNJncMEO0En zAymG4RP$Ru>S*g$qcr=swU-0O#gYH2MEBVO4K#yW3ThdlSNO{1t}9nBwTtla ziF70=6QQmtaGD64qx!zvmYfnMg^Rh`UAd`*J1brc^5MloY*6cUVb;U;1_Suq~>Z(`bm zQhIM8rjbR*dxDsF)5e7AZ(|b&eEBxGeOM-_b3F0*_gb8(b{Mv|`t#asHJ|po+E^lJ zm=;5wV_2Gh4EQkOW8l{FiLuWFQSiE`>?NfZjqVsXxoBt{g9pa3|5y+4h&`82vV!ds zh=-COi0fyYM8|i$naqS)D>{K%!X#Q+42?{}X(pyj;$-9*@X*>jQ0LW}U~Lr@{rXB- z>-AiE{^;l7_O|Xzjp|yx({&!#rl?47Sko-Gf7*5N&_2jg3b&-pcq)a>?IBL}nfqrTz`LF?&AgRi?pe$l zXeJG`Zx$(;S*|Ya&cXmNc4r3NLm6md*k2he$T^2MDn7@9sd{k)T9|_YM(+I)9jvy0 z)R#i|0|&KAP{9~32@48;rHTtyZ{|6rErgX2jirk#_nOVbrm&zKANvpFc9LQqHomnh7k;OdQ zSx7PUzD1J?&?DcIQwR5}u!tg#9EvmO`UhDPStRvpZGwv6ib3 zDt4u;Vlvkn$3!8<7dyI!q4EX<>7s}5F1~nRI;mp%#|G5Vod;M>?>Y|?!+9r_*I}KN z8Qs8xQ{@nQh}_tilWsqR7~{78%v%?C=Tv+Re6+y^vi;EOKBZuNI|@oWHW6#s#GxlQ zad(tW&Kumq3Dj)i)y!-`z=p42>ZliXrP`N=4n0>tg_`xPpL8%I zNvfGIbWKg5`6L?2COe?E7!@2<$oWZ BN`(Lb diff --git a/td/generate/scheme/telegram_api.tl b/td/generate/scheme/telegram_api.tl index 6c47d52ad..09381d698 100644 --- a/td/generate/scheme/telegram_api.tl +++ b/td/generate/scheme/telegram_api.tl @@ -638,7 +638,7 @@ messages.botResults#947ca848 flags:# gallery:flags.0?true query_id:long next_off exportedMessageLink#5dab1af4 link:string html:string = ExportedMessageLink; -messageFwdHeader#ec338270 flags:# from_id:flags.0?int from_name:flags.5?string date:int channel_id:flags.1?int channel_post:flags.2?int post_author:flags.3?string saved_from_peer:flags.4?Peer saved_from_msg_id:flags.4?int = MessageFwdHeader; +messageFwdHeader#353a686b flags:# from_id:flags.0?int from_name:flags.5?string date:int channel_id:flags.1?int channel_post:flags.2?int post_author:flags.3?string saved_from_peer:flags.4?Peer saved_from_msg_id:flags.4?int psa_type:flags.6?string = MessageFwdHeader; auth.codeTypeSms#72a3158c = auth.CodeType; auth.codeTypeCall#741cd3e3 = auth.CodeType; @@ -899,9 +899,6 @@ fileHash#6242c773 offset:int limit:int hash:bytes = FileHash; inputClientProxy#75588b3f address:string port:int = InputClientProxy; -help.proxyDataEmpty#e09e1fb8 expires:int = help.ProxyData; -help.proxyDataPromo#2bf7ee23 expires:int peer:Peer chats:Vector users:Vector = help.ProxyData; - help.termsOfServiceUpdateEmpty#e3309f7f expires:int = help.TermsOfServiceUpdate; help.termsOfServiceUpdate#28ecf961 expires:int terms_of_service:help.TermsOfService = help.TermsOfServiceUpdate; @@ -1127,6 +1124,9 @@ messageInteractionCounters#ad4fc9bd msg_id:int views:int forwards:int = MessageI stats.broadcastStats#bdf78394 period:StatsDateRangeDays followers:StatsAbsValueAndPrev views_per_post:StatsAbsValueAndPrev shares_per_post:StatsAbsValueAndPrev enabled_notifications:StatsPercentValue growth_graph:StatsGraph followers_graph:StatsGraph mute_graph:StatsGraph top_hours_graph:StatsGraph interactions_graph:StatsGraph iv_interactions_graph:StatsGraph views_by_source_graph:StatsGraph new_followers_by_source_graph:StatsGraph languages_graph:StatsGraph recent_message_interactions:Vector = stats.BroadcastStats; +help.promoDataEmpty#98f6ac75 expires:int = help.PromoData; +help.promoData#8c39793f flags:# proxy:flags.0?true expires:int peer:Peer chats:Vector users:Vector psa_type:flags.1?string psa_message:flags.2?string = help.PromoData; + ---functions--- invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; @@ -1398,7 +1398,6 @@ help.getAppChangelog#9010ef6f prev_app_version:string = Updates; help.setBotUpdatesStatus#ec22cfcd pending_updates_count:int message:string = Bool; help.getCdnConfig#52029342 = CdnConfig; help.getRecentMeUrls#3dc0f114 referer:string = help.RecentMeUrls; -help.getProxyData#3d7758e1 = help.ProxyData; help.getTermsOfServiceUpdate#2ca51fd1 = help.TermsOfServiceUpdate; help.acceptTermsOfService#ee72f79a id:DataJSON = Bool; help.getDeepLinkInfo#3fedc75f path:string = help.DeepLinkInfo; @@ -1408,6 +1407,8 @@ help.getPassportConfig#c661ad08 hash:int = help.PassportConfig; help.getSupportName#d360e72c = help.SupportName; help.getUserInfo#38a08d3 user_id:InputUser = help.UserInfo; help.editUserInfo#66b91b70 user_id:InputUser message:string entities:Vector = help.UserInfo; +help.getPromoData#c0977421 = help.PromoData; +help.hidePromoData#1e251c95 peer:InputPeer = Bool; channels.readHistory#cc104937 channel:InputChannel max_id:int = Bool; channels.deleteMessages#84c1fd4e channel:InputChannel id:Vector = messages.AffectedMessages; diff --git a/td/generate/scheme/telegram_api.tlo b/td/generate/scheme/telegram_api.tlo index 9335ffdbf097e02e0d3af0de3f6908c580c2338d..d6fdd39b2e9a3838800a4efabcc9556de9fa0711 100644 GIT binary patch delta 402 zcmaEJmS@TZo(*3_Sh6#$OgH}!IU>sMb@jXmUq)(9fnGpSes2Ee(^`S|!P46mxEM7g zWk4zga#M?o6Vp@O%2Pa26H`))7#J8p;*%$|8BE{7$tWWCmKa{R2>gEn~>`(g>#R zKm)~+=?4VCu1ilX0S6Pvfec{#ZXOfz0XeG3nN5eow(TIu4ciS?F|{yCOqEfU69Q|? V$V^E^=$mfvipgdBmeoua)d1r|k=OtL delta 340 zcmbPof#=Oxo(*3_SPGhq-)#ONazvDW_Q%ZAd>N@Z1$qHR`4yF$PiqC<2TN~P;9}H} zlmV#}$W1LSPE1dAD^KxAO-xBGVqjnZiBEQjG?@P8J(I-b5AOuG?^R|rW}GhYijk8U zD7Rfhm2tx+uu0Q_CS^?CV=FS*Cxc^q!VN|ZCM@Ctw;6BPN$-%K_dpozoC1(@ToOwX zU2_XcDuK?NeqN5r&=BNap!HyIRgNo0`Q3MIGz~zHJBt`7*TF32(~mmwFDdtAbS}YU}k_UD{^Mj;jnEx S2-f~*6;li2_B(5sEUE!+u7-U8 diff --git a/td/telegram/DialogSource.cpp b/td/telegram/DialogSource.cpp new file mode 100644 index 000000000..634c2046a --- /dev/null +++ b/td/telegram/DialogSource.cpp @@ -0,0 +1,97 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2020 +// +// 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/DialogSource.h" + +#include "td/utils/misc.h" + +namespace td { + +DialogSource DialogSource::mtproto_proxy() { + DialogSource result; + result.type_ = Type::MtprotoProxy; + return result; +} + +DialogSource DialogSource::public_service_announcement(string psa_type, string psa_text) { + DialogSource result; + result.type_ = Type::PublicServiceAnnouncement; + result.psa_type_ = std::move(psa_type); + result.psa_text_ = std::move(psa_text); + return result; +} + +Result DialogSource::unserialize(Slice str) { + if (str.empty()) { + // legacy + return mtproto_proxy(); + } + auto type_data = split(str); + TRY_RESULT(type, to_integer_safe(type_data.first)); + switch (type) { + case static_cast(Type::MtprotoProxy): + return mtproto_proxy(); + case static_cast(Type::PublicServiceAnnouncement): { + auto data = split(type_data.second, '\x01'); + return public_service_announcement(data.first.str(), data.second.str()); + } + default: + return Status::Error("Unexpected chat source type"); + } +} + +string DialogSource::serialize() const { + switch (type_) { + case DialogSource::Type::Membership: + UNREACHABLE(); + return ""; + case DialogSource::Type::MtprotoProxy: + return "1"; + case DialogSource::Type::PublicServiceAnnouncement: + return PSTRING() << "2 " << psa_type_ << '\x01' << psa_text_; + default: + UNREACHABLE(); + return ""; + } +} + +td_api::object_ptr DialogSource::get_chat_source_object() const { + switch (type_) { + case DialogSource::Type::Membership: + return nullptr; + case DialogSource::Type::MtprotoProxy: + return td_api::make_object(); + case DialogSource::Type::PublicServiceAnnouncement: + return td_api::make_object(psa_type_, psa_text_); + default: + UNREACHABLE(); + return nullptr; + } +} + +bool operator==(const DialogSource &lhs, const DialogSource &rhs) { + return lhs.type_ == rhs.type_ && lhs.psa_type_ == rhs.psa_type_ && lhs.psa_text_ == rhs.psa_text_; +} + +bool operator!=(const DialogSource &lhs, const DialogSource &rhs) { + return !(lhs == rhs); +} + +StringBuilder &operator<<(StringBuilder &string_builder, const DialogSource &source) { + switch (source.type_) { + case DialogSource::Type::Membership: + return string_builder << "chat list"; + case DialogSource::Type::MtprotoProxy: + return string_builder << "MTProto proxy sponsor"; + case DialogSource::Type::PublicServiceAnnouncement: + return string_builder << "public service announcement of type " << source.psa_type_; + default: + UNREACHABLE(); + return string_builder; + } +} + +} // namespace td diff --git a/td/telegram/DialogSource.h b/td/telegram/DialogSource.h new file mode 100644 index 000000000..5657601d6 --- /dev/null +++ b/td/telegram/DialogSource.h @@ -0,0 +1,41 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2020 +// +// 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/td_api.h" + +#include "td/utils/common.h" +#include "td/utils/Slice.h" +#include "td/utils/Status.h" +#include "td/utils/StringBuilder.h" + +namespace td { + +struct DialogSource { + enum class Type : int32 { Membership, MtprotoProxy, PublicServiceAnnouncement }; + Type type_ = Type::Membership; + string psa_type_; + string psa_text_; + + static DialogSource mtproto_proxy(); + + static DialogSource public_service_announcement(string psa_type, string psa_text); + + static Result unserialize(Slice str); + + string serialize() const; + + td_api::object_ptr get_chat_source_object() const; +}; + +bool operator==(const DialogSource &lhs, const DialogSource &rhs); + +bool operator!=(const DialogSource &lhs, const DialogSource &rhs); + +StringBuilder &operator<<(StringBuilder &string_builder, const DialogSource &source); + +} // namespace td diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 3c8756559..0af051af4 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -10344,15 +10344,17 @@ void MessagesManager::init() { auto sponsored_dialog_id_string = G()->td_db()->get_binlog_pmc()->get("sponsored_dialog_id"); if (!sponsored_dialog_id_string.empty()) { - auto r_dialog_id = to_integer_safe(sponsored_dialog_id_string); - if (r_dialog_id.is_error()) { + auto dialog_id_source = split(Slice(sponsored_dialog_id_string)); + auto r_dialog_id = to_integer_safe(dialog_id_source.first); + auto r_source = DialogSource::unserialize(dialog_id_source.second); + if (r_dialog_id.is_error() || r_source.is_error()) { LOG(ERROR) << "Can't parse " << sponsored_dialog_id_string; } else { DialogId dialog_id(r_dialog_id.ok()); const Dialog *d = get_dialog_force(dialog_id); if (d != nullptr) { - add_sponsored_dialog(d); + add_sponsored_dialog(d, r_source.move_as_ok()); } else { LOG(ERROR) << "Can't load " << dialog_id; } @@ -15454,11 +15456,11 @@ td_api::object_ptr MessagesManager::get_chat_object(const Dialog * get_chat_photo_object(td_->file_manager_.get(), get_dialog_photo(d->dialog_id)), get_dialog_permissions(d->dialog_id).get_chat_permissions_object(), get_message_object(d->dialog_id, get_message(d, d->last_message_id)), get_dialog_order_object(d), - d->pinned_order != DEFAULT_ORDER, d->is_marked_as_unread, is_dialog_sponsored(d), - get_dialog_has_scheduled_messages(d), can_delete_for_self, can_delete_for_all_users, - can_report_dialog(d->dialog_id), d->notification_settings.silent_send_message, - d->server_unread_count + d->local_unread_count, d->last_read_inbox_message_id.get(), - d->last_read_outbox_message_id.get(), d->unread_mention_count, + is_dialog_sponsored(d) ? sponsored_dialog_source_.get_chat_source_object() : nullptr, + d->pinned_order != DEFAULT_ORDER, d->is_marked_as_unread, get_dialog_has_scheduled_messages(d), + can_delete_for_self, can_delete_for_all_users, can_report_dialog(d->dialog_id), + d->notification_settings.silent_send_message, d->server_unread_count + d->local_unread_count, + d->last_read_inbox_message_id.get(), d->last_read_outbox_message_id.get(), d->unread_mention_count, get_chat_notification_settings_object(&d->notification_settings), get_chat_action_bar_object(d), d->pinned_message_id.get(), d->reply_markup_message_id.get(), std::move(draft_message), d->client_data); } @@ -22850,17 +22852,19 @@ void MessagesManager::send_update_chat_unread_mention_count(const Dialog *d) { make_tl_object(d->dialog_id.get(), d->unread_mention_count)); } -void MessagesManager::send_update_chat_is_sponsored(const Dialog *d) const { +void MessagesManager::send_update_chat_source(const Dialog *d) const { if (td_->auth_manager_->is_bot()) { return; } CHECK(d != nullptr); - LOG_CHECK(d->is_update_new_chat_sent) << "Wrong " << d->dialog_id << " in send_update_chat_is_sponsored"; + LOG_CHECK(d->is_update_new_chat_sent) << "Wrong " << d->dialog_id << " in send_update_chat_source"; LOG(INFO) << "Update chat is sponsored for " << d->dialog_id; - send_closure(G()->td(), &Td::send_update, - make_tl_object(d->dialog_id.get(), is_dialog_sponsored(d), - get_dialog_order_object(d))); + send_closure( + G()->td(), &Td::send_update, + make_tl_object( + d->dialog_id.get(), is_dialog_sponsored(d) ? sponsored_dialog_source_.get_chat_source_object() : nullptr, + get_dialog_order_object(d))); } void MessagesManager::send_update_chat_online_member_count(DialogId dialog_id, int32 online_member_count) const { @@ -23862,7 +23866,7 @@ void MessagesManager::set_dialog_folder_id(Dialog *d, FolderId folder_id) { // this will send updateChatChatList if needed DialogId sponsored_dialog_id = sponsored_dialog_id_; if (d->dialog_id == sponsored_dialog_id_ && d->order != DEFAULT_ORDER) { - sponsored_dialog_id_ = DialogId(); // supress updateChatIsSponsored + sponsored_dialog_id_ = DialogId(); // supress updateChatSource } set_dialog_order(d, DEFAULT_ORDER, true, false, "set_dialog_folder_id old"); @@ -28440,7 +28444,7 @@ bool MessagesManager::set_dialog_order(Dialog *d, int64 new_order, bool need_sen send_update_chat_chat_list(d); } if (was_sponsored != is_dialog_sponsored(d)) { - send_update_chat_is_sponsored(d); + send_update_chat_source(d); if (!is_loaded_from_database && !was_sponsored) { // channel is sponsored only if user isn't a channel member remove_all_dialog_notifications(d, false, "set_dialog_order 3"); @@ -30447,23 +30451,24 @@ void MessagesManager::get_payment_receipt(FullMessageId full_message_id, } void MessagesManager::remove_sponsored_dialog() { - set_sponsored_dialog_id(DialogId()); + set_sponsored_dialog(DialogId(), DialogSource()); } -void MessagesManager::on_get_sponsored_dialog_id(tl_object_ptr peer, - vector> users, - vector> chats) { +void MessagesManager::on_get_sponsored_dialog(tl_object_ptr peer, DialogSource source, + vector> users, + vector> chats) { CHECK(peer != nullptr); - td_->contacts_manager_->on_get_users(std::move(users), "on_get_sponsored_dialog_id"); - td_->contacts_manager_->on_get_chats(std::move(chats), "on_get_sponsored_dialog_id"); + td_->contacts_manager_->on_get_users(std::move(users), "on_get_sponsored_dialog"); + td_->contacts_manager_->on_get_chats(std::move(chats), "on_get_sponsored_dialog"); - set_sponsored_dialog_id(DialogId(peer)); + set_sponsored_dialog(DialogId(peer), std::move(source)); } -void MessagesManager::add_sponsored_dialog(const Dialog *d) { +void MessagesManager::add_sponsored_dialog(const Dialog *d, DialogSource source) { CHECK(!sponsored_dialog_id_.is_valid()); sponsored_dialog_id_ = d->dialog_id; + sponsored_dialog_source_ = std::move(source); if (is_dialog_sponsored(d)) { send_update_chat_chat_list(d); @@ -30474,12 +30479,36 @@ void MessagesManager::add_sponsored_dialog(const Dialog *d) { list.last_server_dialog_date_ = max_dialog_date; update_last_dialog_date(folder_id); } - send_update_chat_is_sponsored(d); + send_update_chat_source(d); + // the sponsored dialog must not be saved there } } -void MessagesManager::set_sponsored_dialog_id(DialogId dialog_id) { +void MessagesManager::save_sponsored_dialog() { + if (!G()->parameters().use_message_db) { + return; + } + + LOG(INFO) << "Save sponsored " << sponsored_dialog_id_ << " with source " << sponsored_dialog_source_; + if (sponsored_dialog_id_.is_valid()) { + G()->td_db()->get_binlog_pmc()->set( + "sponsored_dialog_id", + PSTRING() << sponsored_dialog_id_.get() << ' ' << sponsored_dialog_source_.DialogSource::serialize()); + } else { + G()->td_db()->get_binlog_pmc()->erase("sponsored_dialog_id"); + } +} + +void MessagesManager::set_sponsored_dialog(DialogId dialog_id, DialogSource source) { if (sponsored_dialog_id_ == dialog_id) { + if (sponsored_dialog_source_ != source) { + CHECK(sponsored_dialog_id_.is_valid()); + sponsored_dialog_source_ = std::move(source); + const Dialog *d = get_dialog(sponsored_dialog_id_); + CHECK(d != nullptr); + send_update_chat_source(d); + save_sponsored_dialog(); + } return; } @@ -30489,8 +30518,9 @@ void MessagesManager::set_sponsored_dialog_id(DialogId dialog_id) { CHECK(d != nullptr); bool is_sponsored = is_dialog_sponsored(d); sponsored_dialog_id_ = DialogId(); + sponsored_dialog_source_ = DialogSource(); if (is_sponsored) { - send_update_chat_is_sponsored(d); + send_update_chat_source(d); send_update_chat_chat_list(d); need_update_total_chat_count = true; } @@ -30500,7 +30530,7 @@ void MessagesManager::set_sponsored_dialog_id(DialogId dialog_id) { force_create_dialog(dialog_id, "set_sponsored_dialog_id"); const Dialog *d = get_dialog(dialog_id); CHECK(d != nullptr); - add_sponsored_dialog(d); + add_sponsored_dialog(d, std::move(source)); if (is_dialog_sponsored(d)) { need_update_total_chat_count = !need_update_total_chat_count; } @@ -30514,14 +30544,7 @@ void MessagesManager::set_sponsored_dialog_id(DialogId dialog_id) { } } - if (G()->parameters().use_message_db) { - if (sponsored_dialog_id_.is_valid()) { - G()->td_db()->get_binlog_pmc()->set("sponsored_dialog_id", to_string(sponsored_dialog_id_.get())); - } else { - G()->td_db()->get_binlog_pmc()->erase("sponsored_dialog_id"); - } - LOG(INFO) << "Save sponsored " << sponsored_dialog_id_; - } + save_sponsored_dialog(); } td_api::object_ptr MessagesManager::get_update_unread_message_count_object( diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 6437faec3..0a625b1c7 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -19,6 +19,7 @@ #include "td/telegram/DialogId.h" #include "td/telegram/DialogLocation.h" #include "td/telegram/DialogParticipant.h" +#include "td/telegram/DialogSource.h" #include "td/telegram/files/FileId.h" #include "td/telegram/files/FileSourceId.h" #include "td/telegram/FolderId.h" @@ -764,9 +765,9 @@ class MessagesManager : public Actor { void remove_sponsored_dialog(); - void on_get_sponsored_dialog_id(tl_object_ptr peer, - vector> users, - vector> chats); + void on_get_sponsored_dialog(tl_object_ptr peer, DialogSource source, + vector> users, + vector> chats); FileSourceId get_message_file_source_id(FullMessageId full_message_id); @@ -1922,7 +1923,7 @@ class MessagesManager : public Actor { void send_update_chat_unread_mention_count(const Dialog *d); - void send_update_chat_is_sponsored(const Dialog *d) const; + void send_update_chat_source(const Dialog *d) const; void send_update_chat_online_member_count(DialogId dialog_id, int32 online_member_count) const; @@ -2389,9 +2390,11 @@ class MessagesManager : public Actor { tl_object_ptr &&input_chat_photo, Promise &&promise); - void add_sponsored_dialog(const Dialog *d); + void add_sponsored_dialog(const Dialog *d, DialogSource source); - void set_sponsored_dialog_id(DialogId dialog_id); + void save_sponsored_dialog(); + + void set_sponsored_dialog(DialogId dialog_id, DialogSource source); static uint64 get_sequence_dispatcher_id(DialogId dialog_id, MessageContentType message_content_type); @@ -2768,6 +2771,7 @@ class MessagesManager : public Actor { uint32 scheduled_messages_sync_generation_ = 1; DialogId sponsored_dialog_id_; + DialogSource sponsored_dialog_source_; FullMessageId being_readded_message_id_; diff --git a/td/telegram/Version.h b/td/telegram/Version.h index e612a36c0..7a1c98ea0 100644 --- a/td/telegram/Version.h +++ b/td/telegram/Version.h @@ -8,7 +8,7 @@ namespace td { -constexpr int32 MTPROTO_LAYER = 112; +constexpr int32 MTPROTO_LAYER = 113; enum class Version : int32 { Initial, diff --git a/td/telegram/net/ConnectionCreator.cpp b/td/telegram/net/ConnectionCreator.cpp index f09776ef5..73e35a37c 100644 --- a/td/telegram/net/ConnectionCreator.cpp +++ b/td/telegram/net/ConnectionCreator.cpp @@ -10,6 +10,7 @@ #include "td/telegram/ConfigManager.h" #include "td/telegram/ConfigShared.h" +#include "td/telegram/DialogSource.h" #include "td/telegram/Global.h" #include "td/telegram/logevent/LogEvent.h" #include "td/telegram/MessagesManager.h" @@ -439,7 +440,7 @@ void ConnectionCreator::enable_proxy_impl(int32 proxy_id) { void ConnectionCreator::disable_proxy_impl() { if (active_proxy_id_ == 0) { - on_get_proxy_info(make_tl_object(0)); + on_get_proxy_info(make_tl_object(0)); return; } CHECK(proxies_.count(active_proxy_id_) == 1); @@ -474,7 +475,7 @@ void ConnectionCreator::on_proxy_changed(bool from_db) { get_proxy_info_query_token_ = 0; get_proxy_info_timestamp_ = Timestamp(); if (active_proxy_id_ == 0 || !from_db) { - on_get_proxy_info(make_tl_object(0)); + on_get_proxy_info(make_tl_object(0)); } else { schedule_get_proxy_info(0); } @@ -1238,7 +1239,7 @@ void ConnectionCreator::loop() { if (get_proxy_info_timestamp_.is_in_past()) { if (get_proxy_info_query_token_ == 0) { get_proxy_info_query_token_ = next_token(); - auto query = G()->net_query_creator().create(telegram_api::help_getProxyData()); + auto query = G()->net_query_creator().create(telegram_api::help_getPromoData()); G()->net_query_dispatcher().dispatch_with_callback(std::move(query), actor_shared(this, get_proxy_info_query_token_)); } @@ -1282,38 +1283,36 @@ void ConnectionCreator::on_result(NetQueryPtr query) { } get_proxy_info_query_token_ = 0; - auto res = fetch_result(std::move(query)); + auto res = fetch_result(std::move(query)); if (res.is_error()) { if (G()->close_flag()) { return; } - if (res.error().message() == "BOT_METHOD_INVALID") { - get_proxy_info_timestamp_ = Timestamp::in(30 * 86400); - return; - } else { - LOG(ERROR) << "Receive error for getProxyData: " << res.error(); - return schedule_get_proxy_info(60); - } + LOG(ERROR) << "Receive error for getProxyData: " << res.error(); + return schedule_get_proxy_info(60); } on_get_proxy_info(res.move_as_ok()); } -void ConnectionCreator::on_get_proxy_info(telegram_api::object_ptr proxy_data_ptr) { - CHECK(proxy_data_ptr != nullptr); - LOG(DEBUG) << "Receive " << to_string(proxy_data_ptr); +void ConnectionCreator::on_get_proxy_info(telegram_api::object_ptr promo_data_ptr) { + CHECK(promo_data_ptr != nullptr); + LOG(DEBUG) << "Receive " << to_string(promo_data_ptr); int32 expires = 0; - switch (proxy_data_ptr->get_id()) { - case telegram_api::help_proxyDataEmpty::ID: { - auto proxy = telegram_api::move_object_as(proxy_data_ptr); - expires = proxy->expires_; + switch (promo_data_ptr->get_id()) { + case telegram_api::help_promoDataEmpty::ID: { + auto promo = telegram_api::move_object_as(promo_data_ptr); + expires = promo->expires_; send_closure(G()->messages_manager(), &MessagesManager::remove_sponsored_dialog); break; } - case telegram_api::help_proxyDataPromo::ID: { - auto proxy = telegram_api::move_object_as(proxy_data_ptr); - expires = proxy->expires_; - send_closure(G()->messages_manager(), &MessagesManager::on_get_sponsored_dialog_id, std::move(proxy->peer_), - std::move(proxy->users_), std::move(proxy->chats_)); + case telegram_api::help_promoData::ID: { + auto promo = telegram_api::move_object_as(promo_data_ptr); + expires = promo->expires_; + bool is_proxy = (promo->flags_ & telegram_api::help_promoData::PROXY_MASK) != 0; + send_closure(G()->messages_manager(), &MessagesManager::on_get_sponsored_dialog, std::move(promo->peer_), + is_proxy ? DialogSource::mtproto_proxy() + : DialogSource::public_service_announcement(promo->psa_type_, promo->psa_message_), + std::move(promo->users_), std::move(promo->chats_)); break; } default: diff --git a/td/telegram/net/ConnectionCreator.h b/td/telegram/net/ConnectionCreator.h index ac932d337..61de8f1d8 100644 --- a/td/telegram/net/ConnectionCreator.h +++ b/td/telegram/net/ConnectionCreator.h @@ -229,7 +229,7 @@ class ConnectionCreator : public NetQueryCallback { uint64 auth_data_generation, int64 session_id); void client_set_timeout_at(ClientInfo &client, double wakeup_at); - void on_get_proxy_info(telegram_api::object_ptr proxy_data_ptr); + void on_get_proxy_info(telegram_api::object_ptr proxy_data_ptr); void schedule_get_proxy_info(int32 expires); diff --git a/td/telegram/net/NetQuery.cpp b/td/telegram/net/NetQuery.cpp index 6602ae4a4..90e595367 100644 --- a/td/telegram/net/NetQuery.cpp +++ b/td/telegram/net/NetQuery.cpp @@ -54,8 +54,7 @@ void NetQuery::set_error(Status status, string source) { } if (status.message() == "BOT_METHOD_INVALID") { auto id = tl_constructor(); - if (id != telegram_api::help_getNearestDc::ID && id != telegram_api::help_getProxyData::ID && - id != telegram_api::help_getAppConfig::ID) { + if (id != telegram_api::help_getNearestDc::ID && id != telegram_api::help_getAppConfig::ID) { LOG(ERROR) << "Receive BOT_METHOD_INVALID for query " << format::as_hex(id); } }