From 9417dafded645981c314e73884c2dcca6a6a27ed Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 9 Mar 2023 19:07:04 +0300 Subject: added event for event deletion --- include/m_database.h | 2 +- include/m_protoint.h | 3 +++ libs/win32/mir_app.lib | Bin 237994 -> 238324 bytes libs/win64/mir_app.lib | Bin 234944 -> 235280 bytes protocols/Discord/src/dispatch.cpp | 2 +- protocols/VKontakte/src/vk_history.cpp | 2 +- src/mir_app/src/mir_app.def | 1 + src/mir_app/src/mir_app64.def | 1 + src/mir_app/src/proto_interface.cpp | 3 +++ src/mir_core/src/db.cpp | 13 +++++++++++-- 10 files changed, 22 insertions(+), 5 deletions(-) diff --git a/include/m_database.h b/include/m_database.h index c8921e59f0..14c0c9fa1b 100644 --- a/include/m_database.h +++ b/include/m_database.h @@ -289,7 +289,7 @@ EXTERN_C MIR_CORE_DLL(int) db_event_count(MCONTACT hContact); // Returns 0 on success, or nonzero if hDbEvent was invalid // Triggers a db/event/deleted event just *before* the event is deleted -EXTERN_C MIR_CORE_DLL(int) db_event_delete(MEVENT hDbEvent); +EXTERN_C MIR_CORE_DLL(int) db_event_delete(MEVENT hDbEvent, bool bFromServer = false); // Edits an event in the database // Returns 0 on success, or nonzero on error diff --git a/include/m_protoint.h b/include/m_protoint.h index 55ff3a5949..609bbfbd92 100644 --- a/include/m_protoint.h +++ b/include/m_protoint.h @@ -266,6 +266,9 @@ public: // called when the Account Manager needs to draw short account's options virtual MWindow OnCreateAccMgrUI(MWindow hwndParent); + // called when an event is altered in database + virtual void OnEventDeleted(MCONTACT, MEVENT); + // called when an event is altered in database virtual void OnEventEdited(MCONTACT, MEVENT); diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib index 1f82b6f4bc..e2966e62fd 100644 Binary files a/libs/win32/mir_app.lib and b/libs/win32/mir_app.lib differ diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib index a239c67c8e..07df738f4e 100644 Binary files a/libs/win64/mir_app.lib and b/libs/win64/mir_app.lib differ diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index d0619f3c02..149d0339a0 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -457,7 +457,7 @@ void CDiscordProto::OnCommandMessageDelete(const JSONNode &pRoot) if (!msgid.IsEmpty()) { MEVENT hEvent = db_event_getById(m_szModuleName, msgid); if (hEvent) - db_event_delete(hEvent); + db_event_delete(hEvent, true); } } diff --git a/protocols/VKontakte/src/vk_history.cpp b/protocols/VKontakte/src/vk_history.cpp index 00457abd62..559c31c98d 100644 --- a/protocols/VKontakte/src/vk_history.cpp +++ b/protocols/VKontakte/src/vk_history.cpp @@ -303,7 +303,7 @@ void CVkProto::OnReceiveHistoryMessages(NETLIBHTTPREQUEST *reply, AsyncHttpReque MEVENT hDbEvent = db_event_getById(m_szModuleName, strcat(szMid, "_")); if (hDbEvent) - db_event_delete(hDbEvent); + db_event_delete(hDbEvent, true); if (isRead && isOut && datetime > tLastReadMessageTime) tLastReadMessageTime = datetime; diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 765a1f46b0..022ce9a37b 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -822,3 +822,4 @@ Srmm_CreateHotkey @886 NONAME ?OnCreateAccMgrUI@PROTO_INTERFACE@@UAEPAUHWND__@@PAU2@@Z @937 NONAME ?getMStringU@PROTO_INTERFACE@@QAE?AV?$CMStringT@DV?$ChTraitsCRT@D@@@@IPBD0@Z @938 NONAME ?getMStringU@PROTO_INTERFACE@@QAE?AV?$CMStringT@DV?$ChTraitsCRT@D@@@@PBD0@Z @939 NONAME +?OnEventDeleted@PROTO_INTERFACE@@UAEXII@Z @940 NONAME diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 1431875262..196c8cba39 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -822,3 +822,4 @@ Srmm_CreateHotkey @886 NONAME ?OnCreateAccMgrUI@PROTO_INTERFACE@@UEAAPEAUHWND__@@PEAU2@@Z @937 NONAME ?getMStringU@PROTO_INTERFACE@@QEAA?AV?$CMStringT@DV?$ChTraitsCRT@D@@@@IPEBD0@Z @938 NONAME ?getMStringU@PROTO_INTERFACE@@QEAA?AV?$CMStringT@DV?$ChTraitsCRT@D@@@@PEBD0@Z @939 NONAME +?OnEventDeleted@PROTO_INTERFACE@@UEAAXII@Z @940 NONAME diff --git a/src/mir_app/src/proto_interface.cpp b/src/mir_app/src/proto_interface.cpp index d1f8317c2d..a1b005d16b 100644 --- a/src/mir_app/src/proto_interface.cpp +++ b/src/mir_app/src/proto_interface.cpp @@ -79,6 +79,9 @@ MWindow PROTO_INTERFACE::OnCreateAccMgrUI(MWindow) return nullptr; // error } +void PROTO_INTERFACE::OnEventDeleted(MCONTACT, MEVENT) +{} + void PROTO_INTERFACE::OnEventEdited(MCONTACT, MEVENT) {} diff --git a/src/mir_core/src/db.cpp b/src/mir_core/src/db.cpp index 5f77f45774..3c92e965c2 100644 --- a/src/mir_core/src/db.cpp +++ b/src/mir_core/src/db.cpp @@ -412,9 +412,18 @@ MIR_CORE_DLL(int) db_event_count(MCONTACT hContact) return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->GetEventCount(hContact); } -MIR_CORE_DLL(int) db_event_delete(MEVENT hDbEvent) +MIR_CORE_DLL(int) db_event_delete(MEVENT hDbEvent, bool bFromServer) { - return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->DeleteEvent(hDbEvent); + if (g_pCurrDb == nullptr) + return 0; + + if (!bFromServer) { + MCONTACT hContact = g_pCurrDb->GetEventContact(hDbEvent); + if (auto *ppro = Proto_GetInstance(hContact)) + ppro->OnEventDeleted(hContact, hDbEvent); + } + + return g_pCurrDb->DeleteEvent(hDbEvent); } MIR_CORE_DLL(int) db_event_edit(MCONTACT hContact, MEVENT hDbEvent, const DBEVENTINFO *dbei) -- cgit v1.2.3