mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Save/unsave gifts to the profile page.
This commit is contained in:
parent
efbd3ca8fa
commit
7a35577d3a
2 changed files with 106 additions and 15 deletions
|
@ -203,3 +203,7 @@ startGiveawayButtonLoading: InfiniteRadialAnimation(defaultInfiniteRadialAnimati
|
||||||
color: activeButtonFg;
|
color: activeButtonFg;
|
||||||
thickness: 2px;
|
thickness: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
starGiftBox: Box(giveawayGiftCodeBox) {
|
||||||
|
buttonPadding: margins(22px, 11px, 22px, 52px);
|
||||||
|
}
|
||||||
|
|
|
@ -153,6 +153,36 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void ToggleStarGiftSaved(
|
||||||
|
not_null<Window::SessionController*> window,
|
||||||
|
not_null<HistoryItem*> item,
|
||||||
|
bool save,
|
||||||
|
Fn<void(bool)> done) {
|
||||||
|
Expects(item->history()->peer->isUser());
|
||||||
|
|
||||||
|
using Flag = MTPpayments_SaveStarGift::Flag;
|
||||||
|
const auto api = &window->session().api();
|
||||||
|
const auto weak = base::make_weak(window);
|
||||||
|
api->request(MTPpayments_SaveStarGift(
|
||||||
|
MTP_flags(save ? Flag(0) : Flag::f_unsave),
|
||||||
|
item->history()->peer->asUser()->inputUser,
|
||||||
|
MTP_int(item->id.bare)
|
||||||
|
)).done([=] {
|
||||||
|
if (const auto strong = weak.get()) {
|
||||||
|
strong->showPeerInfo(strong->session().user());
|
||||||
|
strong->showToast((save
|
||||||
|
? tr::lng_gift_display_done
|
||||||
|
: tr::lng_gift_display_done_hide)(tr::now));
|
||||||
|
}
|
||||||
|
done(true);
|
||||||
|
}).fail([=](const MTP::Error &error) {
|
||||||
|
if (const auto strong = weak.get()) {
|
||||||
|
strong->showToast(error.type());
|
||||||
|
}
|
||||||
|
done(false);
|
||||||
|
}).send();
|
||||||
|
}
|
||||||
|
|
||||||
void AddViewMediaHandler(
|
void AddViewMediaHandler(
|
||||||
not_null<Ui::RpWidget*> thumb,
|
not_null<Ui::RpWidget*> thumb,
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
|
@ -647,7 +677,15 @@ void ReceiptCreditsBox(
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
const Data::CreditsHistoryEntry &e,
|
const Data::CreditsHistoryEntry &e,
|
||||||
const Data::SubscriptionEntry &s) {
|
const Data::SubscriptionEntry &s) {
|
||||||
box->setStyle(st::giveawayGiftCodeBox);
|
const auto item = controller->session().data().message(
|
||||||
|
PeerId(e.barePeerId), MsgId(e.bareMsgId));
|
||||||
|
const auto isStarGift = (e.convertStars > 0);
|
||||||
|
const auto starGiftSender = (isStarGift && item)
|
||||||
|
? item->history()->peer->asUser()
|
||||||
|
: nullptr;
|
||||||
|
const auto canConvert = isStarGift && !e.converted && starGiftSender;
|
||||||
|
|
||||||
|
box->setStyle(canConvert ? st::starGiftBox : st::giveawayGiftCodeBox);
|
||||||
box->setNoContentMargin(true);
|
box->setNoContentMargin(true);
|
||||||
|
|
||||||
const auto content = box->verticalLayout();
|
const auto content = box->verticalLayout();
|
||||||
|
@ -660,7 +698,6 @@ void ReceiptCreditsBox(
|
||||||
const auto &stUser = st::boostReplaceUserpic;
|
const auto &stUser = st::boostReplaceUserpic;
|
||||||
const auto session = &controller->session();
|
const auto session = &controller->session();
|
||||||
const auto isPrize = e.bareGiveawayMsgId > 0;
|
const auto isPrize = e.bareGiveawayMsgId > 0;
|
||||||
const auto isStarGift = (e.convertStars > 0);
|
|
||||||
const auto starGiftSticker = (isStarGift && e.bareGiftStickerId)
|
const auto starGiftSticker = (isStarGift && e.bareGiftStickerId)
|
||||||
? session->data().document(e.bareGiftStickerId).get()
|
? session->data().document(e.bareGiftStickerId).get()
|
||||||
: nullptr;
|
: nullptr;
|
||||||
|
@ -1043,23 +1080,45 @@ void ReceiptCreditsBox(
|
||||||
rpl::variable<bool> confirmButtonBusy;
|
rpl::variable<bool> confirmButtonBusy;
|
||||||
};
|
};
|
||||||
const auto state = box->lifetime().make_state<State>();
|
const auto state = box->lifetime().make_state<State>();
|
||||||
auto confirmText = rpl::conditional(
|
auto confirmText = canConvert
|
||||||
state->confirmButtonBusy.value(),
|
? (e.savedToProfile
|
||||||
rpl::single(QString()),
|
? tr::lng_gift_display_on_page_hide()
|
||||||
toRenew
|
: tr::lng_gift_display_on_page())
|
||||||
? tr::lng_credits_subscription_off_button()
|
: rpl::conditional(
|
||||||
: toCancel
|
state->confirmButtonBusy.value(),
|
||||||
? tr::lng_credits_subscription_on_button()
|
rpl::single(QString()),
|
||||||
: tr::lng_box_ok());
|
(toRenew
|
||||||
using Flag = MTPpayments_ChangeStarsSubscription::Flag;
|
? tr::lng_credits_subscription_off_button()
|
||||||
|
: toCancel
|
||||||
|
? tr::lng_credits_subscription_on_button()
|
||||||
|
: tr::lng_box_ok()));
|
||||||
|
const auto weakWindow = base::make_weak(controller);
|
||||||
const auto send = [=, weak = Ui::MakeWeak(box)] {
|
const auto send = [=, weak = Ui::MakeWeak(box)] {
|
||||||
if (toRenew && s.expired) {
|
if (canConvert) {
|
||||||
|
const auto save = !e.savedToProfile;
|
||||||
|
const auto window = weakWindow.get();
|
||||||
|
const auto item = session->data().message(
|
||||||
|
starGiftSender->id,
|
||||||
|
MsgId(e.bareMsgId));
|
||||||
|
if (window && item) {
|
||||||
|
ToggleStarGiftSaved(window, item, save, [=](bool ok) {
|
||||||
|
if (const auto strong = weak.data()) {
|
||||||
|
if (ok) {
|
||||||
|
strong->closeBox();
|
||||||
|
} else {
|
||||||
|
state->confirmButtonBusy = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (toRenew && s.expired) {
|
||||||
Api::CheckChatInvite(controller, s.inviteHash, nullptr, [=] {
|
Api::CheckChatInvite(controller, s.inviteHash, nullptr, [=] {
|
||||||
if (const auto strong = weak.data()) {
|
if (const auto strong = weak.data()) {
|
||||||
strong->closeBox();
|
strong->closeBox();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
using Flag = MTPpayments_ChangeStarsSubscription::Flag;
|
||||||
session->api().request(
|
session->api().request(
|
||||||
MTPpayments_ChangeStarsSubscription(
|
MTPpayments_ChangeStarsSubscription(
|
||||||
MTP_flags(Flag::f_canceled),
|
MTP_flags(Flag::f_canceled),
|
||||||
|
@ -1067,12 +1126,13 @@ void ReceiptCreditsBox(
|
||||||
MTP_string(s.id),
|
MTP_string(s.id),
|
||||||
MTP_bool(toCancel)
|
MTP_bool(toCancel)
|
||||||
)).done([=] {
|
)).done([=] {
|
||||||
state->confirmButtonBusy = false;
|
|
||||||
if (const auto strong = weak.data()) {
|
if (const auto strong = weak.data()) {
|
||||||
strong->closeBox();
|
strong->closeBox();
|
||||||
}
|
}
|
||||||
}).fail([=, show = box->uiShow()](const MTP::Error &error) {
|
}).fail([=, show = box->uiShow()](const MTP::Error &error) {
|
||||||
state->confirmButtonBusy = false;
|
if (const auto strong = weak.data()) {
|
||||||
|
state->confirmButtonBusy = false;
|
||||||
|
}
|
||||||
show->showToast(error.type());
|
show->showToast(error.type());
|
||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
@ -1083,7 +1143,7 @@ void ReceiptCreditsBox(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
state->confirmButtonBusy = true;
|
state->confirmButtonBusy = true;
|
||||||
if ((toRenew || toCancel) && peer) {
|
if ((toRenew || toCancel || canConvert) && peer) {
|
||||||
send();
|
send();
|
||||||
} else {
|
} else {
|
||||||
box->closeBox();
|
box->closeBox();
|
||||||
|
@ -1099,11 +1159,38 @@ void ReceiptCreditsBox(
|
||||||
}
|
}
|
||||||
const auto buttonWidth = st::boxWidth
|
const auto buttonWidth = st::boxWidth
|
||||||
- rect::m::sum::h(st::giveawayGiftCodeBox.buttonPadding);
|
- rect::m::sum::h(st::giveawayGiftCodeBox.buttonPadding);
|
||||||
|
|
||||||
button->widthValue() | rpl::filter([=] {
|
button->widthValue() | rpl::filter([=] {
|
||||||
return (button->widthNoMargins() != buttonWidth);
|
return (button->widthNoMargins() != buttonWidth);
|
||||||
}) | rpl::start_with_next([=] {
|
}) | rpl::start_with_next([=] {
|
||||||
button->resizeToWidth(buttonWidth);
|
button->resizeToWidth(buttonWidth);
|
||||||
}, button->lifetime());
|
}, button->lifetime());
|
||||||
|
|
||||||
|
if (canConvert) {
|
||||||
|
using namespace Ui;
|
||||||
|
const auto convert = CreateChild<RoundButton>(
|
||||||
|
button->parentWidget(),
|
||||||
|
tr::lng_gift_convert_to_stars(
|
||||||
|
lt_count,
|
||||||
|
rpl::single(e.convertStars * 1.)),
|
||||||
|
st::defaultLightButton);
|
||||||
|
convert->setTextTransform(RoundButton::TextTransform::NoTransform);
|
||||||
|
convert->widthValue() | rpl::filter([=] {
|
||||||
|
return convert->widthNoMargins() != buttonWidth;
|
||||||
|
}) | rpl::start_with_next([=] {
|
||||||
|
convert->resizeToWidth(buttonWidth);
|
||||||
|
}, convert->lifetime());
|
||||||
|
button->positionValue(
|
||||||
|
) | rpl::start_with_next([=](QPoint position) {
|
||||||
|
convert->move(
|
||||||
|
position.x(),
|
||||||
|
(position.y()
|
||||||
|
+ st::starGiftBox.buttonHeight
|
||||||
|
+ st::starGiftBox.buttonPadding.bottom()
|
||||||
|
- st::starGiftBox.buttonPadding.top()
|
||||||
|
- convert->height()));
|
||||||
|
}, convert->lifetime());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GiftedCreditsBox(
|
void GiftedCreditsBox(
|
||||||
|
|
Loading…
Add table
Reference in a new issue