mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-01 03:50:43 +00:00
Fix crash in MessagesSearch requests.
This commit is contained in:
parent
0a7e25e45a
commit
9f2683a35b
@ -17,10 +17,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "main/main_session.h"
|
||||
|
||||
namespace Api {
|
||||
|
||||
namespace {
|
||||
|
||||
MessageIdsList HistoryItemsFromTL(
|
||||
[[nodiscard]] MessageIdsList HistoryItemsFromTL(
|
||||
not_null<Data::Session*> data,
|
||||
const QVector<MTPMessage> &messages) {
|
||||
auto result = MessageIdsList();
|
||||
@ -45,8 +44,12 @@ MessageIdsList HistoryItemsFromTL(
|
||||
} // namespace
|
||||
|
||||
MessagesSearch::MessagesSearch(not_null<History*> history)
|
||||
: _history(history)
|
||||
, _api(&history->session().mtp()) {
|
||||
: _history(history) {
|
||||
}
|
||||
|
||||
MessagesSearch::~MessagesSearch() {
|
||||
_history->owner().histories().cancelRequest(
|
||||
base::take(_searchInHistoryRequest));
|
||||
}
|
||||
|
||||
void MessagesSearch::searchMessages(const QString &query, PeerData *from) {
|
||||
@ -78,7 +81,7 @@ void MessagesSearch::searchRequest() {
|
||||
const auto flags = _from
|
||||
? MTP_flags(MTPmessages_Search::Flag::f_from_id)
|
||||
: MTP_flags(0);
|
||||
_requestId = _api.request(MTPmessages_Search(
|
||||
_requestId = _history->session().api().request(MTPmessages_Search(
|
||||
flags,
|
||||
_history->peer->input,
|
||||
MTP_string(_query),
|
||||
@ -102,10 +105,11 @@ void MessagesSearch::searchRequest() {
|
||||
}).fail([=](const MTP::Error &error, mtpRequestId id) {
|
||||
_searchInHistoryRequest = 0;
|
||||
|
||||
if (_requestId == id) {
|
||||
_requestId = 0;
|
||||
}
|
||||
if (error.type() == u"SEARCH_QUERY_EMPTY"_q) {
|
||||
_messagesFounds.fire({ 0, MessageIdsList(), nextToken });
|
||||
} else if (_requestId == id) {
|
||||
_requestId = 0;
|
||||
}
|
||||
|
||||
finish();
|
||||
|
@ -7,8 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "mtproto/sender.h"
|
||||
|
||||
class HistoryItem;
|
||||
class History;
|
||||
class PeerData;
|
||||
@ -24,6 +22,7 @@ struct FoundMessages {
|
||||
class MessagesSearch final {
|
||||
public:
|
||||
explicit MessagesSearch(not_null<History*> history);
|
||||
~MessagesSearch();
|
||||
|
||||
void searchMessages(const QString &query, PeerData *from);
|
||||
void searchMore();
|
||||
@ -39,7 +38,6 @@ private:
|
||||
const QString &nextToken);
|
||||
|
||||
const not_null<History*> _history;
|
||||
MTP::Sender _api;
|
||||
|
||||
base::flat_map<QString, TLMessages> _cacheOfStartByToken;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user