diff options
author | George Hazan <ghazan@miranda.im> | 2018-08-22 19:52:27 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-08-22 19:52:27 +0300 |
commit | 635a81a5b4e12538d8aebf5eb85a632b08978f61 (patch) | |
tree | 0d293e1ca0cd4206abfc92a62ea3deafee03ce8f | |
parent | b599a32b617386e5d9cb8df4540589612fae4fc3 (diff) |
Msg_Export: fix for export metacontact's events
-rw-r--r-- | plugins/Import/src/textjson.cpp | 25 | ||||
-rwxr-xr-x | plugins/Msg_Export/src/stdafx.h | 1 | ||||
-rwxr-xr-x | plugins/Msg_Export/src/utils.cpp | 17 |
3 files changed, 36 insertions, 7 deletions
diff --git a/plugins/Import/src/textjson.cpp b/plugins/Import/src/textjson.cpp index 250884e945..d17a87984b 100644 --- a/plugins/Import/src/textjson.cpp +++ b/plugins/Import/src/textjson.cpp @@ -32,20 +32,31 @@ static int mc_makeDatabase(const wchar_t*) ///////////////////////////////////////////////////////////////////////////////////////// // JSON text driver, read-only +static int CompareModules(const char *p1, const char *p2) +{ + return mir_strcmp(p1, p2); +} + class CDbxJson : public MDatabaseReadonly, public MZeroedObject { JSONNode *m_root = nullptr; LIST<JSONNode> m_events; + LIST<char> m_modules; + std::string m_proto; public: CDbxJson() : - m_events(100) + m_events(100), + m_modules(10, CompareModules) {} ~CDbxJson() { if (m_root != nullptr) json_delete(m_root); + + for (auto &it : m_modules) + mir_free(it); } void Load() @@ -71,6 +82,8 @@ public: if ((m_root = json_parse(szFile)) == nullptr) return EGROKPRF_DAMAGED; + m_proto = (*m_root)["info"]["proto"].as_string(); + for (auto &it : m_root->at("history")) m_events.insert(&it); @@ -136,6 +149,16 @@ public: case 'r': dbei->flags |= DBEF_READ; break; } + std::string szModule = (*node)["module"].as_string(); + if (!szModule.empty()) + szModule = m_proto; + + dbei->szModule = m_modules.find((char*)szModule.c_str()); + if (dbei->szModule == nullptr) { + dbei->szModule = mir_strdup(szModule.c_str()); + m_modules.insert(dbei->szModule); + } + std::string szBody = (*node)["body"].as_string(); if (!szBody.empty()) { dbei->flags |= DBEF_UTF; diff --git a/plugins/Msg_Export/src/stdafx.h b/plugins/Msg_Export/src/stdafx.h index b2be179c48..aae56f15b3 100755 --- a/plugins/Msg_Export/src/stdafx.h +++ b/plugins/Msg_Export/src/stdafx.h @@ -30,6 +30,7 @@ using namespace std; #include <newpluginapi.h>
#include <m_database.h>
+#include <m_metacontacts.h>
#include <m_clist.h>
#include <m_contacts.h>
#include <m_langpack.h>
diff --git a/plugins/Msg_Export/src/utils.cpp b/plugins/Msg_Export/src/utils.cpp index 01b9639e10..329a44eb7a 100755 --- a/plugins/Msg_Export/src/utils.cpp +++ b/plugins/Msg_Export/src/utils.cpp @@ -686,6 +686,12 @@ static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, wstring sFilePath wchar_t szTemp[500];
bool bWriteUTF8Format = false;
+ const char *szProto = GetContactProto(hContact);
+ if (szProto == nullptr) {
+ Netlib_Logf(0, MODULENAME ": cannot write message for a contact %d without protocol", hContact);
+ return false;
+ }
+
if (bAppendOnly) {
bWriteUTF8Format = g_bUseUtf8InNewFiles;
@@ -715,12 +721,6 @@ static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, wstring sFilePath bWriteToFile(hFile, ",", 1);
}
else {
- const char *szProto = GetContactProto(hContact);
- if (szProto == nullptr) {
- Netlib_Logf(0, MODULENAME ": cannot write message for a contact %d without protocol", hContact);
- return false;
- }
-
if (g_bUseJson) {
JSONNode pRoot, pInfo, pHist(JSON_ARRAY);
pInfo.set_name("info");
@@ -811,6 +811,8 @@ static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, wstring sFilePath if (g_bUseJson) {
JSONNode pRoot;
pRoot.push_back(JSONNode("type", dbei.eventType));
+ if (mir_strcmp(dbei.szModule, szProto))
+ pRoot.push_back(JSONNode("module", dbei.szModule));
TimeZone_PrintTimeStamp(UTC_TIME_HANDLE, dbei.timestamp, L"I", szTemp, _countof(szTemp), 0);
pRoot.push_back(JSONNode("isotime", T2Utf(szTemp).get()));
@@ -1117,6 +1119,9 @@ bool bExportEvent(MCONTACT hContact, MEVENT hDbEvent, HANDLE hFile, wstring sFil bool result = true;
if (!db_event_get(hDbEvent, &dbei)) {
+ if (db_mc_isMeta(hContact))
+ hContact = db_event_getContact(hDbEvent);
+
// Write the event
result = ExportDBEventInfo(hContact, hFile, sFilePath, dbei, bAppendOnly);
}
|