Allow sending the sticker from the intro.

This commit is contained in:
John Preston 2024-03-21 13:07:22 +04:00
parent 85554d19e4
commit d1a995a863
3 changed files with 46 additions and 2 deletions

View File

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/history_view_about_view.h"
#include "api/api_premium.h"
#include "api/api_sending.h"
#include "apiwrap.h"
#include "base/random.h"
#include "chat_helpers/stickers_lottie.h"
@ -115,10 +116,16 @@ auto GenerateChatIntro(
}
}
}
const auto send = [=] {
Api::SendExistingDocument(Api::MessageToSend(
Api::SendAction(parent->history())
), sticker);
};
return StickerInBubblePart::Data{
.sticker = sticker,
.size = st::chatIntroStickerSize,
.cacheTag = Tag::ChatIntroHelloSticker,
.link = std::make_shared<LambdaClickHandler>(send),
};
};
push(std::make_unique<StickerInBubblePart>(

View File

@ -124,7 +124,7 @@ void MediaInBubble::draw(Painter &p, const PaintContext &context) const {
const auto outer = width();
if (outer < st::msgPadding.left() + st::msgPadding.right() + 1) {
return;
} else {
} else if (_service) {
PainterHighQualityEnabler hq(p);
const auto radius = st::msgServiceGiftBoxRadius;
p.setPen(Qt::NoPen);
@ -367,6 +367,25 @@ void StickerInBubblePart::draw(
}
}
TextState StickerInBubblePart::textState(
QPoint point,
StateRequest request,
int outerWidth) const {
auto result = TextState(_parent);
if (_sticker) {
const auto stickerSize = _sticker->countOptimalSize();
const auto sticker = QRect(
(outerWidth - stickerSize.width()) / 2,
_padding.top() + _skipTop,
stickerSize.width(),
stickerSize.height());
if (sticker.contains(point)) {
result.link = _link;
}
}
return result;
}
bool StickerInBubblePart::hasHeavyPart() {
return _sticker && _sticker->hasHeavyPart();
}
@ -408,6 +427,7 @@ void StickerInBubblePart::ensureCreated(Element *replacing) const {
const auto sticker = data.sticker;
if (const auto info = sticker->sticker()) {
const auto skipPremiumEffect = true;
_link = data.link;
_skipTop = data.skipTop;
_sticker.emplace(_parent, sticker, skipPremiumEffect, replacing);
if (data.singleTimePlayback) {
@ -440,6 +460,13 @@ void StickerWithBadgePart::draw(
}
}
TextState StickerWithBadgePart::textState(
QPoint point,
StateRequest request,
int outerWidth) const {
return _sticker.textState(point, request, outerWidth);
}
bool StickerWithBadgePart::hasHeavyPart() {
return _sticker.hasHeavyPart();
}

View File

@ -75,7 +75,7 @@ public:
bool pressed) override;
bool needsBubble() const override {
return !_service;;
return !_service;
}
bool customInfoLayout() const override {
return false;
@ -169,6 +169,7 @@ public:
int size = 0;
ChatHelpers::StickerLottieSize cacheTag = {};
bool singleTimePlayback = false;
ClickHandlerPtr link;
explicit operator bool() const {
return sticker != nullptr;
@ -192,6 +193,10 @@ public:
not_null<const MediaInBubble*> owner,
const PaintContext &context,
int outerWidth) const override;
TextState textState(
QPoint point,
StateRequest request,
int outerWidth) const override;
bool hasHeavyPart() override;
void unloadHeavyPart() override;
@ -210,6 +215,7 @@ private:
mutable int _skipTop = 0;
mutable QMargins _padding;
mutable std::optional<Sticker> _sticker;
mutable ClickHandlerPtr _link;
};
@ -228,6 +234,10 @@ public:
not_null<const MediaInBubble*> owner,
const PaintContext &context,
int outerWidth) const override;
TextState textState(
QPoint point,
StateRequest request,
int outerWidth) const override;
bool hasHeavyPart() override;
void unloadHeavyPart() override;