From cf6ca3b1ac945f957584387eea5b4c833b5233c5 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 10 Nov 2020 19:38:21 +0300 Subject: [PATCH] Handle bot command clicks in Replies / Scheduled. --- .../SourceFiles/core/click_handler_types.cpp | 16 ++---- .../SourceFiles/core/click_handler_types.h | 26 ++++------ .../SourceFiles/core/local_url_handlers.cpp | 13 ++--- Telegram/SourceFiles/core/ui_integration.cpp | 4 +- Telegram/SourceFiles/core/ui_integration.h | 17 ++++--- .../admin_log/history_admin_log_inner.cpp | 5 ++ .../admin_log/history_admin_log_inner.h | 3 ++ .../history/history_inner_widget.cpp | 35 ++++++++++++- .../history/history_inner_widget.h | 3 ++ .../SourceFiles/history/history_message.cpp | 2 +- .../SourceFiles/history/history_widget.cpp | 12 ++--- .../history/view/history_view_element.cpp | 5 ++ .../history/view/history_view_element.h | 6 +++ .../history/view/history_view_list_widget.cpp | 49 ++++++++++++++++++- .../history/view/history_view_list_widget.h | 15 ++++++ .../view/history_view_pinned_section.cpp | 5 ++ .../view/history_view_pinned_section.h | 3 ++ .../view/history_view_replies_section.cpp | 18 +++++-- .../view/history_view_replies_section.h | 3 ++ .../view/history_view_scheduled_section.cpp | 25 ++++++---- .../view/history_view_scheduled_section.h | 3 ++ .../history/view/media/history_view_game.cpp | 4 +- .../history/view/media/history_view_media.cpp | 2 +- .../view/media/history_view_web_page.cpp | 7 +-- .../media/view/media_view_overlay_widget.cpp | 2 +- 25 files changed, 210 insertions(+), 73 deletions(-) diff --git a/Telegram/SourceFiles/core/click_handler_types.cpp b/Telegram/SourceFiles/core/click_handler_types.cpp index 793ea5ae94..38a16c4b70 100644 --- a/Telegram/SourceFiles/core/click_handler_types.cpp +++ b/Telegram/SourceFiles/core/click_handler_types.cpp @@ -180,20 +180,14 @@ auto CashtagClickHandler::getTextEntity() const -> TextEntity { return { EntityType::Cashtag }; } -PeerData *BotCommandClickHandler::_peer = nullptr; -UserData *BotCommandClickHandler::_bot = nullptr; void BotCommandClickHandler::onClick(ClickContext context) const { const auto button = context.button; if (button == Qt::LeftButton || button == Qt::MiddleButton) { - if (auto peer = peerForCommand()) { - if (auto bot = peer->isUser() ? peer->asUser() : botForCommand()) { - Ui::showPeerHistory(peer, ShowAtTheEndMsgId); - App::sendBotCommand(peer, bot, _cmd); - return; - } - } - - if (auto peer = Ui::getPeerForMouseAction()) { // old way + const auto my = context.other.value(); + if (const auto delegate = my.elementDelegate ? my.elementDelegate() : nullptr) { + delegate->elementSendBotCommand(_cmd, my.itemId); + return; + } else if (auto peer = Ui::getPeerForMouseAction()) { // old way auto bot = peer->isUser() ? peer->asUser() : nullptr; if (!bot) { if (const auto view = App::hoveredLinkItem()) { diff --git a/Telegram/SourceFiles/core/click_handler_types.h b/Telegram/SourceFiles/core/click_handler_types.h index bed3a6becc..152b45076c 100644 --- a/Telegram/SourceFiles/core/click_handler_types.h +++ b/Telegram/SourceFiles/core/click_handler_types.h @@ -13,8 +13,18 @@ namespace Main { class Session; } // namespace Main +namespace HistoryView { +class ElementDelegate; +} // namespace HistoryView + [[nodiscard]] bool UrlRequiresConfirmation(const QUrl &url); +struct ClickHandlerContext { + FullMsgId itemId; + Fn elementDelegate; +}; +Q_DECLARE_METATYPE(ClickHandlerContext); + class HiddenUrlClickHandler : public UrlClickHandler { public: HiddenUrlClickHandler(QString url) : UrlClickHandler(url, false) { @@ -165,30 +175,14 @@ public: return _cmd; } - static void setPeerForCommand(PeerData *peer) { - _peer = peer; - } - static void setBotForCommand(UserData *bot) { - _bot = bot; - } - TextEntity getTextEntity() const override; protected: QString url() const override { return _cmd; } - static PeerData *peerForCommand() { - return _peer; - } - static UserData *botForCommand() { - return _bot; - } private: QString _cmd; - static PeerData *_peer; - static UserData *_bot; - }; diff --git a/Telegram/SourceFiles/core/local_url_handlers.cpp b/Telegram/SourceFiles/core/local_url_handlers.cpp index cda4d91412..19af8f2bac 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.cpp +++ b/Telegram/SourceFiles/core/local_url_handlers.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "core/update_checker.h" #include "core/application.h" +#include "core/click_handler_types.h" #include "boxes/confirm_phone_box.h" #include "boxes/background_preview_box.h" #include "boxes/confirm_box.h" @@ -76,11 +77,11 @@ bool ShowTheme( if (!controller) { return false; } - const auto clickFromMessageId = context.value(); + const auto fromMessageId = context.value().itemId; Core::App().hideMediaView(); controller->session().data().cloudThemes().resolve( match->captured(1), - clickFromMessageId); + fromMessageId); return true; } @@ -280,7 +281,7 @@ bool ResolveUsername( startToken = gameParam; post = ShowAtGameShareMsgId; } - const auto clickFromMessageId = context.value(); + const auto fromMessageId = context.value().itemId; using Navigation = Window::SessionNavigation; controller->showPeerByLink(Navigation::PeerByLinkInfo{ .usernameOrId = domain, @@ -295,7 +296,7 @@ bool ResolveUsername( } : Navigation::RepliesByLinkInfo{ v::null }, .startToken = startToken, - .clickFromMessageId = clickFromMessageId, + .clickFromMessageId = fromMessageId, }); return true; } @@ -319,7 +320,7 @@ bool ResolvePrivatePost( if (!channelId || !IsServerMsgId(msgId)) { return false; } - const auto clickFromMessageId = context.value(); + const auto fromMessageId = context.value().itemId; using Navigation = Window::SessionNavigation; controller->showPeerByLink(Navigation::PeerByLinkInfo{ .usernameOrId = channelId, @@ -333,7 +334,7 @@ bool ResolvePrivatePost( Navigation::ThreadId{ threadId } } : Navigation::RepliesByLinkInfo{ v::null }, - .clickFromMessageId = clickFromMessageId, + .clickFromMessageId = fromMessageId, }); return true; } diff --git a/Telegram/SourceFiles/core/ui_integration.cpp b/Telegram/SourceFiles/core/ui_integration.cpp index e707d25894..fec3bdd665 100644 --- a/Telegram/SourceFiles/core/ui_integration.cpp +++ b/Telegram/SourceFiles/core/ui_integration.cpp @@ -65,7 +65,7 @@ QString UiIntegration::timeFormat() { std::shared_ptr UiIntegration::createLinkHandler( const EntityLinkData &data, const std::any &context) { - const auto my = std::any_cast(&context); + const auto my = std::any_cast(&context); switch (data.type) { case EntityType::Url: return (!data.data.isEmpty() @@ -82,6 +82,7 @@ std::shared_ptr UiIntegration::createLinkHandler( return std::make_shared(data.data); case EntityType::Hashtag: + using HashtagMentionType = MarkedTextContext::HashtagMentionType; if (my && my->type == HashtagMentionType::Twitter) { return std::make_shared( (qsl("https://twitter.com/hashtag/") @@ -101,6 +102,7 @@ std::shared_ptr UiIntegration::createLinkHandler( return std::make_shared(data.data); case EntityType::Mention: + using HashtagMentionType = MarkedTextContext::HashtagMentionType; if (my && my->type == HashtagMentionType::Twitter) { return std::make_shared( qsl("https://twitter.com/") + data.data.mid(1), diff --git a/Telegram/SourceFiles/core/ui_integration.h b/Telegram/SourceFiles/core/ui_integration.h index c7367b8026..2aac9a0aa7 100644 --- a/Telegram/SourceFiles/core/ui_integration.h +++ b/Telegram/SourceFiles/core/ui_integration.h @@ -13,20 +13,25 @@ namespace Main { class Session; } // namespace Main +namespace HistoryView { +class ElementDelegate; +} // namespace HistoryView + namespace Core { -class UiIntegration : public Ui::Integration { -public: +struct MarkedTextContext { enum class HashtagMentionType : uchar { Telegram, Twitter, Instagram, }; - struct Context { - Main::Session *session = nullptr; - HashtagMentionType type = HashtagMentionType::Telegram; - }; + Main::Session *session = nullptr; + HashtagMentionType type = HashtagMentionType::Telegram; +}; + +class UiIntegration : public Ui::Integration { +public: void postponeCall(FnMut &&callable) override; void registerLeaveSubscription(not_null widget) override; void unregisterLeaveSubscription(not_null widget) override; diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index 1bb0e1a8a2..9653ecf01b 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -600,6 +600,11 @@ bool InnerWidget::elementShownUnread(not_null view) { return view->data()->unread(); } +void InnerWidget::elementSendBotCommand( + const QString &command, + const FullMsgId &context) { +} + void InnerWidget::saveState(not_null memento) { memento->setFilter(std::move(_filter)); memento->setAdmins(std::move(_admins)); diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h index bf8f97f865..d402460ae6 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h @@ -116,6 +116,9 @@ public: not_null view) override; bool elementShownUnread( not_null view) override; + void elementSendBotCommand( + const QString &command, + const FullMsgId &context) override; ~InnerWidget(); diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index b94c38b6a2..52720fadab 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include "core/file_utilities.h" #include "core/crash_reports.h" +#include "core/click_handler_types.h" #include "history/history.h" #include "history/history_message.h" #include "history/view/media/history_view_media.h" @@ -1330,7 +1331,14 @@ void HistoryInner::mouseActionFinish( : FullMsgId(); ActivateClickHandler(window(), activated, { button, - QVariant::fromValue(pressedItemId) + QVariant::fromValue(ClickHandlerContext{ + .itemId = pressedItemId, + .elementDelegate = [weak = Ui::MakeWeak(this)] { + return weak + ? HistoryInner::ElementDelegate().get() + : nullptr; + }, + }) }); return; } @@ -2540,6 +2548,24 @@ bool HistoryInner::elementIsGifPaused() { return _controller->isGifPausedAtLeastFor(Window::GifPauseReason::Any); } +void HistoryInner::elementSendBotCommand( + const QString &command, + const FullMsgId &context) { + if (auto peer = Ui::getPeerForMouseAction()) { // old way + auto bot = peer->isUser() ? peer->asUser() : nullptr; + if (!bot) { + if (const auto view = App::hoveredLinkItem()) { + // may return nullptr + bot = view->data()->fromOriginal()->asUser(); + } + } + Ui::showPeerHistory(peer, ShowAtTheEndMsgId); + App::sendBotCommand(peer, bot, command); + } else { + App::insertBotCommand(command); + } +} + auto HistoryInner::getSelectionState() const -> HistoryView::TopBarWidget::SelectedState { auto result = HistoryView::TopBarWidget::SelectedState {}; @@ -3434,6 +3460,13 @@ not_null HistoryInner::ElementDelegate() { bool elementShownUnread(not_null view) override { return view->data()->unread(); } + void elementSendBotCommand( + const QString &command, + const FullMsgId &context) { + if (Instance) { + Instance->elementSendBotCommand(command, context); + } + } }; static Result result; diff --git a/Telegram/SourceFiles/history/history_inner_widget.h b/Telegram/SourceFiles/history/history_inner_widget.h index b671f16751..2532568f87 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.h +++ b/Telegram/SourceFiles/history/history_inner_widget.h @@ -92,6 +92,9 @@ public: const TextWithEntities &text, Fn hiddenCallback); bool elementIsGifPaused(); + void elementSendBotCommand( + const QString &command, + const FullMsgId &context); void updateBotInfo(bool recount = true); diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index f11299973a..91f7673fb7 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -1464,7 +1464,7 @@ void HistoryMessage::setText(const TextWithEntities &textWithEntities) { } clearIsolatedEmoji(); - const auto context = Core::UiIntegration::Context{ + const auto context = Core::MarkedTextContext{ .session = &history()->session() }; _text.setMarkedText( diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 07cd555fc0..75bd8b3350 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -3405,15 +3405,9 @@ void HistoryWidget::sendBotCommand( bool lastKeyboardUsed = (_keyboard->forMsgId() == FullMsgId(_channel, _history->lastKeyboardId)) && (_keyboard->forMsgId() == FullMsgId(_channel, replyTo)); - QString toSend = cmd; - if (bot && (!bot->isUser() || !bot->asUser()->isBot())) { - bot = nullptr; - } - QString username = bot ? bot->asUser()->username : QString(); - int32 botStatus = _peer->isChat() ? _peer->asChat()->botStatus : (_peer->isMegagroup() ? _peer->asChannel()->mgInfo->botStatus : -1); - if (!replyTo && toSend.indexOf('@') < 2 && !username.isEmpty() && (botStatus == 0 || botStatus == 2)) { - toSend += '@' + username; - } + const auto toSend = replyTo + ? cmd + : HistoryView::WrapBotCommandInChat(_peer, cmd, bot); auto message = ApiWrap::MessageToSend(_history); message.textWithTags = { toSend, TextWithTags::Tags() }; diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 44b93d0550..471932bd8d 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -121,6 +121,11 @@ bool SimpleElementDelegate::elementShownUnread( return view->data()->unread(); } +void SimpleElementDelegate::elementSendBotCommand( + const QString &command, + const FullMsgId &context) { +} + TextSelection UnshiftItemSelection( TextSelection selection, uint16 byLength) { diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index 8007612402..1f14d0a240 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -67,6 +67,9 @@ public: virtual bool elementIsGifPaused() = 0; virtual bool elementHideReply(not_null view) = 0; virtual bool elementShownUnread(not_null view) = 0; + virtual void elementSendBotCommand( + const QString &command, + const FullMsgId &context) = 0; }; @@ -99,6 +102,9 @@ public: bool elementIsGifPaused() override; bool elementHideReply(not_null view) override; bool elementShownUnread(not_null view) override; + void elementSendBotCommand( + const QString &command, + const FullMsgId &context) override; private: const not_null _controller; diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 65943d1b46..39ebdf2481 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" #include "mainwidget.h" #include "core/application.h" +#include "core/click_handler_types.h" #include "apiwrap.h" #include "layout.h" #include "window/window_session_controller.h" @@ -37,6 +38,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_media_types.h" #include "data/data_document.h" #include "data/data_peer.h" +#include "data/data_user.h" +#include "data/data_chat.h" +#include "data/data_channel.h" #include "facades.h" #include "styles/style_chat.h" @@ -1290,6 +1294,12 @@ bool ListWidget::elementShownUnread(not_null view) { return _delegate->listElementShownUnread(view); } +void ListWidget::elementSendBotCommand( + const QString &command, + const FullMsgId &context) { + return _delegate->listSendBotCommand(command, context); +} + void ListWidget::saveState(not_null memento) { memento->setAroundPosition(_aroundPosition); auto state = countScrollState(); @@ -2186,7 +2196,14 @@ void ListWidget::mouseActionFinish( mouseActionCancel(); ActivateClickHandler(window(), activated, { button, - QVariant::fromValue(pressState.itemId) + QVariant::fromValue(ClickHandlerContext{ + .itemId = pressState.itemId, + .elementDelegate = [weak = Ui::MakeWeak(this)] { + return weak + ? (ElementDelegate*)weak + : nullptr; + }, + }) }); return; } @@ -2786,4 +2803,34 @@ void ConfirmSendNowSelectedItems(not_null widget) { [=] { navigation->showBackFromStack(); }); } +QString WrapBotCommandInChat( + not_null peer, + const QString &command, + const FullMsgId &context) { + auto result = command; + if (const auto item = peer->owner().message(context)) { + if (const auto user = item->fromOriginal()->asUser()) { + return WrapBotCommandInChat(peer, command, user); + } + } + return result; +} + +QString WrapBotCommandInChat( + not_null peer, + const QString &command, + not_null bot) { + if (!bot->isBot() || bot->username.isEmpty()) { + return command; + } + const auto botStatus = peer->isChat() + ? peer->asChat()->botStatus + : peer->isMegagroup() + ? peer->asChannel()->mgInfo->botStatus + : -1; + return ((command.indexOf('@') < 2) && (botStatus == 0 || botStatus == 2)) + ? command + '@' + bot->username + : command; +} + } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index 38ecc163c2..103416658c 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -87,6 +87,9 @@ public: virtual bool listElementShownUnread(not_null view) = 0; virtual bool listIsGoodForAroundPosition( not_null view) = 0; + virtual void listSendBotCommand( + const QString &command, + const FullMsgId &context) = 0; }; @@ -233,6 +236,9 @@ public: bool elementIsGifPaused() override; bool elementHideReply(not_null view) override; bool elementShownUnread(not_null view) override; + void elementSendBotCommand( + const QString &command, + const FullMsgId &context) override; ~ListWidget(); @@ -556,4 +562,13 @@ void ConfirmDeleteSelectedItems(not_null widget); void ConfirmForwardSelectedItems(not_null widget); void ConfirmSendNowSelectedItems(not_null widget); +[[nodiscard]] QString WrapBotCommandInChat( + not_null peer, + const QString &command, + const FullMsgId &context); +[[nodiscard]] QString WrapBotCommandInChat( + not_null peer, + const QString &command, + not_null bot); + } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp index 5b64324ad1..a2902fd39f 100644 --- a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp @@ -639,6 +639,11 @@ bool PinnedWidget::listIsGoodForAroundPosition( return IsServerMsgId(view->data()->id); } +void PinnedWidget::listSendBotCommand( + const QString &command, + const FullMsgId &context) { +} + void PinnedWidget::confirmDeleteSelected() { ConfirmDeleteSelectedItems(_inner); } diff --git a/Telegram/SourceFiles/history/view/history_view_pinned_section.h b/Telegram/SourceFiles/history/view/history_view_pinned_section.h index 8025e2bc4c..bfc8517deb 100644 --- a/Telegram/SourceFiles/history/view/history_view_pinned_section.h +++ b/Telegram/SourceFiles/history/view/history_view_pinned_section.h @@ -93,6 +93,9 @@ public: bool listElementHideReply(not_null view) override; bool listElementShownUnread(not_null view) override; bool listIsGoodForAroundPosition(not_null view) override; + void listSendBotCommand( + const QString &command, + const FullMsgId &context) override; protected: void resizeEvent(QResizeEvent *e) override; diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 9f931c52e2..1d53ed6651 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 "main/main_session.h" #include "data/data_session.h" #include "data/data_user.h" +#include "data/data_chat.h" #include "data/data_channel.h" #include "data/data_replies_list.h" #include "data/data_changes.h" @@ -445,11 +446,7 @@ void RepliesWidget::setupComposeControls() { if (showSlowmodeError()) { return; } - auto message = ApiWrap::MessageToSend(_history); - message.textWithTags = { command }; - message.action.replyTo = replyToId(); - session().api().sendMessage(std::move(message)); - finishSending(); + listSendBotCommand(command, FullMsgId()); }, lifetime()); const auto saveEditMsgRequestId = lifetime().make_state(0); @@ -1766,6 +1763,17 @@ bool RepliesWidget::listIsGoodForAroundPosition( return IsServerMsgId(view->data()->id); } +void RepliesWidget::listSendBotCommand( + const QString &command, + const FullMsgId &context) { + const auto text = WrapBotCommandInChat(_history->peer, command, context); + auto message = ApiWrap::MessageToSend(_history); + message.textWithTags = { text }; + message.action.replyTo = replyToId(); + session().api().sendMessage(std::move(message)); + finishSending(); +} + void RepliesWidget::confirmDeleteSelected() { ConfirmDeleteSelectedItems(_inner); } diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.h b/Telegram/SourceFiles/history/view/history_view_replies_section.h index a22b5d92f9..63e055abc3 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.h +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.h @@ -126,6 +126,9 @@ public: bool listElementHideReply(not_null view) override; bool listElementShownUnread(not_null view) override; bool listIsGoodForAroundPosition(not_null view) override; + void listSendBotCommand( + const QString &command, + const FullMsgId &context) override; protected: void resizeEvent(QResizeEvent *e) override; diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index 0a2e506b52..57a1680a8f 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -182,15 +182,7 @@ void ScheduledWidget::setupComposeControls() { _composeControls->sendCommandRequests( ) | rpl::start_with_next([=](const QString &command) { - const auto callback = [=](Api::SendOptions options) { - auto message = ApiWrap::MessageToSend(_history); - message.textWithTags = { command }; - message.action.options = options; - session().api().sendMessage(std::move(message)); - }; - Ui::show( - PrepareScheduleBox(this, sendMenuType(), callback), - Ui::LayerOption::KeepOther); + listSendBotCommand(command, FullMsgId()); }, lifetime()); const auto saveEditMsgRequestId = lifetime().make_state(0); @@ -1185,6 +1177,21 @@ bool ScheduledWidget::listIsGoodForAroundPosition( return true; } +void ScheduledWidget::listSendBotCommand( + const QString &command, + const FullMsgId &context) { + const auto callback = [=](Api::SendOptions options) { + const auto text = WrapBotCommandInChat(_history->peer, command, context); + auto message = ApiWrap::MessageToSend(_history); + message.textWithTags = { text }; + message.action.options = options; + session().api().sendMessage(std::move(message)); + }; + Ui::show( + PrepareScheduleBox(this, sendMenuType(), callback), + Ui::LayerOption::KeepOther); +} + void ScheduledWidget::confirmSendNowSelected() { ConfirmSendNowSelectedItems(_inner); } diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.h b/Telegram/SourceFiles/history/view/history_view_scheduled_section.h index ad7b55a565..5d564f9cb7 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.h +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.h @@ -110,6 +110,9 @@ public: bool listElementHideReply(not_null view) override; bool listElementShownUnread(not_null view) override; bool listIsGoodForAroundPosition(not_null view) override; + void listSendBotCommand( + const QString &command, + const FullMsgId &context) override; protected: void resizeEvent(QResizeEvent *e) override; diff --git a/Telegram/SourceFiles/history/view/media/history_view_game.cpp b/Telegram/SourceFiles/history/view/media/history_view_game.cpp index af6f8a282b..cda894a14f 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_game.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_game.cpp @@ -33,7 +33,7 @@ Game::Game( , _title(st::msgMinWidth - st::webPageLeft) , _description(st::msgMinWidth - st::webPageLeft) { if (!consumed.text.isEmpty()) { - const auto context = Core::UiIntegration::Context{ + const auto context = Core::MarkedTextContext{ .session = &history()->session() }; _description.setMarkedText( @@ -418,7 +418,7 @@ void Game::parentTextUpdated() { if (const auto media = _parent->data()->media()) { const auto consumed = media->consumedMessageText(); if (!consumed.text.isEmpty()) { - const auto context = Core::UiIntegration::Context{ + const auto context = Core::MarkedTextContext{ .session = &history()->session() }; _description.setMarkedText( diff --git a/Telegram/SourceFiles/history/view/media/history_view_media.cpp b/Telegram/SourceFiles/history/view/media/history_view_media.cpp index 64eb1ff5dd..b72638f3ba 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media.cpp @@ -139,7 +139,7 @@ Ui::Text::String Media::createCaption( - st::msgPadding.left() - st::msgPadding.right(); auto result = Ui::Text::String(minResizeWidth); - const auto context = Core::UiIntegration::Context{ + const auto context = Core::MarkedTextContext{ .session = &history()->session() }; result.setMarkedText( diff --git a/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp b/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp index 52a6a76edc..87b096b22f 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp @@ -201,11 +201,12 @@ QSize WebPage::countOptimalSize() { - st::msgPadding.right() - st::webPageLeft); } - auto context = Core::UiIntegration::Context(); + auto context = Core::MarkedTextContext(); + using MarkedTextContext = Core::MarkedTextContext; if (_data->siteName == qstr("Twitter")) { - context.type = Core::UiIntegration::HashtagMentionType::Twitter; + context.type = MarkedTextContext::HashtagMentionType::Twitter; } else if (_data->siteName == qstr("Instagram")) { - context.type = Core::UiIntegration::HashtagMentionType::Instagram; + context.type = MarkedTextContext::HashtagMentionType::Instagram; } _description.setMarkedText( st::webPageDescriptionStyle, diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index e7d4fce548..0f3f1a5f8d 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -2018,7 +2018,7 @@ void OverlayWidget::refreshCaption(HistoryItem *item) { const auto base = duration ? DocumentTimestampLinkBase(_document, item->fullId()) : QString(); - const auto context = Core::UiIntegration::Context{ + const auto context = Core::MarkedTextContext{ .session = &item->history()->session() }; _caption.setMarkedText(