From 84858b8940c8ce9f0f7223bf3c26fd01ff1ca27c Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 2 Apr 2019 19:24:34 +0300 Subject: [PATCH] Added MEDIA_NEW_INVALID error handler. Disabled edit media with webp. --- Telegram/SourceFiles/apiwrap.cpp | 6 +++-- .../SourceFiles/boxes/edit_caption_box.cpp | 23 ++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 642d41afd..531b1facd 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -4644,7 +4644,8 @@ void ApiWrap::editUploadedPhoto( applyUpdates(result); }).fail([=](const RPCError &error) { QString err = error.type(); - if (err == qstr("MESSAGE_NOT_MODIFIED")) { + if (err == qstr("MESSAGE_NOT_MODIFIED") + || err == qstr("MEDIA_NEW_INVALID")) { item->returnSavedMedia(); _session->data().sendHistoryChangeNotifications(); } else { @@ -4707,7 +4708,8 @@ void ApiWrap::editUploadedDocument( applyUpdates(result); }).fail([=](const RPCError &error) { QString err = error.type(); - if (err == qstr("MESSAGE_NOT_MODIFIED")) { + if (err == qstr("MESSAGE_NOT_MODIFIED") + || err == qstr("MEDIA_NEW_INVALID")) { item->returnSavedMedia(); _session->data().sendHistoryChangeNotifications(); } else { diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index e4676119d..4d73182c2 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -402,6 +402,16 @@ void EditCaptionBox::createEditMediaButton() { return; } + const auto isWebp = [](QString mimeType) { + if (mimeType == qstr("image/webp")) { + Ui::show( + Box(lang(lng_edit_media_album_error)), + LayerOption::KeepOther); + return true; + } + return false; + }; + if (!result.remoteContent.isEmpty()) { // Don't use remoteContent to edit album item. if (_isAlbum) { @@ -412,10 +422,16 @@ void EditCaptionBox::createEditMediaButton() { QString(), result.remoteContent ).thumbnail; - _preparedList = Storage::PrepareMediaFromImage( + auto list = Storage::PrepareMediaFromImage( std::move(image), std::move(result.remoteContent), st::sendMediaPreviewSize); + + if (isWebp(list.files.front().mime)) { + return; + } + + _preparedList = std::move(list); } else if (!result.paths.isEmpty()) { auto list = Storage::PrepareMediaList( QStringList(result.paths.front()), @@ -442,6 +458,11 @@ void EditCaptionBox::createEditMediaButton() { return; } } + const auto info = QFileInfo(result.paths.front()); + if (isWebp(Core::MimeTypeForFile(info).name())) { + return; + } + _preparedList = std::move(list); } else { return;