Show gift sender badge.

This commit is contained in:
John Preston
2025-12-22 17:41:11 +04:00
parent fac241b87e
commit 321576658f
5 changed files with 129 additions and 2 deletions

View File

@@ -3836,6 +3836,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_gift_unique_backdrop" = "Backdrop";
"lng_gift_unique_symbol" = "Symbol";
"lng_gift_unique_rarity" = "Only {percent} of such collectibles have this attribute.";
"lng_gift_unique_sender" = "{from} sent you this gift on {date}";
"lng_gift_unique_sender_you" = "You bought this gift on {date}";
"lng_gift_unique_availability_label" = "Quantity";
"lng_gift_unique_availability#one" = "{count} of {amount} issued";
"lng_gift_unique_availability#other" = "{count} of {amount} issued";

View File

@@ -7,13 +7,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "boxes/star_gift_box.h"
#include "base/call_delayed.h"
#include "apiwrap.h"
#include "api/api_credits.h"
#include "api/api_global_privacy.h"
#include "api/api_premium.h"
#include "api/api_text_entities.h"
//#include "base/call_delayed.h"
#include "base/event_filter.h"
#include "base/qt_signal_producer.h"
#include "base/random.h"
@@ -36,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "chat_helpers/tabbed_panel.h"
#include "chat_helpers/tabbed_selector.h"
#include "core/application.h"
#include "core/click_handler_types.h"
#include "core/ui_integration.h"
#include "data/components/gift_auctions.h"
#include "data/components/promo_suggestions.h"
@@ -3919,6 +3919,107 @@ void AddWearGiftCover(
}, cover->lifetime());
}
void AttachGiftSenderBadge(
not_null<GenericBox*> box,
std::shared_ptr<ChatHelpers::Show> show,
not_null<PeerData*> from,
const QDateTime &date) {
const auto parent = box->getDelegate()->outerContainer();
const auto dateText = tr::bold(langDayOfMonth(date.date()));
const auto badge = CreateChild<FlatLabel>(
parent,
(from->isSelf()
? tr::lng_gift_unique_sender_you(
lt_date,
rpl::single(dateText),
tr::marked)
: tr::lng_gift_unique_sender(
lt_from,
rpl::single(tr::link(tr::bold(from->shortName()), 1)),
lt_date,
rpl::single(dateText),
tr::marked)),
st::uniqueGiftSenderBadge);
badge->paintOn([=](QPainter &p) {
auto hq = PainterHighQualityEnabler(p);
p.setBrush(st::radialBg);
p.setPen(Qt::NoPen);
const auto radius = badge->height() / 2.;
p.drawRoundedRect(badge->rect(), radius, radius);
});
badge->setLink(1, std::make_shared<LambdaClickHandler>([=] {
if (const auto window = show->resolveWindow()) {
window->showPeerHistory(from);
}
}));
auto widget = static_cast<QWidget*>(box);
while (widget->parentWidget() && widget->parentWidget() != parent) {
widget = widget->parentWidget();
}
const auto updateGeometry = [=] {
const auto outer = parent->rect();
const auto margin = st::msgServiceMargin;
const auto padding = st::msgServicePadding;
const auto available = outer.marginsRemoved(margin).width();
badge->resizeToWidth(std::min(
available - padding.left() - padding.right(),
badge->textMaxWidth()));
const auto inner = Ui::MapFrom(parent, box, box->rect());
const auto top = std::max(
inner.y() - badge->height() - margin.top(),
outer.y() + (margin.top() * 2));
const auto left = margin.left() + (available - badge->width()) / 2;
badge->move(left, top);
};
badge->naturalWidthValue(
) | rpl::on_next(updateGeometry, badge->lifetime());
for (auto w = static_cast<QWidget*>(box)
; w != widget
; w = w->parentWidget()) {
base::install_event_filter(w, [=](not_null<QEvent*> e) {
const auto type = e->type();
if (type == QEvent::Move || type == QEvent::Resize) {
PostponeCall(badge, updateGeometry);
}
return base::EventFilterResult::Continue;
});
}
base::install_event_filter(widget, [=](not_null<QEvent*> e) {
const auto type = e->type();
if (type == QEvent::Show) {
badge->show();
} else if (type == QEvent::Hide) {
badge->hide();
} else if (type == QEvent::Move || type == QEvent::Resize) {
PostponeCall(badge, updateGeometry);
} else if (type == QEvent::ZOrderChange) {
PostponeCall(badge, [=] { badge->raise(); });
}
return base::EventFilterResult::Continue;
});
badge->setVisible(!widget->isHidden());
base::install_event_filter(parent, [=](not_null<QEvent*> e) {
const auto type = e->type();
if (type == QEvent::ChildAdded) {
PostponeCall(badge, [=] { badge->raise(); });
} else if (e->type() == QEvent::Resize) {
PostponeCall(badge, updateGeometry);
}
return base::EventFilterResult::Continue;
});
badge->raise();
box->boxClosing() | rpl::on_next([=] {
delete badge;
}, badge->lifetime());
}
void ShowUniqueGiftWearBox(
std::shared_ptr<ChatHelpers::Show> show,
not_null<PeerData*> peer,

View File

@@ -94,6 +94,12 @@ void AddWearGiftCover(
const Data::UniqueGift &data,
not_null<PeerData*> peer);
void AttachGiftSenderBadge(
not_null<GenericBox*> box,
std::shared_ptr<ChatHelpers::Show> show,
not_null<PeerData*> from,
const QDateTime &date);
void ShowUniqueGiftWearBox(
std::shared_ptr<ChatHelpers::Show> show,
not_null<PeerData*> peer,

View File

@@ -1326,6 +1326,12 @@ void GenericCreditsEntryCover(
.resalePrice = UniqueGiftResalePrice(e.uniqueGift, forceTon),
.resaleClick = resaleClick,
});
if (e.bareGiftOwnerId == session->userPeerId().value) {
if (const auto fromId = PeerId(e.barePeerId)) {
const auto from = session->data().peer(fromId);
AttachGiftSenderBadge(box, show, from, e.date);
}
}
} else if (const auto callback = Ui::PaintPreviewCallback(session, e)) {
const auto thumb = content->add(
GenericEntryPhoto(content, callback, stUser.photoSize),

View File

@@ -320,6 +320,18 @@ uniqueMenuButton: IconButton(uniqueCloseButton) {
color: shadowFg;
}
}
uniqueGiftSenderBadge: FlatLabel(defaultFlatLabel) {
style: semiboldTextStyle;
palette: TextPalette(defaultTextPalette) {
linkFg: radialFg;
monoFg: radialFg;
}
margin: margins(12px, 3px, 12px, 4px);
minWidth: 128px;
align: align(top);
textFg: radialFg;
}
uniqueAttributeTop: 10px;
uniqueAttributeSkip: 8px;
uniqueAttributePadding: margins(6px, 8px, 6px, 8px);