From 22b99b6d3e71b11d9e808961f19a2d1fffd2dbed Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 20 Feb 2025 16:27:12 +0400 Subject: [PATCH] Send paid shared contacts. --- .../SourceFiles/window/window_peer_menu.cpp | 48 ++++++++++++++----- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 01f48bfc4..c94db1a8a 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -1682,23 +1682,49 @@ void PeerMenuShareContactBox( auto recipient = peer->isUser() ? title : ('\xAB' + title + '\xBB'); - const auto weak = base::make_weak(thread); + struct State { + base::weak_ptr weak; + Fn share; + SendPaymentHelper sendPayment; + }; + const auto state = std::make_shared(); + state->weak = thread; + state->share = [=](Api::SendOptions options) { + const auto strong = state->weak.get(); + if (!strong) { + return; + } + const auto withPaymentApproved = [=](int stars) { + auto copy = options; + copy.starsApproved = stars; + state->share(copy); + }; + const auto checked = state->sendPayment.check( + navigation, + peer, + 1, + options.starsApproved, + withPaymentApproved); + if (!checked) { + return; + } + navigation->showThread( + strong, + ShowAtTheEndMsgId, + Window::SectionShow::Way::ClearStack); + auto action = Api::SendAction(strong, options); + action.clearDraft = false; + strong->session().api().shareContact(user, action); + }; + navigation->parentController()->show( Ui::MakeConfirmBox({ .text = tr::lng_forward_share_contact( tr::now, lt_recipient, recipient), - .confirmed = [weak, user, navigation](Fn &&close) { - if (const auto strong = weak.get()) { - navigation->showThread( - strong, - ShowAtTheEndMsgId, - Window::SectionShow::Way::ClearStack); - auto action = Api::SendAction(strong); - action.clearDraft = false; - strong->session().api().shareContact(user, action); - } + .confirmed = [state](Fn &&close) { + state->share({}); close(); }, .confirmText = tr::lng_forward_send(),