/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once #include "base/timer.h" #include "dialogs/ui/posts_search_intro.h" #include "mtproto/sender.h" namespace Main { class Session; } // namespace Main namespace Dialogs { struct PostsSearchState { std::optional intro; std::vector> first; int totalCount = 0; bool loading = false; }; class PostsSearch final { public: explicit PostsSearch(not_null session); [[nodiscard]] rpl::producer stateUpdates() const; void setQuery(const QString &query); int setAllowedStars(int stars); void requestMore(); private: struct Entry { std::vector>> pages; int totalCount = 0; mtpRequestId searchId = 0; mtpRequestId checkId = 0; PeerData *offsetPeer = nullptr; MsgId offsetId = 0; int offsetRate = 0; int allowedStars = 0; bool loaded = false; }; void recheck(); void applyQuery(); void requestSearch(const QString &query); void requestState(const QString &query, bool force = false); void setFloodStateFrom(const MTPDsearchPostsFlood &data); void pushStateUpdate(const Entry &entry); void maybePushPremiumUpdate(); const not_null _session; MTP::Sender _api; base::Timer _timer; base::Timer _recheckTimer; base::flat_map _entries; std::optional _query; std::optional _floodState; rpl::event_stream _stateUpdates; rpl::lifetime _lifetime; }; } // namespace Dialogs