init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
This commit is contained in:
76
Telegram/SourceFiles/api/api_peer_search.h
Normal file
76
Telegram/SourceFiles/api/api_peer_search.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
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 {
|
||||
|
||||
struct SponsoredSearchResult {
|
||||
not_null<PeerData*> peer;
|
||||
QByteArray randomId;
|
||||
TextWithEntities sponsorInfo;
|
||||
TextWithEntities additionalInfo;
|
||||
};
|
||||
|
||||
struct PeerSearchResult {
|
||||
QString query;
|
||||
std::vector<not_null<PeerData*>> my;
|
||||
std::vector<not_null<PeerData*>> peers;
|
||||
std::vector<SponsoredSearchResult> sponsored;
|
||||
};
|
||||
|
||||
class PeerSearch final {
|
||||
public:
|
||||
enum class Type {
|
||||
WithSponsored,
|
||||
JustPeers,
|
||||
};
|
||||
PeerSearch(not_null<Main::Session*> session, Type type);
|
||||
~PeerSearch();
|
||||
|
||||
enum class RequestType {
|
||||
CacheOnly,
|
||||
CacheOrRemote,
|
||||
};
|
||||
void request(
|
||||
const QString &query,
|
||||
Fn<void(PeerSearchResult)> callback,
|
||||
RequestType type = RequestType::CacheOrRemote);
|
||||
void clear();
|
||||
|
||||
private:
|
||||
struct CacheEntry {
|
||||
PeerSearchResult result;
|
||||
bool requested = false;
|
||||
bool peersReady = false;
|
||||
bool sponsoredReady = false;
|
||||
};
|
||||
|
||||
void requestPeers();
|
||||
void requestSponsored();
|
||||
|
||||
void finish(PeerSearchResult result);
|
||||
void finishPeers(mtpRequestId requestId, PeerSearchResult result);
|
||||
void finishSponsored(mtpRequestId requestId, PeerSearchResult result);
|
||||
|
||||
const not_null<Main::Session*> _session;
|
||||
const Type _type;
|
||||
|
||||
QString _query;
|
||||
Fn<void(PeerSearchResult)> _callback;
|
||||
|
||||
base::flat_map<QString, CacheEntry> _cache;
|
||||
base::flat_map<mtpRequestId, QString> _peerRequests;
|
||||
base::flat_map<mtpRequestId, QString> _sponsoredRequests;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Api
|
||||
Reference in New Issue
Block a user