Add webPage.stickers.

This commit is contained in:
levlam 2024-04-24 02:44:42 +03:00
parent 14f31d81c5
commit fe0246093d
2 changed files with 47 additions and 6 deletions

View File

@ -2433,8 +2433,9 @@ webPageInstantView page_blocks:vector<PageBlock> view_count:int32 version:int32
//@voice_note Preview of the content as a voice note, if available; may be null
//@story_sender_chat_id The identifier of the sender of the previewed story; 0 if none
//@story_id The identifier of the previewed story; 0 if none
//@stickers Up to 4 stickers from the sticker set available via the link
//@instant_view_version Version of web page instant view (currently, can be 1 or 2); 0 if none
webPage url:string display_url:string type:string site_name:string title:string description:formattedText photo:photo embed_url:string embed_type:string embed_width:int32 embed_height:int32 duration:int32 author:string has_large_media:Bool show_large_media:Bool skip_confirmation:Bool show_above_text:Bool animation:animation audio:audio document:document sticker:sticker video:video video_note:videoNote voice_note:voiceNote story_sender_chat_id:int53 story_id:int32 instant_view_version:int32 = WebPage;
webPage url:string display_url:string type:string site_name:string title:string description:formattedText photo:photo embed_url:string embed_type:string embed_width:int32 embed_height:int32 duration:int32 author:string has_large_media:Bool show_large_media:Bool skip_confirmation:Bool show_above_text:Bool animation:animation audio:audio document:document sticker:sticker video:video video_note:videoNote voice_note:voiceNote story_sender_chat_id:int53 story_id:int32 stickers:vector<sticker> instant_view_version:int32 = WebPage;
//@description Contains information about a country

View File

@ -27,6 +27,7 @@
#include "td/telegram/Photo.h"
#include "td/telegram/PhotoFormat.h"
#include "td/telegram/StickersManager.h"
#include "td/telegram/StickersManager.hpp"
#include "td/telegram/StoryFullId.h"
#include "td/telegram/StoryId.h"
#include "td/telegram/StoryManager.h"
@ -243,6 +244,7 @@ class WebPagesManager::WebPage {
Document document_;
vector<Document> documents_;
vector<StoryFullId> story_full_ids_;
vector<FileId> sticker_ids_;
WebPageInstantView instant_view_;
FileSourceId file_source_id_;
@ -267,6 +269,7 @@ class WebPagesManager::WebPage {
bool has_no_hash = true;
bool has_documents = !documents_.empty();
bool has_story_full_ids = !story_full_ids_.empty();
bool has_sticker_ids = !sticker_ids_.empty();
BEGIN_STORE_FLAGS();
STORE_FLAG(has_type);
STORE_FLAG(has_site_name);
@ -284,6 +287,7 @@ class WebPagesManager::WebPage {
STORE_FLAG(has_documents);
STORE_FLAG(has_story_full_ids);
STORE_FLAG(has_large_media_);
STORE_FLAG(has_sticker_ids);
END_STORE_FLAGS();
store(url_, storer);
@ -325,6 +329,13 @@ class WebPagesManager::WebPage {
if (has_story_full_ids) {
store(story_full_ids_, storer);
}
if (has_sticker_ids) {
Td *td = storer.context()->td().get_actor_unsafe();
store(static_cast<uint32>(sticker_ids_.size()), storer);
for (auto &sticker_id : sticker_ids_) {
td->stickers_manager_->store_sticker(sticker_id, false, storer, "WebPage");
}
}
}
template <class ParserT>
@ -345,6 +356,7 @@ class WebPagesManager::WebPage {
bool has_no_hash;
bool has_documents;
bool has_story_full_ids;
bool has_sticker_ids;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_type);
PARSE_FLAG(has_site_name);
@ -362,6 +374,7 @@ class WebPagesManager::WebPage {
PARSE_FLAG(has_documents);
PARSE_FLAG(has_story_full_ids);
PARSE_FLAG(has_large_media_);
PARSE_FLAG(has_sticker_ids);
END_PARSE_FLAGS();
parse(url_, parser);
@ -408,6 +421,17 @@ class WebPagesManager::WebPage {
parse(story_full_ids_, parser);
td::remove_if(story_full_ids_, [](StoryFullId story_full_id) { return !story_full_id.is_server(); });
}
if (has_sticker_ids) {
Td *td = parser.context()->td().get_actor_unsafe();
uint32 sticker_count;
parse(sticker_count, parser);
for (size_t i = 0; i < sticker_count; i++) {
auto sticker_id = td->stickers_manager_->parse_sticker(false, parser);
if (sticker_id.is_valid()) {
sticker_ids_.push_back(sticker_id);
}
}
}
if (has_instant_view) {
instant_view_.is_empty_ = false;
@ -425,7 +449,7 @@ class WebPagesManager::WebPage {
lhs.duration_ == rhs.duration_ && lhs.author_ == rhs.author_ &&
lhs.has_large_media_ == rhs.has_large_media_ && lhs.document_ == rhs.document_ &&
lhs.documents_ == rhs.documents_ && lhs.story_full_ids_ == rhs.story_full_ids_ &&
lhs.instant_view_.is_empty_ == rhs.instant_view_.is_empty_ &&
lhs.sticker_ids_ == rhs.sticker_ids_ && lhs.instant_view_.is_empty_ == rhs.instant_view_.is_empty_ &&
lhs.instant_view_.is_v2_ == rhs.instant_view_.is_v2_;
}
};
@ -594,6 +618,16 @@ WebPageId WebPagesManager::on_get_web_page(tl_object_ptr<telegram_api::WebPage>
}
case telegram_api::webPageAttributeStickerSet::ID: {
auto attribute = telegram_api::move_object_as<telegram_api::webPageAttributeStickerSet>(attribute_ptr);
if (!page->sticker_ids_.empty()) {
LOG(ERROR) << "Receive duplicate webPageAttributeStickerSet";
}
for (auto &sticker : attribute->stickers_) {
auto sticker_id =
td_->stickers_manager_->on_get_sticker_document(std::move(sticker), StickerFormat::Unknown).second;
if (sticker_id.is_valid() && page->sticker_ids_.size() < 4) {
page->sticker_ids_.push_back(sticker_id);
}
}
break;
}
default:
@ -1399,7 +1433,9 @@ tl_object_ptr<td_api::webPage> WebPagesManager::get_web_page_object(WebPageId we
}
return false;
}();
return make_tl_object<td_api::webPage>(
auto stickers = transform(web_page->sticker_ids_,
[&](FileId sticker_id) { return td_->stickers_manager_->get_sticker_object(sticker_id); });
return td_api::make_object<td_api::webPage>(
web_page->url_, web_page->display_url_, web_page->type_, web_page->site_name_, web_page->title_,
get_formatted_text_object(description, true, duration == 0 ? std::numeric_limits<int32>::max() : duration),
get_photo_object(td_->file_manager_.get(), web_page->photo_), web_page->embed_url_, web_page->embed_type_,
@ -1426,7 +1462,7 @@ tl_object_ptr<td_api::webPage> WebPagesManager::get_web_page_object(WebPageId we
web_page->document_.type == Document::Type::VoiceNote
? td_->voice_notes_manager_->get_voice_note_object(web_page->document_.file_id)
: nullptr,
td_->dialog_manager_->get_chat_id_object(story_sender_dialog_id, "webPage"), story_id.get(),
td_->dialog_manager_->get_chat_id_object(story_sender_dialog_id, "webPage"), story_id.get(), std::move(stickers),
instant_view_version);
}
@ -1627,7 +1663,7 @@ void WebPagesManager::on_get_web_page_instant_view(WebPage *web_page, tl_object_
if (document_id != 0) {
get_map(document.type)->emplace(document_id, document.file_id);
} else {
LOG(ERROR) << document.type << " has zero ID";
LOG(ERROR) << document.type << " has zero identifier";
}
} else {
LOG(ERROR) << document.type << " has no remote location";
@ -1636,9 +1672,12 @@ void WebPagesManager::on_get_web_page_instant_view(WebPage *web_page, tl_object_
if (!web_page->document_.empty()) {
add_document(web_page->document_);
}
for (auto &document : web_page->documents_) {
for (const auto &document : web_page->documents_) {
add_document(document);
}
for (auto sticker_id : web_page->sticker_ids_) {
add_document({Document::Type::Sticker, sticker_id});
}
LOG(INFO) << "Receive a web page instant view with " << page->blocks_.size() << " blocks, " << animations.size()
<< " animations, " << audios.size() << " audios, " << documents.size() << " documents, " << photos.size()
@ -1958,6 +1997,7 @@ vector<FileId> WebPagesManager::get_web_page_file_ids(const WebPage *web_page) c
for (auto &document : web_page->documents_) {
document.append_file_ids(td_, result);
}
append(result, web_page->sticker_ids_);
if (!web_page->instant_view_.is_empty_) {
for (auto &page_block : web_page->instant_view_.page_blocks_) {
page_block->append_file_ids(td_, result);