From f43f99cff25a24ccb7d67fa830b1e488f89ccc05 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 18 Apr 2024 05:14:19 +0300 Subject: [PATCH] Added initial api support of stickerset attribute in web pages. --- .../boxes/peers/edit_peer_color_box.cpp | 1 + Telegram/SourceFiles/data/data_session.cpp | 30 +++++++++++++++++++ Telegram/SourceFiles/data/data_session.h | 3 ++ Telegram/SourceFiles/data/data_web_page.cpp | 5 ++++ Telegram/SourceFiles/data/data_web_page.h | 12 ++++++++ Telegram/SourceFiles/history/history_item.cpp | 1 + 6 files changed, 52 insertions(+) diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_color_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_color_box.cpp index 018d07915..09b5d273b 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_color_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_color_box.cpp @@ -312,6 +312,7 @@ PreviewWrap::PreviewWrap( nullptr, // document WebPageCollage(), nullptr, // iv + nullptr, // stickerSet 0, // duration QString(), // author false, // hasLargeMedia diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 6d6bb4404..464642d27 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -3377,6 +3377,7 @@ not_null Session::processWebpage( nullptr, WebPageCollage(), nullptr, + nullptr, 0, QString(), false, @@ -3402,6 +3403,7 @@ not_null Session::webpage( nullptr, WebPageCollage(), nullptr, + nullptr, 0, QString(), false, @@ -3420,6 +3422,7 @@ not_null Session::webpage( DocumentData *document, WebPageCollage &&collage, std::unique_ptr iv, + std::unique_ptr stickerSet, int duration, const QString &author, bool hasLargeMedia, @@ -3438,6 +3441,7 @@ not_null 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; + 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(); + 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, + std::unique_ptr 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, diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h index fa58d4847..117823802 100644 --- a/Telegram/SourceFiles/data/data_session.h +++ b/Telegram/SourceFiles/data/data_session.h @@ -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, + std::unique_ptr stickerSet, int duration, const QString &author, bool hasLargeMedia, @@ -857,6 +859,7 @@ private: DocumentData *document, WebPageCollage &&collage, std::unique_ptr iv, + std::unique_ptr stickerSet, int duration, const QString &author, bool hasLargeMedia, diff --git a/Telegram/SourceFiles/data/data_web_page.cpp b/Telegram/SourceFiles/data/data_web_page.cpp index 215e1a407..f8d4b69c4 100644 --- a/Telegram/SourceFiles/data/data_web_page.cpp +++ b/Telegram/SourceFiles/data/data_web_page.cpp @@ -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 newIv, + std::unique_ptr 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; diff --git a/Telegram/SourceFiles/data/data_web_page.h b/Telegram/SourceFiles/data/data_web_page.h index a659780c9..0293106f0 100644 --- a/Telegram/SourceFiles/data/data_web_page.h +++ b/Telegram/SourceFiles/data/data_web_page.h @@ -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> items; + bool isEmoji = false; + bool isTextColor = false; + +}; + struct WebPageData { WebPageData(not_null owner, const WebPageId &id); ~WebPageData(); @@ -87,6 +97,7 @@ struct WebPageData { DocumentData *newDocument, WebPageCollage &&newCollage, std::unique_ptr newIv, + std::unique_ptr newStickerSet, int newDuration, const QString &newAuthor, bool newHasLargeMedia, @@ -114,6 +125,7 @@ struct WebPageData { DocumentData *document = nullptr; WebPageCollage collage; std::unique_ptr iv; + std::unique_ptr stickerSet; int duration = 0; TimeId pendingTill = 0; uint32 version : 30 = 0; diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index a6effce00..079051b8c 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -657,6 +657,7 @@ HistoryItem::HistoryItem( nullptr, WebPageCollage(), nullptr, + nullptr, 0, QString(), false,