summaryrefslogtreecommitdiff
path: root/plugins/Dbx_mdbx/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-09-23 18:50:35 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-09-23 18:50:42 +0300
commit0fcdde09a8e85689d9cfc0764a9015d5d352ff82 (patch)
tree6afe02302b39b157d4d208a84b27b88a7fb265d8 /plugins/Dbx_mdbx/src
parent3bbcf20aa8db080ef1da99e21ef554e8069bff7a (diff)
new event: ME_DB_EVENT_EDITED
Diffstat (limited to 'plugins/Dbx_mdbx/src')
-rw-r--r--plugins/Dbx_mdbx/src/dbevents.cpp33
-rw-r--r--plugins/Dbx_mdbx/src/dbintf.cpp1
-rw-r--r--plugins/Dbx_mdbx/src/dbintf.h3
3 files changed, 22 insertions, 15 deletions
diff --git a/plugins/Dbx_mdbx/src/dbevents.cpp b/plugins/Dbx_mdbx/src/dbevents.cpp
index 3776a4a79c..a99471361f 100644
--- a/plugins/Dbx_mdbx/src/dbevents.cpp
+++ b/plugins/Dbx_mdbx/src/dbevents.cpp
@@ -40,7 +40,7 @@ MEVENT CDbxMDBX::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
if (dbei->timestamp == 0) return 0;
MEVENT dwEventId = InterlockedIncrement(&m_dwMaxEventId);
- if (ERROR_SUCCESS != EditEvent(contactID, dwEventId, dbei))
+ if (!EditEvent(contactID, dwEventId, dbei, true))
return 0;
return dwEventId;
@@ -138,6 +138,11 @@ BOOL CDbxMDBX::EditEvent(MCONTACT contactID, MEVENT hDbEvent, DBEVENTINFO *dbei)
if (dbei == nullptr) return 1;
if (dbei->timestamp == 0) return 1;
+ return EditEvent(contactID, hDbEvent, dbei, false);
+}
+
+bool CDbxMDBX::EditEvent(MCONTACT contactID, MEVENT hDbEvent, DBEVENTINFO *dbei, bool bNew)
+{
DBEvent dbe;
dbe.contactID = contactID; // store native or subcontact's id
dbe.iModuleId = GetModuleID(dbei->szModule);
@@ -146,12 +151,12 @@ BOOL CDbxMDBX::EditEvent(MCONTACT contactID, MEVENT hDbEvent, DBEVENTINFO *dbei)
DBCachedContact *cc, *ccSub = nullptr;
if (contactID != 0) {
if ((cc = m_cache->GetCachedContact(contactID)) == nullptr)
- return 2;
+ return false;
if (cc->IsSub()) {
ccSub = cc;
if ((cc = m_cache->GetCachedContact(cc->parentID)) == nullptr)
- return 2;
+ return false;
// set default sub to the event's source
if (!(dbei->flags & DBEF_SENT))
@@ -163,9 +168,9 @@ BOOL CDbxMDBX::EditEvent(MCONTACT contactID, MEVENT hDbEvent, DBEVENTINFO *dbei)
}
else cc = &m_ccDummy;
- if (m_safetyMode)
+ if (bNew && m_safetyMode)
if (NotifyEventHooks(hEventFilterAddedEvent, contactNotifyID, (LPARAM)dbei))
- return 3;
+ return false;
dbe.timestamp = dbei->timestamp;
dbe.flags = dbei->flags;
@@ -193,52 +198,52 @@ BOOL CDbxMDBX::EditEvent(MCONTACT contactID, MEVENT hDbEvent, DBEVENTINFO *dbei)
txn_ptr trnlck(StartTran());
MDBX_val key = { &hDbEvent, sizeof(MEVENT) }, data = { recBuf, sizeof(DBEvent) + dbe.cbBlob };
if (mdbx_put(trnlck, m_dbEvents, &key, &data, 0) != MDBX_SUCCESS)
- return 4;
+ return false;
// add a sorting key
DBEventSortingKey key2 = { contactID, hDbEvent, dbe.timestamp };
key.iov_len = sizeof(key2); key.iov_base = &key2;
data.iov_len = 1; data.iov_base = (char*)("");
if (mdbx_put(trnlck, m_dbEventsSort, &key, &data, 0) != MDBX_SUCCESS)
- return 4;
+ return false;
cc->Advance(hDbEvent, dbe);
if (contactID != 0) {
MDBX_val keyc = { &contactID, sizeof(MCONTACT) }, datac = { &cc->dbc, sizeof(DBContact) };
if (mdbx_put(trnlck, m_dbContacts, &keyc, &datac, 0) != MDBX_SUCCESS)
- return 4;
+ return false;
// insert an event into a sub's history too
if (ccSub != nullptr) {
key2.hContact = ccSub->contactID;
if (mdbx_put(trnlck, m_dbEventsSort, &key, &data, 0) != MDBX_SUCCESS)
- return 4;
+ return false;
ccSub->Advance(hDbEvent, dbe);
datac.iov_base = &ccSub->dbc;
keyc.iov_base = &ccSub->contactID;
if (mdbx_put(trnlck, m_dbContacts, &keyc, &datac, 0) != MDBX_SUCCESS)
- return 4;
+ return false;
}
}
else {
uint32_t keyVal = 2;
MDBX_val keyc = { &keyVal, sizeof(keyVal) }, datac = { &m_ccDummy.dbc, sizeof(m_ccDummy.dbc) };
if (mdbx_put(trnlck, m_dbGlobal, &keyc, &datac, 0) != MDBX_SUCCESS)
- return 4;
+ return false;
}
if (trnlck.commit() != MDBX_SUCCESS)
- return 4;
+ return false;
}
DBFlush();
// Notify only in safe mode or on really new events
if (m_safetyMode)
- NotifyEventHooks(hEventAddedEvent, contactNotifyID, hDbEvent);
+ NotifyEventHooks(bNew ? hEventAddedEvent : hEventEditedEvent, contactNotifyID, hDbEvent);
- return ERROR_SUCCESS;
+ return true;
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/plugins/Dbx_mdbx/src/dbintf.cpp b/plugins/Dbx_mdbx/src/dbintf.cpp
index 9cbbf2656d..56c092ff36 100644
--- a/plugins/Dbx_mdbx/src/dbintf.cpp
+++ b/plugins/Dbx_mdbx/src/dbintf.cpp
@@ -142,6 +142,7 @@ int CDbxMDBX::Load()
hEventMarkedRead = CreateHookableEvent(ME_DB_EVENT_MARKED_READ);
hEventAddedEvent = CreateHookableEvent(ME_DB_EVENT_ADDED);
+ hEventEditedEvent = CreateHookableEvent(ME_DB_EVENT_EDITED);
hEventDeletedEvent = CreateHookableEvent(ME_DB_EVENT_DELETED);
hEventFilterAddedEvent = CreateHookableEvent(ME_DB_EVENT_FILTER_ADD);
}
diff --git a/plugins/Dbx_mdbx/src/dbintf.h b/plugins/Dbx_mdbx/src/dbintf.h
index 8f1b6ab24b..c250d8cdec 100644
--- a/plugins/Dbx_mdbx/src/dbintf.h
+++ b/plugins/Dbx_mdbx/src/dbintf.h
@@ -150,6 +150,7 @@ class CDbxMDBX : public MDatabaseCommon, public MZeroedObject
return res;
}
+ bool EditEvent(MCONTACT contactID, MEVENT hDbEvent, DBEVENTINFO *dbe, bool bNew);
void FillContacts(void);
int PrepareCheck(void);
void TouchFile(void);
@@ -197,7 +198,7 @@ class CDbxMDBX : public MDatabaseCommon, public MZeroedObject
MDBX_cursor *m_curEvents, *m_curEventsSort, *m_curEventIds;
MEVENT m_dwMaxEventId;
- HANDLE hEventAddedEvent, hEventDeletedEvent, hEventFilterAddedEvent;
+ HANDLE hEventAddedEvent, hEventEditedEvent, hEventDeletedEvent, hEventFilterAddedEvent;
void FindNextUnread(const txn_ptr &_txn, DBCachedContact *cc, DBEventSortingKey &key2);