Commit 53296fb8 authored by Ronan's avatar Ronan

fix(ChatMessage): improve check of loaded contents

parent de8c673f
...@@ -83,6 +83,16 @@ public: ...@@ -83,6 +83,16 @@ public:
void loadContentsFromDatabase () const; void loadContentsFromDatabase () const;
std::list<Content* > &getContents () {
loadContentsFromDatabase();
return contents;
}
const std::list<Content* > &getContents () const {
loadContentsFromDatabase();
return contents;
}
belle_http_request_t *getHttpRequest () const; belle_http_request_t *getHttpRequest () const;
void setHttpRequest (belle_http_request_t *request); void setHttpRequest (belle_http_request_t *request);
...@@ -149,7 +159,6 @@ private: ...@@ -149,7 +159,6 @@ private:
std::string rttMessage; std::string rttMessage;
bool isSecured = false; bool isSecured = false;
mutable bool isReadOnly = false; mutable bool isReadOnly = false;
std::list<Content* > contents;
Content internalContent; Content internalContent;
std::unordered_map<std::string, std::string> customHeaders; std::unordered_map<std::string, std::string> customHeaders;
mutable LinphoneErrorInfo * errorInfo = nullptr; mutable LinphoneErrorInfo * errorInfo = nullptr;
...@@ -180,6 +189,8 @@ private: ...@@ -180,6 +189,8 @@ private:
ChatMessage::State state = ChatMessage::State::Idle; ChatMessage::State state = ChatMessage::State::Idle;
ChatMessage::Direction direction = ChatMessage::Direction::Incoming; ChatMessage::Direction direction = ChatMessage::Direction::Incoming;
std::list<Content* > contents;
bool encryptionPrevented = false; bool encryptionPrevented = false;
bool toBeStored = true; bool toBeStored = true;
mutable bool contentsNotLoadedFromDatabase = false; mutable bool contentsNotLoadedFromDatabase = false;
......
...@@ -183,8 +183,7 @@ string ChatMessagePrivate::getSalCustomHeaderValue (const string &name) { ...@@ -183,8 +183,7 @@ string ChatMessagePrivate::getSalCustomHeaderValue (const string &name) {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool ChatMessagePrivate::hasTextContent() const { bool ChatMessagePrivate::hasTextContent() const {
loadContentsFromDatabase(); for (const Content *c : getContents()) {
for (const Content *c : contents) {
if (c->getContentType() == ContentType::PlainText) { if (c->getContentType() == ContentType::PlainText) {
return true; return true;
} }
...@@ -193,8 +192,7 @@ bool ChatMessagePrivate::hasTextContent() const { ...@@ -193,8 +192,7 @@ bool ChatMessagePrivate::hasTextContent() const {
} }
const Content* ChatMessagePrivate::getTextContent() const { const Content* ChatMessagePrivate::getTextContent() const {
loadContentsFromDatabase(); for (const Content *c : getContents()) {
for (const Content *c : contents) {
if (c->getContentType() == ContentType::PlainText) { if (c->getContentType() == ContentType::PlainText) {
return c; return c;
} }
...@@ -203,8 +201,7 @@ const Content* ChatMessagePrivate::getTextContent() const { ...@@ -203,8 +201,7 @@ const Content* ChatMessagePrivate::getTextContent() const {
} }
bool ChatMessagePrivate::hasFileTransferContent() const { bool ChatMessagePrivate::hasFileTransferContent() const {
loadContentsFromDatabase(); for (const Content *c : getContents()) {
for (const Content *c : contents) {
if (c->getContentType() == ContentType::FileTransfer) { if (c->getContentType() == ContentType::FileTransfer) {
return true; return true;
} }
...@@ -213,7 +210,7 @@ bool ChatMessagePrivate::hasFileTransferContent() const { ...@@ -213,7 +210,7 @@ bool ChatMessagePrivate::hasFileTransferContent() const {
} }
const Content* ChatMessagePrivate::getFileTransferContent() const { const Content* ChatMessagePrivate::getFileTransferContent() const {
for (const Content *c : contents) { for (const Content *c : getContents()) {
if (c->getContentType() == ContentType::FileTransfer) { if (c->getContentType() == ContentType::FileTransfer) {
return c; return c;
} }
...@@ -230,8 +227,7 @@ void ChatMessagePrivate::setFileTransferFilepath (const string &path) { ...@@ -230,8 +227,7 @@ void ChatMessagePrivate::setFileTransferFilepath (const string &path) {
} }
const string &ChatMessagePrivate::getAppdata () const { const string &ChatMessagePrivate::getAppdata () const {
loadContentsFromDatabase(); for (const Content *c : getContents()) {
for (const Content *c : contents) {
if (c->isFile()) { if (c->isFile()) {
FileContent *fileContent = (FileContent *)c; FileContent *fileContent = (FileContent *)c;
return fileContent->getAppData("legacy"); return fileContent->getAppData("legacy");
...@@ -241,8 +237,7 @@ const string &ChatMessagePrivate::getAppdata () const { ...@@ -241,8 +237,7 @@ const string &ChatMessagePrivate::getAppdata () const {
} }
void ChatMessagePrivate::setAppdata (const string &data) { void ChatMessagePrivate::setAppdata (const string &data) {
loadContentsFromDatabase(); for (const Content *c : getContents()) {
for (const Content *c : contents) {
if (c->isFile()) { if (c->isFile()) {
FileContent *fileContent = (FileContent *)c; FileContent *fileContent = (FileContent *)c;
fileContent->setAppData("legacy", data); fileContent->setAppData("legacy", data);
...@@ -338,13 +333,13 @@ LinphoneContent *ChatMessagePrivate::getFileTransferInformation () const { ...@@ -338,13 +333,13 @@ LinphoneContent *ChatMessagePrivate::getFileTransferInformation () const {
if (hasFileTransferContent()) { if (hasFileTransferContent()) {
return getFileTransferContent()->toLinphoneContent(); return getFileTransferContent()->toLinphoneContent();
} }
for (const Content *c : contents) { for (const Content *c : getContents()) {
if (c->isFile()) { if (c->isFile()) {
FileContent *fileContent = (FileContent *)c; FileContent *fileContent = (FileContent *)c;
return fileContent->toLinphoneContent(); return fileContent->toLinphoneContent();
} }
} }
return NULL; return nullptr;
} }
void ChatMessagePrivate::setFileTransferInformation (const LinphoneContent *c_content) { void ChatMessagePrivate::setFileTransferInformation (const LinphoneContent *c_content) {
...@@ -356,7 +351,7 @@ void ChatMessagePrivate::setFileTransferInformation (const LinphoneContent *c_co ...@@ -356,7 +351,7 @@ void ChatMessagePrivate::setFileTransferInformation (const LinphoneContent *c_co
fileContent->setContentType(contentType); fileContent->setContentType(contentType);
fileContent->setFileSize(linphone_content_get_size(c_content)); fileContent->setFileSize(linphone_content_get_size(c_content));
fileContent->setFileName(linphone_content_get_name(c_content)); fileContent->setFileName(linphone_content_get_name(c_content));
if (linphone_content_get_string_buffer(c_content) != NULL) { if (linphone_content_get_string_buffer(c_content)) {
fileContent->setBody(linphone_content_get_string_buffer(c_content)); fileContent->setBody(linphone_content_get_string_buffer(c_content));
} }
...@@ -365,9 +360,8 @@ void ChatMessagePrivate::setFileTransferInformation (const LinphoneContent *c_co ...@@ -365,9 +360,8 @@ void ChatMessagePrivate::setFileTransferInformation (const LinphoneContent *c_co
bool ChatMessagePrivate::downloadFile () { bool ChatMessagePrivate::downloadFile () {
L_Q(); L_Q();
loadContentsFromDatabase();
for (auto &content : contents) for (auto &content : getContents())
if (content->getContentType() == ContentType::FileTransfer) if (content->getContentType() == ContentType::FileTransfer)
return q->downloadFile(*static_cast<FileTransferContent *>(content)); return q->downloadFile(*static_cast<FileTransferContent *>(content));
...@@ -961,22 +955,19 @@ bool ChatMessage::isReadOnly () const { ...@@ -961,22 +955,19 @@ bool ChatMessage::isReadOnly () const {
const list<Content *> &ChatMessage::getContents () const { const list<Content *> &ChatMessage::getContents () const {
L_D(); L_D();
d->loadContentsFromDatabase(); return d->getContents();
return d->contents;
} }
void ChatMessage::addContent (Content &content) { void ChatMessage::addContent (Content &content) {
L_D(); L_D();
if (d->isReadOnly) return; if (!d->isReadOnly)
d->getContents().push_back(&content);
d->contents.push_back(&content);
} }
void ChatMessage::removeContent (const Content &content) { void ChatMessage::removeContent (const Content &content) {
L_D(); L_D();
if (d->isReadOnly) return; if (!d->isReadOnly)
d->getContents().remove(&const_cast<Content &>(content));
d->contents.remove(&const_cast<Content &>(content));
} }
const Content &ChatMessage::getInternalContent () const { const Content &ChatMessage::getInternalContent () const {
......
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