diff options
author | George Hazan <ghazan@miranda.im> | 2022-12-25 21:01:26 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-12-25 21:01:26 +0300 |
commit | 0c66b748a7b6b223d34374994e4d7d207e3d2c71 (patch) | |
tree | bb960016c02b7ba6a57f342c829b65b00b6d2476 | |
parent | 97e9f52c99a41612fcfef3cae099519c46d55710 (diff) |
db_event_replace: new helper to eliminate duplicate events
-rw-r--r-- | include/m_database.h | 5 | ||||
-rw-r--r-- | libs/win32/mir_core.lib | bin | 489886 -> 490112 bytes | |||
-rw-r--r-- | libs/win64/mir_core.lib | bin | 495106 -> 495312 bytes | |||
-rw-r--r-- | plugins/Scriver/src/globals.cpp | 2 | ||||
-rw-r--r-- | plugins/TabSRMM/src/sendqueue.cpp | 2 | ||||
-rw-r--r-- | src/core/stdmsg/src/cmdlist.cpp | 2 | ||||
-rw-r--r-- | src/mir_core/src/db.cpp | 10 | ||||
-rw-r--r-- | src/mir_core/src/mir_core.def | 1 | ||||
-rw-r--r-- | src/mir_core/src/mir_core64.def | 1 |
9 files changed, 20 insertions, 3 deletions
diff --git a/include/m_database.h b/include/m_database.h index 47916a2c40..5f124cbf3b 100644 --- a/include/m_database.h +++ b/include/m_database.h @@ -295,6 +295,11 @@ EXTERN_C MIR_CORE_DLL(int) db_event_delete(MEVENT hDbEvent); EXTERN_C MIR_CORE_DLL(int) db_event_edit(MCONTACT hContact, MEVENT hDbEvent, const DBEVENTINFO *dbei); +// Tries to find an event by its id if present +// if an event is found, it's edited, otherwise a new event is added + +EXTERN_C MIR_CORE_DLL(MEVENT) db_event_replace(MCONTACT hContact, const DBEVENTINFO *dbei); + // Retrieves a handle to the first event in the chain for hContact // Returns the handle, or NULL if hContact is invalid or has no events // Events in a chain are sorted chronologically automatically diff --git a/libs/win32/mir_core.lib b/libs/win32/mir_core.lib Binary files differindex 32d8276525..1b0ef9e871 100644 --- a/libs/win32/mir_core.lib +++ b/libs/win32/mir_core.lib diff --git a/libs/win64/mir_core.lib b/libs/win64/mir_core.lib Binary files differindex 1d691f1672..1d6e1d9f2f 100644 --- a/libs/win64/mir_core.lib +++ b/libs/win64/mir_core.lib diff --git a/plugins/Scriver/src/globals.cpp b/plugins/Scriver/src/globals.cpp index aebeaf2f02..8eecb475ed 100644 --- a/plugins/Scriver/src/globals.cpp +++ b/plugins/Scriver/src/globals.cpp @@ -149,7 +149,7 @@ static int ackevent(WPARAM, LPARAM lParam) NotifyEventHooks(g_chatApi.hevPreCreate, 0, (LPARAM)&evt);
item->sendBuffer = (char *)dbei.pBlob;
- db_event_add(hContact, &dbei);
+ db_event_replace(hContact, &dbei);
if (item->hwndErrorDlg != nullptr)
DestroyWindow(item->hwndErrorDlg);
diff --git a/plugins/TabSRMM/src/sendqueue.cpp b/plugins/TabSRMM/src/sendqueue.cpp index bf6d9202fb..4e8372b7e4 100644 --- a/plugins/TabSRMM/src/sendqueue.cpp +++ b/plugins/TabSRMM/src/sendqueue.cpp @@ -474,7 +474,7 @@ int SendQueue::ackMessage(CMsgDialog *dat, WPARAM wParam, LPARAM lParam) NotifyEventHooks(g_chatApi.hevPreCreate, 0, (LPARAM)&evt); job.szSendBuffer = (char*)dbei.pBlob; - MEVENT hNewEvent = db_event_add(job.hContact, &dbei); + MEVENT hNewEvent = db_event_replace(job.hContact, &dbei); if (dat) if (!NEN::bNoSounds && !dat->m_pContainer->cfg.flags.m_bNoSound) diff --git a/src/core/stdmsg/src/cmdlist.cpp b/src/core/stdmsg/src/cmdlist.cpp index 7f8a420cbe..beb669dcf5 100644 --- a/src/core/stdmsg/src/cmdlist.cpp +++ b/src/core/stdmsg/src/cmdlist.cpp @@ -102,7 +102,7 @@ void msgQueue_processack(MCONTACT hContact, int id, BOOL success, LPARAM lParam) p->szMsg = (char*)dbei.pBlob;
- db_event_add(hContact, &dbei);
+ db_event_replace(hContact, &dbei);
mir_free(p->szMsg);
mir_free(p);
diff --git a/src/mir_core/src/db.cpp b/src/mir_core/src/db.cpp index a680211c82..2965c72842 100644 --- a/src/mir_core/src/db.cpp +++ b/src/mir_core/src/db.cpp @@ -469,6 +469,16 @@ MIR_CORE_DLL(MEVENT) db_event_prev(MCONTACT hContact, MEVENT hDbEvent) return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->FindPrevEvent(hContact, hDbEvent); } +MIR_CORE_DLL(MEVENT) db_event_replace(MCONTACT hContact, const DBEVENTINFO *dbei) +{ + MEVENT ret = 0; + if (dbei->szId) + ret = db_event_getById(dbei->szModule, dbei->szId); + if (!ret) + ret = db_event_add(hContact, dbei); + return ret; +} + MIR_CORE_DLL(MEVENT) db_event_getById(const char *szModule, const char *szId) { return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->GetEventById(szModule, szId); diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index 5d50debe41..09e1804cc4 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -1547,3 +1547,4 @@ _Utils_CorrectFontSize@4 @1762 NONAME ?mir_base64_encode@@YGPADABVMBinBuffer@@@Z @1768 NONAME
?append@MBinBuffer@@QAEXABV1@@Z @1769 NONAME
?appendBefore@MBinBuffer@@QAEXABV1@@Z @1770 NONAME
+db_event_replace @1771
diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index f5f58713cd..9862559f69 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -1547,3 +1547,4 @@ Utils_CorrectFontSize @1762 NONAME ?mir_base64_encode@@YAPEADAEBVMBinBuffer@@@Z @1768 NONAME
?append@MBinBuffer@@QEAAXAEBV1@@Z @1769 NONAME
?appendBefore@MBinBuffer@@QEAAXAEBV1@@Z @1770 NONAME
+db_event_replace @1771
|