From 779fbb6d831e0cd192e844905be9d746558165f2 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 3 Sep 2019 17:13:03 +0300 Subject: [PATCH] Update to layer 100. Add td_api::userPrivacySettingShowPhoneNumber and td_api::topChatCategoryForwardChats. GitOrigin-RevId: 96fd17d9fef8e08b4415ec0d8e13e6cdb37f589b --- td/generate/scheme/td_api.tl | 6 +++ td/generate/scheme/td_api.tlo | Bin 158896 -> 159040 bytes td/generate/scheme/telegram_api.tl | 33 +++++++++++---- td/generate/scheme/telegram_api.tlo | Bin 184668 -> 187308 bytes td/telegram/ContactsManager.cpp | 2 - td/telegram/MessagesManager.cpp | 6 +++ td/telegram/MessagesManager.h | 1 + td/telegram/PrivacyManager.cpp | 11 +++++ td/telegram/PrivacyManager.h | 1 + td/telegram/Td.cpp | 13 ++++-- td/telegram/TopDialogManager.cpp | 62 +++++++++++++++++++++++----- td/telegram/TopDialogManager.h | 14 ++++++- 12 files changed, 125 insertions(+), 24 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index d8de4a7d7..0d3a97d48 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2260,6 +2260,9 @@ userPrivacySettingShowProfilePhoto = UserPrivacySetting; //@description A privacy setting for managing whether a link to the user's account is included in forwarded messages userPrivacySettingShowLinkInForwardedMessages = UserPrivacySetting; +//@description A privacy setting for managing whether the user's phone number is visible +userPrivacySettingShowPhoneNumber = UserPrivacySetting; + //@description A privacy setting for managing whether the user can be invited to chats userPrivacySettingAllowChatInvites = UserPrivacySetting; @@ -2500,6 +2503,9 @@ topChatCategoryInlineBots = TopChatCategory; //@description A category containing frequently used chats used for calls topChatCategoryCalls = TopChatCategory; +//@description A category containing frequently used chats used to forward messages +topChatCategoryForwardChats = TopChatCategory; + //@class TMeUrlType @description Describes the type of a URL linking to an internal Telegram entity diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 44ebcbdd3c0089464fa44787c7429dcafe3b5b3f..82b1de95e0ae02ffa284f1e3b3a46404183f379d 100644 GIT binary patch delta 642 zcmdmRlk>nW&J8+hqCHi8&io;hXDwRoY{0ZY}*ck z#HQQSGOFN~t*B+xz%9E2uk4RnMjhOGZR!{`VsN<% zCl;lE0;L$28QW{>7_Z2%fP!iInOG)+=@;r51-4I_&B!Ax0TM(H4Y0x;>ljUN%d)Iz zbkM}57vf@wn>80*yr4L}aUG+WYCuMQUaDVdZc=Iy0|PF-(__}-vvlP-t;#Q9w~< zSz>Z!aB4|OW?uT_`D~J#UDPX>7#}w8)!e>UlQBJ50%Xd~V?sU*Kv3k&ro&;|b`T^s z-KLgN1-EQPEu#i**&TRgf7CMS;MQwXhsWgY2kIEF$gqGsI6Wqg$zb||21bGHH)b>P z2upwj(R~6|_-7rX32s@B^^6X pinned_msg_id:flags.6?int folder_id:flags.11?int = ChatFull; -channelFull#3648977 flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_view_stats:flags.12?true id:int about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?int migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int pts:int = ChatFull; +channelFull#9882e516 flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_view_stats:flags.12?true id:int about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?int migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.13?int pts:int = ChatFull; chatParticipant#c8d7493e user_id:int inviter_id:int date:int = ChatParticipant; chatParticipantCreator#da13538a user_id:int = ChatParticipant; @@ -232,7 +232,7 @@ messages.dialogsSlice#71e094f3 count:int dialogs:Vector messages:Vector< messages.dialogsNotModified#f0e3e596 count:int = messages.Dialogs; messages.messages#8c718e87 messages:Vector chats:Vector users:Vector = messages.Messages; -messages.messagesSlice#a6c47aaa flags:# inexact:flags.1?true count:int messages:Vector chats:Vector users:Vector = messages.Messages; +messages.messagesSlice#c8edce1e flags:# inexact:flags.1?true count:int next_rate:flags.0?int messages:Vector chats:Vector users:Vector = messages.Messages; messages.channelMessages#99262e37 flags:# inexact:flags.1?true pts:int count:int messages:Vector chats:Vector users:Vector = messages.Messages; messages.messagesNotModified#74535f21 count:int = messages.Messages; @@ -425,6 +425,7 @@ inputPrivacyKeyPhoneCall#fabadc5f = InputPrivacyKey; inputPrivacyKeyPhoneP2P#db9e70d2 = InputPrivacyKey; inputPrivacyKeyForwards#a4dd4c08 = InputPrivacyKey; inputPrivacyKeyProfilePhoto#5719bacc = InputPrivacyKey; +inputPrivacyKeyPhoneNumber#352dafa = InputPrivacyKey; privacyKeyStatusTimestamp#bc2eab30 = PrivacyKey; privacyKeyChatInvite#500e6dfa = PrivacyKey; @@ -432,6 +433,7 @@ privacyKeyPhoneCall#3d662b7b = PrivacyKey; privacyKeyPhoneP2P#39491cc8 = PrivacyKey; privacyKeyForwards#69ec56a3 = PrivacyKey; privacyKeyProfilePhoto#96151fed = PrivacyKey; +privacyKeyPhoneNumber#d19ae46d = PrivacyKey; inputPrivacyValueAllowContacts#d09e07b = InputPrivacyRule; inputPrivacyValueAllowAll#184b35ce = InputPrivacyRule; @@ -439,6 +441,8 @@ inputPrivacyValueAllowUsers#131cc67f users:Vector = InputPrivacyRule; inputPrivacyValueDisallowContacts#ba52007 = InputPrivacyRule; inputPrivacyValueDisallowAll#d66b66c9 = InputPrivacyRule; inputPrivacyValueDisallowUsers#90110467 users:Vector = InputPrivacyRule; +inputPrivacyValueAllowChatParticipants#4c81c1ba chats:Vector = InputPrivacyRule; +inputPrivacyValueDisallowChatParticipants#d82363af chats:Vector = InputPrivacyRule; privacyValueAllowContacts#fffe1bac = PrivacyRule; privacyValueAllowAll#65427b82 = PrivacyRule; @@ -446,8 +450,10 @@ privacyValueAllowUsers#4d5bbe0c users:Vector = PrivacyRule; privacyValueDisallowContacts#f888fa1a = PrivacyRule; privacyValueDisallowAll#8b73e763 = PrivacyRule; privacyValueDisallowUsers#c7f49b7 users:Vector = PrivacyRule; +privacyValueAllowChatParticipants#18be796b chats:Vector = PrivacyRule; +privacyValueDisallowChatParticipants#acae0690 chats:Vector = PrivacyRule; -account.privacyRules#554abb6f rules:Vector users:Vector = account.PrivacyRules; +account.privacyRules#50a04e45 rules:Vector chats:Vector users:Vector = account.PrivacyRules; accountDaysTTL#b8d0afdf days:int = AccountDaysTTL; @@ -471,7 +477,6 @@ messages.affectedMessages#84d19185 pts:int pts_count:int = messages.AffectedMess contactLinkUnknown#5f4f9247 = ContactLink; contactLinkNone#feedd3ad = ContactLink; -contactLinkHasPhone#268f3f59 = ContactLink; contactLinkContact#d502c2d0 = ContactLink; webPageEmpty#eb1477e8 id:long = WebPage; @@ -643,6 +648,8 @@ topPeerCategoryCorrespondents#637b7ed = TopPeerCategory; topPeerCategoryGroups#bd17a14a = TopPeerCategory; topPeerCategoryChannels#161d9628 = TopPeerCategory; topPeerCategoryPhoneCalls#1e76a78c = TopPeerCategory; +topPeerCategoryForwardUsers#a8406ca9 = TopPeerCategory; +topPeerCategoryForwardChats#fbeec0f0 = TopPeerCategory; topPeerCategoryPeers#fb834291 category:TopPeerCategory count:int peers:Vector = TopPeerCategoryPeers; @@ -827,6 +834,7 @@ channelAdminLogEventActionChangeStickerSet#b1c3caa7 prev_stickerset:InputSticker channelAdminLogEventActionTogglePreHistoryHidden#5f5c95f1 new_value:Bool = ChannelAdminLogEventAction; channelAdminLogEventActionDefaultBannedRights#2df5fc0a prev_banned_rights:ChatBannedRights new_banned_rights:ChatBannedRights = ChannelAdminLogEventAction; channelAdminLogEventActionStopPoll#8f079643 message:Message = ChannelAdminLogEventAction; +channelAdminLogEventActionChangeLinkedChat#a26f881b prev_value:int new_value:int = ChannelAdminLogEventAction; channelAdminLogEvent#3b5a3e40 id:long date:int user_id:int action:ChannelAdminLogEventAction = ChannelAdminLogEvent; @@ -1031,6 +1039,12 @@ inputFolderPeer#fbd2c296 peer:InputPeer folder_id:int = InputFolderPeer; folderPeer#e9baa668 peer:Peer folder_id:int = FolderPeer; +messages.searchCounter#e844ebff flags:# inexact:flags.1?true filter:MessagesFilter count:int = messages.SearchCounter; + +urlAuthResultRequest#92d33a0e flags:# request_write_access:flags.0?true bot:User domain:string = UrlAuthResult; +urlAuthResultAccepted#8f8c0e4e url:string = UrlAuthResult; +urlAuthResultDefault#a9d6db1f = UrlAuthResult; + ---functions--- invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; @@ -1129,7 +1143,7 @@ contacts.unblock#e54100bd id:InputUser = Bool; contacts.getBlocked#f57c350f offset:int limit:int = contacts.Blocked; contacts.search#11f812d8 q:string limit:int = contacts.Found; contacts.resolveUsername#f93ccba3 username:string = contacts.ResolvedPeer; -contacts.getTopPeers#d4982db5 flags:# correspondents:flags.0?true bots_pm:flags.1?true bots_inline:flags.2?true phone_calls:flags.3?true groups:flags.10?true channels:flags.15?true offset:int limit:int hash:int = contacts.TopPeers; +contacts.getTopPeers#d4982db5 flags:# correspondents:flags.0?true bots_pm:flags.1?true bots_inline:flags.2?true phone_calls:flags.3?true forward_users:flags.4?true forward_chats:flags.5?true groups:flags.10?true channels:flags.15?true offset:int limit:int hash:int = contacts.TopPeers; contacts.resetTopPeerRating#1ae373ac category:TopPeerCategory peer:InputPeer = Bool; contacts.resetSaved#879537f1 = Bool; contacts.getSaved#82f1e39f = Vector; @@ -1183,7 +1197,7 @@ messages.startBot#e6df7378 bot:InputUser peer:InputPeer random_id:long start_par messages.getMessagesViews#c4c8a55d peer:InputPeer id:Vector increment:Bool = Vector; messages.editChatAdmin#a9e69f2e chat_id:int user_id:InputUser is_admin:Bool = Bool; messages.migrateChat#15a3b8e3 chat_id:int = Updates; -messages.searchGlobal#9e3cacb0 q:string offset_date:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages; +messages.searchGlobal#f79c611 q:string offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages; messages.reorderStickerSets#78337739 flags:# masks:flags.0?true order:Vector = Bool; messages.getDocumentByHash#338e2464 sha256:bytes size:int mime_type:string = Document; messages.searchGifs#bf9a776b q:string offset:int = messages.FoundGifs; @@ -1245,6 +1259,9 @@ messages.getEmojiKeywords#35a0e062 lang_code:string = EmojiKeywordsDifference; messages.getEmojiKeywordsDifference#1508b6af lang_code:string from_version:int = EmojiKeywordsDifference; messages.getEmojiKeywordsLanguages#4e9963b2 lang_codes:Vector = Vector; messages.getEmojiURL#d5b10c26 lang_code:string = EmojiURL; +messages.getSearchCounters#732eef00 peer:InputPeer filters:Vector = Vector; +messages.requestUrlAuth#e33f5613 peer:InputPeer msg_id:int button_id:int = UrlAuthResult; +messages.acceptUrlAuth#f729ea98 flags:# write_allowed:flags.0?true peer:InputPeer msg_id:int button_id:int = UrlAuthResult; updates.getState#edd4882a = updates.State; updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference; @@ -1313,6 +1330,8 @@ channels.readMessageContents#eab5dc38 channel:InputChannel id:Vector = Bool channels.deleteHistory#af369d42 channel:InputChannel max_id:int = Bool; channels.togglePreHistoryHidden#eabbb94c channel:InputChannel enabled:Bool = Updates; channels.getLeftChannels#8341ecc0 offset:int = messages.Chats; +channels.getGroupsForDiscussion#f5dad378 = messages.Chats; +channels.setDiscussionGroup#40582bb2 broadcast:InputChannel group:InputChannel = Bool; bots.sendCustomRequest#aa2769ed custom_method:string params:DataJSON = DataJSON; bots.answerWebhookJSONQuery#e6213f4d query_id:long data:DataJSON = Bool; diff --git a/td/generate/scheme/telegram_api.tlo b/td/generate/scheme/telegram_api.tlo index 98946de23d302dd8da8b755356490586b5aa0fe4..61d97ea333246265b778995a700b6f82a1a829ef 100644 GIT binary patch delta 3596 zcma)9eQZFS z8Jxw8P#DlEDTLc{QHRuoGBvDGm(^hpHngQ`L{q6B`RJys+eAM%%GwdyqE%ZVd-q+( zaZF#d{1M%E&iVb$J?EZt@9|&HWe&-i*&qD;{*Ai$U;eMNAA#xnE+09!1`R+XIsli0 zd^7+GVrStFko}9u-NX7?4=-&F`+TU+V2-hj1oAc>?w2xa1Ad8jN%da;o-`FPlI}B@ zdYi75Maebf%rOEz`FuW_lacpmtM6*Yf}Kt^%qzGp z7G}n!&0(LQN4JXD*qf`jF{Tgyk=~ZGBM@{7La3IPgx!Hqr%Hz$MPsJ6n@@~n?+p2B z!jh+15W_x6r%Q|7Dw>1LrpA6}?8~)R49to0PcER5va!{3|8!hm)gg!?zgrO3|3KhF zE>CSB?3YlD5@*Do#Xu%4c9i=(mm&E<(VBX7ajLe33TzKnE*6YFShZNtT1zd^nR(2Y z^AgTcL0LQw3PK6Vdk%`i{U3wEQ`?Nx&bcYh)w8LUNP$K><4SfE``lxh^)?;shqWhZoy?3R>ZXac(2pe&)NF`wcM0 zY>%E_&X7`%P4FLqQnE_kz^acQKa=V5@P5DGBYi;hB)f%*ld_oJ-NWRpAmoC(O|g>N zyl!OPwf6Kuz@qMQJte;6v8`lD+oT=~k)f}CV$oLmx~!VY*kG4!Crf%Rm6yoS^$EMS z(muI_GB|0|Mh-8foSn3nYHcVvtN(eoIc*I(G-)hu40k*xgmhXUR58V|{K)hYj^3E&5?m(2l^o1(UpZ9&Z8SNx%0#Nu$%iDb z%NykVlBgr5nEL{7xV;G&??L{`RWehG{x-dO)jh}*sOmko<(*F>EV(yRvq5CIz5&>@ zwLJ~Ms;wPgQp+?hg{^J`wic~jB`2!mqh}{g!Nkkp^aT7u{QPxVc--9x>@0Z|Qe!4E zJf`^8)-p}N#;A5&6L8Q~qzQ1^h*1ThsXgrk_652sLYy4lp3dL1YvbWP%=^MZjn5a@ zfA7iC4JC>qmFDEKmxio(QmL1Md$GF3V0AZg#0f_3W6ATFnj<2^jxHsGn%d)CNTH2SWS#kb9>ngv9@cV|Mgk|NRDzwSC2#Dxy;odacZ?g3D^j3HMu<_-fZT@4=u7CCYl^eki4Uh{2$94!T+d7<@5 zP-XFxAX^W&$K5m0!S#i6YEJGeROsYnG zfxZzjvH@Nyutuiey$XUn?~{77Flg7f(tRJGVntpT3)T zRlcelV4*zG3@6f&^qC#M(E^9{*}G_SqWT}(R?L5>RnV7`J(~p5wDRZH?etQ++1^}%k`-JFg)dSMC82zv|;LYgM-r_hdPpHPNHQW>)T zNoY)?8cQz>QsL9R&;qQwo9o3jiJu3`Ate1mP%b2$Y3yPlnz(E?EZ^nzNkoF)f54o+ zIsDqIIy|sP@vYX(;8U<7?)$xyaE5xg(g#N}Ecp+A|HFcWhY-Ce;wd4K;`X0GJMz3} zS%}?z7M`bUa@KQjoYp>`>4!&{ysMo#xP1V|8!9>gIS|6zk3uuaiylu5KsWVXc@A3d F{~sRjEF1s; delta 2391 zcmaJ?Z%kWN6z85ky0$?0V+qee=8MCvb5H3Kk`b*DZ8r*SvO*v_#iUK!$h5W%D;qPN zV+lGib+BFJl1+`MnauV>%_DhC`OqbeTMQp`D+UcQXf`t=CTP@<%n$ay`(Rt$Yd@X- ze&=`o+;{IeDYZJFe8&zb@ zJa4e~`C|JALLq#{STFHh3|0H*o4U&Ek#NlCkGT(pU*#0VY-z|?d-UCRgv$1CbRg#G zKXkz`E|Z4@s*<7S4}{yZ~Ao^2^W1iP&OnYXJx>l>{;vT;ifPv1mgO%%i2HBp;%79$haEZWM2Vr2RCA~`3n zTY36U3#(P$?s8tKNeVepec?F=Gp2IQ+U_@UMG}dN)_Y?~v)`=_@^oGl7Dh2LcK}(m z+4TdcQJZb{6l0@B*_5YPUa=F2{Azxj71m5K679@uHQ98YMND-e@qZCzOE;Q*l&6EWutHFWx>e9izriBm^XS8{ad39B00K_ z93~^(Ks1hyOqW8^O#j|JXFhv9dx6Atz$>fj?5LH5Okg2vIuJU@+?#BTPb+ffJJ;AlW+w7FCou2TP3VI}fuaIdcJ~7$x^!gsX@Juq0ua iOQ&ofkaSZ0IAkFSR^l0h23nGV2q_4#KqDz=Z2AunbxI2W diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 8f797a06e..150cc4dd9 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -7314,8 +7314,6 @@ ContactsManager::LinkState ContactsManager::get_link_state(tl_object_ptrtop_dialog_manager(), &TopDialogManager::on_dialog_used, TopDialogCategory::BotInline, DialogId(m->via_bot_user_id), m->date); } + if (m->forward_info != nullptr && d->last_outgoing_forwarded_message_date < m->date) { + TopDialogCategory category = + dialog_id.get_type() == DialogType::User ? TopDialogCategory::ForwardUsers : TopDialogCategory::ForwardChats; + send_closure(G()->top_dialog_manager(), &TopDialogManager::on_dialog_used, category, dialog_id, m->date); + d->last_outgoing_forwarded_message_date = m->date; + } TopDialogCategory category = TopDialogCategory::Size; switch (dialog_id.get_type()) { diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index d201c60b4..86223c84f 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1011,6 +1011,7 @@ class MessagesManager : public Actor { int32 pending_last_message_date = 0; MessageId pending_last_message_id; MessageId max_notification_message_id; + int32 last_outgoing_forwarded_message_date = 0; MessageId max_added_message_id; MessageId being_added_message_id; diff --git a/td/telegram/PrivacyManager.cpp b/td/telegram/PrivacyManager.cpp index d36cb3fee..3f5964d8c 100644 --- a/td/telegram/PrivacyManager.cpp +++ b/td/telegram/PrivacyManager.cpp @@ -48,6 +48,9 @@ PrivacyManager::UserPrivacySetting::UserPrivacySetting(const telegram_api::Priva case telegram_api::privacyKeyProfilePhoto::ID: type_ = Type::UserProfilePhoto; break; + case telegram_api::privacyKeyPhoneNumber::ID: + type_ = Type::UserPhoneNumber; + break; default: UNREACHABLE(); type_ = Type::UserStatus; @@ -68,6 +71,8 @@ tl_object_ptr PrivacyManager::UserPrivacySetting::as return make_tl_object(); case Type::UserProfilePhoto: return make_tl_object(); + case Type::UserPhoneNumber: + return make_tl_object(); default: UNREACHABLE(); return nullptr; @@ -87,6 +92,8 @@ tl_object_ptr PrivacyManager::UserPrivacySetting: return make_tl_object(); case Type::UserProfilePhoto: return make_tl_object(); + case Type::UserPhoneNumber: + return make_tl_object(); default: UNREACHABLE(); return nullptr; @@ -113,6 +120,9 @@ PrivacyManager::UserPrivacySetting::UserPrivacySetting(const td_api::UserPrivacy case td_api::userPrivacySettingShowProfilePhoto::ID: type_ = Type::UserProfilePhoto; break; + case td_api::userPrivacySettingShowPhoneNumber::ID: + type_ = Type::UserPhoneNumber; + break; default: UNREACHABLE(); type_ = Type::UserStatus; @@ -244,6 +254,7 @@ vector PrivacyManager::UserPrivacySettingRule::user_ids_as_td_api() const Result PrivacyManager::UserPrivacySettingRules::from_telegram_api( tl_object_ptr rules) { G()->td().get_actor_unsafe()->contacts_manager_->on_get_users(std::move(rules->users_), "on get privacy rules"); + G()->td().get_actor_unsafe()->contacts_manager_->on_get_chats(std::move(rules->chats_), "on get privacy rules"); return from_telegram_api(std::move(rules->rules_)); } diff --git a/td/telegram/PrivacyManager.h b/td/telegram/PrivacyManager.h index 0aedf70a9..07c46ccea 100644 --- a/td/telegram/PrivacyManager.h +++ b/td/telegram/PrivacyManager.h @@ -45,6 +45,7 @@ class PrivacyManager : public NetQueryCallback { PeerToPeerCall, LinkInForwardedMessages, UserProfilePhoto, + UserPhoneNumber, Size }; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 4e90e2ae5..d0370fbeb 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5448,7 +5448,8 @@ void Td::on_request(uint64 id, td_api::getTopChats &request) { } }); send_closure(top_dialog_manager_, &TopDialogManager::get_top_dialogs, - top_dialog_category_from_td_api(*request.category_), request.limit_, std::move(query_promise)); + top_dialog_category_from_td_api(*request.category_), narrow_cast(request.limit_), + std::move(query_promise)); } void Td::on_request(uint64 id, const td_api::removeTopChat &request) { @@ -5457,10 +5458,14 @@ void Td::on_request(uint64 id, const td_api::removeTopChat &request) { return send_error_raw(id, 400, "Top chat category should not be empty"); } + DialogId dialog_id(request.chat_id_); + if (!dialog_id.is_valid()) { + return send_error_raw(id, 400, "Invalid chat identifier"); + } send_closure(top_dialog_manager_, &TopDialogManager::remove_dialog, - top_dialog_category_from_td_api(*request.category_), DialogId(request.chat_id_), - messages_manager_->get_input_peer(DialogId(request.chat_id_), AccessRights::Read)); - send_closure(actor_id(this), &Td::send_result, id, make_tl_object()); + top_dialog_category_from_td_api(*request.category_), dialog_id, + messages_manager_->get_input_peer(dialog_id, AccessRights::Read)); + send_closure(actor_id(this), &Td::send_result, id, td_api::make_object()); } void Td::on_request(uint64 id, const td_api::getChats &request) { diff --git a/td/telegram/TopDialogManager.cpp b/td/telegram/TopDialogManager.cpp index c4c162669..fd6e4fd05 100644 --- a/td/telegram/TopDialogManager.cpp +++ b/td/telegram/TopDialogManager.cpp @@ -50,6 +50,10 @@ static CSlice top_dialog_category_name(TopDialogCategory category) { return CSlice("channel"); case TopDialogCategory::Call: return CSlice("call"); + case TopDialogCategory::ForwardUsers: + return CSlice("forward_users"); + case TopDialogCategory::ForwardChats: + return CSlice("forward_chats"); default: UNREACHABLE(); } @@ -69,6 +73,10 @@ static TopDialogCategory top_dialog_category_from_telegram_api(const telegram_ap return TopDialogCategory::Channel; case telegram_api::topPeerCategoryPhoneCalls::ID: return TopDialogCategory::Call; + case telegram_api::topPeerCategoryForwardUsers::ID: + return TopDialogCategory::ForwardUsers; + case telegram_api::topPeerCategoryForwardChats::ID: + return TopDialogCategory::ForwardChats; default: UNREACHABLE(); } @@ -88,6 +96,10 @@ static tl_object_ptr top_dialog_category_as_teleg return make_tl_object(); case TopDialogCategory::Call: return make_tl_object(); + case TopDialogCategory::ForwardUsers: + return make_tl_object(); + case TopDialogCategory::ForwardChats: + return make_tl_object(); default: UNREACHABLE(); } @@ -174,6 +186,11 @@ void TopDialogManager::remove_dialog(TopDialogCategory category, DialogId dialog if (!is_active_ || !is_enabled_) { return; } + CHECK(dialog_id.is_valid()); + + if (category == TopDialogCategory::ForwardUsers && dialog_id.get_type() != DialogType::User) { + category = TopDialogCategory::ForwardChats; + } auto pos = static_cast(category); CHECK(pos < by_category_.size()); @@ -276,13 +293,28 @@ void TopDialogManager::normalize_rating() { } void TopDialogManager::do_get_top_dialogs(GetTopDialogsQuery &&query) { - auto pos = static_cast(query.category); - CHECK(pos < by_category_.size()); - auto &top_dialogs = by_category_[pos]; + vector dialog_ids; + if (query.category != TopDialogCategory::ForwardUsers) { + auto pos = static_cast(query.category); + CHECK(pos < by_category_.size()); + dialog_ids = transform(by_category_[pos].dialogs, [](const auto &x) { return x.dialog_id; }); + } else { + // merge ForwardUsers and ForwardChats + auto &users = by_category_[static_cast(TopDialogCategory::ForwardUsers)]; + auto &chats = by_category_[static_cast(TopDialogCategory::ForwardChats)]; + size_t users_pos = 0; + size_t chats_pos = 0; + while (users_pos < users.dialogs.size() || chats_pos < chats.dialogs.size()) { + if (chats_pos == chats.dialogs.size() || + (users_pos < users.dialogs.size() && users.dialogs[users_pos] < chats.dialogs[chats_pos])) { + dialog_ids.push_back(users.dialogs[users_pos++].dialog_id); + } else { + dialog_ids.push_back(chats.dialogs[chats_pos++].dialog_id); + } + } + } - auto limit = std::min({query.limit, MAX_TOP_DIALOGS_LIMIT, top_dialogs.dialogs.size()}); - - vector dialog_ids = transform(top_dialogs.dialogs, [](const auto &x) { return x.dialog_id; }); + auto limit = std::min({query.limit, MAX_TOP_DIALOGS_LIMIT, dialog_ids.size()}); auto promise = PromiseCreator::lambda([query = std::move(query), dialog_ids, limit](Result) mutable { vector result; @@ -351,11 +383,21 @@ void TopDialogManager::do_get_top_peers() { int32 flags = contacts_getTopPeers::CORRESPONDENTS_MASK | contacts_getTopPeers::BOTS_PM_MASK | contacts_getTopPeers::BOTS_INLINE_MASK | contacts_getTopPeers::GROUPS_MASK | - contacts_getTopPeers::CHANNELS_MASK | contacts_getTopPeers::PHONE_CALLS_MASK; + contacts_getTopPeers::CHANNELS_MASK | contacts_getTopPeers::PHONE_CALLS_MASK | + contacts_getTopPeers::FORWARD_USERS_MASK | contacts_getTopPeers::FORWARD_CHATS_MASK; - contacts_getTopPeers query{ - flags, true /*correspondents*/, true /*bot_pm*/, true /*bot_inline */, true /*phone_calls*/, - true /*groups*/, true /*channels*/, 0 /*offset*/, 100 /*limit*/, hash}; + contacts_getTopPeers query{flags, + true /*correspondents*/, + true /*bot_pm*/, + true /*bot_inline */, + true /*phone_calls*/, + true /*groups*/, + true /*channels*/, + true /*forward_users*/, + true /*forward_chats*/, + 0 /*offset*/, + 100 /*limit*/, + hash}; auto net_query = G()->net_query_creator().create(create_storer(query)); G()->net_query_dispatcher().dispatch_with_callback(std::move(net_query), actor_shared(this)); } diff --git a/td/telegram/TopDialogManager.h b/td/telegram/TopDialogManager.h index 1117f1255..c5fc77af8 100644 --- a/td/telegram/TopDialogManager.h +++ b/td/telegram/TopDialogManager.h @@ -23,7 +23,17 @@ namespace td { -enum class TopDialogCategory : int32 { Correspondent, BotPM, BotInline, Group, Channel, Call, Size }; +enum class TopDialogCategory : int32 { + Correspondent, + BotPM, + BotInline, + Group, + Channel, + Call, + ForwardUsers, + ForwardChats, + Size +}; inline TopDialogCategory top_dialog_category_from_td_api(const td_api::TopChatCategory &category) { switch (category.get_id()) { @@ -39,6 +49,8 @@ inline TopDialogCategory top_dialog_category_from_td_api(const td_api::TopChatCa return TopDialogCategory::Channel; case td_api::topChatCategoryCalls::ID: return TopDialogCategory::Call; + case td_api::topChatCategoryForwardChats::ID: + return TopDialogCategory::ForwardUsers; default: UNREACHABLE(); }