Skip to content

Commit

Permalink
Removed methods with MTP signature from compose controls.
Browse files Browse the repository at this point in the history
  • Loading branch information
23rd authored and john-preston committed Jun 14, 2022
1 parent 326304c commit 3403b3c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ class WebpageProcessor final {

private:
void updatePreview();
void gotPreview(const MTPmessageMedia &result, const QString &links);
void getWebPagePreview();

const not_null<History*> _history;
Expand Down Expand Up @@ -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(
Expand All @@ -282,7 +250,32 @@ void WebpageProcessor::getWebPagePreview() {
MTP_string(links),
MTPVector<MTPMessageEntity>()
)).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();
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,6 @@ class ComposeControls final {
// 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;
Expand Down

0 comments on commit 3403b3c

Please sign in to comment.