Added mini preview for some types of webpages.
This commit is contained in:
parent
563b8d1468
commit
6471d43c71
|
@ -1506,15 +1506,57 @@ bool MediaWebPage::replyPreviewLoaded() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemPreview MediaWebPage::toPreview(ToPreviewOptions options) const {
|
ItemPreview MediaWebPage::toPreview(ToPreviewOptions options) const {
|
||||||
auto text = options.ignoreMessageText
|
const auto caption = [&] {
|
||||||
? TextWithEntities()
|
const auto text = options.ignoreMessageText
|
||||||
: options.translated
|
? TextWithEntities()
|
||||||
? parent()->translatedText()
|
: options.translated
|
||||||
: parent()->originalText();
|
? parent()->translatedText()
|
||||||
if (text.empty()) {
|
: parent()->originalText();
|
||||||
text = Ui::Text::Colorized(_page->url);
|
return text.empty() ? Ui::Text::Colorized(_page->url) : text;
|
||||||
|
}();
|
||||||
|
const auto pageTypeWithPreview = _page->type == WebPageType::Photo
|
||||||
|
|| _page->type == WebPageType::Video
|
||||||
|
|| _page->type == WebPageType::Document;
|
||||||
|
if (pageTypeWithPreview || !_page->collage.items.empty()) {
|
||||||
|
if (auto found = FindCachedPreview(options.existing, _page, false)) {
|
||||||
|
return { .text = caption, .images = { std::move(found) } };
|
||||||
|
}
|
||||||
|
auto context = std::any();
|
||||||
|
auto images = std::vector<ItemPreviewImage>();
|
||||||
|
auto prepared = ItemPreviewImage();
|
||||||
|
const auto radius = ImageRoundRadius::Small;
|
||||||
|
if (const auto photo = MediaWebPage::photo()) {
|
||||||
|
const auto media = photo->createMediaView();
|
||||||
|
prepared = PreparePhotoPreview(parent(), media, radius, false);
|
||||||
|
if (prepared || !prepared.cacheKey) {
|
||||||
|
images.push_back(std::move(prepared));
|
||||||
|
if (!prepared.cacheKey) {
|
||||||
|
context = media;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const auto document = MediaWebPage::document();
|
||||||
|
if (document
|
||||||
|
&& document->hasThumbnail()
|
||||||
|
&& (document->isGifv() || document->isVideoFile())) {
|
||||||
|
const auto media = document->createMediaView();
|
||||||
|
prepared = PrepareFilePreview(parent(), media, radius, false);
|
||||||
|
if (prepared || !prepared.cacheKey) {
|
||||||
|
images.push_back(std::move(prepared));
|
||||||
|
if (!prepared.cacheKey) {
|
||||||
|
context = media;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
.text = caption,
|
||||||
|
.images = std::move(images),
|
||||||
|
.loadingContext = std::move(context),
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return { .text = caption };
|
||||||
}
|
}
|
||||||
return { .text = text };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextWithEntities MediaWebPage::notificationText() const {
|
TextWithEntities MediaWebPage::notificationText() const {
|
||||||
|
|
|
@ -141,7 +141,7 @@ WebPageType ParseWebPageType(
|
||||||
const QString &type,
|
const QString &type,
|
||||||
const QString &embedUrl,
|
const QString &embedUrl,
|
||||||
bool hasIV) {
|
bool hasIV) {
|
||||||
if (type == u"video"_q || !embedUrl.isEmpty()) {
|
if (type == u"video"_q || type == u"gif"_q || !embedUrl.isEmpty()) {
|
||||||
return WebPageType::Video;
|
return WebPageType::Video;
|
||||||
} else if (type == u"photo"_q) {
|
} else if (type == u"photo"_q) {
|
||||||
return WebPageType::Photo;
|
return WebPageType::Photo;
|
||||||
|
|
Loading…
Reference in New Issue