From 983b6af0b4e84718b870dbc9a44d7294022741ce Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 8 Nov 2022 14:30:26 +0400 Subject: [PATCH] Update API scheme to layer 149. --- Telegram/Resources/tl/api.tl | 10 ++++++---- Telegram/SourceFiles/api/api_updates.cpp | 14 +++++++------- Telegram/SourceFiles/data/data_forum.cpp | 15 ++++++--------- Telegram/SourceFiles/data/data_forum.h | 1 - Telegram/SourceFiles/data/data_session.cpp | 3 --- 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/Telegram/Resources/tl/api.tl b/Telegram/Resources/tl/api.tl index 742f02e12..be5012ab2 100644 --- a/Telegram/Resources/tl/api.tl +++ b/Telegram/Resources/tl/api.tl @@ -266,7 +266,7 @@ messages.dialogsNotModified#f0e3e596 count:int = messages.Dialogs; messages.messages#8c718e87 messages:Vector chats:Vector users:Vector = messages.Messages; messages.messagesSlice#3a54685e flags:# inexact:flags.1?true count:int next_rate:flags.0?int offset_id_offset:flags.2?int messages:Vector chats:Vector users:Vector = messages.Messages; -messages.channelMessages#64479808 flags:# inexact:flags.1?true pts:int count:int offset_id_offset:flags.2?int messages:Vector chats:Vector users:Vector = messages.Messages; +messages.channelMessages#c776ba4e flags:# inexact:flags.1?true pts:int count:int offset_id_offset:flags.2?int messages:Vector topics:Vector chats:Vector users:Vector = messages.Messages; messages.messagesNotModified#74535f21 count:int = messages.Messages; messages.chats#64ff9fd5 chats:Vector = messages.Chats; @@ -401,7 +401,8 @@ updateRecentEmojiStatuses#30f443db = Update; updateRecentReactions#6f7863f4 = Update; updateMoveStickerSetToTop#86fccf85 flags:# masks:flags.0?true emojis:flags.1?true stickerset:long = Update; updateMessageExtendedMedia#5a73a98c peer:Peer msg_id:int extended_media:MessageExtendedMedia = Update; -updateChannelPinnedTopic#f694b0ae flags:# channel_id:long topic_id:flags.0?int = Update; +updateChannelPinnedTopic#192efbe3 flags:# pinned:flags.0?true channel_id:long topic_id:int = Update; +updateChannelPinnedTopics#fe198602 flags:# channel_id:long order:flags.0?Vector = Update; updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State; @@ -1466,7 +1467,7 @@ stickerKeyword#fcfeb29c document_id:long keyword:Vector = StickerKeyword username#b4073647 flags:# editable:flags.0?true active:flags.1?true username:string = Username; forumTopicDeleted#23f109b id:int = ForumTopic; -forumTopic#71701da9 flags:# my:flags.1?true closed:flags.2?true pinned:flags.3?true id:int date:int title:string icon_color:int icon_emoji_id:flags.0?long top_message:int read_inbox_max_id:int read_outbox_max_id:int unread_count:int unread_mentions_count:int unread_reactions_count:int from_id:Peer notify_settings:PeerNotifySettings draft:flags.4?DraftMessage = ForumTopic; +forumTopic#71701da9 flags:# my:flags.1?true closed:flags.2?true pinned:flags.3?true short:flags.5?true id:int date:int title:string icon_color:int icon_emoji_id:flags.0?long top_message:int read_inbox_max_id:int read_outbox_max_id:int unread_count:int unread_mentions_count:int unread_reactions_count:int from_id:Peer notify_settings:PeerNotifySettings draft:flags.4?DraftMessage = ForumTopic; messages.forumTopics#367617d3 flags:# order_by_create_date:flags.0?true count:int topics:Vector messages:Vector chats:Vector users:Vector pts:int = messages.ForumTopics; @@ -1880,6 +1881,7 @@ channels.getForumTopicsByID#b0831eb9 channel:InputChannel topics:Vector = m channels.editForumTopic#6c883e2d flags:# channel:InputChannel topic_id:int title:flags.0?string icon_emoji_id:flags.1?long closed:flags.2?Bool = Updates; channels.updatePinnedForumTopic#6c2d9026 channel:InputChannel topic_id:int pinned:Bool = Updates; channels.deleteTopicHistory#34435f2d channel:InputChannel top_msg_id:int = messages.AffectedHistory; +channels.reorderPinnedForumTopics#2950a18f flags:# force:flags.0?true channel:InputChannel order:Vector = Updates; bots.sendCustomRequest#aa2769ed custom_method:string params:DataJSON = DataJSON; bots.answerWebhookJSONQuery#e6213f4d query_id:long data:DataJSON = Bool; @@ -1958,4 +1960,4 @@ stats.getMegagroupStats#dcdf8607 flags:# dark:flags.0?true channel:InputChannel stats.getMessagePublicForwards#5630281b channel:InputChannel msg_id:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages; stats.getMessageStats#b6e0a3f5 flags:# dark:flags.0?true channel:InputChannel msg_id:int = stats.MessageStats; -// LAYER 148 +// LAYER 149 diff --git a/Telegram/SourceFiles/api/api_updates.cpp b/Telegram/SourceFiles/api/api_updates.cpp index 27804c4cf..b7ed8477e 100644 --- a/Telegram/SourceFiles/api/api_updates.cpp +++ b/Telegram/SourceFiles/api/api_updates.cpp @@ -2297,19 +2297,19 @@ void Updates::feedUpdate(const MTPUpdate &update) { const auto &d = update.c_updateChannelPinnedTopic(); const auto peerId = peerFromChannel(d.vchannel_id()); if (const auto peer = session().data().peerLoaded(peerId)) { - const auto rootId = d.vtopic_id().value_or_empty(); + const auto rootId = d.vtopic_id().v; if (const auto topic = peer->forumTopicFor(rootId)) { - session().data().setChatPinned(topic, 0, true); + session().data().setChatPinned(topic, 0, d.is_pinned()); } else if (const auto forum = peer->forum()) { - if (rootId) { - forum->requestTopic(rootId); - } else { - forum->unpinTopic(); - } + forum->requestTopic(rootId); } } } break; + case mtpc_updateChannelPinnedTopics: { + const auto &d = update.c_updateChannelPinnedTopics(); + } break; + // Pinned message. case mtpc_updatePinnedMessages: { const auto &d = update.c_updatePinnedMessages(); diff --git a/Telegram/SourceFiles/data/data_forum.cpp b/Telegram/SourceFiles/data/data_forum.cpp index 60518864d..8e3230cad 100644 --- a/Telegram/SourceFiles/data/data_forum.cpp +++ b/Telegram/SourceFiles/data/data_forum.cpp @@ -37,13 +37,14 @@ constexpr auto kTopicsFirstLoad = 20; constexpr auto kLoadedTopicsMinCount = 20; constexpr auto kTopicsPerPage = 500; constexpr auto kStalePerRequest = 100; +constexpr auto kPinnedLimit = 5; // constexpr auto kGeneralColorId = 0xA9A9A9; } // namespace Forum::Forum(not_null history) : _history(history) -, _topicsList(&session(), FilterId(0), rpl::single(1)) { +, _topicsList(&session(), FilterId(0), rpl::single(kPinnedLimit)) { Expects(_history->peer->isChannel()); if (_history->inChatList()) { @@ -95,13 +96,6 @@ not_null Forum::topicsList() { return &_topicsList; } -void Forum::unpinTopic() { - const auto list = _topicsList.pinned(); - while (!list->order().empty()) { - list->setPinned(list->order().front(), false); - } -} - rpl::producer<> Forum::destroyed() const { return channel()->flagsValue( ) | rpl::filter([=](const ChannelData::Flags::Change &update) { @@ -147,9 +141,12 @@ void Forum::requestTopics() { MTP_int(_offset.topicId), MTP_int(loadCount) )).done([=](const MTPmessages_ForumTopics &result) { + const auto previousOffset = _offset; applyReceivedTopics(result, _offset); const auto &list = result.data().vtopics().v; - if (list.isEmpty() || list.size() == result.data().vcount().v) { + if (list.isEmpty() + || list.size() == result.data().vcount().v + || (_offset == previousOffset)) { _topicsList.setLoaded(); } _requestId = 0; diff --git a/Telegram/SourceFiles/data/data_forum.h b/Telegram/SourceFiles/data/data_forum.h index 6d0a141a8..89477c931 100644 --- a/Telegram/SourceFiles/data/data_forum.h +++ b/Telegram/SourceFiles/data/data_forum.h @@ -53,7 +53,6 @@ public: void requestTopics(); [[nodiscard]] rpl::producer<> chatsListChanges() const; [[nodiscard]] rpl::producer<> chatsListLoadedEvents() const; - void unpinTopic(); void requestTopic(MsgId rootId, Fn done = nullptr); ForumTopic *applyTopicAdded( diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 440faa9d6..1f3214bfb 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -1921,9 +1921,6 @@ void Session::setChatPinned( const auto list = (filterId ? chatsFilters().chatsList(filterId) : chatsListFor(key.entry()))->pinned(); - if (const auto topic = key.topic()) { - topic->forum()->unpinTopic(); - } list->setPinned(key, pinned); notifyPinnedDialogsOrderUpdated(); }