Added initial api support of stickerset attribute in web pages.

This commit is contained in:
23rd 2024-04-18 05:14:19 +03:00 committed by John Preston
parent a3b8397361
commit f43f99cff2
6 changed files with 52 additions and 0 deletions

View File

@ -312,6 +312,7 @@ PreviewWrap::PreviewWrap(
nullptr, // document
WebPageCollage(),
nullptr, // iv
nullptr, // stickerSet
0, // duration
QString(), // author
false, // hasLargeMedia

View File

@ -3377,6 +3377,7 @@ not_null<WebPageData*> Session::processWebpage(
nullptr,
WebPageCollage(),
nullptr,
nullptr,
0,
QString(),
false,
@ -3402,6 +3403,7 @@ not_null<WebPageData*> Session::webpage(
nullptr,
WebPageCollage(),
nullptr,
nullptr,
0,
QString(),
false,
@ -3420,6 +3422,7 @@ not_null<WebPageData*> Session::webpage(
DocumentData *document,
WebPageCollage &&collage,
std::unique_ptr<Iv::Data> iv,
std::unique_ptr<WebPageStickerSet> stickerSet,
int duration,
const QString &author,
bool hasLargeMedia,
@ -3438,6 +3441,7 @@ not_null<WebPageData*> Session::webpage(
document,
std::move(collage),
std::move(iv),
std::move(stickerSet),
duration,
author,
hasLargeMedia,
@ -3490,6 +3494,29 @@ void Session::webpageApplyFields(
}
return nullptr;
};
using WebPageStickerSetPtr = std::unique_ptr<WebPageStickerSet>;
const auto lookupStickerSet = [&]() -> WebPageStickerSetPtr {
if (const auto attributes = data.vattributes()) {
for (const auto &attribute : attributes->v) {
auto result = attribute.match([&](
const MTPDwebPageAttributeStickerSet &data) {
auto result = std::make_unique<WebPageStickerSet>();
result->isEmoji = data.is_emojis();
result->isTextColor = data.is_text_color();
for (const auto &tl : data.vstickers().v) {
result->items.push_back(processDocument(tl));
}
return result;
}, [](const auto &) {
return WebPageStickerSetPtr(nullptr);
});
if (!result->items.empty()) {
return result;
}
}
}
return nullptr;
};
auto story = (Data::Story*)nullptr;
auto storyId = FullStoryId();
if (const auto attributes = data.vattributes()) {
@ -3581,6 +3608,7 @@ void Session::webpageApplyFields(
: lookupThemeDocument()),
WebPageCollage(this, data),
std::move(iv),
lookupStickerSet(),
data.vduration().value_or_empty(),
qs(data.vauthor().value_or_empty()),
data.is_has_large_media(),
@ -3600,6 +3628,7 @@ void Session::webpageApplyFields(
DocumentData *document,
WebPageCollage &&collage,
std::unique_ptr<Iv::Data> iv,
std::unique_ptr<WebPageStickerSet> stickerSet,
int duration,
const QString &author,
bool hasLargeMedia,
@ -3617,6 +3646,7 @@ void Session::webpageApplyFields(
document,
std::move(collage),
std::move(iv),
std::move(stickerSet),
duration,
author,
hasLargeMedia,

View File

@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
class Image;
class HistoryItem;
struct WebPageCollage;
struct WebPageStickerSet;
enum class WebPageType : uint8;
enum class NewMessageType;
@ -579,6 +580,7 @@ public:
DocumentData *document,
WebPageCollage &&collage,
std::unique_ptr<Iv::Data> iv,
std::unique_ptr<WebPageStickerSet> stickerSet,
int duration,
const QString &author,
bool hasLargeMedia,
@ -857,6 +859,7 @@ private:
DocumentData *document,
WebPageCollage &&collage,
std::unique_ptr<Iv::Data> iv,
std::unique_ptr<WebPageStickerSet> stickerSet,
int duration,
const QString &author,
bool hasLargeMedia,

View File

@ -166,6 +166,8 @@ WebPageType ParseWebPageType(
return WebPageType::ChannelBoost;
} else if (type == u"telegram_giftcode"_q) {
return WebPageType::Giftcode;
} else if (type == u"telegram_stickerset"_q) {
return WebPageType::StickerSet;
} else if (hasIV) {
return WebPageType::ArticleWithIV;
} else {
@ -219,6 +221,7 @@ bool WebPageData::applyChanges(
DocumentData *newDocument,
WebPageCollage &&newCollage,
std::unique_ptr<Iv::Data> newIv,
std::unique_ptr<WebPageStickerSet> newStickerSet,
int newDuration,
const QString &newAuthor,
bool newHasLargeMedia,
@ -272,6 +275,7 @@ bool WebPageData::applyChanges(
&& collage.items == newCollage.items
&& (!iv == !newIv)
&& (!iv || iv->partial() == newIv->partial())
&& (!stickerSet == !newStickerSet)
&& duration == newDuration
&& author == resultAuthor
&& hasLargeMedia == (newHasLargeMedia ? 1 : 0)
@ -293,6 +297,7 @@ bool WebPageData::applyChanges(
document = newDocument;
collage = std::move(newCollage);
iv = std::move(newIv);
stickerSet = std::move(newStickerSet);
duration = newDuration;
author = resultAuthor;
pendingTill = newPendingTill;

View File

@ -46,6 +46,7 @@ enum class WebPageType : uint8 {
WallPaper,
Theme,
Story,
StickerSet,
Article,
ArticleWithIV,
@ -68,6 +69,15 @@ struct WebPageCollage {
};
struct WebPageStickerSet {
WebPageStickerSet() = default;
std::vector<not_null<DocumentData*>> items;
bool isEmoji = false;
bool isTextColor = false;
};
struct WebPageData {
WebPageData(not_null<Data::Session*> owner, const WebPageId &id);
~WebPageData();
@ -87,6 +97,7 @@ struct WebPageData {
DocumentData *newDocument,
WebPageCollage &&newCollage,
std::unique_ptr<Iv::Data> newIv,
std::unique_ptr<WebPageStickerSet> newStickerSet,
int newDuration,
const QString &newAuthor,
bool newHasLargeMedia,
@ -114,6 +125,7 @@ struct WebPageData {
DocumentData *document = nullptr;
WebPageCollage collage;
std::unique_ptr<Iv::Data> iv;
std::unique_ptr<WebPageStickerSet> stickerSet;
int duration = 0;
TimeId pendingTill = 0;
uint32 version : 30 = 0;

View File

@ -657,6 +657,7 @@ HistoryItem::HistoryItem(
nullptr,
WebPageCollage(),
nullptr,
nullptr,
0,
QString(),
false,