From 519b59a6aed73060bbe492630cc1820ca3deb83d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 23 Apr 2023 14:20:38 +0300 Subject: fixes #3502 (Import: Discord contacts duplicated instead of merged) --- plugins/Import/src/import.cpp | 25 ++++++++++++++++++++++++- plugins/Import/src/stdafx.h | 1 + plugins/Import/src/version.h | 4 ++-- 3 files changed, 27 insertions(+), 3 deletions(-) (limited to 'plugins/Import/src') diff --git a/plugins/Import/src/import.cpp b/plugins/Import/src/import.cpp index eb01a4b67f..675d6fbf76 100644 --- a/plugins/Import/src/import.cpp +++ b/plugins/Import/src/import.cpp @@ -100,6 +100,21 @@ MCONTACT CImportBatch::HContactFromID(const char *pszProtoName, const char *pszS return INVALID_CONTACT_ID; } +MCONTACT CImportBatch::HContactFromBlobID(const char *pszProtoName, const char *pszSetting, const DBVARIANT &id) +{ + for (MCONTACT hContact = dstDb->FindFirstContact(pszProtoName); hContact; hContact = dstDb->FindNextContact(hContact, pszProtoName)) { + DBVARIANT dbv = { DBVT_BLOB }; + if (db_get_s(hContact, pszProtoName, pszSetting, &dbv, 0)) + continue; + + bool bEqual = (dbv.cpbVal == id.cpbVal && !memcmp(dbv.pbVal, id.pbVal, id.cpbVal)); + srcDb->FreeVariant(&dbv); + if (bEqual) + return hContact; + } + return INVALID_CONTACT_ID; +} + MCONTACT CImportBatch::HContactFromNumericID(const char *pszProtoName, const char *pszSetting, uint32_t dwID) { for (MCONTACT hContact = dstDb->FindFirstContact(pszProtoName); hContact; hContact = dstDb->FindNextContact(hContact, pszProtoName)) @@ -728,7 +743,7 @@ MCONTACT CImportBatch::ImportContact(MCONTACT hSrc) if (!myGet(hSrc, cc->szProto, (m_pPattern != nullptr) ? "ID" : pszUniqueSetting, &dbv)) { // Does the contact already exist? MCONTACT hDst; - wchar_t id[40]; + wchar_t id[100]; switch (dbv.type) { case DBVT_DWORD: pszUniqueID = _ltow(dbv.dVal, id, 10); @@ -746,6 +761,14 @@ MCONTACT CImportBatch::ImportContact(MCONTACT hSrc) hDst = HContactFromID(szDstModuleName, pszUniqueSetting, pszUniqueID); break; + case DBVT_BLOB: + if (dbv.cpbVal < _countof(id) / 2) { + pszUniqueID = bin2hexW(dbv.pbVal, dbv.cpbVal, id); + hDst = HContactFromBlobID(szDstModuleName, pszUniqueSetting, dbv); + break; + } + else __fallthrough; + default: hDst = INVALID_CONTACT_ID; } diff --git a/plugins/Import/src/stdafx.h b/plugins/Import/src/stdafx.h index 3df8c0917a..9427c8a94b 100644 --- a/plugins/Import/src/stdafx.h +++ b/plugins/Import/src/stdafx.h @@ -285,6 +285,7 @@ class CImportBatch : public MZeroedObject PROTOACCOUNT* FindMyAccount(const char *szProto, const char *szBaseProto, const wchar_t *ptszName, bool bStrict); MCONTACT HContactFromID(const char *pszProtoName, const char *pszSetting, wchar_t *pwszID); + MCONTACT HContactFromBlobID(const char *pszProtoName, const char *pszSetting, const DBVARIANT &dbv); MCONTACT HContactFromNumericID(const char *pszProtoName, const char *pszSetting, uint32_t dwID); public: diff --git a/plugins/Import/src/version.h b/plugins/Import/src/version.h index f76dfe14a3..3315d47998 100644 --- a/plugins/Import/src/version.h +++ b/plugins/Import/src/version.h @@ -1,6 +1,6 @@ #define __MAJOR_VERSION 0 -#define __MINOR_VERSION 95 -#define __RELEASE_NUM 11 +#define __MINOR_VERSION 96 +#define __RELEASE_NUM 3 #define __BUILD_NUM 1 #include -- cgit v1.2.3