Update API scheme to layer 220.

Allow offering to buy gifts.
This commit is contained in:
John Preston
2025-11-28 11:37:32 +04:00
parent 4439cbf553
commit 23880ac6c1
15 changed files with 281 additions and 74 deletions

View File

@@ -964,6 +964,21 @@ void ProcessReceivedSubscriptions(
// (owner->isChannel() && owner->asChannel()->canTransferGifts());
}
[[nodiscard]] bool ShowOfferBuyButton(
not_null<Main::Session*> session,
const Data::CreditsHistoryEntry &e) {
const auto unique = e.uniqueGift.get();
const auto owner = (unique && unique->ownerId)
? session->data().peer(unique->ownerId).get()
: nullptr;
return owner
&& owner->isUser()
&& !owner->isSelf()
&& (unique->starsMinOffer >= 0);
// Currently we're not making offers for channel gifts.
// (owner->isChannel() && !owner->asChannel()->canTransferGifts());
}
void FillUniqueGiftMenu(
std::shared_ptr<ChatHelpers::Show> show,
not_null<Ui::PopupMenu*> menu,
@@ -1158,6 +1173,10 @@ void FillUniqueGiftMenu(
}));
}, st.unlist ? st.unlist : &st::menuIconTagRemove);
}
} else if (ShowOfferBuyButton(&show->session(), e)) {
menu->addAction(tr::lng_gift_offer_button(tr::now), [=] {
ShowOfferBuyBox(show, unique);
}, st.offer ? st.offer : &st::menuIconEarn);
}
}
@@ -1193,6 +1212,7 @@ CreditsEntryBoxStyleOverrides DarkCreditsEntryBoxStyle() {
.hide = &st::darkGiftHide,
.pin = &st::darkGiftPin,
.unpin = &st::darkGiftUnpin,
.offer = &st::darkGiftOffer,
.shareBox = std::make_shared<ShareBoxStyleOverrides>(
DarkShareBoxStyle()),
.giftWearBox = std::make_shared<GiftWearBoxStyleOverride>(

View File

@@ -127,6 +127,7 @@ struct CreditsEntryBoxStyleOverrides {
const style::icon *hide = nullptr;
const style::icon *pin = nullptr;
const style::icon *unpin = nullptr;
const style::icon *offer = nullptr;
std::shared_ptr<ShareBoxStyleOverrides> shareBox;
std::shared_ptr<GiftWearBoxStyleOverride> giftWearBox;
};