/* 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 namespace Main { class Session; } // namespace Main namespace Api { namespace details { struct SingleMessageSearchKey { QString domainOrId; MsgId postId = 0; [[nodiscard]] bool empty() const { return domainOrId.isEmpty() || !postId; } [[nodiscard]] explicit operator bool() const { return !empty(); } [[nodiscard]] bool operator<(const SingleMessageSearchKey &other) const { return std::tie(domainOrId, postId) < std::tie(other.domainOrId, other.postId); } [[nodiscard]] bool operator==( const SingleMessageSearchKey &other) const { return std::tie(domainOrId, postId) == std::tie(other.domainOrId, other.postId); } }; } // namespace details class SingleMessageSearch { public: explicit SingleMessageSearch(not_null session); ~SingleMessageSearch(); void clear(); // If 'ready' callback is empty, the result must not be 'nullopt'. [[nodiscard]] std::optional lookup( const QString &query, Fn ready = nullptr); private: using Key = details::SingleMessageSearchKey; [[nodiscard]] std::optional performLookup( Fn ready); [[nodiscard]] std::optional performLookupById( ChannelId channelId, Fn ready); [[nodiscard]] std::optional performLookupByUsername( const QString &username, Fn ready); [[nodiscard]] std::optional performLookupByChannel( not_null channel, Fn ready); const not_null _session; std::map _cache; mtpRequestId _requestId = 0; Key _requestKey; }; [[nodiscard]] QString ConvertPeerSearchQuery(const QString &query); } // namespace Api