Show large photos in web pages with IV.

This commit is contained in:
John Preston 2018-10-31 14:11:01 +04:00
parent 8850d974a2
commit 5aa2e66d02
6 changed files with 57 additions and 63 deletions

View File

@ -1259,7 +1259,7 @@ not_null<WebPageData*> Session::webpage(const MTPDwebPagePending &data) {
const auto result = webpage(data.vid.v); const auto result = webpage(data.vid.v);
webpageApplyFields( webpageApplyFields(
result, result,
QString(), WebPageType::Article,
QString(), QString(),
QString(), QString(),
QString(), QString(),
@ -1282,7 +1282,7 @@ not_null<WebPageData*> Session::webpage(
const TextWithEntities &content) { const TextWithEntities &content) {
return webpage( return webpage(
id, id,
qsl("article"), WebPageType::Article,
QString(), QString(),
QString(), QString(),
siteName, siteName,
@ -1298,7 +1298,7 @@ not_null<WebPageData*> Session::webpage(
not_null<WebPageData*> Session::webpage( not_null<WebPageData*> Session::webpage(
WebPageId id, WebPageId id,
const QString &type, WebPageType type,
const QString &url, const QString &url,
const QString &displayUrl, const QString &displayUrl,
const QString &siteName, const QString &siteName,
@ -1347,7 +1347,7 @@ void Session::webpageApplyFields(
const auto pendingTill = TimeId(0); const auto pendingTill = TimeId(0);
webpageApplyFields( webpageApplyFields(
page, page,
data.has_type() ? qs(data.vtype) : qsl("article"), ParseWebPageType(data),
qs(data.vurl), qs(data.vurl),
qs(data.vdisplay_url), qs(data.vdisplay_url),
siteName, siteName,
@ -1363,7 +1363,7 @@ void Session::webpageApplyFields(
void Session::webpageApplyFields( void Session::webpageApplyFields(
not_null<WebPageData*> page, not_null<WebPageData*> page,
const QString &type, WebPageType type,
const QString &url, const QString &url,
const QString &displayUrl, const QString &displayUrl,
const QString &siteName, const QString &siteName,

View File

@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
class HistoryItem; class HistoryItem;
class BoxContent; class BoxContent;
struct WebPageCollage; struct WebPageCollage;
enum class WebPageType;
namespace HistoryView { namespace HistoryView {
struct Group; struct Group;
@ -302,7 +303,7 @@ public:
const TextWithEntities &content); const TextWithEntities &content);
not_null<WebPageData*> webpage( not_null<WebPageData*> webpage(
WebPageId id, WebPageId id,
const QString &type, WebPageType type,
const QString &url, const QString &url,
const QString &displayUrl, const QString &displayUrl,
const QString &siteName, const QString &siteName,
@ -484,7 +485,7 @@ private:
const MTPDwebPage &data); const MTPDwebPage &data);
void webpageApplyFields( void webpageApplyFields(
not_null<WebPageData*> page, not_null<WebPageData*> page,
const QString &type, WebPageType type,
const QString &url, const QString &url,
const QString &displayUrl, const QString &displayUrl,
const QString &siteName, const QString &siteName,

View File

@ -128,12 +128,22 @@ WebPageCollage ExtractCollage(const MTPDwebPage &data) {
} // namespace } // 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::WebPageCollage(const MTPDwebPage &data)
: WebPageCollage(ExtractCollage(data)) { : WebPageCollage(ExtractCollage(data)) {
} }
bool WebPageData::applyChanges( bool WebPageData::applyChanges(
const QString &newType, WebPageType newType,
const QString &newUrl, const QString &newUrl,
const QString &newDisplayUrl, const QString &newDisplayUrl,
const QString &newSiteName, const QString &newSiteName,
@ -153,7 +163,6 @@ bool WebPageData::applyChanges(
return false; return false;
} }
const auto resultType = toWebPageType(newType);
const auto resultUrl = TextUtilities::Clean(newUrl); const auto resultUrl = TextUtilities::Clean(newUrl);
const auto resultDisplayUrl = TextUtilities::Clean( const auto resultDisplayUrl = TextUtilities::Clean(
newDisplayUrl); newDisplayUrl);
@ -177,7 +186,7 @@ bool WebPageData::applyChanges(
return QString(); return QString();
}(); }();
if (type == resultType if (type == newType
&& url == resultUrl && url == resultUrl
&& displayUrl == resultDisplayUrl && displayUrl == resultDisplayUrl
&& siteName == resultSiteName && siteName == resultSiteName
@ -194,7 +203,7 @@ bool WebPageData::applyChanges(
if (pendingTill > 0 && newPendingTill <= 0) { if (pendingTill > 0 && newPendingTill <= 0) {
Auth().api().clearWebPageRequest(this); Auth().api().clearWebPageRequest(this);
} }
type = resultType; type = newType;
url = resultUrl; url = resultUrl;
displayUrl = resultDisplayUrl; displayUrl = resultDisplayUrl;
siteName = resultSiteName; siteName = resultSiteName;

View File

@ -10,19 +10,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_photo.h" #include "data/data_photo.h"
#include "data/data_document.h" #include "data/data_document.h"
enum WebPageType { enum class WebPageType {
WebPagePhoto, Photo,
WebPageVideo, Video,
WebPageProfile, Profile,
WebPageArticle Article,
ArticleWithIV,
}; };
inline WebPageType toWebPageType(const QString &type) { WebPageType ParseWebPageType(const MTPDwebPage &type);
if (type == qstr("photo")) return WebPagePhoto;
if (type == qstr("video")) return WebPageVideo;
if (type == qstr("profile")) return WebPageProfile;
return WebPageArticle;
}
struct WebPageCollage { struct WebPageCollage {
using Item = base::variant<PhotoData*, DocumentData*>; using Item = base::variant<PhotoData*, DocumentData*>;
@ -37,37 +33,9 @@ struct WebPageCollage {
struct WebPageData { struct WebPageData {
WebPageData(const WebPageId &id) : id(id) { 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( bool applyChanges(
const QString &newType, WebPageType newType,
const QString &newUrl, const QString &newUrl,
const QString &newDisplayUrl, const QString &newDisplayUrl,
const QString &newSiteName, const QString &newSiteName,
@ -81,7 +49,7 @@ struct WebPageData {
int newPendingTill); int newPendingTill);
WebPageId id = 0; WebPageId id = 0;
WebPageType type = WebPageArticle; WebPageType type = WebPageType::Article;
QString url; QString url;
QString displayUrl; QString displayUrl;
QString siteName; QString siteName;

View File

@ -3476,18 +3476,28 @@ QSize HistoryWebPage::countOptimalSize() {
} }
// init layout // 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()) { if (!_collage.empty()) {
_asArticle = false; _asArticle = false;
} else if (!_data->document && _data->photo && _data->type != WebPagePhoto && _data->type != WebPageVideo) { } else if (!_data->document
if (_data->type == WebPageProfile) { && _data->photo
&& _data->type != WebPageType::Photo
&& _data->type != WebPageType::Video) {
if (_data->type == WebPageType::Profile) {
_asArticle = true; _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; _asArticle = false;
} else { } else {
_asArticle = true; _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; _asArticle = false;
} }
} else { } else {
@ -3585,7 +3595,7 @@ QSize HistoryWebPage::countOptimalSize() {
minHeight += bottomInfoPadding(); minHeight += bottomInfoPadding();
} }
} }
if (_data->type == WebPageVideo && _data->duration) { if (_data->type == WebPageType::Video && _data->duration) {
_duration = formatDurationText(_data->duration); _duration = formatDurationText(_data->duration);
_durationWidth = st::msgDateFont->width(_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 pixwidth = _attach->width();
auto pixheight = _attach->height(); auto pixheight = _attach->height();
if (_data->type == WebPageVideo && _attach->type() == MediaTypePhoto) { if (_data->type == WebPageType::Video
&& _attach->type() == MediaTypePhoto) {
if (_attach->isReadyForOpen()) { if (_attach->isReadyForOpen()) {
if (_data->siteName == qstr("YouTube")) { if (_data->siteName == qstr("YouTube")) {
st::youtubeIcon.paint(p, (pixwidth - st::youtubeIcon.width()) / 2, (pixheight - st::youtubeIcon.height()) / 2, width()); 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); result = _attach->textState(point - QPoint(attachLeft, attachTop), request);
if (result.link && !_data->document && _data->photo && _collage.empty() && _attach->isReadyForOpen()) { 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; 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 // leave photo link
} else { } else {
result.link = _openl; result.link = _openl;

View File

@ -1246,9 +1246,11 @@ Link::Link(
_page->document, _page->document,
parent->fullId()); parent->fullId());
} else if (_page->photo) { } else if (_page->photo) {
if (_page->type == WebPageProfile || _page->type == WebPageVideo) { if (_page->type == WebPageType::Profile || _page->type == WebPageType::Video) {
_photol = std::make_shared<UrlClickHandler>(_page->url); _photol = std::make_shared<UrlClickHandler>(_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<PhotoOpenClickHandler>( _photol = std::make_shared<PhotoOpenClickHandler>(
_page->photo, _page->photo,
parent->fullId()); parent->fullId());