From 93a590774e16e609bfd6cf789964abb3a799e2f2 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 20 Feb 2025 17:49:50 +0400 Subject: [PATCH] Send paid stickers/gifs/inline-results. --- .../chat_helpers/gifs_list_widget.cpp | 15 +++---- .../chat_helpers/gifs_list_widget.h | 5 ++- .../SourceFiles/history/history_widget.cpp | 42 +++++++++++++++++-- .../view/history_view_replies_section.cpp | 12 ++++-- .../view/history_view_replies_section.h | 4 +- .../view/history_view_scheduled_section.cpp | 10 +++-- .../view/history_view_scheduled_section.h | 4 +- .../inline_bot_layout_internal.cpp | 42 +++++++++---------- .../inline_bots/inline_bot_layout_internal.h | 21 ++++++---- .../inline_bots/inline_bot_layout_item.cpp | 24 ++++++----- .../inline_bots/inline_bot_layout_item.h | 8 ++-- .../inline_bots/inline_bot_result.cpp | 4 +- .../inline_bots/inline_bot_result.h | 4 +- .../inline_bots/inline_results_inner.cpp | 20 +++++---- .../inline_bots/inline_results_inner.h | 4 +- .../media/stories/media_stories_reply.cpp | 10 +++-- .../media/stories/media_stories_reply.h | 4 +- .../business/settings_shortcut_messages.cpp | 16 ++++--- .../SourceFiles/window/window_peer_menu.cpp | 7 ++-- 19 files changed, 161 insertions(+), 95 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp index 89c666188..ba0a303b7 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp @@ -666,14 +666,15 @@ GifsListWidget::LayoutItem *GifsListWidget::layoutPrepareSavedGif( } GifsListWidget::LayoutItem *GifsListWidget::layoutPrepareInlineResult( - not_null result) { - auto it = _inlineLayouts.find(result); + std::shared_ptr result) { + const auto raw = result.get(); + auto it = _inlineLayouts.find(raw); if (it == _inlineLayouts.cend()) { if (auto layout = LayoutItem::createLayout( this, - result, + std::move(result), _inlineWithThumb)) { - it = _inlineLayouts.emplace(result, std::move(layout)).first; + it = _inlineLayouts.emplace(raw, std::move(layout)).first; it->second->initDimensions(); } else { return nullptr; @@ -746,8 +747,8 @@ int GifsListWidget::refreshInlineRows(const InlineCacheEntry *entry, bool result from, count ) | ranges::views::transform([&]( - const std::unique_ptr &r) { - return layoutPrepareInlineResult(r.get()); + const std::shared_ptr &r) { + return layoutPrepareInlineResult(r); }) | ranges::views::filter([](const LayoutItem *item) { return item != nullptr; }) | ranges::to>>; @@ -770,7 +771,7 @@ int GifsListWidget::validateExistingInlineRows(const InlineResults &results) { const auto until = _mosaic.validateExistingRows([&]( not_null item, int untilIndex) { - return item->getResult() != results[untilIndex].get(); + return item->getResult().get() != results[untilIndex].get(); }, results.size()); if (_mosaic.empty()) { diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h index 249ba5d0c..355686a34 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h @@ -131,7 +131,7 @@ private: }; using InlineResult = InlineBots::Result; - using InlineResults = std::vector>; + using InlineResults = std::vector>; using LayoutItem = InlineBots::Layout::ItemBase; struct InlineCacheEntry { @@ -162,7 +162,8 @@ private: void clearInlineRows(bool resultsDeleted); LayoutItem *layoutPrepareSavedGif(not_null document); - LayoutItem *layoutPrepareInlineResult(not_null result); + LayoutItem *layoutPrepareInlineResult( + std::shared_ptr result); void deleteUnusedGifLayouts(); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 5e9aa5ca2..9609054cc 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -7329,10 +7329,21 @@ void HistoryWidget::sendInlineResult(InlineBots::ResultSelected result) { return; } else if (showSlowmodeError()) { return; + } else if (const auto error = result.result->getErrorOnSend(_history)) { + Data::ShowSendErrorToast(controller(), _peer, error); + return; } - if (const auto error = result.result->getErrorOnSend(_history)) { - Data::ShowSendErrorToast(controller(), _peer, error); + const auto withPaymentApproved = [=](int approved) { + auto copy = result; + copy.options.starsApproved = approved; + sendInlineResult(copy); + }; + const auto checked = checkSendPayment( + 1, + result.options.starsApproved, + withPaymentApproved); + if (!checked) { return; } @@ -7343,7 +7354,7 @@ void HistoryWidget::sendInlineResult(InlineBots::ResultSelected result) { action.generateLocal = true; session().api().sendInlineResult( result.bot, - result.result, + result.result.get(), action, result.messageSendingFrom.localId); @@ -7984,6 +7995,18 @@ bool HistoryWidget::sendExistingDocument( || ShowSendPremiumError(controller(), document)) { return false; } + const auto withPaymentApproved = [=](int approved) { + auto copy = messageToSend; + copy.action.options.starsApproved = approved; + sendExistingDocument(document, std::move(copy), localId); + }; + const auto checked = checkSendPayment( + 1, + messageToSend.action.options.starsApproved, + withPaymentApproved); + if (!checked) { + return false; + } Api::SendExistingDocument( std::move(messageToSend), @@ -8021,6 +8044,19 @@ bool HistoryWidget::sendExistingPhoto( return false; } + const auto withPaymentApproved = [=](int approved) { + auto copy = options; + copy.starsApproved = approved; + sendExistingPhoto(photo, copy); + }; + const auto checked = checkSendPayment( + 1, + options.starsApproved, + withPaymentApproved); + if (!checked) { + return false; + } + Api::SendExistingPhoto( Api::MessageToSend(prepareSendAction(options)), photo); diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index a899e94b2..3d64635cd 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -1458,13 +1458,13 @@ bool RepliesWidget::sendExistingPhoto( } void RepliesWidget::sendInlineResult( - not_null result, + std::shared_ptr result, not_null bot) { if (const auto error = result->getErrorOnSend(_history)) { Data::ShowSendErrorToast(controller(), _history->peer, error); return; } - sendInlineResult(result, bot, {}, std::nullopt); + sendInlineResult(std::move(result), bot, {}, std::nullopt); //const auto callback = [=](Api::SendOptions options) { // sendInlineResult(result, bot, options); //}; @@ -1474,13 +1474,17 @@ void RepliesWidget::sendInlineResult( } void RepliesWidget::sendInlineResult( - not_null result, + std::shared_ptr result, not_null bot, Api::SendOptions options, std::optional localMessageId) { auto action = prepareSendAction(options); action.generateLocal = true; - session().api().sendInlineResult(bot, result, action, localMessageId); + session().api().sendInlineResult( + bot, + result.get(), + action, + localMessageId); _composeControls->clear(); //_saveDraftText = true; diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.h b/Telegram/SourceFiles/history/view/history_view_replies_section.h index 8af0e66dd..7f3a6f4dc 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.h +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.h @@ -318,10 +318,10 @@ private: not_null photo, Api::SendOptions options); void sendInlineResult( - not_null result, + std::shared_ptr result, not_null bot); void sendInlineResult( - not_null result, + std::shared_ptr result, not_null bot, Api::SendOptions options, std::optional localMessageId); diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index 950ae9f17..6313d88d0 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -909,7 +909,7 @@ bool ScheduledWidget::sendExistingPhoto( } void ScheduledWidget::sendInlineResult( - not_null result, + std::shared_ptr result, not_null bot) { if (const auto error = result->getErrorOnSend(_history)) { Data::ShowSendErrorToast(controller(), _history->peer, error); @@ -923,12 +923,16 @@ void ScheduledWidget::sendInlineResult( } void ScheduledWidget::sendInlineResult( - not_null result, + std::shared_ptr result, not_null bot, Api::SendOptions options) { auto action = prepareSendAction(options); action.generateLocal = true; - session().api().sendInlineResult(bot, result, action, std::nullopt); + session().api().sendInlineResult( + bot, + result.get(), + action, + std::nullopt); _composeControls->clear(); //_saveDraftText = true; diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.h b/Telegram/SourceFiles/history/view/history_view_scheduled_section.h index a2e3a5438..bd79ded77 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.h +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.h @@ -274,10 +274,10 @@ private: not_null photo, Api::SendOptions options); void sendInlineResult( - not_null result, + std::shared_ptr result, not_null bot); void sendInlineResult( - not_null result, + std::shared_ptr result, not_null bot, Api::SendOptions options); diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp index 616280a7e..7f6f41581 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp @@ -49,8 +49,8 @@ constexpr auto kMaxInlineArea = 1280 * 720; return dimensions.width() * dimensions.height() <= kMaxInlineArea; } -FileBase::FileBase(not_null context, not_null result) -: ItemBase(context, result) { +FileBase::FileBase(not_null context, std::shared_ptr result) +: ItemBase(context, std::move(result)) { } FileBase::FileBase( @@ -95,8 +95,8 @@ int FileBase::content_duration() const { return getResultDuration(); } -Gif::Gif(not_null context, not_null result) -: FileBase(context, result) { +Gif::Gif(not_null context, std::shared_ptr result) +: FileBase(context, std::move(result)) { Expects(getResultDocument() != nullptr); } @@ -442,8 +442,8 @@ void Gif::clipCallback(Media::Clip::Notification notification) { } } -Sticker::Sticker(not_null context, not_null result) -: FileBase(context, result) { +Sticker::Sticker(not_null context, std::shared_ptr result) +: FileBase(context, std::move(result)) { Expects(getResultDocument() != nullptr); } @@ -654,8 +654,8 @@ void Sticker::clipCallback(Media::Clip::Notification notification) { update(); } -Photo::Photo(not_null context, not_null result) -: ItemBase(context, result) { +Photo::Photo(not_null context, std::shared_ptr result) +: ItemBase(context, std::move(result)) { Expects(getShownPhoto() != nullptr); } @@ -769,8 +769,8 @@ void Photo::prepareThumbnail(QSize size, QSize frame) const { validateThumbnail(_photoMedia->thumbnailInline(), size, frame, false); } -Video::Video(not_null context, not_null result) -: FileBase(context, result) +Video::Video(not_null context, std::shared_ptr result) +: FileBase(context, std::move(result)) , _link(getResultPreviewHandler()) , _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) , _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) { @@ -925,11 +925,11 @@ void CancelFileClickHandler::onClickImpl() const { _result->cancelFile(); } -File::File(not_null context, not_null result) -: FileBase(context, result) +File::File(not_null context, std::shared_ptr result) +: FileBase(context, std::move(result)) , _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineFileSize - st::inlineThumbSkip) , _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineFileSize - st::inlineThumbSkip) -, _cancel(std::make_shared(result)) +, _cancel(std::make_shared(_result.get())) , _document(getShownDocument()) { Expects(getResultDocument() != nullptr); @@ -1173,8 +1173,8 @@ void File::setStatusSize( } } -Contact::Contact(not_null context, not_null result) -: ItemBase(context, result) +Contact::Contact(not_null context, std::shared_ptr result) +: ItemBase(context, std::move(result)) , _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) , _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) { } @@ -1265,16 +1265,16 @@ void Contact::prepareThumbnail(int width, int height) const { Article::Article( not_null context, - not_null result, + std::shared_ptr result, bool withThumb) -: ItemBase(context, result) +: ItemBase(context, std::move(result)) , _url(getResultUrlHandler()) , _link(getResultPreviewHandler()) , _withThumb(withThumb) , _title(st::emojiPanWidth / 2) , _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) { if (!_link) { - if (const auto point = result->getLocationPoint()) { + if (const auto point = _result->getLocationPoint()) { _link = std::make_shared(*point); } } @@ -1300,7 +1300,7 @@ void Article::initDimensions() { _minh += st::inlineRowMargin * 2 + st::inlineRowBorder; } -int32 Article::resizeGetHeight(int32 width) { +int Article::resizeGetHeight(int width) { _width = qMin(width, _maxw); if (_url) { _urlText = getResultUrl(); @@ -1422,8 +1422,8 @@ void Article::prepareThumbnail(int width, int height) const { }); } -Game::Game(not_null context, not_null result) -: ItemBase(context, result) +Game::Game(not_null context, std::shared_ptr result) +: ItemBase(context, std::move(result)) , _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) , _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) { countFrameSize(); diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.h b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.h index 83794b1b6..e483f858a 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.h +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.h @@ -29,7 +29,7 @@ namespace internal { class FileBase : public ItemBase { public: - FileBase(not_null context, not_null result); + FileBase(not_null context, std::shared_ptr result); // For saved gif layouts. FileBase(not_null context, not_null document); @@ -58,7 +58,7 @@ private: class Gif final : public FileBase { public: - Gif(not_null context, not_null result); + Gif(not_null context, std::shared_ptr result); Gif( not_null context, not_null document, @@ -138,7 +138,7 @@ private: class Photo : public ItemBase { public: - Photo(not_null context, not_null result); + Photo(not_null context, std::shared_ptr result); // Not used anywhere currently. //Photo(not_null context, not_null photo); @@ -178,7 +178,7 @@ private: class Sticker : public FileBase { public: - Sticker(not_null context, not_null result); + Sticker(not_null context, std::shared_ptr result); ~Sticker(); // Not used anywhere currently. //Sticker(not_null context, not_null document); @@ -229,7 +229,7 @@ private: class Video : public FileBase { public: - Video(not_null context, not_null result); + Video(not_null context, std::shared_ptr result); void initDimensions() override; @@ -269,7 +269,7 @@ private: class File : public FileBase { public: - File(not_null context, not_null result); + File(not_null context, std::shared_ptr result); ~File(); void initDimensions() override; @@ -347,7 +347,7 @@ private: class Contact : public ItemBase { public: - Contact(not_null context, not_null result); + Contact(not_null context, std::shared_ptr result); void initDimensions() override; @@ -366,7 +366,10 @@ private: class Article : public ItemBase { public: - Article(not_null context, not_null result, bool withThumb); + Article( + not_null context, + std::shared_ptr result, + bool withThumb); void initDimensions() override; int resizeGetHeight(int width) override; @@ -391,7 +394,7 @@ private: class Game : public ItemBase { public: - Game(not_null context, not_null result); + Game(not_null context, std::shared_ptr result); void setPosition(int32 position) override; void initDimensions() override; diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp index 34acc4093..89b0e41b1 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp @@ -29,7 +29,7 @@ base::NeverFreedPointer documentItemsMap; } // namespace -Result *ItemBase::getResult() const { +std::shared_ptr ItemBase::getResult() const { return _result; } @@ -92,33 +92,37 @@ void ItemBase::layoutChanged() { std::unique_ptr ItemBase::createLayout( not_null context, - not_null result, + std::shared_ptr result, bool forceThumb) { using Type = Result::Type; switch (result->_type) { case Type::Photo: - return std::make_unique(context, result); + return std::make_unique(context, std::move(result)); case Type::Audio: case Type::File: - return std::make_unique(context, result); + return std::make_unique(context, std::move(result)); case Type::Video: - return std::make_unique(context, result); + return std::make_unique(context, std::move(result)); case Type::Sticker: - return std::make_unique(context, result); + return std::make_unique( + context, + std::move(result)); case Type::Gif: - return std::make_unique(context, result); + return std::make_unique(context, std::move(result)); case Type::Article: case Type::Geo: case Type::Venue: return std::make_unique( context, - result, + std::move(result), forceThumb); case Type::Game: - return std::make_unique(context, result); + return std::make_unique(context, std::move(result)); case Type::Contact: - return std::make_unique(context, result); + return std::make_unique( + context, + std::move(result)); } return nullptr; } diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.h b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.h index 67574f7e0..e370b3477 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.h +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.h @@ -59,7 +59,7 @@ public: class ItemBase : public LayoutItemBase { public: - ItemBase(not_null context, not_null result) + ItemBase(not_null context, std::shared_ptr result) : _result(result) , _context(context) { } @@ -80,7 +80,7 @@ public: return false; } - Result *getResult() const; + std::shared_ptr getResult() const; DocumentData *getDocument() const; PhotoData *getPhoto() const; @@ -112,7 +112,7 @@ public: static std::unique_ptr createLayout( not_null context, - not_null result, + std::shared_ptr result, bool forceThumb); static std::unique_ptr createLayoutGif( not_null context, @@ -135,7 +135,7 @@ protected: } Data::FileOrigin fileOrigin() const; - Result *_result = nullptr; + std::shared_ptr _result; DocumentData *_document = nullptr; PhotoData *_photo = nullptr; diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp index e5e1566d5..0b5c01cd3 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp @@ -53,7 +53,7 @@ Result::Result(not_null session, const Creator &creator) , _type(creator.type) { } -std::unique_ptr Result::Create( +std::shared_ptr Result::Create( not_null session, uint64 queryId, const MTPBotInlineResult &data) { @@ -84,7 +84,7 @@ std::unique_ptr Result::Create( return nullptr; } - auto result = std::make_unique( + auto result = std::make_shared( session, Creator{ queryId, type }); const auto message = data.match([&](const MTPDbotInlineResult &data) { diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_result.h b/Telegram/SourceFiles/inline_bots/inline_bot_result.h index 67b3a0fd1..bf40bc2ee 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_result.h +++ b/Telegram/SourceFiles/inline_bots/inline_bot_result.h @@ -43,7 +43,7 @@ public: // You should use create() static method instead. Result(not_null session, const Creator &creator); - static std::unique_ptr Create( + static std::shared_ptr Create( not_null session, uint64 queryId, const MTPBotInlineResult &mtpData); @@ -130,7 +130,7 @@ private: }; struct ResultSelected { - not_null result; + std::shared_ptr result; not_null bot; PeerData *recipientOverride = nullptr; Api::SendOptions options; diff --git a/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp b/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp index c2ab83e95..41ee7f426 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp @@ -331,7 +331,7 @@ void Inner::selectInlineResult( if (const auto inlineResult = item->getResult()) { if (inlineResult->onChoose(item)) { _resultSelectedCallback({ - .result = inlineResult, + .result = std::move(inlineResult), .bot = _inlineBot, .options = std::move(options), .messageSendingFrom = messageSendingFrom(), @@ -448,11 +448,15 @@ void Inner::clearInlineRows(bool resultsDeleted) { _mosaic.clearRows(resultsDeleted); } -ItemBase *Inner::layoutPrepareInlineResult(Result *result) { - auto it = _inlineLayouts.find(result); +ItemBase *Inner::layoutPrepareInlineResult(std::shared_ptr result) { + const auto raw = result.get(); + auto it = _inlineLayouts.find(raw); if (it == _inlineLayouts.cend()) { - if (auto layout = ItemBase::createLayout(this, result, _inlineWithThumb)) { - it = _inlineLayouts.emplace(result, std::move(layout)).first; + if (auto layout = ItemBase::createLayout( + this, + std::move(result), + _inlineWithThumb)) { + it = _inlineLayouts.emplace(raw, std::move(layout)).first; it->second->initDimensions(); } else { return nullptr; @@ -560,8 +564,8 @@ int Inner::refreshInlineRows(PeerData *queryPeer, UserData *bot, const CacheEntr const auto resultItems = entry->results | ranges::views::slice( from, count - ) | ranges::views::transform([&](const std::unique_ptr &r) { - return layoutPrepareInlineResult(r.get()); + ) | ranges::views::transform([&](const std::shared_ptr &r) { + return layoutPrepareInlineResult(r); }) | ranges::views::filter([](const ItemBase *item) { return item != nullptr; }) | ranges::to>>; @@ -585,7 +589,7 @@ int Inner::validateExistingInlineRows(const Results &results) { const auto until = _mosaic.validateExistingRows([&]( not_null item, int untilIndex) { - return item->getResult() != results[untilIndex].get(); + return item->getResult().get() != results[untilIndex].get(); }, results.size()); if (_mosaic.empty()) { diff --git a/Telegram/SourceFiles/inline_bots/inline_results_inner.h b/Telegram/SourceFiles/inline_bots/inline_results_inner.h index 28b305513..e7d47a30a 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_inner.h +++ b/Telegram/SourceFiles/inline_bots/inline_results_inner.h @@ -50,7 +50,7 @@ namespace InlineBots { namespace Layout { class ItemBase; -using Results = std::vector>; +using Results = std::vector>; struct CacheEntry { QString nextOffset; @@ -135,7 +135,7 @@ private: void updateInlineItems(); void repaintItems(crl::time now = 0); void clearInlineRows(bool resultsDeleted); - ItemBase *layoutPrepareInlineResult(Result *result); + ItemBase *layoutPrepareInlineResult(std::shared_ptr result); void updateRestrictedLabelGeometry(); void deleteUnusedInlineLayouts(); diff --git a/Telegram/SourceFiles/media/stories/media_stories_reply.cpp b/Telegram/SourceFiles/media/stories/media_stories_reply.cpp index 934d86243..ad06525c3 100644 --- a/Telegram/SourceFiles/media/stories/media_stories_reply.cpp +++ b/Telegram/SourceFiles/media/stories/media_stories_reply.cpp @@ -307,7 +307,7 @@ bool ReplyArea::sendExistingPhoto( } void ReplyArea::sendInlineResult( - not_null result, + std::shared_ptr result, not_null bot) { if (const auto error = result->getErrorOnSend(history())) { const auto show = _controller->uiShow(); @@ -318,13 +318,17 @@ void ReplyArea::sendInlineResult( } void ReplyArea::sendInlineResult( - not_null result, + std::shared_ptr result, not_null bot, Api::SendOptions options, std::optional localMessageId) { auto action = prepareSendAction(options); action.generateLocal = true; - session().api().sendInlineResult(bot, result, action, localMessageId); + session().api().sendInlineResult( + bot, + result.get(), + action, + localMessageId); auto &bots = cRefRecentInlineBots(); const auto index = bots.indexOf(bot); diff --git a/Telegram/SourceFiles/media/stories/media_stories_reply.h b/Telegram/SourceFiles/media/stories/media_stories_reply.h index 981cc48c1..d3cdec47d 100644 --- a/Telegram/SourceFiles/media/stories/media_stories_reply.h +++ b/Telegram/SourceFiles/media/stories/media_stories_reply.h @@ -127,10 +127,10 @@ private: not_null photo, Api::SendOptions options); void sendInlineResult( - not_null result, + std::shared_ptr result, not_null bot); void sendInlineResult( - not_null result, + std::shared_ptr result, not_null bot, Api::SendOptions options, std::optional localMessageId); diff --git a/Telegram/SourceFiles/settings/business/settings_shortcut_messages.cpp b/Telegram/SourceFiles/settings/business/settings_shortcut_messages.cpp index 995a98202..db5a4d99a 100644 --- a/Telegram/SourceFiles/settings/business/settings_shortcut_messages.cpp +++ b/Telegram/SourceFiles/settings/business/settings_shortcut_messages.cpp @@ -223,10 +223,10 @@ private: not_null photo, Api::SendOptions options); void sendInlineResult( - not_null result, + std::shared_ptr result, not_null bot); void sendInlineResult( - not_null result, + std::shared_ptr result, not_null bot, Api::SendOptions options, std::optional localMessageId); @@ -1534,7 +1534,7 @@ bool ShortcutMessages::sendExistingPhoto( } void ShortcutMessages::sendInlineResult( - not_null result, + std::shared_ptr result, not_null bot) { if (showPremiumRequired()) { return; @@ -1542,11 +1542,11 @@ void ShortcutMessages::sendInlineResult( Data::ShowSendErrorToast(_controller, _history->peer, error); return; } - sendInlineResult(result, bot, {}, std::nullopt); + sendInlineResult(std::move(result), bot, {}, std::nullopt); } void ShortcutMessages::sendInlineResult( - not_null result, + std::shared_ptr result, not_null bot, Api::SendOptions options, std::optional localMessageId) { @@ -1555,7 +1555,11 @@ void ShortcutMessages::sendInlineResult( } auto action = prepareSendAction(options); action.generateLocal = true; - _session->api().sendInlineResult(bot, result, action, localMessageId); + _session->api().sendInlineResult( + bot, + result.get(), + action, + localMessageId); _composeControls->clear(); //_saveDraftText = true; diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index c94db1a8a..760c27537 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -1684,12 +1684,12 @@ void PeerMenuShareContactBox( : ('\xAB' + title + '\xBB'); struct State { base::weak_ptr weak; - Fn share; + FnMut share; SendPaymentHelper sendPayment; }; - const auto state = std::make_shared(); + auto state = std::make_shared(); state->weak = thread; - state->share = [=](Api::SendOptions options) { + state->share = [=](Api::SendOptions options) mutable { const auto strong = state->weak.get(); if (!strong) { return; @@ -1715,6 +1715,7 @@ void PeerMenuShareContactBox( auto action = Api::SendAction(strong, options); action.clearDraft = false; strong->session().api().shareContact(user, action); + state = nullptr; }; navigation->parentController()->show(