Fix sending paid intro sticker.

This commit is contained in:
John Preston 2025-03-07 19:03:22 +04:00
parent 72a35ba58b
commit 4ff4e63a11
5 changed files with 38 additions and 5 deletions

View file

@ -4346,6 +4346,9 @@ void HistoryInner::refreshAboutView(bool force) {
_aboutView->refreshRequests() | rpl::start_with_next([=] {
updateBotInfo();
}, _aboutView->lifetime());
_aboutView->sendIntroSticker() | rpl::start_to_stream(
_sendIntroSticker,
_aboutView->lifetime());
}
};
if (const auto user = _peer->asUser()) {
@ -4777,6 +4780,11 @@ ClickContext HistoryInner::prepareClickContext(
};
}
auto HistoryInner::sendIntroSticker() const
-> rpl::producer<not_null<DocumentData*>> {
return _sendIntroSticker.events();
}
auto HistoryInner::DelegateMixin()
-> std::unique_ptr<HistoryMainElementDelegateMixin> {
return std::make_unique<HistoryMainElementDelegate>();

View file

@ -221,6 +221,9 @@ public:
Qt::MouseButton button,
FullMsgId itemId) const;
[[nodiscard]] auto sendIntroSticker() const
-> rpl::producer<not_null<DocumentData*>>;
[[nodiscard]] static auto DelegateMixin()
-> std::unique_ptr<HistoryMainElementDelegateMixin>;
@ -466,6 +469,7 @@ private:
std::unique_ptr<HistoryView::AboutView> _aboutView;
std::unique_ptr<HistoryView::EmptyPainter> _emptyPainter;
std::unique_ptr<HistoryView::TranslateTracker> _translateTracker;
rpl::event_stream<not_null<DocumentData*>> _sendIntroSticker;
mutable History *_curHistory = nullptr;
mutable int _curBlock = 0;

View file

@ -2525,6 +2525,12 @@ void HistoryWidget::showHistory(
_scroll->hide();
_list = _scroll->setOwnedWidget(
object_ptr<HistoryInner>(this, _scroll, controller(), _history));
_list->sendIntroSticker(
) | rpl::start_with_next([=](not_null<DocumentData*> sticker) {
sendExistingDocument(
sticker,
Api::MessageToSend(prepareSendAction({})));
}, _list->lifetime());
_list->show();
if (const auto channel = _peer->asChannel()) {

View file

@ -199,7 +199,8 @@ auto GenerateChatIntro(
not_null<Element*> parent,
Element *replacing,
const Data::ChatIntro &data,
Fn<void(not_null<DocumentData*>)> helloChosen)
Fn<void(not_null<DocumentData*>)> helloChosen,
Fn<void(not_null<DocumentData*>)> sendIntroSticker)
-> Fn<void(
not_null<MediaGeneric*>,
Fn<void(std::unique_ptr<MediaGenericPart>)>)> {
@ -243,9 +244,7 @@ auto GenerateChatIntro(
}
}
const auto send = [=] {
Api::SendExistingDocument(Api::MessageToSend(
Api::SendAction(parent->history())
), sticker);
sendIntroSticker(sticker);
};
return StickerInBubblePart::Data{
.sticker = sticker,
@ -598,9 +597,17 @@ void AboutView::make(Data::ChatIntro data, bool preview) {
}
}
};
const auto sendIntroSticker = [=](not_null<DocumentData*> sticker) {
_sendIntroSticker.fire_copy(sticker);
};
owned->overrideMedia(std::make_unique<HistoryView::MediaGeneric>(
owned.get(),
GenerateChatIntro(owned.get(), _item.get(), data, helloChosen),
GenerateChatIntro(
owned.get(),
_item.get(),
data,
helloChosen,
sendIntroSticker),
HistoryView::MediaGenericDescriptor{
.maxWidth = st::chatIntroWidth,
.serviceLink = std::make_shared<LambdaClickHandler>(handler),
@ -613,6 +620,10 @@ void AboutView::make(Data::ChatIntro data, bool preview) {
setItem(std::move(owned), data.sticker);
}
rpl::producer<not_null<DocumentData*>> AboutView::sendIntroSticker() const {
return _sendIntroSticker.events();
}
rpl::producer<> AboutView::refreshRequests() const {
return _refreshRequests.events();
}

View file

@ -30,6 +30,8 @@ public:
void make(Data::ChatIntro data, bool preview = false);
[[nodiscard]] auto sendIntroSticker() const
-> rpl::producer<not_null<DocumentData*>>;
[[nodiscard]] rpl::producer<> refreshRequests() const;
[[nodiscard]] rpl::lifetime &lifetime();
@ -63,6 +65,8 @@ private:
DocumentData *_sticker = nullptr;
int _version = 0;
rpl::event_stream<not_null<DocumentData*>> _sendIntroSticker;
bool _commonGroupsStale = false;
bool _commonGroupsRequested = false;
std::vector<not_null<PeerData*>> _commonGroups;