From 720783e4a86c5a89592847c79b4ab932f9ff6879 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 13 Mar 2014 19:42:54 +0000 Subject: fix for db_event_count in subs git-svn-id: http://svn.miranda-ng.org/main/trunk@8598 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Db3x_mmap/src/dbevents.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'plugins/Db3x_mmap/src/dbevents.cpp') diff --git a/plugins/Db3x_mmap/src/dbevents.cpp b/plugins/Db3x_mmap/src/dbevents.cpp index 7513348cad..7be737b1ba 100644 --- a/plugins/Db3x_mmap/src/dbevents.cpp +++ b/plugins/Db3x_mmap/src/dbevents.cpp @@ -46,12 +46,14 @@ STDMETHODIMP_(HANDLE) CDb3Mmap::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) dbe.cbBlob = dbei->cbBlob; BYTE *pBlob = dbei->pBlob; + DBCachedContact *ccSub = NULL; if (contactID != 0) { DBCachedContact *cc = m_cache->GetCachedContact(contactID); if (cc == NULL) return NULL; if (cc->IsSub()) { + ccSub = cc; // set default sub to the event's source db_mc_setDefault(cc->parentID, contactID); contactID = cc->parentID; // and add an event to a metahistory @@ -137,6 +139,11 @@ STDMETHODIMP_(HANDLE) CDb3Mmap::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) } else neednotify = m_safetyMode; + if (ccSub != NULL) { + DBContact *pSub = (DBContact*)DBRead(ccSub->dwDriverData, sizeof(DBContact), NULL); + pSub->eventCount++; + } + DBWrite(ofsContact, &dbc, sizeof(DBContact)); DBWrite(ofsNew, &dbe, offsetof(DBEvent, blob)); DBWrite(ofsNew + offsetof(DBEvent, blob), pBlob, dbe.cbBlob); @@ -224,6 +231,15 @@ STDMETHODIMP_(BOOL) CDb3Mmap::DeleteEvent(MCONTACT contactID, HANDLE hDbEvent) //decrement event count dbc.eventCount--; DBWrite(ofsContact, &dbc, sizeof(DBContact)); + + // also update a sub + if (dbc.dwContactID != contactID) { + DBCachedContact *cc = m_cache->GetCachedContact(dbc.dwContactID); + DBContact *pSub = (DBContact*)DBRead(cc->dwDriverData, sizeof(DBContact), NULL); + if (pSub->eventCount > 0) + pSub->eventCount--; + } + DBFlush(0); return 0; } -- cgit v1.2.3