From 17a5c27658b903ef675024e3524e5caf7c102d2d Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 2 Jun 2023 11:46:19 +0400 Subject: [PATCH] Update API scheme on layer 160. Leave plain scheme in api.tl. --- Telegram/SourceFiles/api/api_updates.cpp | 4 +- Telegram/SourceFiles/data/data_stories.cpp | 77 +++++++++++-------- Telegram/SourceFiles/data/data_stories.h | 6 +- .../tl => SourceFiles/mtproto/scheme}/api.tl | 41 ++-------- Telegram/SourceFiles/mtproto/scheme/layer.tl | 1 + .../mtproto/scheme}/mtproto.tl | 0 Telegram/cmake/td_scheme.cmake | 12 +-- 7 files changed, 63 insertions(+), 78 deletions(-) rename Telegram/{Resources/tl => SourceFiles/mtproto/scheme}/api.tl (98%) create mode 100644 Telegram/SourceFiles/mtproto/scheme/layer.tl rename Telegram/{Resources/tl => SourceFiles/mtproto/scheme}/mtproto.tl (100%) diff --git a/Telegram/SourceFiles/api/api_updates.cpp b/Telegram/SourceFiles/api/api_updates.cpp index 62bf94ba7b..55a15d2a76 100644 --- a/Telegram/SourceFiles/api/api_updates.cpp +++ b/Telegram/SourceFiles/api/api_updates.cpp @@ -2520,8 +2520,8 @@ void Updates::feedUpdate(const MTPUpdate &update) { _session->api().transcribes().apply(data); } break; - case mtpc_updateStories: { - _session->data().stories().apply(update.c_updateStories()); + case mtpc_updateStory: { + _session->data().stories().apply(update.c_updateStory()); } break; } diff --git a/Telegram/SourceFiles/data/data_stories.cpp b/Telegram/SourceFiles/data/data_stories.cpp index 5cc08e8b50..90d6971265 100644 --- a/Telegram/SourceFiles/data/data_stories.cpp +++ b/Telegram/SourceFiles/data/data_stories.cpp @@ -276,8 +276,29 @@ Main::Session &Stories::session() const { return _owner->session(); } -void Stories::apply(const MTPDupdateStories &data) { - applyChanges(parse(data.vstories())); +void Stories::apply(const MTPDupdateStory &data) { + const auto peerId = peerFromUser(data.vuser_id()); + const auto peer = _owner->peer(peerId); + const auto i = ranges::find(_all, peer, &StoriesList::user); + const auto id = parseAndApply(peer, data.vstory()); + if (i != end(_all)) { + auto added = false; + if (id && !i->ids.contains(id)) { + i->ids.emplace(id); + ++i->total; + added = true; + } + if (added) { + ranges::rotate(begin(_all), i, i + 1); + } + } else if (id) { + _all.insert(begin(_all), StoriesList{ + .user = peer->asUser(), + .ids = { id }, + .readTill = 0, + .total = 1, + }); + } _allChanged.fire({}); } @@ -294,19 +315,11 @@ StoriesList Stories::parse(const MTPUserStories &stories) { const auto &list = data.vstories().v; result.ids.reserve(list.size()); for (const auto &story : list) { - story.match([&](const MTPDstoryItem &data) { - if (const auto story = parseAndApply(result.user, data)) { - result.ids.emplace(story->id()); - } else { - applyDeleted({ peerFromUser(userId), data.vid().v }); - --result.total; - } - }, [&](const MTPDstoryItemSkipped &data) { - result.ids.emplace(data.vid().v); - }, [&](const MTPDstoryItemDeleted &data) { - applyDeleted({ peerFromUser(userId), data.vid().v }); + if (const auto id = parseAndApply(result.user, story)) { + result.ids.emplace(id); + } else { --result.total; - }); + } } result.total = std::max(result.total, int(result.ids.size())); return result; @@ -339,6 +352,23 @@ Story *Stories::parseAndApply( return result; } +StoryId Stories::parseAndApply( + not_null peer, + const MTPstoryItem &story) { + return story.match([&](const MTPDstoryItem &data) { + if (const auto story = parseAndApply(peer, data)) { + return story->id(); + } + applyDeleted({ peer->id, data.vid().v }); + return StoryId(); + }, [&](const MTPDstoryItemSkipped &data) { + return StoryId(data.vid().v); + }, [&](const MTPDstoryItemDeleted &data) { + applyDeleted({ peer->id, data.vid().v }); + return StoryId(); + }); +} + void Stories::updateDependentMessages(not_null story) { const auto i = _dependentMessages.find(story); if (i != end(_dependentMessages)) { @@ -603,25 +633,6 @@ void Stories::pushToBack(StoriesList &&list) { } } -void Stories::applyChanges(StoriesList &&list) { - const auto i = ranges::find(_all, list.user, &StoriesList::user); - if (i != end(_all)) { - auto added = false; - for (const auto id : list.ids) { - if (!i->ids.contains(id)) { - i->ids.emplace(id); - ++i->total; - added = true; - } - } - if (added) { - ranges::rotate(begin(_all), i, i + 1); - } - } else if (!list.ids.empty()) { - _all.insert(begin(_all), std::move(list)); - } -} - void Stories::loadAround(FullStoryId id) { const auto i = ranges::find(_all, id.peer, [](const StoriesList &list) { return list.user->id; diff --git a/Telegram/SourceFiles/data/data_stories.h b/Telegram/SourceFiles/data/data_stories.h index b4a53f859a..aa0fcbda57 100644 --- a/Telegram/SourceFiles/data/data_stories.h +++ b/Telegram/SourceFiles/data/data_stories.h @@ -122,7 +122,7 @@ public: not_null dependency); void loadMore(); - void apply(const MTPDupdateStories &data); + void apply(const MTPDupdateStory &data); void loadAround(FullStoryId id); [[nodiscard]] const std::vector &all(); @@ -148,6 +148,9 @@ private: [[nodiscard]] Story *parseAndApply( not_null peer, const MTPDstoryItem &data); + StoryId parseAndApply( + not_null peer, + const MTPstoryItem &story); void processResolvedStories( not_null peer, const QVector &list); @@ -155,7 +158,6 @@ private: void finalizeResolve(FullStoryId id); void pushToBack(StoriesList &&list); - void applyChanges(StoriesList &&list); void applyDeleted(FullStoryId id); void removeDependencyStory(not_null story); diff --git a/Telegram/Resources/tl/api.tl b/Telegram/SourceFiles/mtproto/scheme/api.tl similarity index 98% rename from Telegram/Resources/tl/api.tl rename to Telegram/SourceFiles/mtproto/scheme/api.tl index d5b1f36520..f603e31aec 100644 --- a/Telegram/Resources/tl/api.tl +++ b/Telegram/SourceFiles/mtproto/scheme/api.tl @@ -1,33 +1,3 @@ -/////////////////////////////// -/////////////////// Layer cons -/////////////////////////////// - -//invokeAfterMsg#cb9f372d msg_id:long query:!X = X; -//invokeAfterMsgs#3dc4b4f0 msg_ids:Vector query:!X = X; -//invokeWithLayer1#53835315 query:!X = X; -//invokeWithLayer2#289dd1f6 query:!X = X; -//invokeWithLayer3#b7475268 query:!X = X; -//invokeWithLayer4#dea0d430 query:!X = X; -//invokeWithLayer5#417a57ae query:!X = X; -//invokeWithLayer6#3a64d54d query:!X = X; -//invokeWithLayer7#a5be56d3 query:!X = X; -//invokeWithLayer8#e9abd9fd query:!X = X; -//invokeWithLayer9#76715a63 query:!X = X; -//invokeWithLayer10#39620c41 query:!X = X; -//invokeWithLayer11#a6b88fdf query:!X = X; -//invokeWithLayer12#dda60d3c query:!X = X; -//invokeWithLayer13#427c8ea2 query:!X = X; -//invokeWithLayer14#2b9b08fa query:!X = X; -//invokeWithLayer15#b4418b64 query:!X = X; -//invokeWithLayer16#cf5f0987 query:!X = X; -//invokeWithLayer17#50858a19 query:!X = X; -//invokeWithLayer18#1c900537 query:!X = X; -//invokeWithLayer#da9b0d0d layer:int query:!X = X; // after 18 layer - -/////////////////////////////// -///////// Main application API -/////////////////////////////// - boolFalse#bc799737 = Bool; boolTrue#997275b5 = Bool; @@ -110,7 +80,7 @@ storage.fileMp4#b3cea0e4 = storage.FileType; storage.fileWebp#1081464c = storage.FileType; userEmpty#d3bc4b7a id:long = User; -user#8f97c628 flags:# self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true support:flags.23?true scam:flags.24?true apply_min_photo:flags.25?true fake:flags.26?true bot_attach_menu:flags.27?true premium:flags.28?true attach_menu_enabled:flags.29?true flags2:# bot_can_edit:flags2.1?true close_friend:flags2.2?true stories_available:flags2.3?true stories_unavailable:flags2.4?true id:long access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?Vector bot_inline_placeholder:flags.19?string lang_code:flags.22?string emoji_status:flags.30?EmojiStatus usernames:flags2.0?Vector = User; +user#8f97c628 flags:# self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true support:flags.23?true scam:flags.24?true apply_min_photo:flags.25?true fake:flags.26?true bot_attach_menu:flags.27?true premium:flags.28?true attach_menu_enabled:flags.29?true flags2:# bot_can_edit:flags2.1?true close_friend:flags2.2?true stories_available:flags2.3?true stories_unavailable:flags2.4?true stories_hidden:flags2.5?true id:long access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?Vector bot_inline_placeholder:flags.19?string lang_code:flags.22?string emoji_status:flags.30?EmojiStatus usernames:flags2.0?Vector = User; userProfilePhotoEmpty#4f11bae1 = UserProfilePhoto; userProfilePhoto#82d1f706 flags:# has_video:flags.0?true personal:flags.2?true photo_id:long stripped_thumb:flags.1?bytes dc_id:int = UserProfilePhoto; @@ -410,7 +380,7 @@ updateChannelPinnedTopics#fe198602 flags:# channel_id:long order:flags.0?Vector< updateUser#20529438 user_id:long = Update; updateAutoSaveSettings#ec05b097 = Update; updateGroupInvitePrivacyForbidden#ccf08ad6 user_id:long = Update; -updateStories#66fad7b5 stories:UserStories = Update; +updateStory#205a4133 user_id:long story:StoryItem = Update; updateReadStories#feb5345a user_id:long max_id:int = Update; updateStoryID#1bf335b9 id:int random_id:long = Update; @@ -1557,7 +1527,7 @@ storyViews#d36760cf flags:# views_count:int recent_viewers:flags.0?Vector storyItemDeleted#51e6ee4f id:int = StoryItem; storyItemSkipped#a1d8cf8f id:int date:int = StoryItem; -storyItem#8fcd96ac flags:# pinned:flags.5?true expired:flags.6?true public:flags.7?true id:int date:int caption:flags.0?string entities:flags.1?Vector media:MessageMedia privacy:flags.2?Vector views:flags.3?StoryViews = StoryItem; +storyItem#8fcd96ac flags:# pinned:flags.5?true expired:flags.6?true id:int date:int caption:flags.0?string entities:flags.1?Vector media:MessageMedia privacy:flags.2?Vector views:flags.3?StoryViews = StoryItem; userStories#8611a200 flags:# user_id:long max_read_id:flags.0?int stories:Vector = UserStories; @@ -1727,6 +1697,7 @@ contacts.resolvePhone#8af94344 phone:string = contacts.ResolvedPeer; contacts.exportContactToken#f8654027 = ExportedContactToken; contacts.importContactToken#13005788 token:string = User; contacts.editCloseFriends#ba6705f0 id:Vector = Bool; +contacts.toggleStoriesHidden#753fb865 id:InputUser hidden:Bool = Bool; messages.getMessages#63c66506 id:Vector = messages.Messages; messages.getDialogs#a0f4cb4f flags:# exclude_pinned:flags.0?true folder_id:flags.1?int offset_date:int offset_id:int offset_peer:InputPeer limit:int hash:long = messages.Dialogs; @@ -2115,7 +2086,7 @@ stories.sendStory#8b5c6986 flags:# pinned:flags.2?true media:InputMedia caption: stories.editStory#2aae7a41 flags:# id:int media:flags.0?InputMedia caption:flags.1?string entities:flags.1?Vector privacy_rules:flags.2?Vector = Updates; stories.deleteStories#b5d501d7 id:Vector = Vector; stories.togglePinned#51602944 id:Vector pinned:Bool = Vector; -stories.getAllStories#eeb0d625 flags:# next:flags.1?true state:flags.0?string = stories.AllStories; +stories.getAllStories#eeb0d625 flags:# next:flags.1?true include_hidden:flags.2?true state:flags.0?string = stories.AllStories; stories.getUserStories#96d528e0 user_id:InputUser = stories.UserStories; stories.getPinnedStories#b471137 user_id:InputUser offset_id:int limit:int = stories.Stories; stories.getExpiredStories#8f792f2 offset_id:int limit:int = stories.Stories; @@ -2124,5 +2095,3 @@ stories.readStories#edc5105b user_id:InputUser max_id:int = Vector; stories.incrementStoryViews#22126127 user_id:InputUser id:Vector = Bool; stories.getStoryViewsList#4b3b5e97 id:int offset_date:int offset_id:long limit:int = stories.StoryViewsList; stories.getStoriesViews#9a75d6a6 id:Vector = stories.StoryViews; - -// LAYER 160 diff --git a/Telegram/SourceFiles/mtproto/scheme/layer.tl b/Telegram/SourceFiles/mtproto/scheme/layer.tl new file mode 100644 index 0000000000..5e910a52b2 --- /dev/null +++ b/Telegram/SourceFiles/mtproto/scheme/layer.tl @@ -0,0 +1 @@ +// LAYER 160 diff --git a/Telegram/Resources/tl/mtproto.tl b/Telegram/SourceFiles/mtproto/scheme/mtproto.tl similarity index 100% rename from Telegram/Resources/tl/mtproto.tl rename to Telegram/SourceFiles/mtproto/scheme/mtproto.tl diff --git a/Telegram/cmake/td_scheme.cmake b/Telegram/cmake/td_scheme.cmake index 20b956382b..11129f20fc 100644 --- a/Telegram/cmake/td_scheme.cmake +++ b/Telegram/cmake/td_scheme.cmake @@ -11,16 +11,18 @@ add_library(tdesktop::td_scheme ALIAS td_scheme) include(cmake/generate_scheme.cmake) set(scheme_files - ${res_loc}/tl/mtproto.tl - ${res_loc}/tl/api.tl + ${src_loc}/mtproto/scheme/api.tl + ${src_loc}/mtproto/scheme/layer.tl + ${src_loc}/mtproto/scheme/mtproto.tl ) generate_scheme(td_scheme ${src_loc}/codegen/scheme/codegen_scheme.py "${scheme_files}") -nice_target_sources(td_scheme ${res_loc} +nice_target_sources(td_scheme ${src_loc}/mtproto/scheme PRIVATE - tl/mtproto.tl - tl/api.tl + api.tl + layer.tl + mtproto.tl ) target_include_directories(td_scheme