mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
Send real craft requests.
This commit is contained in:
@@ -1273,59 +1273,6 @@ void SendGift(
|
||||
});
|
||||
}
|
||||
|
||||
[[nodiscard]] std::shared_ptr<Data::GiftUpgradeResult> FindUniqueGift(
|
||||
not_null<Main::Session*> session,
|
||||
const MTPUpdates &updates) {
|
||||
auto result = std::shared_ptr<Data::GiftUpgradeResult>();
|
||||
const auto checkAction = [&](const MTPDmessageService &message) {
|
||||
const auto &action = message.vaction();
|
||||
action.match([&](const MTPDmessageActionStarGiftUnique &data) {
|
||||
if (const auto gift = Api::FromTL(session, data.vgift())) {
|
||||
const auto to = data.vpeer()
|
||||
? peerFromMTP(*data.vpeer())
|
||||
: PeerId();
|
||||
const auto service = data.vfrom_id()
|
||||
&& session->data().peer(
|
||||
peerFromMTP(*data.vfrom_id()))->isServiceUser();
|
||||
const auto channel = (service && peerIsChannel(to))
|
||||
? session->data().channel(peerToChannel(to)).get()
|
||||
: nullptr;
|
||||
const auto channelSavedId = channel
|
||||
? data.vsaved_id().value_or_empty()
|
||||
: uint64();
|
||||
const auto realGiftMsgId = (peerIsUser(to) && data.vsaved_id())
|
||||
? MsgId(data.vsaved_id().value_or_empty())
|
||||
: MsgId(message.vid().v);
|
||||
|
||||
result = std::make_shared<Data::GiftUpgradeResult>(
|
||||
Data::GiftUpgradeResult{
|
||||
.info = *gift,
|
||||
.manageId = (channel && channelSavedId)
|
||||
? Data::SavedStarGiftId::Chat(
|
||||
channel,
|
||||
channelSavedId)
|
||||
: Data::SavedStarGiftId::User(realGiftMsgId),
|
||||
.date = message.vdate().v,
|
||||
.starsForDetailsRemove = int(
|
||||
data.vdrop_original_details_stars(
|
||||
).value_or_empty()),
|
||||
.saved = data.is_saved(),
|
||||
});
|
||||
}
|
||||
}, [](const auto &) {});
|
||||
};
|
||||
updates.match([&](const MTPDupdates &data) {
|
||||
for (const auto &update : data.vupdates().v) {
|
||||
update.match([&](const MTPDupdateNewMessage &data) {
|
||||
data.vmessage().match([&](const MTPDmessageService &data) {
|
||||
checkAction(data);
|
||||
}, [](const auto &) {});
|
||||
}, [](const auto &) {});
|
||||
}
|
||||
}, [](const auto &) {});
|
||||
return result;
|
||||
}
|
||||
|
||||
void ShowGiftUpgradedToast(
|
||||
not_null<Window::SessionController*> window,
|
||||
not_null<Main::Session*> session,
|
||||
@@ -5070,4 +5017,57 @@ void SendGiftBox(
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Data::GiftUpgradeResult> FindUniqueGift(
|
||||
not_null<Main::Session*> session,
|
||||
const MTPUpdates &updates) {
|
||||
auto result = std::shared_ptr<Data::GiftUpgradeResult>();
|
||||
const auto checkAction = [&](const MTPDmessageService &message) {
|
||||
const auto &action = message.vaction();
|
||||
action.match([&](const MTPDmessageActionStarGiftUnique &data) {
|
||||
if (const auto gift = Api::FromTL(session, data.vgift())) {
|
||||
const auto to = data.vpeer()
|
||||
? peerFromMTP(*data.vpeer())
|
||||
: PeerId();
|
||||
const auto service = data.vfrom_id()
|
||||
&& session->data().peer(
|
||||
peerFromMTP(*data.vfrom_id()))->isServiceUser();
|
||||
const auto channel = (service && peerIsChannel(to))
|
||||
? session->data().channel(peerToChannel(to)).get()
|
||||
: nullptr;
|
||||
const auto channelSavedId = channel
|
||||
? data.vsaved_id().value_or_empty()
|
||||
: uint64();
|
||||
const auto realGiftMsgId = (peerIsUser(to) && data.vsaved_id())
|
||||
? MsgId(data.vsaved_id().value_or_empty())
|
||||
: MsgId(message.vid().v);
|
||||
|
||||
result = std::make_shared<Data::GiftUpgradeResult>(
|
||||
Data::GiftUpgradeResult{
|
||||
.info = *gift,
|
||||
.manageId = (channel && channelSavedId)
|
||||
? Data::SavedStarGiftId::Chat(
|
||||
channel,
|
||||
channelSavedId)
|
||||
: Data::SavedStarGiftId::User(realGiftMsgId),
|
||||
.date = message.vdate().v,
|
||||
.starsForDetailsRemove = int(
|
||||
data.vdrop_original_details_stars(
|
||||
).value_or_empty()),
|
||||
.saved = data.is_saved(),
|
||||
});
|
||||
}
|
||||
}, [](const auto &) {});
|
||||
};
|
||||
updates.match([&](const MTPDupdates &data) {
|
||||
for (const auto &update : data.vupdates().v) {
|
||||
update.match([&](const MTPDupdateNewMessage &data) {
|
||||
data.vmessage().match([&](const MTPDmessageService &data) {
|
||||
checkAction(data);
|
||||
}, [](const auto &) {});
|
||||
}, [](const auto &) {});
|
||||
}
|
||||
}, [](const auto &) {});
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace Ui
|
||||
|
||||
@@ -176,4 +176,8 @@ void SendGiftBox(
|
||||
uint64 nextToUpgradeStickerId = 0,
|
||||
Fn<void()> nextToUpgradeShow = nullptr);
|
||||
|
||||
[[nodiscard]] std::shared_ptr<Data::GiftUpgradeResult> FindUniqueGift(
|
||||
not_null<Main::Session*> session,
|
||||
const MTPUpdates &updates);
|
||||
|
||||
} // namespace Ui
|
||||
|
||||
@@ -103,6 +103,10 @@ struct GiftForCraft {
|
||||
std::shared_ptr<Data::UniqueGift> unique;
|
||||
Data::SavedStarGiftId manageId;
|
||||
|
||||
[[nodiscard]] QString slugId() const {
|
||||
return unique ? unique->slug : QString();
|
||||
}
|
||||
|
||||
explicit operator bool() const {
|
||||
return unique != nullptr;
|
||||
}
|
||||
@@ -624,8 +628,8 @@ void ShowSelectGiftBox(
|
||||
&state->delegate),
|
||||
});
|
||||
const auto button = state->entries.back().button;
|
||||
const auto proj = &GiftForCraft::manageId;
|
||||
if (ranges::contains(selected, gift.manageId, proj)) {
|
||||
const auto proj = &GiftForCraft::slugId;
|
||||
if (ranges::contains(selected, gift.info.unique->slug, proj)) {
|
||||
button->toggleSelected(
|
||||
true,
|
||||
GiftSelectionMode::Inset,
|
||||
@@ -676,7 +680,8 @@ void ShowSelectGiftBox(
|
||||
box->verticalLayout(),
|
||||
state->resale,
|
||||
rpl::single(false),
|
||||
bought);
|
||||
bought,
|
||||
true);
|
||||
}
|
||||
|
||||
box->addButton(tr::lng_box_ok(), [=] {
|
||||
@@ -921,11 +926,12 @@ void ShowSelectGiftBox(
|
||||
void Craft(
|
||||
not_null<GenericBox*> box,
|
||||
not_null<Window::SessionController*> controller,
|
||||
std::shared_ptr<ChatHelpers::Show> show,
|
||||
std::shared_ptr<CraftState> state,
|
||||
const std::vector<GiftForCraft> &gifts,
|
||||
Fn<void()> closeParent) {
|
||||
auto show = controller->uiShow();
|
||||
auto startRequest = [=](CraftResultCallback done) {
|
||||
#if 0
|
||||
constexpr auto kDelays = std::array<crl::time, 7>{
|
||||
100, 200, 300, 400, 500, 1000, 2000
|
||||
};
|
||||
@@ -953,6 +959,24 @@ void Craft(
|
||||
done(nullptr);
|
||||
}
|
||||
});
|
||||
#endif
|
||||
|
||||
auto inputs = QVector<MTPInputSavedStarGift>();
|
||||
for (const auto &gift : gifts) {
|
||||
inputs.push_back(
|
||||
Api::InputSavedStarGiftId(gift.manageId, gift.unique));
|
||||
}
|
||||
const auto weak = base::make_weak(controller);
|
||||
const auto session = &controller->session();
|
||||
session->api().request(MTPpayments_CraftStarGift(
|
||||
MTP_vector<MTPInputSavedStarGift>(inputs)
|
||||
)).done([=](const MTPUpdates &result) {
|
||||
session->api().applyUpdates(result);
|
||||
session->data().nextForUpgradeGiftInvalidate(session->user());
|
||||
done(FindUniqueGift(session, result));
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
show->showToast(error.type());
|
||||
}).send();
|
||||
};
|
||||
const auto requested = std::make_shared<bool>();
|
||||
const auto giftId = gifts.front().unique->initialGiftId;
|
||||
@@ -1319,7 +1343,6 @@ void MakeCraftContent(
|
||||
Craft(
|
||||
box,
|
||||
controller,
|
||||
controller->uiShow(),
|
||||
state->craftState,
|
||||
state->chosen.current(),
|
||||
closeParent);
|
||||
|
||||
@@ -543,7 +543,8 @@ void AddResaleGiftsList(
|
||||
not_null<VerticalLayout*> container,
|
||||
Data::ResaleGiftsDescriptor descriptor,
|
||||
rpl::producer<bool> forceTon,
|
||||
Fn<void(std::shared_ptr<Data::UniqueGift>)> bought) {
|
||||
Fn<void(std::shared_ptr<Data::UniqueGift>)> bought,
|
||||
bool forCraft) {
|
||||
struct State {
|
||||
rpl::event_stream<> updated;
|
||||
ResaleGiftsDescriptor data;
|
||||
@@ -553,6 +554,7 @@ void AddResaleGiftsList(
|
||||
int lastMinHeight = 0;
|
||||
};
|
||||
const auto state = container->lifetime().make_state<State>();
|
||||
state->filter = ResaleGiftsFilter{ .forCraft = forCraft };
|
||||
state->data = std::move(descriptor);
|
||||
state->ton = std::move(forceTon);
|
||||
|
||||
@@ -668,7 +670,7 @@ void ShowResaleGiftBoughtToast(
|
||||
not_null<PeerData*> to,
|
||||
const Data::UniqueGift &gift) {
|
||||
show->showToast({
|
||||
.title = tr::lng_gift_sent_title(tr::now),
|
||||
.title = to->isSelf() ? QString() : tr::lng_gift_sent_title(tr::now),
|
||||
.text = TextWithEntities{ (to->isSelf()
|
||||
? tr::lng_gift_sent_resale_done_self(
|
||||
tr::now,
|
||||
|
||||
@@ -47,6 +47,7 @@ void AddResaleGiftsList(
|
||||
not_null<VerticalLayout*> container,
|
||||
Data::ResaleGiftsDescriptor descriptor,
|
||||
rpl::producer<bool> forceTon,
|
||||
Fn<void(std::shared_ptr<Data::UniqueGift>)> bought = nullptr);
|
||||
Fn<void(std::shared_ptr<Data::UniqueGift>)> bought = nullptr,
|
||||
bool forCraft = false);
|
||||
|
||||
} // namespace Ui
|
||||
|
||||
Reference in New Issue
Block a user