Start editing chat intro in Telegram Business.

This commit is contained in:
John Preston
2024-03-19 10:09:00 +04:00
parent cf1d0677d1
commit 191c35914f
30 changed files with 1056 additions and 44 deletions
+59
View File
@@ -109,6 +109,18 @@ rpl::producer<> Premium::cloudSetUpdated() const {
return _cloudSetUpdated.events();
}
auto Premium::helloStickers() const
-> const std::vector<not_null<DocumentData*>> & {
if (_helloStickers.empty()) {
const_cast<Premium*>(this)->reloadHelloStickers();
}
return _helloStickers;
}
rpl::producer<> Premium::helloStickersUpdated() const {
return _helloStickersUpdated.events();
}
int64 Premium::monthlyAmount() const {
return _monthlyAmount;
}
@@ -225,6 +237,33 @@ void Premium::reloadCloudSet() {
}).send();
}
void Premium::reloadHelloStickers() {
if (_helloStickersRequestId) {
return;
}
_helloStickersRequestId = _api.request(MTPmessages_GetStickers(
MTP_string("\xf0\x9f\x91\x8b\xe2\xad\x90\xef\xb8\x8f"),
MTP_long(_helloStickersHash)
)).done([=](const MTPmessages_Stickers &result) {
_helloStickersRequestId = 0;
result.match([&](const MTPDmessages_stickersNotModified &) {
}, [&](const MTPDmessages_stickers &data) {
_helloStickersHash = data.vhash().v;
const auto owner = &_session->data();
_helloStickers.clear();
for (const auto &sticker : data.vstickers().v) {
const auto document = owner->processDocument(sticker);
if (document->sticker()) {
_helloStickers.push_back(document);
}
}
_helloStickersUpdated.fire({});
});
}).fail([=] {
_helloStickersRequestId = 0;
}).send();
}
void Premium::checkGiftCode(
const QString &slug,
Fn<void(GiftCode)> done) {
@@ -609,4 +648,24 @@ RequirePremiumState ResolveRequiresPremiumToWrite(
return RequirePremiumState::Unknown;
}
rpl::producer<DocumentData*> RandomHelloStickerValue(
not_null<Main::Session*> session) {
const auto premium = &session->api().premium();
const auto random = [=] {
const auto &v = premium->helloStickers();
Assert(!v.empty());
return v[base::RandomIndex(v.size())].get();
};
const auto &v = premium->helloStickers();
if (!v.empty()) {
return rpl::single(random());
}
return rpl::single<DocumentData*>(
nullptr
) | rpl::then(premium->helloStickersUpdated(
) | rpl::filter([=] {
return !premium->helloStickers().empty();
}) | rpl::take(1) | rpl::map(random));
}
} // namespace Api