From 021454dbd40ddd7ff87473694e42158a9c7aa3e3 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 10 Mar 2017 18:45:22 +0300 Subject: [PATCH] Add .jpg to inputFile filename when photo is sent. Server has some extensions checking for inputMediaUploadedPhoto, so force the extension to be .jpg anyway. It doesn't matter, because the filename from inputFile is not used anywhere. Also own PhotoData::UploadingData through std::unique_ptr. --- Telegram/SourceFiles/app.cpp | 3 +-- Telegram/SourceFiles/historywidget.cpp | 6 +++++- Telegram/SourceFiles/storage/file_upload.cpp | 20 ++++++++++--------- .../SourceFiles/storage/localimageloader.cpp | 4 ++-- Telegram/SourceFiles/structs.cpp | 10 ++-------- Telegram/SourceFiles/structs.h | 11 +++++----- 6 files changed, 26 insertions(+), 28 deletions(-) diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 1ae11252a..a78961b13 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -1602,8 +1602,7 @@ namespace { ::photosData.erase(i); } convert->id = photo; - delete convert->uploadingData; - convert->uploadingData = 0; + convert->uploadingData.reset(); } if (date) { convert->access = access; diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 5aaa81341..d77425680 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -6667,7 +6667,11 @@ bool HistoryWidget::confirmSendingFiles(const SendingFilesLists &lists, Compress auto type = compressed ? SendMediaType::Photo : SendMediaType::File; uploadFilesAfterConfirmation(files, QByteArray(), image, std::move(information), type, caption); }; - auto box = Box(files, lists.allFilesForCompress ? compressed : CompressConfirm::None); + auto boxCompressConfirm = compressed; + if (files.size() > 1 && !lists.allFilesForCompress) { + boxCompressConfirm = CompressConfirm::None; + } + auto box = Box(files, boxCompressConfirm); return showSendFilesBox(std::move(box), insertTextOnCancel, addedComment, std::move(sendCallback)); }); } diff --git a/Telegram/SourceFiles/storage/file_upload.cpp b/Telegram/SourceFiles/storage/file_upload.cpp index e837990d5..963035466 100644 --- a/Telegram/SourceFiles/storage/file_upload.cpp +++ b/Telegram/SourceFiles/storage/file_upload.cpp @@ -52,15 +52,10 @@ void FileUploader::uploadMedia(const FullMsgId &msgId, const SendMediaReady &med void FileUploader::upload(const FullMsgId &msgId, const FileLoadResultPtr &file) { if (file->type == SendMediaType::Photo) { - PhotoData *photo = App::feedPhoto(file->photo, file->photoThumbs); - photo->uploadingData = new PhotoData::UploadingData(file->partssize); + auto photo = App::feedPhoto(file->photo, file->photoThumbs); + photo->uploadingData = std::make_unique(file->partssize); } else if (file->type == SendMediaType::File || file->type == SendMediaType::Audio) { - DocumentData *document; - if (file->thumb.isNull()) { - document = App::feedDocument(file->document); - } else { - document = App::feedDocument(file->document, file->thumb); - } + auto document = file->thumb.isNull() ? App::feedDocument(file->document) : App::feedDocument(file->document, file->thumb); document->status = FileUploading; if (!file->content.isEmpty()) { document->setData(file->content); @@ -141,7 +136,14 @@ void FileUploader::sendNext() { if (requestsSent.isEmpty() && docRequestsSent.isEmpty()) { bool silent = i->file && i->file->to.silent; if (i->type() == SendMediaType::Photo) { - emit photoReady(uploading, silent, MTP_inputFile(MTP_long(i->id()), MTP_int(i->partsCount), MTP_string(i->filename()), MTP_bytes(i->file ? i->file->filemd5 : i->media.jpeg_md5))); + auto photoFilename = i->filename(); + if (!photoFilename.endsWith(qstr(".jpg"), Qt::CaseInsensitive)) { + // Server has some extensions checking for inputMediaUploadedPhoto, + // so force the extension to be .jpg anyway. It doesn't matter, + // because the filename from inputFile is not used anywhere. + photoFilename += qstr(".jpg"); + } + emit photoReady(uploading, silent, MTP_inputFile(MTP_long(i->id()), MTP_int(i->partsCount), MTP_string(photoFilename), MTP_bytes(i->file ? i->file->filemd5 : i->media.jpeg_md5))); } else if (i->type() == SendMediaType::File || i->type() == SendMediaType::Audio) { QByteArray docMd5(32, Qt::Uninitialized); hashMd5Hex(i->md5Hash.result(), docMd5.data()); diff --git a/Telegram/SourceFiles/storage/localimageloader.cpp b/Telegram/SourceFiles/storage/localimageloader.cpp index 1510eeb84..7f7bed2b6 100644 --- a/Telegram/SourceFiles/storage/localimageloader.cpp +++ b/Telegram/SourceFiles/storage/localimageloader.cpp @@ -314,7 +314,7 @@ bool FileLoadTask::CheckForImage(const QString &filepath, const QByteArray &cont } void FileLoadTask::process() { - const QString stickerMime = qsl("image/webp"); + const auto stickerMime = qsl("image/webp"); _result = MakeShared(_id, _to, _caption); @@ -323,7 +323,7 @@ void FileLoadTask::process() { QByteArray filedata; uint64 thumbId = 0; - QString thumbname = "thumb.jpg"; + auto thumbname = qsl("thumb.jpg"); QByteArray thumbdata; auto isAnimation = false; diff --git a/Telegram/SourceFiles/structs.cpp b/Telegram/SourceFiles/structs.cpp index cb2d4c2a2..9b6bca4e2 100644 --- a/Telegram/SourceFiles/structs.cpp +++ b/Telegram/SourceFiles/structs.cpp @@ -859,9 +859,7 @@ PhotoData::PhotoData(const PhotoId &id, const uint64 &access, int32 date, const , date(date) , thumb(thumb) , medium(medium) -, full(full) -, peer(0) -, uploadingData(0) { +, full(full) { } void PhotoData::automaticLoad(const HistoryItem *item) { @@ -926,7 +924,7 @@ int32 PhotoData::loadOffset() const { } bool PhotoData::uploading() const { - return uploadingData; + return !!uploadingData; } void PhotoData::forget() { @@ -950,10 +948,6 @@ ImagePtr PhotoData::makeReplyPreview() { return replyPreview; } -PhotoData::~PhotoData() { - delete base::take(uploadingData); -} - void PhotoOpenClickHandler::onClickImpl() const { App::wnd()->showPhoto(this, App::hoveredLinkItem() ? App::hoveredLinkItem() : App::contextItem()); } diff --git a/Telegram/SourceFiles/structs.h b/Telegram/SourceFiles/structs.h index 4f48b0247..d472cbe0d 100644 --- a/Telegram/SourceFiles/structs.h +++ b/Telegram/SourceFiles/structs.h @@ -1000,8 +1000,6 @@ public: void forget(); ImagePtr makeReplyPreview(); - ~PhotoData(); - PhotoId id; uint64 access; int32 date; @@ -1009,15 +1007,16 @@ public: ImagePtr medium; ImagePtr full; - PeerData *peer; // for chat and channel photos connection + PeerData *peer = nullptr; // for chat and channel photos connection // geo, caption struct UploadingData { - UploadingData(int32 size) : offset(0), size(size) { + UploadingData(int size) : size(size) { } - int32 offset, size; + int offset = 0; + int size = 0; }; - UploadingData *uploadingData; + std::unique_ptr uploadingData; private: void notifyLayoutChanged() const;