Add gift menu with Share and Transfer.

This commit is contained in:
John Preston 2025-01-07 10:38:14 +04:00
parent ba34d92cd3
commit 409389a994
5 changed files with 107 additions and 11 deletions

View file

@ -1206,7 +1206,7 @@ void AddStarGiftTable(
const auto selfBareId = session->userPeerId().value;
const auto giftToSelf = (peerId == session->userPeerId())
&& (entry.in || entry.bareGiftOwnerId == selfBareId);
if (unique) {
if (unique && entry.bareGiftOwnerId) {
const auto ownerId = PeerId(entry.bareGiftOwnerId);
const auto transfer = entry.in
&& entry.bareMsgId
@ -1223,6 +1223,11 @@ void AddStarGiftTable(
tr::lng_gift_unique_owner(),
MakePeerTableValue(table, controller, ownerId, send, handler),
st::giveawayGiftCodePeerMargin);
} else if (unique) {
AddTableRow(
table,
tr::lng_gift_unique_owner(),
rpl::single(TextWithEntities{ unique->ownerName }));
} else if (peerId) {
if (!giftToSelf) {
const auto user = session->data().peer(peerId)->asUser();

View file

@ -70,6 +70,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/fields/input_field.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/checkbox.h"
#include "ui/widgets/popup_menu.h"
#include "ui/widgets/shadow.h"
#include "window/themes/window_theme.h"
#include "window/section_widget.h"
@ -82,6 +83,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_menu_icons.h"
#include "styles/style_premium.h"
#include "styles/style_settings.h"
#include "styles/style_widgets.h"
#include <QtWidgets/QApplication>
@ -2494,19 +2496,50 @@ void ShowStarGiftUpgradeBox(StarGiftUpgradeArgs &&args) {
}).send();
}
void AddUniqueCloseButton(not_null<GenericBox*> box) {
const auto button = Ui::CreateChild<IconButton>(
void AddUniqueCloseButton(
not_null<GenericBox*> box,
Fn<void(not_null<Ui::PopupMenu*>)> fillMenu) {
const auto close = Ui::CreateChild<IconButton>(
box,
st::uniqueCloseButton);
button->show();
button->raise();
const auto menu = fillMenu
? Ui::CreateChild<IconButton>(box, st::uniqueMenuButton)
: nullptr;
close->show();
close->raise();
if (menu) {
menu->show();
menu->raise();
}
box->widthValue() | rpl::start_with_next([=](int width) {
button->moveToRight(0, 0, width);
button->raise();
}, button->lifetime());
button->setClickedCallback([=] {
close->moveToRight(0, 0, width);
close->raise();
if (menu) {
menu->moveToRight(close->width(), 0, width);
menu->raise();
}
}, close->lifetime());
close->setClickedCallback([=] {
box->closeBox();
});
if (menu) {
const auto state = menu->lifetime().make_state<
base::unique_qptr<Ui::PopupMenu>
>();
menu->setClickedCallback([=] {
if (*state) {
*state = nullptr;
return;
}
*state = base::make_unique_q<Ui::PopupMenu>(
menu,
st::popupMenuWithIcons);
fillMenu(state->get());
if (!(*state)->empty()) {
(*state)->popup(QCursor::pos());
}
});
}
}
void RequestStarsFormAndSubmit(

View file

@ -27,6 +27,7 @@ class CustomEmoji;
namespace Ui {
class PopupMenu;
class GenericBox;
class VerticalLayout;
@ -73,7 +74,9 @@ struct StarGiftUpgradeArgs {
};
void ShowStarGiftUpgradeBox(StarGiftUpgradeArgs &&args);
void AddUniqueCloseButton(not_null<GenericBox*> box);
void AddUniqueCloseButton(
not_null<GenericBox*> box,
Fn<void(not_null<PopupMenu*>)> fillMenu = nullptr);
void RequestStarsFormAndSubmit(
not_null<Window::SessionController*> window,

View file

@ -12,10 +12,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "api/api_earn.h"
#include "api/api_premium.h"
#include "apiwrap.h"
#include "base/random.h"
#include "base/timer_rpl.h"
#include "base/unixtime.h"
#include "boxes/gift_premium_box.h"
#include "boxes/share_box.h"
#include "boxes/star_gift_box.h"
#include "boxes/transfer_gift_box.h"
#include "chat_helpers/stickers_gift_box_pack.h"
#include "chat_helpers/stickers_lottie.h"
#include "core/application.h"
@ -73,6 +76,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/buttons.h"
#include "ui/widgets/discrete_sliders.h"
#include "ui/widgets/fields/number_input.h"
#include "ui/widgets/popup_menu.h"
#include "ui/widgets/label_with_custom_emoji.h"
#include "ui/widgets/labels.h"
#include "ui/widgets/tooltip.h"
@ -88,6 +92,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_giveaway.h"
#include "styles/style_info.h"
#include "styles/style_layers.h"
#include "styles/style_menu_icons.h"
#include "styles/style_premium.h"
#include "styles/style_settings.h"
#include "styles/style_statistics.h"
@ -825,6 +830,44 @@ void ProcessReceivedSubscriptions(
}
}
void FillUniqueGiftMenu(
not_null<Window::SessionController*> controller,
not_null<Ui::PopupMenu*> menu,
const Data::CreditsHistoryEntry &e) {
Expects(e.uniqueGift != nullptr);
const auto unique = e.uniqueGift;
const auto show = controller->uiShow();
const auto weak = base::make_weak(controller);
const auto local = u"nft/"_q + unique->slug;
const auto url = controller->session().createInternalLinkFull(local);
menu->addAction(tr::lng_context_copy_link(tr::now), [=] {
TextUtilities::SetClipboardText({ url });
if (const auto strong = weak.get()) {
strong->showToast(
tr::lng_channel_public_link_copied(tr::now));
}
}, &st::menuIconLink);
menu->addAction(tr::lng_chat_link_share(tr::now), [=] {
if (const auto strong = weak.get()) {
FastShareLink(strong, url);
}
}, &st::menuIconShare);
const auto messageId = MsgId(e.bareMsgId);
const auto transfer = e.in
&& messageId
&& (unique->starsForTransfer >= 0);
if (transfer) {
menu->addAction(tr::lng_gift_transfer_button(tr::now), [=] {
if (const auto strong = weak.get()) {
ShowTransferGiftBox(strong, unique, messageId);
}
}, &st::menuIconReplace);
}
}
void ReceiptCreditsBox(
not_null<Ui::GenericBox*> box,
not_null<Window::SessionController*> controller,
@ -892,7 +935,9 @@ void ReceiptCreditsBox(
AddSkip(content, st::defaultVerticalListSkip * 2);
AddUniqueCloseButton(box);
AddUniqueCloseButton(box, [=](not_null<Ui::PopupMenu*> menu) {
FillUniqueGiftMenu(controller, menu, e);
});
} else if (const auto callback = Ui::PaintPreviewCallback(session, e)) {
const auto thumb = content->add(object_ptr<Ui::CenterWrap<>>(
content,

View file

@ -196,6 +196,16 @@ uniqueCloseButton: IconButton(boxTitleClose) {
color: shadowFg;
}
}
uniqueMenuButton: IconButton(uniqueCloseButton) {
width: 40px;
rippleAreaPosition: point(0px, 4px);
icon: icon {{ "title_menu_dots", videoPlayIconFg }};
iconOver: icon {{ "title_menu_dots", videoPlayIconFg }};
ripple: RippleAnimation(defaultRippleAnimation) {
color: shadowFg;
}
}
upgradeGiftBox: Box(giftBox) {
buttonPadding: margins(22px, 3px, 22px, 22px);
}