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