api_messages_search_merged.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "api/api_messages_search.h"
  9. class History;
  10. class PeerData;
  11. namespace Data {
  12. struct ReactionId;
  13. } // namespace Data
  14. namespace Api {
  15. // Search in both of history and migrated history, if it exists.
  16. class MessagesSearchMerged final {
  17. public:
  18. using Request = MessagesSearch::Request;
  19. using CachedRequests = base::flat_set<Request>;
  20. MessagesSearchMerged(not_null<History*> history);
  21. void clear();
  22. void search(const Request &search);
  23. void searchMore();
  24. void disableMigrated();
  25. [[nodiscard]] const FoundMessages &messages() const;
  26. [[nodiscard]] const Request &request() const;
  27. [[nodiscard]] rpl::producer<> newFounds() const;
  28. [[nodiscard]] rpl::producer<> nextFounds() const;
  29. private:
  30. void addFound(const FoundMessages &data);
  31. MessagesSearch _apiSearch;
  32. Request _request;
  33. std::optional<MessagesSearch> _migratedSearch;
  34. FoundMessages _migratedFirstFound;
  35. FoundMessages _concatedFound;
  36. bool _waitingForTotal = false;
  37. bool _isFull = false;
  38. rpl::event_stream<> _newFounds;
  39. rpl::event_stream<> _nextFounds;
  40. rpl::lifetime _lifetime;
  41. };
  42. } // namespace Api