summaryrefslogtreecommitdiff
path: root/plugins/Dbx_mdb/src/dbcontacts.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Dbx_mdb/src/dbcontacts.cpp')
-rw-r--r--plugins/Dbx_mdb/src/dbcontacts.cpp47
1 files changed, 39 insertions, 8 deletions
diff --git a/plugins/Dbx_mdb/src/dbcontacts.cpp b/plugins/Dbx_mdb/src/dbcontacts.cpp
index 6a3c4dca44..958f48676a 100644
--- a/plugins/Dbx_mdb/src/dbcontacts.cpp
+++ b/plugins/Dbx_mdb/src/dbcontacts.cpp
@@ -152,23 +152,54 @@ BOOL CDbxMdb::MetaSetDefault(DBCachedContact *cc)
return db_set_dw(cc->contactID, META_PROTO, "Default", cc->nDefault);
}
-static int SortEvent(const DBEvent *p1, const DBEvent *p2)
-{
- return (LONG)p1->timestamp - (LONG)p2->timestamp;
-}
+/////////////////////////////////////////////////////////////////////////////////////////
BOOL CDbxMdb::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub)
{
- mir_cslock lck(m_csDbAccess);
- return -11;
+ DBEventSortingKey keyVal = { 0, 0, ccSub->contactID }, insVal = { 0, 0, ccMeta->contactID };
+ MDB_val key = { sizeof(keyVal), &keyVal }, key2 = { sizeof(insVal), &insVal }, data;
+
+ txn_ptr trnlck(m_pMdbEnv);
+
+ cursor_ptr cursor(trnlck, m_dbEventsSort);
+ mdb_cursor_get(cursor, &key, &data, MDB_SET);
+ while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == MDB_SUCCESS) {
+ DBEventSortingKey *pKey = (DBEventSortingKey*)key.mv_data;
+ if (pKey->dwContactId != ccSub->contactID)
+ break;
+
+ insVal.ts = pKey->ts;
+ insVal.dwEventId = pKey->dwEventId;
+ mdb_put(trnlck, m_dbEventsSort, &key2, &data, 0);
+ }
+
+ trnlck.commit();
+ return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
BOOL CDbxMdb::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub)
{
- mir_cslock lck(m_csDbAccess);
- return -11;
+ DBEventSortingKey keyVal = { 0, 0, ccSub->contactID }, delVal = { 0, 0, ccMeta->contactID };
+ MDB_val key = { sizeof(keyVal), &keyVal }, key2 = { sizeof(delVal), &delVal }, data;
+
+ txn_ptr trnlck(m_pMdbEnv);
+
+ cursor_ptr cursor(trnlck, m_dbEventsSort);
+ mdb_cursor_get(cursor, &key, &data, MDB_SET);
+ while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == MDB_SUCCESS) {
+ DBEventSortingKey *pKey = (DBEventSortingKey*)key.mv_data;
+ if (pKey->dwContactId != ccSub->contactID)
+ break;
+
+ delVal.ts = pKey->ts;
+ delVal.dwEventId = pKey->dwEventId;
+ mdb_del(trnlck, m_dbEventsSort, &key2, &data);
+ }
+
+ trnlck.commit();
+ return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////