2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Support paid files-with-comment and polls.

This commit is contained in:
John Preston
2025-02-20 14:55:34 +04:00
parent 3633c19208
commit 101d626d4f
5 changed files with 136 additions and 27 deletions

View File

@@ -1737,11 +1737,27 @@ void PeerMenuCreatePoll(
disabled,
sendType,
sendMenuDetails);
const auto weak = Ui::MakeWeak(box.data());
const auto lock = box->lifetime().make_state<bool>(false);
box->submitRequests(
) | rpl::start_with_next([=](const CreatePollBox::Result &result) {
if (std::exchange(*lock, true)) {
struct State {
QPointer<CreatePollBox> weak;
Fn<void(const CreatePollBox::Result &)> create;
SendPaymentHelper sendPayment;
bool lock = false;
};
const auto state = std::make_shared<State>();
state->weak = box;
state->create = [=](const CreatePollBox::Result &result) {
const auto withPaymentApproved = [=](int stars) {
auto copy = result;
copy.options.starsApproved = stars;
state->create(copy);
};
const auto checked = state->sendPayment.check(
controller,
peer,
1,
result.options.starsApproved,
withPaymentApproved);
if (!checked || std::exchange(state->lock, true)) {
return;
}
auto action = Api::SendAction(
@@ -1755,13 +1771,16 @@ void PeerMenuCreatePoll(
action.clearDraft = false;
}
const auto api = &peer->session().api();
const auto weak = state->weak;
api->polls().create(result.poll, action, crl::guard(weak, [=] {
weak->closeBox();
}), crl::guard(weak, [=] {
*lock = false;
state->lock = false;
weak->submitFailed(tr::lng_attach_failed(tr::now));
}));
}, box->lifetime());
};
box->submitRequests(
) | rpl::start_with_next(state->create, box->lifetime());
controller->show(std::move(box), Ui::LayerOption::CloseOther);
}