Commit 30f90763 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Improve isFile use in Contents for FileTransfer

parent 10564ec1
......@@ -187,7 +187,7 @@ void ChatMessagePrivate::setFileTransferFilepath (const string &path) {
const string &ChatMessagePrivate::getAppdata () const {
for (const Content *c : contents) {
if (c->getContentType().isFile()) {
if (c->isFile()) {
FileContent *fileContent = (FileContent *)c;
return fileContent->getAppData("legacy");
}
......@@ -197,7 +197,7 @@ const string &ChatMessagePrivate::getAppdata () const {
void ChatMessagePrivate::setAppdata (const string &data) {
for (const Content *c : contents) {
if (c->getContentType().isFile()) {
if (c->isFile()) {
FileContent *fileContent = (FileContent *)c;
fileContent->setAppData("legacy", data);
break;
......@@ -281,7 +281,7 @@ LinphoneContent *ChatMessagePrivate::getFileTransferInformation () const {
return getFileTransferContent()->toLinphoneContent();
}
for (const Content *c : contents) {
if (c->getContentType().isFile()) {
if (c->isFile()) {
FileContent *fileContent = (FileContent *)c;
return fileContent->toLinphoneContent();
}
......@@ -657,7 +657,7 @@ void ChatMessagePrivate::store() {
bool messageToBeStored = false;
for (Content *c : contents) {
ContentType contentType = c->getContentType();
if (contentType == ContentType::FileTransfer || contentType == ContentType::PlainText || contentType.isFile()) {
if (contentType == ContentType::FileTransfer || contentType == ContentType::PlainText || c->isFile()) {
messageToBeStored = true;
}
}
......
......@@ -48,9 +48,8 @@ ChatMessageModifier::Result FileTransferChatMessageModifier::encode (const share
currentFileContentToTransfer = nullptr;
// For each FileContent, upload it and create a FileTransferContent
for (Content *content : message->getContents()) {
ContentType contentType = content->getContentType();
if (contentType.isFile()) {
lInfo() << "Found content with type " << contentType.asString() << ", set it for file upload";
if (content->isFile()) {
lInfo() << "Found file content, set it for file upload";
FileContent *fileContent = (FileContent *)content;
currentFileContentToTransfer = fileContent;
break;
......
......@@ -161,10 +161,6 @@ bool ContentType::isValid () const {
return !d->type.empty() && !d->subType.empty();
}
bool ContentType::isFile () const {
return isFile(*this);
}
string ContentType::asString () const {
L_D();
if (isValid()) {
......@@ -176,8 +172,14 @@ string ContentType::asString () const {
return "";
}
bool ContentType::isFile () const {
// TODO Remove when not needed anymore in step 2.1 of maindb
return isFile(*this);
}
bool ContentType::isFile (const ContentType &contentType) {
// TODO Improve.
// TODO Remove when not needed anymore in step 2.1 of maindb
return contentType != FileTransfer &&
contentType != PlainText &&
contentType != ExternalBody &&
......
......@@ -168,6 +168,10 @@ bool Content::isValid () const {
return d->contentType.isValid() || (d->contentType.isEmpty() && d->body.empty());
}
bool Content::isFile () const {
return false;
}
LinphoneContent *Content::toLinphoneContent () const {
LinphoneContent *content = linphone_core_create_content(nullptr);
linphone_content_set_type(content, getContentType().getType().c_str());
......
......@@ -69,6 +69,8 @@ public:
bool isEmpty () const;
virtual bool isFile () const;
// TODO: Remove me later.
virtual LinphoneContent *toLinphoneContent () const;
......
......@@ -115,6 +115,10 @@ const string &FileContent::getFilePath () const {
return d->filePath;
}
bool FileContent::isFile () const {
return true;
}
LinphoneContent *FileContent::toLinphoneContent () const {
LinphoneContent *content = linphone_core_create_content(nullptr);
linphone_content_set_type(content, getContentType().getType().c_str());
......
......@@ -48,6 +48,8 @@ public:
void setFilePath (const std::string &path);
const std::string &getFilePath () const;
bool isFile () const override;
// TODO: Remove me later.
LinphoneContent *toLinphoneContent () const override;
......
......@@ -155,4 +155,8 @@ LinphoneContent *FileTransferContent::toLinphoneContent () const {
return content;
}
bool FileTransferContent::isFile () const {
return false;
}
LINPHONE_END_NAMESPACE
......@@ -55,6 +55,8 @@ public:
void setFileSize (size_t size);
size_t getFileSize () const;
bool isFile () const override;
// TODO: Remove me later.
LinphoneContent *toLinphoneContent () const override;
......
......@@ -263,7 +263,7 @@ void MainDbPrivate::insertContent (long long eventId, const Content &content) {
soci::use(body);
const long long &chatMessageContentId = dbSession.getLastInsertId();
if (content.getContentType().isFile()) {
if (content.isFile()) {
const FileContent &fileContent = static_cast<const FileContent &>(content);
const string &name = fileContent.getFileName();
const size_t &size = fileContent.getFileSize();
......
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