From 53c1ef20ef30976eef4d6709f5ff28fe51cfc2e3 Mon Sep 17 00:00:00 2001 From: "andrew (from workstation)" Date: Mon, 18 May 2020 13:57:47 +0200 Subject: [PATCH] super fix --- td/telegram/WebPagesManager.cpp | 116 +------------------------------- 1 file changed, 1 insertion(+), 115 deletions(-) diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index b023c5e8..56fa05b2 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -1169,121 +1169,7 @@ bool WebPagesManager::have_web_page(WebPageId web_page_id) const { } tl_object_ptr WebPagesManager::get_web_page_object(WebPageId web_page_id) const { - if (!web_page_id.is_valid()) { - 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 &entities, auto replace_url) { - int32 current_offset = 0; - for (auto &entity : entities) { - CHECK(entity.offset >= current_offset); - text = utf8_utf16_substr(text, static_cast(entity.offset - current_offset)); - auto entity_text = utf8_utf16_substr(text, 0, static_cast(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( - 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); + return nullptr; } tl_object_ptr WebPagesManager::get_web_page_instant_view_object(