Commit 5bbd468b authored by Ronan's avatar Ronan

feat(EventsDb): import app data from legacy messages

parent e1888dc1
......@@ -39,14 +39,14 @@ public:
Content::Content () : ClonableObject(*new ContentPrivate) {}
Content::Content (const Content &src) : ClonableObject(*new ContentPrivate), AppDataContainer() {
Content::Content (const Content &src) : ClonableObject(*new ContentPrivate), AppDataContainer(src) {
L_D();
d->body = src.getBody();
d->contentType = src.getContentType();
d->contentDisposition = src.getContentDisposition();
}
Content::Content (Content &&src) : ClonableObject(*new ContentPrivate) {
Content::Content (Content &&src) : ClonableObject(*new ContentPrivate), AppDataContainer(src) {
L_D();
d->body = move(src.getPrivate()->body);
d->contentType = move(src.getPrivate()->contentType);
......@@ -59,6 +59,7 @@ Content &Content::operator= (const Content &src) {
d->body = src.getBody();
d->contentType = src.getContentType();
d->contentDisposition = src.getContentDisposition();
AppDataContainer::operator=(src);
}
return *this;
......@@ -69,6 +70,7 @@ Content &Content::operator= (Content &&src) {
d->body = move(src.getPrivate()->body);
d->contentType = move(src.getPrivate()->contentType);
d->contentDisposition = move(src.getPrivate()->contentDisposition);
AppDataContainer::operator=(move(src));
return *this;
}
......
......@@ -160,12 +160,20 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {}
}
void EventsDbPrivate::insertContent (long messageEventId, const Content &content) {
L_Q();
soci::session *session = dbSession.getBackendSession<soci::session>();
long contentTypeId = insertContentType(content.getContentType().asString());
*session << "INSERT INTO message_content (message_event_id, content_type_id, body) VALUES"
" (:messageEventId, :contentTypeId, :body)", soci::use(messageEventId), soci::use(contentTypeId),
soci::use(content.getBodyAsString());
long messageContentId = q->getLastInsertId();
for (const auto &appData : content.getAppDataMap())
*session << "INSERT INTO message_content_app_data (message_content_id, key, data) VALUES"
" (:messageContentId, :key, :data)",
soci::use(messageContentId), soci::use(appData.first), soci::use(appData.second);
}
long EventsDbPrivate::insertContentType (const string &contentType) {
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <unordered_map>
#include <memory>
#include "app-data-container.h"
......@@ -29,40 +29,51 @@ LINPHONE_BEGIN_NAMESPACE
class AppDataContainerPrivate {
public:
unordered_map<string, string> appData;
shared_ptr<unordered_map<string, string>> appData;
};
// -----------------------------------------------------------------------------
AppDataContainer::AppDataContainer () : mPrivate(new AppDataContainerPrivate) {}
AppDataContainer::AppDataContainer () : mPrivate(new AppDataContainerPrivate) {
L_D();
d->appData = make_shared<unordered_map<string, string>>();
}
// Empty copy constructor. Don't change this pattern.
// AppDataContainer is an Entity component, not a simple structure.
// An Entity is UNIQUE.
AppDataContainer::AppDataContainer (const AppDataContainer &) : mPrivate(new AppDataContainerPrivate) {}
AppDataContainer::AppDataContainer (const AppDataContainer &src) : mPrivate(new AppDataContainerPrivate) {
L_D();
d->appData = src.getPrivate()->appData;
}
AppDataContainer::~AppDataContainer () {
delete mPrivate;
}
AppDataContainer &AppDataContainer::operator= (const AppDataContainer &) {
AppDataContainer &AppDataContainer::operator= (const AppDataContainer &src) {
L_D();
if (this != &src)
d->appData = src.getPrivate()->appData;
return *this;
}
const unordered_map<string, string> &AppDataContainer::getAppDataMap () const {
L_D();
return *d->appData.get();
}
string AppDataContainer::getAppData (const string &name) const {
L_D();
auto it = d->appData.find(name);
return it == d->appData.cend() ? string() : it->second;
auto it = d->appData->find(name);
return it == d->appData->cend() ? string() : it->second;
}
void AppDataContainer::setAppData (const string &name, const string &appData) {
L_D();
d->appData[name] = appData;
(*d->appData)[name] = appData;
}
void AppDataContainer::setAppData (const string &name, string &&appData) {
L_D();
d->appData[name] = move(appData);
(*d->appData)[name] = move(appData);
}
LINPHONE_END_NAMESPACE
......@@ -21,6 +21,7 @@
#define _APP_DATA_CONTAINER_H_
#include <string>
#include <unordered_map>
#include "linphone/utils/general.h"
......@@ -38,6 +39,8 @@ public:
AppDataContainer &operator= (const AppDataContainer &src);
const std::unordered_map<std::string, std::string> &getAppDataMap () const;
std::string getAppData (const std::string &name) const;
void setAppData (const std::string &name, const std::string &appData);
void setAppData (const std::string &name, std::string &&appData);
......
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