mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Start/Update/End toasts for starref programs.
This commit is contained in:
parent
ca89aa8377
commit
1ebd25e76e
5 changed files with 45 additions and 26 deletions
|
@ -1661,6 +1661,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_star_ref_warning_end" = "End Anyway";
|
||||
"lng_star_ref_created_title" = "Affiliate program started";
|
||||
"lng_star_ref_created_text" = "Any Telegram user, channel owner or mini app developer can now join your program.";
|
||||
"lng_star_ref_updated_title" = "Affiliate program updated";
|
||||
"lng_star_ref_updated_text" = "Any Telegram user, channel owner or mini app developer can join your program.";
|
||||
"lng_star_ref_ended_title" = "Affiliate program ended";
|
||||
"lng_star_ref_ended_text" = "Participating affiliates have been notified. All referral links will be disabled in **24** hours.";
|
||||
"lng_star_ref_list_title" = "Affiliate Programs";
|
||||
|
|
|
@ -423,8 +423,8 @@ object_ptr<Ui::BoxContent> ConfirmEndBox(Fn<void()> finish) {
|
|||
padded->paintRequest() | rpl::start_with_next([=] {
|
||||
auto p = QPainter(padded);
|
||||
auto hq = PainterHighQualityEnabler(p);
|
||||
const auto size = st::boxTextFont->spacew;
|
||||
const auto top = (st::boxTextFont->height - size) / 2;
|
||||
const auto size = st::starrefEndBulletSize;
|
||||
const auto top = st::starrefEndBulletTop;
|
||||
p.setBrush(st::windowFg);
|
||||
p.setPen(Qt::NoPen);
|
||||
p.drawEllipse(0, top, size, size);
|
||||
|
@ -519,15 +519,19 @@ std::unique_ptr<Ui::AbstractButton> MakePeerBubbleButton(
|
|||
return result;
|
||||
}
|
||||
|
||||
void FinishProgram(
|
||||
void UpdateProgram(
|
||||
std::shared_ptr<Ui::Show> show,
|
||||
not_null<UserData*> bot,
|
||||
const StarRefProgram &program,
|
||||
Fn<void()> finished) {
|
||||
using Flag = MTPbots_UpdateStarRefProgram::Flag;
|
||||
bot->session().api().request(MTPbots_UpdateStarRefProgram(
|
||||
MTP_flags(0),
|
||||
MTP_flags((program.commission > 0 && program.durationMonths > 0)
|
||||
? Flag::f_duration_months
|
||||
: Flag()),
|
||||
bot->inputUser,
|
||||
MTP_int(0),
|
||||
MTP_int(0)
|
||||
MTP_int(program.commission),
|
||||
MTP_int(program.durationMonths)
|
||||
)).done([=](const MTPStarRefProgram &result) {
|
||||
bot->setStarRefProgram(Data::ParseStarRefProgram(&result));
|
||||
finished();
|
||||
|
@ -536,6 +540,13 @@ void FinishProgram(
|
|||
}).send();
|
||||
}
|
||||
|
||||
void FinishProgram(
|
||||
std::shared_ptr<Ui::Show> show,
|
||||
not_null<UserData*> bot,
|
||||
Fn<void()> finished) {
|
||||
UpdateProgram(std::move(show), bot, {}, std::move(finished));
|
||||
}
|
||||
|
||||
ConnectedBots Parse(
|
||||
not_null<Main::Session*> session,
|
||||
const MTPpayments_ConnectedStarRefBots &bots) {
|
||||
|
|
|
@ -73,6 +73,11 @@ std::unique_ptr<Ui::AbstractButton> MakePeerBubbleButton(
|
|||
not_null<PeerData*> peer,
|
||||
Ui::RpWidget *right = nullptr);
|
||||
|
||||
void UpdateProgram(
|
||||
std::shared_ptr<Ui::Show> show,
|
||||
not_null<UserData*> bot,
|
||||
const StarRefProgram &program,
|
||||
Fn<void()> finished);
|
||||
void FinishProgram(
|
||||
std::shared_ptr<Ui::Show> show,
|
||||
not_null<UserData*> bot,
|
||||
|
|
|
@ -749,6 +749,7 @@ void InnerWidget::setupEnd() {
|
|||
.text = tr::lng_star_ref_ended_text(
|
||||
tr::now,
|
||||
Ui::Text::RichLangValue),
|
||||
.duration = Ui::Toast::kDefaultDuration * 3,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -1003,30 +1004,28 @@ std::unique_ptr<Ui::RpWidget> Widget::setupBottom() {
|
|||
st::boxDividerLabel),
|
||||
QMargins(margins.left(), 0, margins.right(), 0));
|
||||
save->setClickedCallback([=] {
|
||||
using Flag = MTPbots_UpdateStarRefProgram::Flag;
|
||||
const auto weak = Ui::MakeWeak(this);
|
||||
const auto user = _state->user;
|
||||
auto program = StarRefProgram{
|
||||
const auto program = StarRefProgram{
|
||||
.commission = _state->program.commission,
|
||||
.durationMonths = _state->program.durationMonths,
|
||||
};
|
||||
user->session().api().request(MTPbots_UpdateStarRefProgram(
|
||||
MTP_flags((program.commission > 0 && program.durationMonths > 0)
|
||||
? Flag::f_duration_months
|
||||
: Flag()),
|
||||
user->inputUser,
|
||||
MTP_int(program.commission),
|
||||
MTP_int(program.durationMonths)
|
||||
)).done([=] {
|
||||
user->botInfo->starRefProgram.commission = program.commission;
|
||||
user->botInfo->starRefProgram.durationMonths
|
||||
= program.durationMonths;
|
||||
if (weak) {
|
||||
controller()->showBackFromStack();
|
||||
}
|
||||
}).fail(crl::guard(weak, [=] {
|
||||
controller()->showToast("Failed!");
|
||||
})).send();
|
||||
|
||||
const auto show = controller()->uiShow();
|
||||
const auto exists = _state->exists;
|
||||
UpdateProgram(show, user, program, crl::guard(this, [=] {
|
||||
controller()->showBackFromStack();
|
||||
show->showToast({
|
||||
.title = (exists
|
||||
? tr::lng_star_ref_updated_title
|
||||
: tr::lng_star_ref_created_title)(tr::now),
|
||||
.text = (exists
|
||||
? tr::lng_star_ref_updated_text
|
||||
: tr::lng_star_ref_created_text)(
|
||||
tr::now,
|
||||
Ui::Text::RichLangValue),
|
||||
.duration = Ui::Toast::kDefaultDuration * 3,
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
widthValue() | rpl::start_with_next([=](int width) {
|
||||
|
|
|
@ -461,3 +461,5 @@ starrefBottomButtonSublabel: FlatLabel(starrefBottomButtonLabel) {
|
|||
}
|
||||
starrefBottomButtonLabelTop: 5px;
|
||||
starrefBottomButtonSublabelTop: 23px;
|
||||
starrefEndBulletSize: 6px;
|
||||
starrefEndBulletTop: 8px;
|
||||
|
|
Loading…
Add table
Reference in a new issue