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.
This commit is contained in:
John Preston 2017-03-10 18:45:22 +03:00
parent f6918feea3
commit 021454dbd4
6 changed files with 26 additions and 28 deletions

View File

@ -1602,8 +1602,7 @@ namespace {
::photosData.erase(i); ::photosData.erase(i);
} }
convert->id = photo; convert->id = photo;
delete convert->uploadingData; convert->uploadingData.reset();
convert->uploadingData = 0;
} }
if (date) { if (date) {
convert->access = access; convert->access = access;

View File

@ -6667,7 +6667,11 @@ bool HistoryWidget::confirmSendingFiles(const SendingFilesLists &lists, Compress
auto type = compressed ? SendMediaType::Photo : SendMediaType::File; auto type = compressed ? SendMediaType::Photo : SendMediaType::File;
uploadFilesAfterConfirmation(files, QByteArray(), image, std::move(information), type, caption); uploadFilesAfterConfirmation(files, QByteArray(), image, std::move(information), type, caption);
}; };
auto box = Box<SendFilesBox>(files, lists.allFilesForCompress ? compressed : CompressConfirm::None); auto boxCompressConfirm = compressed;
if (files.size() > 1 && !lists.allFilesForCompress) {
boxCompressConfirm = CompressConfirm::None;
}
auto box = Box<SendFilesBox>(files, boxCompressConfirm);
return showSendFilesBox(std::move(box), insertTextOnCancel, addedComment, std::move(sendCallback)); return showSendFilesBox(std::move(box), insertTextOnCancel, addedComment, std::move(sendCallback));
}); });
} }

View File

@ -52,15 +52,10 @@ void FileUploader::uploadMedia(const FullMsgId &msgId, const SendMediaReady &med
void FileUploader::upload(const FullMsgId &msgId, const FileLoadResultPtr &file) { void FileUploader::upload(const FullMsgId &msgId, const FileLoadResultPtr &file) {
if (file->type == SendMediaType::Photo) { if (file->type == SendMediaType::Photo) {
PhotoData *photo = App::feedPhoto(file->photo, file->photoThumbs); auto photo = App::feedPhoto(file->photo, file->photoThumbs);
photo->uploadingData = new PhotoData::UploadingData(file->partssize); photo->uploadingData = std::make_unique<PhotoData::UploadingData>(file->partssize);
} else if (file->type == SendMediaType::File || file->type == SendMediaType::Audio) { } else if (file->type == SendMediaType::File || file->type == SendMediaType::Audio) {
DocumentData *document; auto document = file->thumb.isNull() ? App::feedDocument(file->document) : App::feedDocument(file->document, file->thumb);
if (file->thumb.isNull()) {
document = App::feedDocument(file->document);
} else {
document = App::feedDocument(file->document, file->thumb);
}
document->status = FileUploading; document->status = FileUploading;
if (!file->content.isEmpty()) { if (!file->content.isEmpty()) {
document->setData(file->content); document->setData(file->content);
@ -141,7 +136,14 @@ void FileUploader::sendNext() {
if (requestsSent.isEmpty() && docRequestsSent.isEmpty()) { if (requestsSent.isEmpty() && docRequestsSent.isEmpty()) {
bool silent = i->file && i->file->to.silent; bool silent = i->file && i->file->to.silent;
if (i->type() == SendMediaType::Photo) { 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) { } else if (i->type() == SendMediaType::File || i->type() == SendMediaType::Audio) {
QByteArray docMd5(32, Qt::Uninitialized); QByteArray docMd5(32, Qt::Uninitialized);
hashMd5Hex(i->md5Hash.result(), docMd5.data()); hashMd5Hex(i->md5Hash.result(), docMd5.data());

View File

@ -314,7 +314,7 @@ bool FileLoadTask::CheckForImage(const QString &filepath, const QByteArray &cont
} }
void FileLoadTask::process() { void FileLoadTask::process() {
const QString stickerMime = qsl("image/webp"); const auto stickerMime = qsl("image/webp");
_result = MakeShared<FileLoadResult>(_id, _to, _caption); _result = MakeShared<FileLoadResult>(_id, _to, _caption);
@ -323,7 +323,7 @@ void FileLoadTask::process() {
QByteArray filedata; QByteArray filedata;
uint64 thumbId = 0; uint64 thumbId = 0;
QString thumbname = "thumb.jpg"; auto thumbname = qsl("thumb.jpg");
QByteArray thumbdata; QByteArray thumbdata;
auto isAnimation = false; auto isAnimation = false;

View File

@ -859,9 +859,7 @@ PhotoData::PhotoData(const PhotoId &id, const uint64 &access, int32 date, const
, date(date) , date(date)
, thumb(thumb) , thumb(thumb)
, medium(medium) , medium(medium)
, full(full) , full(full) {
, peer(0)
, uploadingData(0) {
} }
void PhotoData::automaticLoad(const HistoryItem *item) { void PhotoData::automaticLoad(const HistoryItem *item) {
@ -926,7 +924,7 @@ int32 PhotoData::loadOffset() const {
} }
bool PhotoData::uploading() const { bool PhotoData::uploading() const {
return uploadingData; return !!uploadingData;
} }
void PhotoData::forget() { void PhotoData::forget() {
@ -950,10 +948,6 @@ ImagePtr PhotoData::makeReplyPreview() {
return replyPreview; return replyPreview;
} }
PhotoData::~PhotoData() {
delete base::take(uploadingData);
}
void PhotoOpenClickHandler::onClickImpl() const { void PhotoOpenClickHandler::onClickImpl() const {
App::wnd()->showPhoto(this, App::hoveredLinkItem() ? App::hoveredLinkItem() : App::contextItem()); App::wnd()->showPhoto(this, App::hoveredLinkItem() ? App::hoveredLinkItem() : App::contextItem());
} }

View File

@ -1000,8 +1000,6 @@ public:
void forget(); void forget();
ImagePtr makeReplyPreview(); ImagePtr makeReplyPreview();
~PhotoData();
PhotoId id; PhotoId id;
uint64 access; uint64 access;
int32 date; int32 date;
@ -1009,15 +1007,16 @@ public:
ImagePtr medium; ImagePtr medium;
ImagePtr full; ImagePtr full;
PeerData *peer; // for chat and channel photos connection PeerData *peer = nullptr; // for chat and channel photos connection
// geo, caption // geo, caption
struct UploadingData { 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> uploadingData;
private: private:
void notifyLayoutChanged() const; void notifyLayoutChanged() const;