mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Show upgraded gift from old "View" button.
This commit is contained in:
parent
4f702e12b7
commit
e2bff474db
3 changed files with 83 additions and 33 deletions
|
@ -142,6 +142,7 @@ struct GiftCode {
|
||||||
TextWithEntities message;
|
TextWithEntities message;
|
||||||
ChannelData *channel = nullptr;
|
ChannelData *channel = nullptr;
|
||||||
MsgId giveawayMsgId = 0;
|
MsgId giveawayMsgId = 0;
|
||||||
|
MsgId upgradeMsgId = 0;
|
||||||
int starsConverted = 0;
|
int starsConverted = 0;
|
||||||
int starsToUpgrade = 0;
|
int starsToUpgrade = 0;
|
||||||
int starsUpgradedBySender = 0;
|
int starsUpgradedBySender = 0;
|
||||||
|
|
|
@ -5661,6 +5661,7 @@ void HistoryItem::applyAction(const MTPMessageAction &action) {
|
||||||
data.vmessage()->data().ventities().v),
|
data.vmessage()->data().ventities().v),
|
||||||
}
|
}
|
||||||
: TextWithEntities()),
|
: TextWithEntities()),
|
||||||
|
.upgradeMsgId = data.vupgrade_msg_id().value_or_empty(),
|
||||||
.starsConverted = int(data.vconvert_stars().value_or_empty()),
|
.starsConverted = int(data.vconvert_stars().value_or_empty()),
|
||||||
.starsUpgradedBySender = int(
|
.starsUpgradedBySender = int(
|
||||||
data.vupgrade_stars().value_or_empty()),
|
data.vupgrade_stars().value_or_empty()),
|
||||||
|
|
|
@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "history/view/media/history_view_premium_gift.h"
|
#include "history/view/media/history_view_premium_gift.h"
|
||||||
|
|
||||||
|
#include "apiwrap.h"
|
||||||
|
#include "api/api_premium.h"
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
#include "boxes/gift_premium_box.h" // ResolveGiftCode
|
#include "boxes/gift_premium_box.h" // ResolveGiftCode
|
||||||
#include "chat_helpers/stickers_gift_box_pack.h"
|
#include "chat_helpers/stickers_gift_box_pack.h"
|
||||||
|
@ -177,44 +179,90 @@ ClickHandlerPtr PremiumGift::createViewLink() {
|
||||||
const auto peer = _parent->history()->peer;
|
const auto peer = _parent->history()->peer;
|
||||||
const auto date = _parent->data()->date();
|
const auto date = _parent->data()->date();
|
||||||
const auto data = *_gift->gift();
|
const auto data = *_gift->gift();
|
||||||
return std::make_shared<LambdaClickHandler>([=](ClickContext context) {
|
const auto showForWeakWindow = [=](
|
||||||
const auto my = context.other.value<ClickHandlerContext>();
|
base::weak_ptr<Window::SessionController> weak) {
|
||||||
if (const auto controller = my.sessionWindow.get()) {
|
const auto controller = weak.get();
|
||||||
const auto selfId = controller->session().userPeerId();
|
if (!controller) {
|
||||||
const auto sent = (from->id == selfId);
|
return;
|
||||||
if (starGift()) {
|
}
|
||||||
const auto item = controller->session().data().message(itemId);
|
const auto selfId = controller->session().userPeerId();
|
||||||
if (item) {
|
const auto sent = (from->id == selfId);
|
||||||
controller->show(Box(
|
if (starGift()) {
|
||||||
Settings::StarGiftViewBox,
|
const auto item = controller->session().data().message(itemId);
|
||||||
controller,
|
if (item) {
|
||||||
data,
|
|
||||||
item));
|
|
||||||
}
|
|
||||||
} else if (creditsPrize()) {
|
|
||||||
controller->show(Box(
|
controller->show(Box(
|
||||||
Settings::CreditsPrizeBox,
|
Settings::StarGiftViewBox,
|
||||||
controller,
|
controller,
|
||||||
data,
|
data,
|
||||||
date));
|
item));
|
||||||
} else if (data.type == Data::GiftType::Credits) {
|
|
||||||
const auto to = sent ? peer : peer->session().user();
|
|
||||||
controller->show(Box(
|
|
||||||
Settings::GiftedCreditsBox,
|
|
||||||
controller,
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
data.count,
|
|
||||||
date));
|
|
||||||
} else if (data.slug.isEmpty()) {
|
|
||||||
const auto months = data.count;
|
|
||||||
Settings::ShowGiftPremium(controller, peer, months, sent);
|
|
||||||
} else {
|
|
||||||
const auto fromId = from->id;
|
|
||||||
const auto toId = sent ? peer->id : selfId;
|
|
||||||
ResolveGiftCode(controller, data.slug, fromId, toId);
|
|
||||||
}
|
}
|
||||||
|
} else if (creditsPrize()) {
|
||||||
|
controller->show(Box(
|
||||||
|
Settings::CreditsPrizeBox,
|
||||||
|
controller,
|
||||||
|
data,
|
||||||
|
date));
|
||||||
|
} else if (data.type == Data::GiftType::Credits) {
|
||||||
|
const auto to = sent ? peer : peer->session().user();
|
||||||
|
controller->show(Box(
|
||||||
|
Settings::GiftedCreditsBox,
|
||||||
|
controller,
|
||||||
|
from,
|
||||||
|
to,
|
||||||
|
data.count,
|
||||||
|
date));
|
||||||
|
} else if (data.slug.isEmpty()) {
|
||||||
|
const auto months = data.count;
|
||||||
|
Settings::ShowGiftPremium(controller, peer, months, sent);
|
||||||
|
} else {
|
||||||
|
const auto fromId = from->id;
|
||||||
|
const auto toId = sent ? peer->id : selfId;
|
||||||
|
ResolveGiftCode(controller, data.slug, fromId, toId);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (const auto upgradeTo = data.upgradeMsgId) {
|
||||||
|
const auto requesting = std::make_shared<bool>();
|
||||||
|
return std::make_shared<LambdaClickHandler>([=](
|
||||||
|
ClickContext context) {
|
||||||
|
const auto my = context.other.value<ClickHandlerContext>();
|
||||||
|
const auto weak = my.sessionWindow;
|
||||||
|
const auto controller = weak.get();
|
||||||
|
if (!controller || *requesting) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*requesting = true;
|
||||||
|
controller->session().api().request(MTPpayments_GetUserStarGift(
|
||||||
|
MTP_vector<MTPint>(1, MTP_int(upgradeTo))
|
||||||
|
)).done([=](const MTPpayments_UserStarGifts &result) {
|
||||||
|
*requesting = false;
|
||||||
|
if (const auto window = weak.get()) {
|
||||||
|
const auto &data = result.data();
|
||||||
|
window->session().data().processUsers(data.vusers());
|
||||||
|
const auto self = window->session().user();
|
||||||
|
const auto &list = data.vgifts().v;
|
||||||
|
if (list.empty()) {
|
||||||
|
showForWeakWindow(weak);
|
||||||
|
} else if (auto parsed = Api::FromTL(self, list[0])) {
|
||||||
|
window->show(Box(
|
||||||
|
Settings::UserStarGiftBox,
|
||||||
|
window,
|
||||||
|
self,
|
||||||
|
*parsed));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).fail([=](const MTP::Error &error) {
|
||||||
|
*requesting = false;
|
||||||
|
if (const auto window = weak.get()) {
|
||||||
|
window->showToast(error.type());
|
||||||
|
}
|
||||||
|
showForWeakWindow(weak);
|
||||||
|
}).send();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return std::make_shared<LambdaClickHandler>([=](ClickContext context) {
|
||||||
|
showForWeakWindow(
|
||||||
|
context.other.value<ClickHandlerContext>().sessionWindow);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue