diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 507670e46a..b7b4562f84 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -1259,7 +1259,7 @@ not_null Session::webpage(const MTPDwebPagePending &data) { const auto result = webpage(data.vid.v); webpageApplyFields( result, - QString(), + WebPageType::Article, QString(), QString(), QString(), @@ -1282,7 +1282,7 @@ not_null Session::webpage( const TextWithEntities &content) { return webpage( id, - qsl("article"), + WebPageType::Article, QString(), QString(), siteName, @@ -1298,7 +1298,7 @@ not_null Session::webpage( not_null Session::webpage( WebPageId id, - const QString &type, + WebPageType type, const QString &url, const QString &displayUrl, const QString &siteName, @@ -1347,7 +1347,7 @@ void Session::webpageApplyFields( const auto pendingTill = TimeId(0); webpageApplyFields( page, - data.has_type() ? qs(data.vtype) : qsl("article"), + ParseWebPageType(data), qs(data.vurl), qs(data.vdisplay_url), siteName, @@ -1363,7 +1363,7 @@ void Session::webpageApplyFields( void Session::webpageApplyFields( not_null page, - const QString &type, + WebPageType type, const QString &url, const QString &displayUrl, const QString &siteName, diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h index 0fcf7a782a..7b871bc0f2 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 HistoryItem; class BoxContent; struct WebPageCollage; +enum class WebPageType; namespace HistoryView { struct Group; @@ -302,7 +303,7 @@ public: const TextWithEntities &content); not_null webpage( WebPageId id, - const QString &type, + WebPageType type, const QString &url, const QString &displayUrl, const QString &siteName, @@ -484,7 +485,7 @@ private: const MTPDwebPage &data); void webpageApplyFields( not_null page, - const QString &type, + WebPageType type, const QString &url, const QString &displayUrl, const QString &siteName, diff --git a/Telegram/SourceFiles/data/data_web_page.cpp b/Telegram/SourceFiles/data/data_web_page.cpp index bffceffcfa..4c8af1521d 100644 --- a/Telegram/SourceFiles/data/data_web_page.cpp +++ b/Telegram/SourceFiles/data/data_web_page.cpp @@ -128,12 +128,22 @@ WebPageCollage ExtractCollage(const MTPDwebPage &data) { } // namespace +WebPageType ParseWebPageType(const MTPDwebPage &page) { + const auto type = page.has_type() ? qs(page.vtype) : QString(); + if (type == qstr("photo")) return WebPageType::Photo; + if (type == qstr("video")) return WebPageType::Video; + if (type == qstr("profile")) return WebPageType::Profile; + return page.has_cached_page() + ? WebPageType::ArticleWithIV + : WebPageType::Article; +} + WebPageCollage::WebPageCollage(const MTPDwebPage &data) : WebPageCollage(ExtractCollage(data)) { } bool WebPageData::applyChanges( - const QString &newType, + WebPageType newType, const QString &newUrl, const QString &newDisplayUrl, const QString &newSiteName, @@ -153,7 +163,6 @@ bool WebPageData::applyChanges( return false; } - const auto resultType = toWebPageType(newType); const auto resultUrl = TextUtilities::Clean(newUrl); const auto resultDisplayUrl = TextUtilities::Clean( newDisplayUrl); @@ -177,7 +186,7 @@ bool WebPageData::applyChanges( return QString(); }(); - if (type == resultType + if (type == newType && url == resultUrl && displayUrl == resultDisplayUrl && siteName == resultSiteName @@ -194,7 +203,7 @@ bool WebPageData::applyChanges( if (pendingTill > 0 && newPendingTill <= 0) { Auth().api().clearWebPageRequest(this); } - type = resultType; + type = newType; url = resultUrl; displayUrl = resultDisplayUrl; siteName = resultSiteName; diff --git a/Telegram/SourceFiles/data/data_web_page.h b/Telegram/SourceFiles/data/data_web_page.h index c4a9ad0d63..931128ca82 100644 --- a/Telegram/SourceFiles/data/data_web_page.h +++ b/Telegram/SourceFiles/data/data_web_page.h @@ -10,19 +10,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_photo.h" #include "data/data_document.h" -enum WebPageType { - WebPagePhoto, - WebPageVideo, - WebPageProfile, - WebPageArticle +enum class WebPageType { + Photo, + Video, + Profile, + Article, + ArticleWithIV, }; -inline WebPageType toWebPageType(const QString &type) { - if (type == qstr("photo")) return WebPagePhoto; - if (type == qstr("video")) return WebPageVideo; - if (type == qstr("profile")) return WebPageProfile; - return WebPageArticle; -} +WebPageType ParseWebPageType(const MTPDwebPage &type); struct WebPageCollage { using Item = base::variant; @@ -37,37 +33,9 @@ struct WebPageCollage { struct WebPageData { WebPageData(const WebPageId &id) : id(id) { } - WebPageData( - const WebPageId &id, - WebPageType type, - const QString &url, - const QString &displayUrl, - const QString &siteName, - const QString &title, - const TextWithEntities &description, - PhotoData *photo, - DocumentData *document, - WebPageCollage &&collage, - int duration, - const QString &author, - int pendingTill) - : id(id) - , type(type) - , url(url) - , displayUrl(displayUrl) - , siteName(siteName) - , title(title) - , description(description) - , duration(duration) - , author(author) - , photo(photo) - , document(document) - , collage(std::move(collage)) - , pendingTill(pendingTill) { - } bool applyChanges( - const QString &newType, + WebPageType newType, const QString &newUrl, const QString &newDisplayUrl, const QString &newSiteName, @@ -81,7 +49,7 @@ struct WebPageData { int newPendingTill); WebPageId id = 0; - WebPageType type = WebPageArticle; + WebPageType type = WebPageType::Article; QString url; QString displayUrl; QString siteName; diff --git a/Telegram/SourceFiles/history/history_media_types.cpp b/Telegram/SourceFiles/history/history_media_types.cpp index 26cd3dc263..277e12b5f4 100644 --- a/Telegram/SourceFiles/history/history_media_types.cpp +++ b/Telegram/SourceFiles/history/history_media_types.cpp @@ -3476,18 +3476,28 @@ QSize HistoryWebPage::countOptimalSize() { } // init layout - auto title = TextUtilities::SingleLine(_data->title.isEmpty() ? _data->author : _data->title); + auto title = TextUtilities::SingleLine(_data->title.isEmpty() + ? _data->author + : _data->title); if (!_collage.empty()) { _asArticle = false; - } else if (!_data->document && _data->photo && _data->type != WebPagePhoto && _data->type != WebPageVideo) { - if (_data->type == WebPageProfile) { + } else if (!_data->document + && _data->photo + && _data->type != WebPageType::Photo + && _data->type != WebPageType::Video) { + if (_data->type == WebPageType::Profile) { _asArticle = true; - } else if (_data->siteName == qstr("Twitter") || _data->siteName == qstr("Facebook")) { + } else if (_data->siteName == qstr("Twitter") + || _data->siteName == qstr("Facebook") + || _data->type == WebPageType::ArticleWithIV) { _asArticle = false; } else { _asArticle = true; } - if (_asArticle && _data->description.text.isEmpty() && title.isEmpty() && _data->siteName.isEmpty()) { + if (_asArticle + && _data->description.text.isEmpty() + && title.isEmpty() + && _data->siteName.isEmpty()) { _asArticle = false; } } else { @@ -3585,7 +3595,7 @@ QSize HistoryWebPage::countOptimalSize() { minHeight += bottomInfoPadding(); } } - if (_data->type == WebPageVideo && _data->duration) { + if (_data->type == WebPageType::Video && _data->duration) { _duration = formatDurationText(_data->duration); _durationWidth = st::msgDateFont->width(_duration); } @@ -3810,7 +3820,8 @@ void HistoryWebPage::draw(Painter &p, const QRect &r, TextSelection selection, T auto pixwidth = _attach->width(); auto pixheight = _attach->height(); - if (_data->type == WebPageVideo && _attach->type() == MediaTypePhoto) { + if (_data->type == WebPageType::Video + && _attach->type() == MediaTypePhoto) { if (_attach->isReadyForOpen()) { if (_data->siteName == qstr("YouTube")) { st::youtubeIcon.paint(p, (pixwidth - st::youtubeIcon.width()) / 2, (pixheight - st::youtubeIcon.height()) / 2, width()); @@ -3922,9 +3933,12 @@ TextState HistoryWebPage::textState(QPoint point, StateRequest request) const { result = _attach->textState(point - QPoint(attachLeft, attachTop), request); if (result.link && !_data->document && _data->photo && _collage.empty() && _attach->isReadyForOpen()) { - if (_data->type == WebPageProfile || _data->type == WebPageVideo) { + if (_data->type == WebPageType::Profile + || _data->type == WebPageType::Video) { result.link = _openl; - } else if (_data->type == WebPagePhoto || _data->siteName == qstr("Twitter") || _data->siteName == qstr("Facebook")) { + } else if (_data->type == WebPageType::Photo + || _data->siteName == qstr("Twitter") + || _data->siteName == qstr("Facebook")) { // leave photo link } else { result.link = _openl; diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index 6707ab601a..d481e21890 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -1246,9 +1246,11 @@ Link::Link( _page->document, parent->fullId()); } else if (_page->photo) { - if (_page->type == WebPageProfile || _page->type == WebPageVideo) { + if (_page->type == WebPageType::Profile || _page->type == WebPageType::Video) { _photol = std::make_shared(_page->url); - } else if (_page->type == WebPagePhoto || _page->siteName == qstr("Twitter") || _page->siteName == qstr("Facebook")) { + } else if (_page->type == WebPageType::Photo + || _page->siteName == qstr("Twitter") + || _page->siteName == qstr("Facebook")) { _photol = std::make_shared( _page->photo, parent->fullId());