void FileUploader::partLoaded(const MTPBool &result, mtpRequestId requestId) { QMap<mtpRequestId, int32>::iterator j = docRequestsSent.end(); QMap<mtpRequestId, QByteArray>::iterator i = requestsSent.find(requestId); if (i == requestsSent.cend()) { j = docRequestsSent.find(requestId); } if (i != requestsSent.cend() || j != docRequestsSent.cend()) { if (!result.v) { // failed to upload current file currentFailed(); return; } else { QMap<mtpRequestId, int32>::iterator dcIt = dcMap.find(requestId); if (dcIt == dcMap.cend()) { // must not happen currentFailed(); return; } int32 dc = dcIt.value(); dcMap.erase(dcIt); Queue::const_iterator k = queue.constFind(uploading); if (i != requestsSent.cend()) { sentSize -= i.value().size(); sentSizes[dc] -= i.value().size(); requestsSent.erase(i); } else { sentSize -= k->docPartSize; sentSizes[dc] -= k->docPartSize; docRequestsSent.erase(j); } if (k->media.type == ToPreparePhoto) { emit photoProgress(k.key()); } else if (k->media.type == ToPrepareDocument) { DocumentData *doc = App::document(k->media.id); if (doc->status == FileUploading) { doc->uploadOffset = (k->docSentParts - docRequestsSent.size()) * k->docPartSize; if (doc->uploadOffset > doc->size) { doc->uploadOffset = doc->size; } } emit documentProgress(k.key()); } else if (k->media.type == ToPrepareAudio) { AudioData *audio = App::audio(k->media.id); if (audio->status == FileUploading) { audio->uploadOffset = (k->docSentParts - docRequestsSent.size()) * k->docPartSize; if (audio->uploadOffset > audio->size) { audio->uploadOffset = audio->size; } } } } } sendNext(); }
void FileUploader::partLoaded(const MTPBool &result, mtpRequestId requestId) { QMap<mtpRequestId, int32>::iterator j = docRequestsSent.end(); QMap<mtpRequestId, QByteArray>::iterator i = requestsSent.find(requestId); if (i == requestsSent.cend()) { j = docRequestsSent.find(requestId); } if (i != requestsSent.cend() || j != docRequestsSent.cend()) { if (mtpIsFalse(result)) { // failed to upload current file currentFailed(); return; } else { QMap<mtpRequestId, int32>::iterator dcIt = dcMap.find(requestId); if (dcIt == dcMap.cend()) { // must not happen currentFailed(); return; } int32 dc = dcIt.value(); dcMap.erase(dcIt); int32 sentPartSize = 0; Queue::const_iterator k = queue.constFind(uploading); if (i != requestsSent.cend()) { sentPartSize = i.value().size(); requestsSent.erase(i); } else { sentPartSize = k->docPartSize; docRequestsSent.erase(j); } sentSize -= sentPartSize; sentSizes[dc] -= sentPartSize; if (k->type() == PreparePhoto) { k->fileSentSize += sentPartSize; PhotoData *photo = App::photo(k->id()); if (photo->uploading() && k->file) { photo->uploadingData->size = k->file->partssize; photo->uploadingData->offset = k->fileSentSize; } emit photoProgress(k.key()); } else if (k->type() == PrepareDocument || k->type() == PrepareAudio) { DocumentData *doc = App::document(k->id()); if (doc->uploading()) { doc->uploadOffset = (k->docSentParts - docRequestsSent.size()) * k->docPartSize; if (doc->uploadOffset > doc->size) { doc->uploadOffset = doc->size; } } emit documentProgress(k.key()); } } } sendNext(); }