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