mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-24 20:33:19 +00:00
Moved searching of sticker mimes to single place.
This commit is contained in:
parent
f3595e379c
commit
d1d5312ead
@ -490,7 +490,7 @@ void EditCaptionBox::createEditMediaButton() {
|
|||||||
const auto callback = [=](FileDialog::OpenResult &&result) {
|
const auto callback = [=](FileDialog::OpenResult &&result) {
|
||||||
|
|
||||||
auto isValidFile = [](QString mimeType) {
|
auto isValidFile = [](QString mimeType) {
|
||||||
if (mimeType == qstr("image/webp")) {
|
if (Core::IsMimeSticker(mimeType)) {
|
||||||
Ui::show(
|
Ui::show(
|
||||||
Box<InformBox>(tr::lng_edit_media_invalid_file(tr::now)),
|
Box<InformBox>(tr::lng_edit_media_invalid_file(tr::now)),
|
||||||
Ui::LayerOption::KeepOther);
|
Ui::LayerOption::KeepOther);
|
||||||
|
@ -49,8 +49,6 @@ namespace {
|
|||||||
constexpr auto kMinPreviewWidth = 20;
|
constexpr auto kMinPreviewWidth = 20;
|
||||||
constexpr auto kShrinkDuration = crl::time(150);
|
constexpr auto kShrinkDuration = crl::time(150);
|
||||||
constexpr auto kDragDuration = crl::time(200);
|
constexpr auto kDragDuration = crl::time(200);
|
||||||
const auto kStickerMimeString = qstr("image/webp");
|
|
||||||
const auto kAnimatedStickerMimeString = qstr("application/x-tgsticker");
|
|
||||||
|
|
||||||
inline bool CanAddUrls(const QList<QUrl> &urls) {
|
inline bool CanAddUrls(const QList<QUrl> &urls) {
|
||||||
return !urls.isEmpty() && ranges::find_if(
|
return !urls.isEmpty() && ranges::find_if(
|
||||||
@ -145,7 +143,7 @@ void FileDialogCallback(
|
|||||||
bool isAlbum,
|
bool isAlbum,
|
||||||
Fn<void(Storage::PreparedList)> callback) {
|
Fn<void(Storage::PreparedList)> callback) {
|
||||||
auto isValidFile = [](QString mimeType) {
|
auto isValidFile = [](QString mimeType) {
|
||||||
if (mimeType != qstr("image/webp")) {
|
if (!Core::IsMimeSticker(mimeType)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Ui::show(
|
Ui::show(
|
||||||
@ -751,14 +749,12 @@ SingleMediaPreview *SingleMediaPreview::Create(
|
|||||||
preview.height())) {
|
preview.height())) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
const auto sticker = (file.information->filemime == kStickerMimeString)
|
|
||||||
|| (file.information->filemime == kAnimatedStickerMimeString);
|
|
||||||
return Ui::CreateChild<SingleMediaPreview>(
|
return Ui::CreateChild<SingleMediaPreview>(
|
||||||
parent,
|
parent,
|
||||||
controller,
|
controller,
|
||||||
preview,
|
preview,
|
||||||
animated,
|
animated,
|
||||||
sticker,
|
Core::IsMimeSticker(file.information->filemime),
|
||||||
animationPreview ? file.path : QString());
|
animationPreview ? file.path : QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,4 +102,9 @@ MimeType MimeTypeForData(const QByteArray &data) {
|
|||||||
return MimeType(QMimeDatabase().mimeTypeForData(data));
|
return MimeType(QMimeDatabase().mimeTypeForData(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsMimeSticker(const QString &mime) {
|
||||||
|
return mime == qsl("image/webp")
|
||||||
|
|| mime == qsl("application/x-tgsticker");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
@ -39,4 +39,6 @@ MimeType MimeTypeForName(const QString &mime);
|
|||||||
MimeType MimeTypeForFile(const QFileInfo &file);
|
MimeType MimeTypeForFile(const QFileInfo &file);
|
||||||
MimeType MimeTypeForData(const QByteArray &data);
|
MimeType MimeTypeForData(const QByteArray &data);
|
||||||
|
|
||||||
|
bool IsMimeSticker(const QString &mime);
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
#include "api/api_text_entities.h"
|
#include "api/api_text_entities.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
|
#include "core/mime_type.h" // Core::IsMimeSticker
|
||||||
#include "core/crash_reports.h" // CrashReports::SetAnnotation
|
#include "core/crash_reports.h" // CrashReports::SetAnnotation
|
||||||
#include "ui/image/image.h"
|
#include "ui/image/image.h"
|
||||||
#include "ui/image/image_source.h" // Images::LocalFileSource
|
#include "ui/image/image_source.h" // Images::LocalFileSource
|
||||||
@ -2390,8 +2391,7 @@ not_null<DocumentData*> Session::processDocument(
|
|||||||
case mtpc_document: {
|
case mtpc_document: {
|
||||||
const auto &fields = data.c_document();
|
const auto &fields = data.c_document();
|
||||||
const auto mime = qs(fields.vmime_type());
|
const auto mime = qs(fields.vmime_type());
|
||||||
const auto format = (mime == qstr("image/webp")
|
const auto format = Core::IsMimeSticker(mime)
|
||||||
|| mime == qstr("application/x-tgsticker"))
|
|
||||||
? "WEBP"
|
? "WEBP"
|
||||||
: "JPG";
|
: "JPG";
|
||||||
return document(
|
return document(
|
||||||
|
@ -656,9 +656,6 @@ bool FileLoadTask::FillImageInformation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FileLoadTask::process() {
|
void FileLoadTask::process() {
|
||||||
const auto stickerMime = qsl("image/webp");
|
|
||||||
const auto animatedStickerMime = qsl("application/x-tgsticker");
|
|
||||||
|
|
||||||
_result = std::make_shared<FileLoadResult>(
|
_result = std::make_shared<FileLoadResult>(
|
||||||
id(),
|
id(),
|
||||||
_id,
|
_id,
|
||||||
@ -700,7 +697,7 @@ void FileLoadTask::process() {
|
|||||||
if (auto image = base::get_if<FileMediaInformation::Image>(
|
if (auto image = base::get_if<FileMediaInformation::Image>(
|
||||||
&_information->media)) {
|
&_information->media)) {
|
||||||
fullimage = base::take(image->data);
|
fullimage = base::take(image->data);
|
||||||
if (filemime != stickerMime && filemime != animatedStickerMime) {
|
if (!Core::IsMimeSticker(filemime)) {
|
||||||
fullimage = Images::prepareOpaque(std::move(fullimage));
|
fullimage = Images::prepareOpaque(std::move(fullimage));
|
||||||
}
|
}
|
||||||
isAnimation = image->animated;
|
isAnimation = image->animated;
|
||||||
@ -719,7 +716,7 @@ void FileLoadTask::process() {
|
|||||||
}
|
}
|
||||||
const auto mimeType = Core::MimeTypeForData(_content);
|
const auto mimeType = Core::MimeTypeForData(_content);
|
||||||
filemime = mimeType.name();
|
filemime = mimeType.name();
|
||||||
if (filemime != stickerMime && filemime != animatedStickerMime) {
|
if (!Core::IsMimeSticker(filemime)) {
|
||||||
fullimage = Images::prepareOpaque(std::move(fullimage));
|
fullimage = Images::prepareOpaque(std::move(fullimage));
|
||||||
}
|
}
|
||||||
if (filemime == "image/jpeg") {
|
if (filemime == "image/jpeg") {
|
||||||
@ -831,8 +828,7 @@ void FileLoadTask::process() {
|
|||||||
attributes.push_back(MTP_documentAttributeImageSize(MTP_int(w), MTP_int(h)));
|
attributes.push_back(MTP_documentAttributeImageSize(MTP_int(w), MTP_int(h)));
|
||||||
|
|
||||||
if (ValidateThumbDimensions(w, h)) {
|
if (ValidateThumbDimensions(w, h)) {
|
||||||
isSticker = (filemime == stickerMime
|
isSticker = Core::IsMimeSticker(filemime)
|
||||||
|| filemime == animatedStickerMime)
|
|
||||||
&& (w > 0)
|
&& (w > 0)
|
||||||
&& (h > 0)
|
&& (h > 0)
|
||||||
&& (w <= StickerMaxSize)
|
&& (w <= StickerMaxSize)
|
||||||
|
@ -34,9 +34,7 @@ bool HasExtensionFrom(const QString &file, const QStringList &extensions) {
|
|||||||
bool ValidPhotoForAlbum(
|
bool ValidPhotoForAlbum(
|
||||||
const FileMediaInformation::Image &image,
|
const FileMediaInformation::Image &image,
|
||||||
const QString &mime) {
|
const QString &mime) {
|
||||||
if (image.animated
|
if (image.animated || Core::IsMimeSticker(mime)) {
|
||||||
|| mime == qstr("image/webp")
|
|
||||||
|| mime == qstr("application/x-tgsticker")) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const auto width = image.data.width();
|
const auto width = image.data.width();
|
||||||
@ -397,7 +395,7 @@ bool PreparedList::canAddCaption(bool isAlbum, bool compressImages) const {
|
|||||||
if (files.empty()) {
|
if (files.empty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return (files.front().mime == qstr("image/webp"))
|
return Core::IsMimeSticker(files.front().mime)
|
||||||
|| files.front().path.endsWith(
|
|| files.front().path.endsWith(
|
||||||
qstr(".tgs"),
|
qstr(".tgs"),
|
||||||
Qt::CaseInsensitive);
|
Qt::CaseInsensitive);
|
||||||
|
Loading…
Reference in New Issue
Block a user