diff options
author | George Hazan <ghazan@miranda.im> | 2022-02-06 18:11:23 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-02-06 18:11:23 +0300 |
commit | 8975af6cee9cfed40a075a16841cb0e6428ebaa6 (patch) | |
tree | 95a0bba4bf6c6751e932d25f6976d3a0d164e36d /src/mir_app | |
parent | 75650597de2eab62279fc20f9d5ea6a158a761ae (diff) |
duplicate event checking code moved to the core
Diffstat (limited to 'src/mir_app')
-rw-r--r-- | src/mir_app/src/db_events.cpp | 133 | ||||
-rw-r--r-- | src/mir_app/src/mir_app.def | 1 | ||||
-rw-r--r-- | src/mir_app/src/mir_app64.def | 1 |
3 files changed, 135 insertions, 0 deletions
diff --git a/src/mir_app/src/db_events.cpp b/src/mir_app/src/db_events.cpp index c42fc6ba67..f30b0af087 100644 --- a/src/mir_app/src/db_events.cpp +++ b/src/mir_app/src/db_events.cpp @@ -314,3 +314,136 @@ uint8_t* DB::AUTH_BLOB::makeBlob() return pBlob;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static uint32_t dwPreviousTimeStamp = -1;
+static MCONTACT hPreviousContact = INVALID_CONTACT_ID;
+static MEVENT hPreviousDbEvent = 0;
+
+// Returns TRUE if the event already exist in the database
+MIR_APP_DLL(bool) DB::IsDuplicateEvent(MCONTACT hContact, DBEVENTINFO &dbei)
+{
+ // get last event
+ MEVENT hExistingDbEvent = db_event_last(hContact);
+ if (!hExistingDbEvent)
+ 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 != 0) {
+ 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 != 0) {
+ 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 != 0) {
+ 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;
+}
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index be81fe60de..20befc32d3 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -791,3 +791,4 @@ _Netlib_SslWrite@12 @877 NONAME ?setTyping@CSrmmBaseDialog@@QAEXHPBUUSERINFO@@@Z @879 NONAME
?SafeRecycleBin@PU@@YGHPB_W@Z @880 NONAME
?IsMirandaFolderWritable@PU@@YG_NXZ @881 NONAME
+?IsDuplicateEvent@DB@@YG_NIAAUDBEVENTINFO@@@Z @882 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 52a1e3b701..0330b8708a 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -791,3 +791,4 @@ Netlib_SslWrite @877 NONAME ?setTyping@CSrmmBaseDialog@@QEAAXHPEBUUSERINFO@@@Z @879 NONAME
?SafeRecycleBin@PU@@YAHPEB_W@Z @880 NONAME
?IsMirandaFolderWritable@PU@@YA_NXZ @881 NONAME
+?IsDuplicateEvent@DB@@YA_NIAEAUDBEVENTINFO@@@Z @882 NONAME
|