diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 377b3df98..4cc8c5e76 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -47,6 +47,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/file_utilities.h" #include "main/main_session.h" #include "data/data_session.h" +#include "data/data_document.h" #include "data/data_user.h" #include "data/data_chat.h" #include "data/data_channel.h" @@ -486,7 +487,20 @@ void RepliesWidget::setupComposeControls() { _composeControls->inlineResultChosen( ) | rpl::start_with_next([=](Selector::InlineChosen chosen) { - sendInlineResult(chosen.result, chosen.bot, chosen.options); + if (chosen.sendPreview) { + const auto request = chosen.result->openRequest(); + if (const auto photo = request.photo()) { + sendExistingPhoto(photo, chosen.options); + } else if (const auto document = request.document()) { + sendExistingDocument(document, chosen.options); + } + + addRecentBot(chosen.bot); + _composeControls->clear(); + finishSending(); + } else { + sendInlineResult(chosen.result, chosen.bot, chosen.options); + } }, lifetime()); _composeControls->scrollRequests( @@ -855,6 +869,20 @@ bool RepliesWidget::showSendingFilesError( return true; } +void RepliesWidget::addRecentBot(not_null bot) { + auto &bots = cRefRecentInlineBots(); + const auto index = bots.indexOf(bot); + if (index) { + if (index > 0) { + bots.removeAt(index); + } else if (bots.size() >= RecentInlineBotsLimit) { + bots.resize(RecentInlineBotsLimit - 1); + } + bots.push_front(bot); + bot->session().local().writeRecentHashtagsAndBots(); + } +} + void RepliesWidget::send() { if (_composeControls->getTextWithAppliedMarkdown().text.isEmpty()) { return; @@ -1025,7 +1053,12 @@ bool RepliesWidget::sendExistingDocument( auto message = Api::MessageToSend(_history); message.action.replyTo = replyToId(); message.action.options = options; - Api::SendExistingDocument(std::move(message), document); + + if (document->hasRemoteLocation()) { + Api::SendExistingDocument(std::move(message), document); + } else { + Api::SendWebDocument(std::move(message), document); + } _composeControls->cancelReplyMessage(); finishSending(); @@ -1100,17 +1133,7 @@ void RepliesWidget::sendInlineResult( //_saveDraftStart = crl::now(); //onDraftSave(); - auto &bots = cRefRecentInlineBots(); - const auto index = bots.indexOf(bot); - if (index) { - if (index > 0) { - bots.removeAt(index); - } else if (bots.size() >= RecentInlineBotsLimit) { - bots.resize(RecentInlineBotsLimit - 1); - } - bots.push_front(bot); - bot->session().local().writeRecentHashtagsAndBots(); - } + addRecentBot(bot); finishSending(); } diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.h b/Telegram/SourceFiles/history/view/history_view_replies_section.h index f3a329b9c..d451dba1e 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.h +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.h @@ -183,6 +183,8 @@ private: void clearSelected(); void setPinnedVisibility(bool shown); + void addRecentBot(not_null bot); + void send(); void send(Api::SendOptions options); void sendVoice(Controls::VoiceToSend &&data); diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index 93a01a828..3a3b1a975 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -229,7 +229,21 @@ void ScheduledWidget::setupComposeControls() { _composeControls->inlineResultChosen( ) | rpl::start_with_next([=](Selector::InlineChosen chosen) { - sendInlineResult(chosen.result, chosen.bot); + if (chosen.sendPreview) { + const auto request = chosen.result->openRequest(); + if (const auto photo = request.photo()) { + sendExistingPhoto(photo); + } else if (const auto document = request.document()) { + sendExistingDocument(document); + } + + addRecentBot(chosen.bot); + _composeControls->clear(); + _composeControls->hidePanelsAnimated(); + _composeControls->focus(); + } else { + sendInlineResult(chosen.result, chosen.bot); + } }, lifetime()); _composeControls->scrollRequests( @@ -494,6 +508,20 @@ bool ScheduledWidget::showSendingFilesError( return true; } +void ScheduledWidget::addRecentBot(not_null bot) { + auto &bots = cRefRecentInlineBots(); + const auto index = bots.indexOf(bot); + if (index) { + if (index > 0) { + bots.removeAt(index); + } else if (bots.size() >= RecentInlineBotsLimit) { + bots.resize(RecentInlineBotsLimit - 1); + } + bots.push_front(bot); + bot->session().local().writeRecentHashtagsAndBots(); + } +} + void ScheduledWidget::send() { if (_composeControls->getTextWithAppliedMarkdown().text.isEmpty()) { return; @@ -729,17 +757,7 @@ void ScheduledWidget::sendInlineResult( //_saveDraftStart = crl::now(); //onDraftSave(); - auto &bots = cRefRecentInlineBots(); - const auto index = bots.indexOf(bot); - if (index) { - if (index > 0) { - bots.removeAt(index); - } else if (bots.size() >= RecentInlineBotsLimit) { - bots.resize(RecentInlineBotsLimit - 1); - } - bots.push_front(bot); - bot->session().local().writeRecentHashtagsAndBots(); - } + addRecentBot(bot); _composeControls->hidePanelsAnimated(); _composeControls->focus(); diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.h b/Telegram/SourceFiles/history/view/history_view_scheduled_section.h index 28f2c3fea..c63928234 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.h +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.h @@ -149,6 +149,8 @@ private: void confirmDeleteSelected(); void clearSelected(); + void addRecentBot(not_null bot); + void send(); void send(Api::SendOptions options); void sendVoice(QByteArray bytes, VoiceWaveform waveform, int duration);