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);
}
convert->id = photo;
delete convert->uploadingData;
convert->uploadingData = 0;
convert->uploadingData.reset();
}
if (date) {
convert->access = access;

View file

@ -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<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));
});
}

View file

@ -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<PhotoData::UploadingData>(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());

View file

@ -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<FileLoadResult>(_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;

View file

@ -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());
}

View file

@ -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> uploadingData;
private:
void notifyLayoutChanged() const;