From 3403b3c47165952b91ef81dd243b958fbdf21a27 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 14 May 2022 20:12:58 +0300 Subject: [PATCH] Removed methods with MTP signature from compose controls. --- .../history_view_compose_controls.cpp | 128 ++++++++---------- .../controls/history_view_compose_controls.h | 3 - 2 files changed, 56 insertions(+), 75 deletions(-) diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index 7483500f85..5e42b6ba3d 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -122,7 +122,6 @@ public: private: void updatePreview(); - void gotPreview(const MTPmessageMedia &result, const QString &links); void getWebPagePreview(); const not_null _history; @@ -243,37 +242,6 @@ void WebpageProcessor::updatePreview() { _paintRequests.fire({}); } -void WebpageProcessor::gotPreview( - const MTPmessageMedia &result, - const QString &links) { - if (_previewRequest) { - _previewRequest = 0; - } - result.match([=](const MTPDmessageMediaWebPage &d) { - const auto page = _history->owner().processWebpage(d.vwebpage()); - _previewCache.insert({ links, page->id }); - auto &till = page->pendingTill; - if (till > 0 && till <= base::unixtime::now()) { - till = -1; - } - if (links == _previewLinks - && _previewState == Data::PreviewState::Allowed) { - _previewData = (page->id && page->pendingTill >= 0) - ? page.get() - : nullptr; - updatePreview(); - } - }, [=](const MTPDmessageMediaEmpty &d) { - _previewCache.insert({ links, 0 }); - if (links == _previewLinks - && _previewState == Data::PreviewState::Allowed) { - _previewData = nullptr; - updatePreview(); - } - }, [](const auto &d) { - }); -} - void WebpageProcessor::getWebPagePreview() { const auto links = _previewLinks; _previewRequest = _api.request( @@ -282,7 +250,32 @@ void WebpageProcessor::getWebPagePreview() { MTP_string(links), MTPVector() )).done([=](const MTPMessageMedia &result) { - gotPreview(result, links); + _previewRequest = 0; + result.match([=](const MTPDmessageMediaWebPage &d) { + const auto page = _history->owner().processWebpage(d.vwebpage()); + _previewCache.insert({ links, page->id }); + auto &till = page->pendingTill; + if (till > 0 && till <= base::unixtime::now()) { + till = -1; + } + if (links == _previewLinks + && _previewState == Data::PreviewState::Allowed) { + _previewData = (page->id && page->pendingTill >= 0) + ? page.get() + : nullptr; + updatePreview(); + } + }, [=](const MTPDmessageMediaEmpty &d) { + _previewCache.insert({ links, 0 }); + if (links == _previewLinks + && _previewState == Data::PreviewState::Allowed) { + _previewData = nullptr; + updatePreview(); + } + }, [](const auto &d) { + }); + }).fail([=] { + _previewRequest = 0; }).send(); } @@ -1899,42 +1892,6 @@ void ComposeControls::initSendAsButton() { }, _wrap->lifetime()); } -void ComposeControls::inlineBotResolveDone( - const MTPcontacts_ResolvedPeer &result) { - Expects(result.type() == mtpc_contacts_resolvedPeer); - - _inlineBotResolveRequestId = 0; - const auto &data = result.c_contacts_resolvedPeer(); - const auto resolvedBot = [&]() -> UserData* { - if (const auto result = session().data().processUsers(data.vusers())) { - if (result->isBot() - && !result->botInfo->inlinePlaceholder.isEmpty()) { - return result; - } - } - return nullptr; - }(); - session().data().processChats(data.vchats()); - - const auto query = ParseInlineBotQuery(&session(), _field); - if (_inlineBotUsername == query.username) { - applyInlineBotQuery( - query.lookingUpBot ? resolvedBot : query.bot, - query.query); - } else { - clearInlineBot(); - } -} - -void ComposeControls::inlineBotResolveFail( - const MTP::Error &error, - const QString &username) { - _inlineBotResolveRequestId = 0; - if (username == _inlineBotUsername) { - clearInlineBot(); - } -} - void ComposeControls::cancelInlineBot() { const auto &textWithTags = _field->getTextWithTags(); if (textWithTags.text.size() > _inlineBotUsername.size() + 2) { @@ -2580,9 +2537,36 @@ void ComposeControls::updateInlineBotQuery() { _inlineBotResolveRequestId = api.request( MTPcontacts_ResolveUsername(MTP_string(username)) ).done([=](const MTPcontacts_ResolvedPeer &result) { - inlineBotResolveDone(result); - }).fail([=](const MTP::Error &error) { - inlineBotResolveFail(error, username); + Expects(result.type() == mtpc_contacts_resolvedPeer); + + const auto &data = result.c_contacts_resolvedPeer(); + const auto resolvedBot = [&]() -> UserData* { + if (const auto user = session().data().processUsers( + data.vusers())) { + if (user->isBot() + && !user->botInfo->inlinePlaceholder.isEmpty()) { + return user; + } + } + return nullptr; + }(); + session().data().processChats(data.vchats()); + + _inlineBotResolveRequestId = 0; + const auto query = ParseInlineBotQuery(&session(), _field); + if (_inlineBotUsername == query.username) { + applyInlineBotQuery( + query.lookingUpBot ? resolvedBot : query.bot, + query.query); + } else { + clearInlineBot(); + } + + }).fail([=] { + _inlineBotResolveRequestId = 0; + if (username == _inlineBotUsername) { + clearInlineBot(); + } }).send(); } else { applyInlineBotQuery(query.bot, query.query); diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h index b3793dc565..87458c08b0 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h @@ -257,9 +257,6 @@ private: // Request to show results in the emoji panel. void applyInlineBotQuery(UserData *bot, const QString &query); - void inlineBotResolveDone(const MTPcontacts_ResolvedPeer &result); - void inlineBotResolveFail(const MTP::Error &error, const QString &username); - [[nodiscard]] Data::DraftKey draftKey( DraftType type = DraftType::Normal) const; [[nodiscard]] Data::DraftKey draftKeyCurrent() const;