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
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
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
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
This commit is contained in:
76
Telegram/SourceFiles/api/api_single_message_search.h
Normal file
76
Telegram/SourceFiles/api/api_single_message_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 {
|
||||
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<Main::Session*> session);
|
||||
~SingleMessageSearch();
|
||||
|
||||
void clear();
|
||||
|
||||
// If 'ready' callback is empty, the result must not be 'nullopt'.
|
||||
[[nodiscard]] std::optional<HistoryItem*> lookup(
|
||||
const QString &query,
|
||||
Fn<void()> ready = nullptr);
|
||||
|
||||
private:
|
||||
using Key = details::SingleMessageSearchKey;
|
||||
|
||||
[[nodiscard]] std::optional<HistoryItem*> performLookup(
|
||||
Fn<void()> ready);
|
||||
[[nodiscard]] std::optional<HistoryItem*> performLookupById(
|
||||
ChannelId channelId,
|
||||
Fn<void()> ready);
|
||||
[[nodiscard]] std::optional<HistoryItem*> performLookupByUsername(
|
||||
const QString &username,
|
||||
Fn<void()> ready);
|
||||
[[nodiscard]] std::optional<HistoryItem*> performLookupByChannel(
|
||||
not_null<ChannelData*> channel,
|
||||
Fn<void()> ready);
|
||||
|
||||
const not_null<Main::Session*> _session;
|
||||
std::map<Key, FullMsgId> _cache;
|
||||
mtpRequestId _requestId = 0;
|
||||
Key _requestKey;
|
||||
|
||||
};
|
||||
|
||||
[[nodiscard]] QString ConvertPeerSearchQuery(const QString &query);
|
||||
|
||||
} // namespace Api
|
||||
Reference in New Issue
Block a user