diff options
author | George Hazan <ghazan@miranda.im> | 2018-03-26 20:14:44 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-03-26 20:14:44 +0300 |
commit | 9285557d9f8a2ee7b06d483aed1735c9888f8aff (patch) | |
tree | 147709ae148770ad9b55daee587f9f65775073fa /plugins/Dbx_mdbx/src | |
parent | a076ee7deea97716cfdce8905d5361df98ad9424 (diff) |
fix for system history processing
Diffstat (limited to 'plugins/Dbx_mdbx/src')
-rw-r--r-- | plugins/Dbx_mdbx/src/dbevents.cpp | 118 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/dbintf.cpp | 5 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/dbintf.h | 5 |
3 files changed, 87 insertions, 41 deletions
diff --git a/plugins/Dbx_mdbx/src/dbevents.cpp b/plugins/Dbx_mdbx/src/dbevents.cpp index baf75a04fe..572c193475 100644 --- a/plugins/Dbx_mdbx/src/dbevents.cpp +++ b/plugins/Dbx_mdbx/src/dbevents.cpp @@ -25,6 +25,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. STDMETHODIMP_(LONG) CDbxMDBX::GetEventCount(MCONTACT contactID)
{
+ if (!contactID)
+ return m_ccDummy.dbc.dwEventCount;
+
DBCachedContact *cc = m_cache->GetCachedContact(contactID);
return (cc == nullptr) ? 0 : cc->dbc.dwEventCount;
}
@@ -42,21 +45,24 @@ STDMETHODIMP_(MEVENT) CDbxMDBX::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) MCONTACT contactNotifyID = contactID;
DBCachedContact *cc, *ccSub = nullptr;
- if ((cc = m_cache->GetCachedContact(contactID)) == nullptr)
- return 0;
-
- if (cc->IsSub()) {
- ccSub = cc;
- if ((cc = m_cache->GetCachedContact(cc->parentID)) == nullptr)
+ if (contactID != 0) {
+ if ((cc = m_cache->GetCachedContact(contactID)) == nullptr)
return 0;
- // set default sub to the event's source
- if (!(dbei->flags & DBEF_SENT))
- db_mc_setDefault(cc->contactID, contactID, false);
- contactID = cc->contactID; // and add an event to a metahistory
- if (db_mc_isEnabled())
- contactNotifyID = contactID;
+ if (cc->IsSub()) {
+ ccSub = cc;
+ if ((cc = m_cache->GetCachedContact(cc->parentID)) == nullptr)
+ return 0;
+
+ // set default sub to the event's source
+ if (!(dbei->flags & DBEF_SENT))
+ db_mc_setDefault(cc->contactID, contactID, false);
+ contactID = cc->contactID; // and add an event to a metahistory
+ if (db_mc_isEnabled())
+ contactNotifyID = contactID;
+ }
}
+ else cc = &m_ccDummy;
if (m_safetyMode)
if (NotifyEventHooks(hEventFilterAddedEvent, contactNotifyID, (LPARAM)dbei))
@@ -99,20 +105,28 @@ STDMETHODIMP_(MEVENT) CDbxMDBX::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) return 0;
cc->Advance(dwEventId, dbe);
- MDBX_val keyc = { &contactID, sizeof(MCONTACT) }, datac = { &cc->dbc, sizeof(DBContact) };
- if (mdbx_put(trnlck, m_dbContacts, &keyc, &datac, 0) != MDBX_SUCCESS)
- return 0;
-
- // 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)
+ 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 0;
- ccSub->Advance(dwEventId, dbe);
- datac.iov_base = &ccSub->dbc;
- keyc.iov_base = &ccSub->contactID;
- if (mdbx_put(trnlck, m_dbContacts, &keyc, &datac, 0) != MDBX_SUCCESS)
+ // 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 0;
+
+ ccSub->Advance(dwEventId, dbe);
+ datac.iov_base = &ccSub->dbc;
+ keyc.iov_base = &ccSub->contactID;
+ if (mdbx_put(trnlck, m_dbContacts, &keyc, &datac, 0) != MDBX_SUCCESS)
+ return 0;
+ }
+ }
+ 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 0;
}
@@ -131,7 +145,7 @@ STDMETHODIMP_(MEVENT) CDbxMDBX::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) STDMETHODIMP_(BOOL) CDbxMDBX::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent)
{
- DBCachedContact *cc = m_cache->GetCachedContact(contactID), *cc2 = nullptr;
+ DBCachedContact *cc = (contactID != 0) ? m_cache->GetCachedContact(contactID) : &m_ccDummy, *cc2 = nullptr;
if (cc == nullptr || cc->dbc.dwEventCount == 0)
return 1;
@@ -155,7 +169,7 @@ STDMETHODIMP_(BOOL) CDbxMDBX::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent) if (mdbx_del(trnlck, m_dbEventsSort, &key, nullptr) != MDBX_SUCCESS)
return 1;
- {
+ if (contactID != 0) {
key.iov_len = sizeof(MCONTACT); key.iov_base = &contactID;
cc->dbc.dwEventCount--;
if (cc->dbc.evFirstUnread == hDbEvent)
@@ -165,6 +179,16 @@ STDMETHODIMP_(BOOL) CDbxMDBX::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent) if (mdbx_put(trnlck, m_dbContacts, &key, &data, 0) != MDBX_SUCCESS)
return 1;
}
+ else {
+ m_ccDummy.dbc.dwEventCount--;
+ if (m_ccDummy.dbc.evFirstUnread == hDbEvent)
+ FindNextUnread(trnlck, &m_ccDummy, key2);
+
+ 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 0;
+ }
if (cc2) {
key2.hContact = dbe.contactID;
@@ -181,7 +205,7 @@ STDMETHODIMP_(BOOL) CDbxMDBX::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent) return 1;
}
- // remove a event
+ // remove an event
key.iov_len = sizeof(MEVENT); key.iov_base = &hDbEvent;
if (mdbx_del(trnlck, m_dbEvents, &key, nullptr) != MDBX_SUCCESS)
return 1;
@@ -338,9 +362,13 @@ STDMETHODIMP_(MCONTACT) CDbxMDBX::GetEventContact(MEVENT hDbEvent) STDMETHODIMP_(MEVENT) CDbxMDBX::FindFirstEvent(MCONTACT contactID)
{
- DBCachedContact *cc = m_cache->GetCachedContact(contactID);
- if (cc == nullptr)
- return 0;
+ DBCachedContact *cc;
+ if (contactID != 0) {
+ cc = m_cache->GetCachedContact(contactID);
+ if (cc == nullptr)
+ return 0;
+ }
+ else cc = &m_ccDummy;
DBEventSortingKey keyVal = { contactID, 0, 0 };
MDBX_val key = { &keyVal, sizeof(keyVal) }, data;
@@ -368,9 +396,13 @@ STDMETHODIMP_(MEVENT) CDbxMDBX::FindFirstUnreadEvent(MCONTACT contactID) STDMETHODIMP_(MEVENT) CDbxMDBX::FindLastEvent(MCONTACT contactID)
{
- DBCachedContact *cc = m_cache->GetCachedContact(contactID);
- if (cc == nullptr)
- return 0;
+ DBCachedContact *cc;
+ if (contactID != 0) {
+ cc = m_cache->GetCachedContact(contactID);
+ if (cc == nullptr)
+ return 0;
+ }
+ else cc = &m_ccDummy;
DBEventSortingKey keyVal = { contactID, 0xFFFFFFFF, 0xFFFFFFFFFFFFFFFF };
MDBX_val key = { &keyVal, sizeof(keyVal) }, data;
@@ -396,9 +428,13 @@ STDMETHODIMP_(MEVENT) CDbxMDBX::FindLastEvent(MCONTACT contactID) STDMETHODIMP_(MEVENT) CDbxMDBX::FindNextEvent(MCONTACT contactID, MEVENT hDbEvent)
{
- DBCachedContact *cc = m_cache->GetCachedContact(contactID);
- if (cc == nullptr)
- return 0;
+ DBCachedContact *cc;
+ if (contactID != 0) {
+ cc = m_cache->GetCachedContact(contactID);
+ if (cc == nullptr)
+ return 0;
+ }
+ else cc = &m_ccDummy;
if (hDbEvent == 0)
return cc->t_evLast = 0;
@@ -431,9 +467,13 @@ STDMETHODIMP_(MEVENT) CDbxMDBX::FindNextEvent(MCONTACT contactID, MEVENT hDbEven STDMETHODIMP_(MEVENT) CDbxMDBX::FindPrevEvent(MCONTACT contactID, MEVENT hDbEvent)
{
- DBCachedContact *cc = m_cache->GetCachedContact(contactID);
- if (cc == nullptr)
- return 0;
+ DBCachedContact *cc;
+ if (contactID != 0) {
+ cc = m_cache->GetCachedContact(contactID);
+ if (cc == nullptr)
+ return 0;
+ }
+ else cc = &m_ccDummy;
if (hDbEvent == 0)
return cc->t_evLast = 0;
diff --git a/plugins/Dbx_mdbx/src/dbintf.cpp b/plugins/Dbx_mdbx/src/dbintf.cpp index ee0c7b8e3c..79f5f0a4f1 100644 --- a/plugins/Dbx_mdbx/src/dbintf.cpp +++ b/plugins/Dbx_mdbx/src/dbintf.cpp @@ -96,6 +96,11 @@ int CDbxMDBX::Load(bool bSkipInit) data.iov_base = &m_header; data.iov_len = sizeof(m_header);
mdbx_put(trnlck, m_dbGlobal, &key, &data, 0);
}
+
+ keyVal = 2;
+ if (mdbx_get(trnlck, m_dbGlobal, &key, &data) == MDBX_SUCCESS)
+ m_ccDummy.dbc = *(const DBContact*)data.iov_base;
+
trnlck.commit();
}
{
diff --git a/plugins/Dbx_mdbx/src/dbintf.h b/plugins/Dbx_mdbx/src/dbintf.h index ac29a30115..d858deeb3e 100644 --- a/plugins/Dbx_mdbx/src/dbintf.h +++ b/plugins/Dbx_mdbx/src/dbintf.h @@ -213,11 +213,12 @@ protected: MDBX_env *m_env;
CMDBX_txn_ro m_txn_ro;
- MDBX_dbi m_dbGlobal;
+ MDBX_dbi m_dbGlobal;
DBHeader m_header;
-
HANDLE hSettingChangeEvent, hContactDeletedEvent, hContactAddedEvent, hEventMarkedRead;
+ DBCachedContact m_ccDummy; // dummy contact to serve a cache item for MCONTACT = 0
+
////////////////////////////////////////////////////////////////////////////
// settings
|