mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Support tags in ComposeSearch.
This commit is contained in:
@@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "apiwrap.h"
|
||||
#include "data/data_channel.h"
|
||||
#include "data/data_histories.h"
|
||||
#include "data/data_message_reaction_id.h"
|
||||
#include "data/data_peer.h"
|
||||
#include "data/data_session.h"
|
||||
#include "history/history.h"
|
||||
@@ -43,6 +44,23 @@ constexpr auto kSearchPerPage = 50;
|
||||
return result;
|
||||
}
|
||||
|
||||
[[nodiscard]] QString RequestToToken(
|
||||
const MessagesSearch::Request &request) {
|
||||
auto result = request.query;
|
||||
if (request.from) {
|
||||
result += '\n' + QString::number(request.from->id.value);
|
||||
}
|
||||
for (const auto &tag : request.tags) {
|
||||
result += '\n';
|
||||
if (const auto customId = tag.custom()) {
|
||||
result += u"custom"_q + QString::number(customId);
|
||||
} else {
|
||||
result += u"emoji"_q + tag.emoji();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
MessagesSearch::MessagesSearch(not_null<History*> history)
|
||||
@@ -54,9 +72,8 @@ MessagesSearch::~MessagesSearch() {
|
||||
base::take(_searchInHistoryRequest));
|
||||
}
|
||||
|
||||
void MessagesSearch::searchMessages(const QString &query, PeerData *from) {
|
||||
_query = query;
|
||||
_from = from;
|
||||
void MessagesSearch::searchMessages(Request request) {
|
||||
_request = std::move(request);
|
||||
_offsetId = {};
|
||||
searchRequest();
|
||||
}
|
||||
@@ -69,8 +86,7 @@ void MessagesSearch::searchMore() {
|
||||
}
|
||||
|
||||
void MessagesSearch::searchRequest() {
|
||||
const auto nextToken = _query
|
||||
+ QString::number(_from ? _from->id.value : 0);
|
||||
const auto nextToken = RequestToToken(_request);
|
||||
if (!_offsetId) {
|
||||
const auto it = _cacheOfStartByToken.find(nextToken);
|
||||
if (it != end(_cacheOfStartByToken)) {
|
||||
@@ -80,18 +96,21 @@ void MessagesSearch::searchRequest() {
|
||||
}
|
||||
}
|
||||
auto callback = [=](Fn<void()> finish) {
|
||||
const auto flags = _from
|
||||
? MTP_flags(MTPmessages_Search::Flag::f_from_id)
|
||||
: MTP_flags(0);
|
||||
using Flag = MTPmessages_Search::Flag;
|
||||
const auto from = _request.from;
|
||||
const auto fromPeer = _history->peer->isUser() ? nullptr : from;
|
||||
const auto savedPeer = _history->peer->isSelf() ? from : nullptr;
|
||||
_requestId = _history->session().api().request(MTPmessages_Search(
|
||||
flags,
|
||||
MTP_flags((fromPeer ? Flag::f_from_id : Flag())
|
||||
| (savedPeer ? Flag::f_saved_peer_id : Flag())
|
||||
| (_request.tags.empty() ? Flag() : Flag::f_saved_reaction)),
|
||||
_history->peer->input,
|
||||
MTP_string(_query),
|
||||
(_from
|
||||
? _from->input
|
||||
: MTP_inputPeerEmpty()),
|
||||
MTPInputPeer(), // saved_peer_id
|
||||
MTPVector<MTPReaction>(), // saved_reaction
|
||||
MTP_string(_request.query),
|
||||
(fromPeer ? fromPeer->input : MTP_inputPeerEmpty()),
|
||||
(savedPeer ? savedPeer->input : MTP_inputPeerEmpty()),
|
||||
MTP_vector_from_range(_request.tags | ranges::views::transform(
|
||||
Data::ReactionToMTP
|
||||
)),
|
||||
MTPint(), // top_msg_id
|
||||
MTP_inputMessagesFilterEmpty(),
|
||||
MTP_int(0), // min_date
|
||||
|
@@ -7,10 +7,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "base/qt/qt_compare.h"
|
||||
#include "data/data_message_reaction_id.h"
|
||||
|
||||
class HistoryItem;
|
||||
class History;
|
||||
class PeerData;
|
||||
|
||||
namespace Data {
|
||||
struct ReactionId;
|
||||
} // namespace Data
|
||||
|
||||
namespace Api {
|
||||
|
||||
struct FoundMessages {
|
||||
@@ -21,10 +28,23 @@ struct FoundMessages {
|
||||
|
||||
class MessagesSearch final {
|
||||
public:
|
||||
struct Request {
|
||||
QString query;
|
||||
PeerData *from = nullptr;
|
||||
std::vector<Data::ReactionId> tags;
|
||||
|
||||
friend inline bool operator==(
|
||||
const Request &,
|
||||
const Request &) = default;
|
||||
friend inline auto operator<=>(
|
||||
const Request &,
|
||||
const Request &) = default;
|
||||
};
|
||||
|
||||
explicit MessagesSearch(not_null<History*> history);
|
||||
~MessagesSearch();
|
||||
|
||||
void searchMessages(const QString &query, PeerData *from);
|
||||
void searchMessages(Request request);
|
||||
void searchMore();
|
||||
|
||||
[[nodiscard]] rpl::producer<FoundMessages> messagesFounds() const;
|
||||
@@ -41,8 +61,7 @@ private:
|
||||
|
||||
base::flat_map<QString, TLMessages> _cacheOfStartByToken;
|
||||
|
||||
QString _query;
|
||||
PeerData *_from = nullptr;
|
||||
Request _request;
|
||||
MsgId _offsetId;
|
||||
|
||||
int _searchInHistoryRequest = 0; // Not real mtpRequestId.
|
||||
|
@@ -11,12 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
namespace Api {
|
||||
|
||||
bool MessagesSearchMerged::RequestCompare::operator()(
|
||||
const Request &a,
|
||||
const Request &b) const {
|
||||
return (a.query < b.query) && (a.from < b.from);
|
||||
}
|
||||
|
||||
MessagesSearchMerged::MessagesSearchMerged(not_null<History*> history)
|
||||
: _apiSearch(history) {
|
||||
if (const auto migrated = history->migrateFrom()) {
|
||||
@@ -88,9 +82,9 @@ void MessagesSearchMerged::clear() {
|
||||
void MessagesSearchMerged::search(const Request &search) {
|
||||
if (_migratedSearch) {
|
||||
_waitingForTotal = true;
|
||||
_migratedSearch->searchMessages(search.query, search.from);
|
||||
_migratedSearch->searchMessages(search);
|
||||
}
|
||||
_apiSearch.searchMessages(search.query, search.from);
|
||||
_apiSearch.searchMessages(search);
|
||||
}
|
||||
|
||||
void MessagesSearchMerged::searchMore() {
|
||||
|
@@ -12,19 +12,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
class History;
|
||||
class PeerData;
|
||||
|
||||
namespace Data {
|
||||
struct ReactionId;
|
||||
} // namespace Data
|
||||
|
||||
namespace Api {
|
||||
|
||||
// Search in both of history and migrated history, if it exists.
|
||||
class MessagesSearchMerged final {
|
||||
public:
|
||||
struct Request {
|
||||
QString query;
|
||||
PeerData *from = nullptr;
|
||||
};
|
||||
struct RequestCompare {
|
||||
bool operator()(const Request &a, const Request &b) const;
|
||||
};
|
||||
using CachedRequests = std::set<Request, RequestCompare>;
|
||||
using Request = MessagesSearch::Request;
|
||||
using CachedRequests = base::flat_set<Request>;
|
||||
|
||||
MessagesSearchMerged(not_null<History*> history);
|
||||
|
||||
|
Reference in New Issue
Block a user