mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 05:07:10 +02:00
Implement paid location sending.
This commit is contained in:
parent
93a590774e
commit
37dd648686
2 changed files with 50 additions and 17 deletions
|
@ -41,6 +41,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/stickers/data_stickers.h"
|
||||
#include "history/history.h"
|
||||
#include "history/history_item.h"
|
||||
#include "history/history_item_helpers.h"
|
||||
#include "info/bot/starref/info_bot_starref_common.h" // MakePeerBubbleButton
|
||||
#include "info/profile/info_profile_values.h"
|
||||
#include "inline_bots/inline_bot_result.h"
|
||||
|
@ -2482,18 +2483,46 @@ void ChooseAndSendLocation(
|
|||
not_null<Window::SessionController*> controller,
|
||||
const Ui::LocationPickerConfig &config,
|
||||
Api::SendAction action) {
|
||||
const auto weak = base::make_weak(controller);
|
||||
const auto session = &controller->session();
|
||||
if (const auto picker = session->locationPickers().lookup(action)) {
|
||||
picker->activate();
|
||||
return;
|
||||
}
|
||||
const auto callback = [=](Data::InputVenue venue) {
|
||||
struct State {
|
||||
SendPaymentHelper sendPayment;
|
||||
Fn<void(Data::InputVenue, Api::SendAction)> send;
|
||||
};
|
||||
const auto state = std::make_shared<State>();
|
||||
state->send = [=](Data::InputVenue venue, Api::SendAction action) {
|
||||
if (const auto strong = weak.get()) {
|
||||
const auto withPaymentApproved = [=](int stars) {
|
||||
if (const auto onstack = state->send) {
|
||||
auto copy = action;
|
||||
copy.options.starsApproved = stars;
|
||||
onstack(venue, copy);
|
||||
}
|
||||
};
|
||||
const auto checked = state->sendPayment.check(
|
||||
strong,
|
||||
action.history->peer,
|
||||
1,
|
||||
action.options.starsApproved,
|
||||
withPaymentApproved);
|
||||
if (!checked) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
state->send = nullptr;
|
||||
if (venue.justLocation()) {
|
||||
Api::SendLocation(action, venue.lat, venue.lon);
|
||||
} else {
|
||||
Api::SendVenue(action, venue);
|
||||
}
|
||||
};
|
||||
const auto callback = [=](Data::InputVenue venue) {
|
||||
state->send(venue, action);
|
||||
};
|
||||
const auto picker = Ui::LocationPicker::Show({
|
||||
.parent = controller->widget(),
|
||||
.config = config,
|
||||
|
|
|
@ -1684,20 +1684,23 @@ void PeerMenuShareContactBox(
|
|||
: ('\xAB' + title + '\xBB');
|
||||
struct State {
|
||||
base::weak_ptr<Data::Thread> weak;
|
||||
FnMut<void(Api::SendOptions)> share;
|
||||
Fn<void(Api::SendOptions)> share;
|
||||
SendPaymentHelper sendPayment;
|
||||
};
|
||||
auto state = std::make_shared<State>();
|
||||
const auto state = std::make_shared<State>();
|
||||
state->weak = thread;
|
||||
state->share = [=](Api::SendOptions options) mutable {
|
||||
state->share = [=](Api::SendOptions options) {
|
||||
const auto strong = state->weak.get();
|
||||
if (!strong) {
|
||||
state->share = nullptr;
|
||||
return;
|
||||
}
|
||||
const auto withPaymentApproved = [=](int stars) {
|
||||
auto copy = options;
|
||||
copy.starsApproved = stars;
|
||||
state->share(copy);
|
||||
if (const auto onstack = state->share) {
|
||||
auto copy = options;
|
||||
copy.starsApproved = stars;
|
||||
onstack(copy);
|
||||
}
|
||||
};
|
||||
const auto checked = state->sendPayment.check(
|
||||
navigation,
|
||||
|
@ -1715,7 +1718,7 @@ void PeerMenuShareContactBox(
|
|||
auto action = Api::SendAction(strong, options);
|
||||
action.clearDraft = false;
|
||||
strong->session().api().shareContact(user, action);
|
||||
state = nullptr;
|
||||
state->share = nullptr;
|
||||
};
|
||||
|
||||
navigation->parentController()->show(
|
||||
|
@ -1765,19 +1768,20 @@ void PeerMenuCreatePoll(
|
|||
sendType,
|
||||
sendMenuDetails);
|
||||
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;
|
||||
const auto weak = QPointer<CreatePollBox>(box);
|
||||
const auto state = box->lifetime().make_state<State>();
|
||||
state->create = [=](const CreatePollBox::Result &result) {
|
||||
const auto withPaymentApproved = [=](int stars) {
|
||||
auto copy = result;
|
||||
copy.options.starsApproved = stars;
|
||||
state->create(copy);
|
||||
};
|
||||
const auto withPaymentApproved = crl::guard(weak, [=](int stars) {
|
||||
if (const auto onstack = state->create) {
|
||||
auto copy = result;
|
||||
copy.options.starsApproved = stars;
|
||||
onstack(copy);
|
||||
}
|
||||
});
|
||||
const auto checked = state->sendPayment.check(
|
||||
controller,
|
||||
peer,
|
||||
|
@ -1798,8 +1802,8 @@ 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, [=] {
|
||||
state->create = nullptr;
|
||||
weak->closeBox();
|
||||
}), crl::guard(weak, [=] {
|
||||
state->lock = false;
|
||||
|
|
Loading…
Add table
Reference in a new issue