Fix boost reassign.

This commit is contained in:
John Preston 2023-10-31 11:17:55 +04:00
parent 076291b98f
commit bde39970a0
2 changed files with 14 additions and 9 deletions

View File

@ -685,6 +685,7 @@ void SessionNavigation::applyBoost(
done(false); done(false);
return; return;
} }
auto slot = int();
auto different = PeerId(); auto different = PeerId();
auto earliest = TimeId(-1); auto earliest = TimeId(-1);
const auto now = base::unixtime::now(); const auto now = base::unixtime::now();
@ -695,13 +696,13 @@ void SessionNavigation::applyBoost(
? peerFromMTP(*data.vpeer()) ? peerFromMTP(*data.vpeer())
: PeerId(); : PeerId();
if (!peerId && cooldown <= now) { if (!peerId && cooldown <= now) {
applyBoostChecked(channel, done); applyBoostChecked(channel, data.vslot().v, done);
return; return;
} else if (peerId != channel->id) { } else if (peerId != channel->id
&& (earliest < 0 || cooldown < earliest)) {
slot = data.vslot().v;
different = peerId; different = peerId;
if (earliest < 0 || cooldown < earliest) { earliest = cooldown;
earliest = cooldown;
}
} }
} }
if (different) { if (different) {
@ -727,7 +728,7 @@ void SessionNavigation::applyBoost(
done(false); done(false);
} else { } else {
const auto peer = _session->data().peer(different); const auto peer = _session->data().peer(different);
replaceBoostConfirm(peer, channel, done); replaceBoostConfirm(peer, channel, slot, done);
} }
} else { } else {
uiShow()->show(Ui::MakeConfirmBox({ uiShow()->show(Ui::MakeConfirmBox({
@ -748,11 +749,12 @@ void SessionNavigation::applyBoost(
void SessionNavigation::replaceBoostConfirm( void SessionNavigation::replaceBoostConfirm(
not_null<PeerData*> from, not_null<PeerData*> from,
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
int slot,
Fn<void(bool)> done) { Fn<void(bool)> done) {
const auto forwarded = std::make_shared<bool>(false); const auto forwarded = std::make_shared<bool>(false);
const auto confirmed = [=](Fn<void()> close) { const auto confirmed = [=](Fn<void()> close) {
*forwarded = true; *forwarded = true;
applyBoostChecked(channel, done); applyBoostChecked(channel, slot, done);
close(); close();
}; };
const auto box = uiShow()->show(Box([=](not_null<Ui::GenericBox*> box) { const auto box = uiShow()->show(Box([=](not_null<Ui::GenericBox*> box) {
@ -781,10 +783,11 @@ void SessionNavigation::replaceBoostConfirm(
void SessionNavigation::applyBoostChecked( void SessionNavigation::applyBoostChecked(
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
int slot,
Fn<void(bool)> done) { Fn<void(bool)> done) {
_api.request(MTPpremium_ApplyBoost( _api.request(MTPpremium_ApplyBoost(
MTP_flags(0), MTP_flags(MTPpremium_ApplyBoost::Flag::f_slots),
MTPVector<MTPint>(), // slots MTP_vector<MTPint>({ MTP_int(slot) }),
channel->input channel->input
)).done([=](const MTPpremium_MyBoosts &result) { )).done([=](const MTPpremium_MyBoosts &result) {
done(true); done(true);

View File

@ -318,9 +318,11 @@ private:
void replaceBoostConfirm( void replaceBoostConfirm(
not_null<PeerData*> from, not_null<PeerData*> from,
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
int slot,
Fn<void(bool)> done); Fn<void(bool)> done);
void applyBoostChecked( void applyBoostChecked(
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
int slot,
Fn<void(bool)> done); Fn<void(bool)> done);
const not_null<Main::Session*> _session; const not_null<Main::Session*> _session;