super fix
This commit is contained in:
parent
878022bc0d
commit
53c1ef20ef
@ -1169,121 +1169,7 @@ bool WebPagesManager::have_web_page(WebPageId web_page_id) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tl_object_ptr<td_api::webPage> WebPagesManager::get_web_page_object(WebPageId web_page_id) const {
|
tl_object_ptr<td_api::webPage> WebPagesManager::get_web_page_object(WebPageId web_page_id) const {
|
||||||
if (!web_page_id.is_valid()) {
|
return nullptr;
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
const WebPage *web_page = get_web_page(web_page_id);
|
|
||||||
if (web_page == nullptr) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
int32 instant_view_version = [web_page] {
|
|
||||||
if (web_page->instant_view.is_empty) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (web_page->instant_view.is_v2) {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}();
|
|
||||||
|
|
||||||
FormattedText description;
|
|
||||||
description.text = web_page->description;
|
|
||||||
description.entities = find_entities(web_page->description, true);
|
|
||||||
|
|
||||||
auto r_url = parse_url(web_page->display_url);
|
|
||||||
if (r_url.is_ok()) {
|
|
||||||
Slice host = r_url.ok().host_;
|
|
||||||
if (!host.empty() && host.back() == '.') {
|
|
||||||
host.truncate(host.size() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto replace_entities = [](Slice text, vector<MessageEntity> &entities, auto replace_url) {
|
|
||||||
int32 current_offset = 0;
|
|
||||||
for (auto &entity : entities) {
|
|
||||||
CHECK(entity.offset >= current_offset);
|
|
||||||
text = utf8_utf16_substr(text, static_cast<size_t>(entity.offset - current_offset));
|
|
||||||
auto entity_text = utf8_utf16_substr(text, 0, static_cast<size_t>(entity.length));
|
|
||||||
text = text.substr(entity_text.size());
|
|
||||||
current_offset = entity.offset + entity.length;
|
|
||||||
|
|
||||||
auto replaced_url = replace_url(entity, entity_text);
|
|
||||||
if (!replaced_url.empty()) {
|
|
||||||
entity = MessageEntity(MessageEntity::Type::TextUrl, entity.offset, entity.length, std::move(replaced_url));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (host == "instagram.com" || ends_with(host, ".instagram.com")) {
|
|
||||||
replace_entities(description.text, description.entities, [](const MessageEntity &entity, Slice text) {
|
|
||||||
if (entity.type == MessageEntity::Type::Mention) {
|
|
||||||
return PSTRING() << "https://www.instagram.com/" << text.substr(1) << '/';
|
|
||||||
}
|
|
||||||
if (entity.type == MessageEntity::Type::Hashtag) {
|
|
||||||
return PSTRING() << "https://www.instagram.com/explore/tags/" << url_encode(text.substr(1)) << '/';
|
|
||||||
}
|
|
||||||
return string();
|
|
||||||
});
|
|
||||||
} else if (host == "twitter.com" || ends_with(host, ".twitter.com")) {
|
|
||||||
replace_entities(description.text, description.entities, [](const MessageEntity &entity, Slice text) {
|
|
||||||
if (entity.type == MessageEntity::Type::Mention) {
|
|
||||||
return PSTRING() << "https://twitter.com/" << text.substr(1);
|
|
||||||
}
|
|
||||||
if (entity.type == MessageEntity::Type::Hashtag) {
|
|
||||||
return PSTRING() << "https://twitter.com/hashtag/" << url_encode(text.substr(1));
|
|
||||||
}
|
|
||||||
return string();
|
|
||||||
});
|
|
||||||
} else if (host == "t.me" || host == "telegram.me" || host == "telegram.dog" || host == "telesco.pe") {
|
|
||||||
// leave everything as is
|
|
||||||
} else {
|
|
||||||
td::remove_if(description.entities,
|
|
||||||
[](const MessageEntity &entity) { return entity.type == MessageEntity::Type::Mention; });
|
|
||||||
|
|
||||||
if (host == "youtube.com" || host == "www.youtube.com") {
|
|
||||||
replace_entities(description.text, description.entities, [](const MessageEntity &entity, Slice text) {
|
|
||||||
if (entity.type == MessageEntity::Type::Hashtag) {
|
|
||||||
return PSTRING() << "https://www.youtube.com/results?search_query=" << url_encode(text);
|
|
||||||
}
|
|
||||||
return string();
|
|
||||||
});
|
|
||||||
} else if (host == "music.youtube.com") {
|
|
||||||
replace_entities(description.text, description.entities, [](const MessageEntity &entity, Slice text) {
|
|
||||||
if (entity.type == MessageEntity::Type::Hashtag) {
|
|
||||||
return PSTRING() << "https://music.youtube.com/search?q=" << url_encode(text);
|
|
||||||
}
|
|
||||||
return string();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return make_tl_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), get_photo_object(td_->file_manager_.get(), &web_page->photo),
|
|
||||||
web_page->embed_url, web_page->embed_type, web_page->embed_dimensions.width, web_page->embed_dimensions.height,
|
|
||||||
web_page->duration, web_page->author,
|
|
||||||
web_page->document.type == Document::Type::Animation
|
|
||||||
? td_->animations_manager_->get_animation_object(web_page->document.file_id, "get_web_page_object")
|
|
||||||
: nullptr,
|
|
||||||
web_page->document.type == Document::Type::Audio
|
|
||||||
? td_->audios_manager_->get_audio_object(web_page->document.file_id)
|
|
||||||
: nullptr,
|
|
||||||
web_page->document.type == Document::Type::General
|
|
||||||
? td_->documents_manager_->get_document_object(web_page->document.file_id)
|
|
||||||
: nullptr,
|
|
||||||
web_page->document.type == Document::Type::Sticker
|
|
||||||
? td_->stickers_manager_->get_sticker_object(web_page->document.file_id)
|
|
||||||
: nullptr,
|
|
||||||
web_page->document.type == Document::Type::Video
|
|
||||||
? td_->videos_manager_->get_video_object(web_page->document.file_id)
|
|
||||||
: nullptr,
|
|
||||||
web_page->document.type == Document::Type::VideoNote
|
|
||||||
? td_->video_notes_manager_->get_video_note_object(web_page->document.file_id)
|
|
||||||
: nullptr,
|
|
||||||
web_page->document.type == Document::Type::VoiceNote
|
|
||||||
? td_->voice_notes_manager_->get_voice_note_object(web_page->document.file_id)
|
|
||||||
: nullptr,
|
|
||||||
instant_view_version);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tl_object_ptr<td_api::webPageInstantView> WebPagesManager::get_web_page_instant_view_object(
|
tl_object_ptr<td_api::webPageInstantView> WebPagesManager::get_web_page_instant_view_object(
|
||||||
|
Reference in New Issue
Block a user