Commit 3e30c16a authored by Sylvain Berfini's avatar Sylvain Berfini 🎩
Browse files

Keep contents in the same order during upload

parent 10fa1ae1
......@@ -200,6 +200,7 @@ public:
void addContent (Content *content);
void removeContent (Content *content);
void replaceContent (Content *contentToRemove, Content *contentToAdd);
bool downloadFile ();
......
......@@ -552,6 +552,20 @@ void ChatMessagePrivate::removeContent (Content *content) {
getContents().remove(content);
}
void ChatMessagePrivate::replaceContent (Content *contentToRemove, Content *contentToAdd) {
list<Content*>::iterator it = contents.begin();
while (it != contents.end()) {
Content *content = *it;
if (content == contentToRemove) {
it = contents.erase(it);
it = contents.insert(it, contentToAdd);
break;
} else {
it++;
}
}
}
void ChatMessagePrivate::loadFileTransferUrlFromBodyToContent() {
L_Q();
int errorCode = 0;
......@@ -837,8 +851,9 @@ void ChatMessagePrivate::restoreFileTransferContentAsFileContent() {
Content *content = *it;
if (content->isFileTransfer()) {
FileTransferContent *fileTransferContent = static_cast<FileTransferContent *>(content);
FileContent *fileContent = fileTransferContent->getFileContent();
it = contents.erase(it);
addContent(fileTransferContent->getFileContent());
it =contents.insert(it, fileContent);
delete fileTransferContent;
} else {
it++;
......
......@@ -244,11 +244,10 @@ belle_sip_body_handler_t *FileTransferChatMessageModifier::prepare_upload_body_h
fileTransferContent->setContentType(ContentType::FileTransfer);
fileTransferContent->setFileSize(currentFileContentToTransfer->getFileSize()); // Copy file size information
fileTransferContent->setFilePath(currentFileContentToTransfer->getFilePath()); // Copy file path information
message->getPrivate()->addContent(fileTransferContent);
currentFileTransferContent = fileTransferContent;
currentFileTransferContent = fileTransferContent;
currentFileTransferContent->setFileContent(currentFileContentToTransfer);
message->getPrivate()->removeContent(currentFileContentToTransfer);
message->getPrivate()->replaceContent(currentFileContentToTransfer, currentFileTransferContent);
// shall we encrypt the file
if (isFileEncryptionEnabled && message->getChatRoom()) {
......@@ -418,7 +417,7 @@ void FileTransferChatMessageModifier::processResponseFromPostFile (const belle_h
fileUploadEndBackgroundTask();
} else {
lWarning() << "Received empty response from server, file transfer failed";
message->getPrivate()->removeContent(currentFileTransferContent);
message->getPrivate()->replaceContent(currentFileTransferContent, currentFileContentToTransfer);
delete currentFileTransferContent;
currentFileTransferContent = nullptr;
......@@ -428,7 +427,7 @@ void FileTransferChatMessageModifier::processResponseFromPostFile (const belle_h
}
} else if (code == 400) {
lWarning() << "Received HTTP code response " << code << " for file transfer, probably meaning file is too large";
message->getPrivate()->removeContent(currentFileTransferContent);
message->getPrivate()->replaceContent(currentFileTransferContent, currentFileContentToTransfer);
delete currentFileTransferContent;
currentFileTransferContent = nullptr;
......@@ -437,7 +436,7 @@ void FileTransferChatMessageModifier::processResponseFromPostFile (const belle_h
fileUploadEndBackgroundTask();
} else if (code == 401) {
lWarning() << "Received HTTP code response " << code << " for file transfer, probably meaning that our credentials were rejected";
message->getPrivate()->removeContent(currentFileTransferContent);
message->getPrivate()->replaceContent(currentFileTransferContent, currentFileContentToTransfer);
delete currentFileTransferContent;
currentFileTransferContent = nullptr;
......@@ -446,7 +445,7 @@ void FileTransferChatMessageModifier::processResponseFromPostFile (const belle_h
fileUploadEndBackgroundTask();
} else {
lWarning() << "Unhandled HTTP code response " << code << " for file transfer";
message->getPrivate()->removeContent(currentFileTransferContent);
message->getPrivate()->replaceContent(currentFileTransferContent, currentFileContentToTransfer);
delete currentFileTransferContent;
currentFileTransferContent = nullptr;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment