From 8975af6cee9cfed40a075a16841cb0e6428ebaa6 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 6 Feb 2022 18:11:23 +0300 Subject: duplicate event checking code moved to the core --- plugins/Import/src/import.cpp | 2 +- plugins/Import/src/stdafx.h | 2 - plugins/Import/src/utils.cpp | 131 ------------------------------------------ 3 files changed, 1 insertion(+), 134 deletions(-) (limited to 'plugins/Import') diff --git a/plugins/Import/src/import.cpp b/plugins/Import/src/import.cpp index 9ea7f723df..a90a993b80 100644 --- a/plugins/Import/src/import.cpp +++ b/plugins/Import/src/import.cpp @@ -951,7 +951,7 @@ void CImportBatch::ImportHistory(MCONTACT hContact, PROTOACCOUNT **protocol, int continue; // check for duplicate entries - if ((m_iOptions & IOPT_CHECKDUPS) != 0 && IsDuplicateEvent(hDst, dbei)) { + if ((m_iOptions & IOPT_CHECKDUPS) != 0 && DB::IsDuplicateEvent(hDst, dbei)) { nDupes++; continue; } diff --git a/plugins/Import/src/stdafx.h b/plugins/Import/src/stdafx.h index df21b67c16..ed7e5e0e23 100644 --- a/plugins/Import/src/stdafx.h +++ b/plugins/Import/src/stdafx.h @@ -308,8 +308,6 @@ public: CImportPattern *m_pPattern; }; -bool IsDuplicateEvent(MCONTACT hContact, DBEVENTINFO dbei); - int CreateGroup(const wchar_t *name, MCONTACT hContact); uint32_t RLInteger(const uint8_t *p); diff --git a/plugins/Import/src/utils.cpp b/plugins/Import/src/utils.cpp index d6f2ba929f..3c83bf11a9 100644 --- a/plugins/Import/src/utils.cpp +++ b/plugins/Import/src/utils.cpp @@ -48,137 +48,6 @@ int CreateGroup(const wchar_t *group, MCONTACT hContact) return 1; } -// Returns TRUE if the event already exist in the database -bool IsDuplicateEvent(MCONTACT hContact, DBEVENTINFO dbei) -{ - static uint32_t dwPreviousTimeStamp = -1; - static MCONTACT hPreviousContact = INVALID_CONTACT_ID; - static MEVENT hPreviousDbEvent = NULL; - - // get last event - MEVENT hExistingDbEvent = db_event_last(hContact); - if (hExistingDbEvent == NULL) - return FALSE; - - DBEVENTINFO dbeiExisting = {}; - db_event_get(hExistingDbEvent, &dbeiExisting); - uint32_t dwEventTimeStamp = dbeiExisting.timestamp; - - // compare with last timestamp - if (dbei.timestamp > dwEventTimeStamp) { - // remember event - hPreviousDbEvent = hExistingDbEvent; - dwPreviousTimeStamp = dwEventTimeStamp; - return FALSE; - } - - if (hContact != hPreviousContact) { - hPreviousContact = hContact; - // remember event - hPreviousDbEvent = hExistingDbEvent; - dwPreviousTimeStamp = dwEventTimeStamp; - - // get first event - if (!(hExistingDbEvent = db_event_first(hContact))) - return FALSE; - - memset(&dbeiExisting, 0, sizeof(dbeiExisting)); - db_event_get(hExistingDbEvent, &dbeiExisting); - dwEventTimeStamp = dbeiExisting.timestamp; - - // compare with first timestamp - if (dbei.timestamp <= dwEventTimeStamp) { - // remember event - dwPreviousTimeStamp = dwEventTimeStamp; - hPreviousDbEvent = hExistingDbEvent; - if (dbei.timestamp != dwEventTimeStamp) - return FALSE; - } - } - - // check for equal timestamps - if (dbei.timestamp == dwPreviousTimeStamp) { - memset(&dbeiExisting, 0, sizeof(dbeiExisting)); - db_event_get(hPreviousDbEvent, &dbeiExisting); - - if (dbei == dbeiExisting) - return TRUE; - - // find event with another timestamp - hExistingDbEvent = db_event_next(hContact, hPreviousDbEvent); - while (hExistingDbEvent != NULL) { - memset(&dbeiExisting, 0, sizeof(dbeiExisting)); - db_event_get(hExistingDbEvent, &dbeiExisting); - - if (dbeiExisting.timestamp != dwPreviousTimeStamp) { - // use found event - hPreviousDbEvent = hExistingDbEvent; - dwPreviousTimeStamp = dbeiExisting.timestamp; - break; - } - - hPreviousDbEvent = hExistingDbEvent; - hExistingDbEvent = db_event_next(hContact, hExistingDbEvent); - } - } - - hExistingDbEvent = hPreviousDbEvent; - - if (dbei.timestamp <= dwPreviousTimeStamp) { - // look back - while (hExistingDbEvent != NULL) { - memset(&dbeiExisting, 0, sizeof(dbeiExisting)); - db_event_get(hExistingDbEvent, &dbeiExisting); - - if (dbei.timestamp > dbeiExisting.timestamp) { - // remember event - hPreviousDbEvent = hExistingDbEvent; - dwPreviousTimeStamp = dbeiExisting.timestamp; - return FALSE; - } - - // Compare event with import candidate - if (dbei == dbeiExisting) { - // remember event - hPreviousDbEvent = hExistingDbEvent; - dwPreviousTimeStamp = dbeiExisting.timestamp; - return TRUE; - } - - // Get previous event in chain - hExistingDbEvent = db_event_prev(hContact, hExistingDbEvent); - } - } - else { - // look forward - while (hExistingDbEvent != NULL) { - memset(&dbeiExisting, 0, sizeof(dbeiExisting)); - db_event_get(hExistingDbEvent, &dbeiExisting); - - if (dbei.timestamp < dbeiExisting.timestamp) { - // remember event - hPreviousDbEvent = hExistingDbEvent; - dwPreviousTimeStamp = dbeiExisting.timestamp; - return FALSE; - } - - // Compare event with import candidate - if (dbei == dbeiExisting) { - // remember event - hPreviousDbEvent = hExistingDbEvent; - dwPreviousTimeStamp = dbeiExisting.timestamp; - return TRUE; - } - - // Get next event in chain - hExistingDbEvent = db_event_next(hContact, hExistingDbEvent); - } - } - // reset last event - hPreviousContact = INVALID_CONTACT_ID; - return FALSE; -} - ///////////////////////////////////////////////////////////////////////////////////////// // rtl integers -- cgit v1.2.3