summaryrefslogtreecommitdiff
path: root/plugins/Msg_Export/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-01-22 13:57:00 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-01-22 13:57:00 +0300
commit5dbd97ae09f42a2c1b62b156d2ec316d2bcdacf2 (patch)
treece066554c2062251e1dc3b5463ce5a448a2035d6 /plugins/Msg_Export/src
parentd15131c8dd6ec9ccca39242fd032c9722bb1ea64 (diff)
MsgExport: export of user nicks in group chats
Diffstat (limited to 'plugins/Msg_Export/src')
-rw-r--r--plugins/Msg_Export/src/stdafx.h1
-rw-r--r--plugins/Msg_Export/src/utils.cpp30
2 files changed, 21 insertions, 10 deletions
diff --git a/plugins/Msg_Export/src/stdafx.h b/plugins/Msg_Export/src/stdafx.h
index 24989198aa..9db4cfaf19 100644
--- a/plugins/Msg_Export/src/stdafx.h
+++ b/plugins/Msg_Export/src/stdafx.h
@@ -34,6 +34,7 @@ using namespace std;
#include <newpluginapi.h>
#include <m_database.h>
#include <m_metacontacts.h>
+#include <m_chat_int.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 b4a48cac06..1c819d20de 100644
--- a/plugins/Msg_Export/src/utils.cpp
+++ b/plugins/Msg_Export/src/utils.cpp
@@ -628,6 +628,12 @@ static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, const wstring &sF
wstring sRemoteUser;
string::size_type nFirstColumnWidth;
+ const char *szProto = Proto_GetBaseAccountName(hContact);
+ if (szProto == nullptr) {
+ Netlib_Logf(0, MODULENAME ": cannot write message for a contact %d without protocol", hContact);
+ return false;
+ }
+
if (g_bUseLessAndGreaterInExport) {
sLocalUser = L"<<";
sRemoteUser = L">>";
@@ -636,6 +642,13 @@ static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, const wstring &sF
else {
sLocalUser = ptrW(GetMyOwnNick(hContact));
sRemoteUser = Clist_GetContactDisplayName(hContact);
+ if (dbei.szUserId && Contact::IsGroupChat(hContact)) {
+ ptrW contactId(Contact::GetInfo(CNF_UNIQUEID, hContact, szProto));
+ if (auto *si = Chat_Find(contactId, szProto))
+ if (auto *pUser = g_chatApi.UM_FindUser(si, Utf2T(dbei.szUserId)))
+ sRemoteUser = pUser->pszNick;
+ }
+
nFirstColumnWidth = max(sRemoteUser.size(), clFileTo1ColWidth[sFilePath]);
nFirstColumnWidth = max(sLocalUser.size(), nFirstColumnWidth);
nFirstColumnWidth += 2;
@@ -644,12 +657,6 @@ static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, const wstring &sF
wchar_t szTemp[500];
bool bWriteUTF8Format = false;
- const char *szProto = Proto_GetBaseAccountName(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;
@@ -681,9 +688,9 @@ static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, const wstring &sF
pInfo.push_back(JSONNode("user", T2Utf(sRemoteUser.c_str()).get()));
pInfo.push_back(JSONNode("proto", szProto));
- ptrW id(Contact::GetInfo(CNF_UNIQUEID, hContact, szProto));
- if (id != NULL)
- pInfo.push_back(JSONNode("uin", T2Utf(id).get()));
+ ptrW contactId(Contact::GetInfo(CNF_UNIQUEID, hContact, szProto));
+ if (contactId != NULL)
+ pInfo.push_back(JSONNode("uin", T2Utf(contactId).get()));
szTemp[0] = (wchar_t)db_get_b(hContact, szProto, "Gender", 0);
if (szTemp[0]) {
@@ -761,6 +768,9 @@ static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, const wstring &sF
if (mir_strcmp(dbei.szModule, szProto))
pRoot.push_back(JSONNode("module", dbei.szModule));
+ if (dbei.szUserId && !(dbei.flags & DBEF_SENT))
+ pRoot.push_back(JSONNode("member", T2Utf(sRemoteUser.c_str()).get()));
+
TimeZone_PrintTimeStamp(UTC_TIME_HANDLE, dbei.timestamp, L"I", szTemp, _countof(szTemp), 0);
pRoot.push_back(JSONNode("isotime", T2Utf(szTemp).get()));
@@ -804,7 +814,7 @@ static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, const wstring &sF
}
// Get time stamp
- int nIndent = mir_snwprintf(szTemp, L"%-*s", nFirstColumnWidth, dbei.flags & DBEF_SENT ? sLocalUser.c_str() : sRemoteUser.c_str());
+ int nIndent = mir_snwprintf(szTemp, L"%-*s", (int)nFirstColumnWidth, dbei.flags & DBEF_SENT ? sLocalUser.c_str() : sRemoteUser.c_str());
TimeZone_ToStringT(dbei.timestamp, g_sTimeFormat.c_str(), &szTemp[nIndent], _countof(szTemp) - nIndent - 2);