summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2025-06-06 15:18:35 +0300
committerGeorge Hazan <george.hazan@gmail.com>2025-06-06 15:36:07 +0300
commit59c69952e5a14de5e6a4e9d567aaaf0ce7685d86 (patch)
treeecb4f1a27401356fa604bac6edcf49b4cfdb43cd
parentd9a702e80233b1fd7e6d9476793bef89b9181b04 (diff)
Telegram protocol not to use db_event_edit to update reactions, because it exports a message each time
-rw-r--r--include/m_database.h1
-rw-r--r--include/m_db_int.h3
-rw-r--r--libs/win32/mir_app.libbin309246 -> 309576 bytes
-rw-r--r--libs/win32/mir_core.libbin500916 -> 501182 bytes
-rw-r--r--libs/win64/mir_app.libbin309426 -> 309766 bytes
-rw-r--r--libs/win64/mir_core.libbin506256 -> 506528 bytes
-rw-r--r--plugins/Dbx_sqlite/src/dbevents.cpp47
-rw-r--r--plugins/Dbx_sqlite/src/dbintf.h3
-rw-r--r--protocols/Telegram/src/server.cpp4
-rw-r--r--src/mir_app/src/MDatabaseCommon.cpp5
-rw-r--r--src/mir_app/src/mir_app.def1
-rw-r--r--src/mir_app/src/mir_app64.def1
-rw-r--r--src/mir_core/src/db.cpp10
-rw-r--r--src/mir_core/src/mir_core.def1
-rw-r--r--src/mir_core/src/mir_core64.def1
15 files changed, 72 insertions, 5 deletions
diff --git a/include/m_database.h b/include/m_database.h
index 52b4621107..e0a22b207b 100644
--- a/include/m_database.h
+++ b/include/m_database.h
@@ -401,6 +401,7 @@ EXTERN_C MIR_CORE_DLL(MEVENT) db_event_getById(const char *szModule, const char
// Sets a value to the JSON field in the blob
MIR_CORE_DLL(int) db_event_setJson(MEVENT hDbEvent, const char *szSetting, DBVARIANT *dbv);
+MIR_CORE_DLL(int) db_event_setJson(MEVENT hDbEvent, const char *pBlob);
// Updates the server ID associated with an event
// Returns 0 on success or a failure otherwise
diff --git a/include/m_db_int.h b/include/m_db_int.h
index 0304cc263c..f9aa88a479 100644
--- a/include/m_db_int.h
+++ b/include/m_db_int.h
@@ -132,7 +132,9 @@ interface MIR_APP_EXPORT MIDatabase
STDMETHOD_(MEVENT, FindLastEvent)(MCONTACT contactID) PURE;
STDMETHOD_(MEVENT, FindNextEvent)(MCONTACT contactID, MEVENT hDbEvent) PURE;
STDMETHOD_(MEVENT, FindPrevEvent)(MCONTACT contactID, MEVENT hDbEvent) PURE;
+
STDMETHOD_(int, SetEventJson)(MEVENT hDbEvent, const char *szSetting, DBVARIANT *dbv) PURE;
+ STDMETHOD_(int, SetEventJson)(MEVENT hDbEvent, const char *pBlob) PURE;
STDMETHOD_(BOOL, DeleteModule)(MCONTACT contactID, LPCSTR szModule) PURE;
STDMETHOD_(BOOL, EnumModuleNames)(DBMODULEENUMPROC pFunc, void *pParam) PURE;
@@ -226,6 +228,7 @@ public:
STDMETHODIMP_(BOOL) WriteContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv) override;
STDMETHODIMP_(int) SetEventJson(MEVENT hDbEvent, const char *szSetting, DBVARIANT *dbv) override;
+ STDMETHODIMP_(int) SetEventJson(MEVENT hDbEvent, const char *pBlob) override;
STDMETHODIMP_(BOOL) EnumResidentSettings(DBMODULEENUMPROC pFunc, void *pParam) override;
STDMETHODIMP_(BOOL) SetSettingResident(BOOL bIsResident, const char *pszSettingName) override;
diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib
index d7664e4e94..b9c3ffbc33 100644
--- a/libs/win32/mir_app.lib
+++ b/libs/win32/mir_app.lib
Binary files differ
diff --git a/libs/win32/mir_core.lib b/libs/win32/mir_core.lib
index 8ef33d6630..9cdcd20f15 100644
--- a/libs/win32/mir_core.lib
+++ b/libs/win32/mir_core.lib
Binary files differ
diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib
index 3ba5c5399c..ea8fcb1d86 100644
--- a/libs/win64/mir_app.lib
+++ b/libs/win64/mir_app.lib
Binary files differ
diff --git a/libs/win64/mir_core.lib b/libs/win64/mir_core.lib
index 0273f82db9..87b0a95ebe 100644
--- a/libs/win64/mir_core.lib
+++ b/libs/win64/mir_core.lib
Binary files differ
diff --git a/plugins/Dbx_sqlite/src/dbevents.cpp b/plugins/Dbx_sqlite/src/dbevents.cpp
index 814e6428c6..e3f027afa3 100644
--- a/plugins/Dbx_sqlite/src/dbevents.cpp
+++ b/plugins/Dbx_sqlite/src/dbevents.cpp
@@ -330,6 +330,51 @@ BOOL CDbxSQLite::EditEvent(MEVENT hDbEvent, const DBEVENTINFO *dbei)
/////////////////////////////////////////////////////////////////////////////////////////
+int CDbxSQLite::SetEventJson(MEVENT hDbEvent, const char *pBlob)
+{
+ size_t cbBlob = mir_strlen(pBlob);
+ int flags = DBEF_JSON;
+
+ mir_ptr<char> pCryptBlob;
+ if (m_bEncrypted) {
+ if (pBlob) {
+ size_t len;
+ char *pResult = (char *)m_crypto->encodeBuffer(pBlob, cbBlob, &len);
+ if (pResult != nullptr) {
+ pBlob = pCryptBlob = pResult;
+ cbBlob = len;
+ flags |= DBEF_ENCRYPTED;
+ }
+ }
+ else flags |= DBEF_ENCRYPTED;
+ }
+
+ {
+ mir_cslock lock(m_csDbAccess);
+ sqlite3_stmt *stmt = InitQuery("UPDATE events SET data=?, flags=flags | ? WHERE id = ?;", qEvSetJson2);
+ sqlite3_bind_text(stmt, 1, pBlob, (int)cbBlob, nullptr);
+ sqlite3_bind_int64(stmt, 2, flags);
+ sqlite3_bind_int64(stmt, 3, hDbEvent);
+ int rc = sqlite3_step(stmt);
+ logError(rc, __FILE__, __LINE__);
+ sqlite3_reset(stmt);
+ }
+
+ DBFlush();
+
+ if (m_safetyMode) {
+ MCONTACT hContact = GetEventContact(hDbEvent);
+ if (auto *cc = m_cache->GetCachedContact(hContact))
+ if (cc->IsSub())
+ hContact = cc->parentID;
+
+ NotifyEventHooks(g_hevEventSetJson, hContact, hDbEvent);
+ }
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
static void str2json(CMStringA &str)
{
str.Replace("\\", "\\\\");
@@ -337,7 +382,7 @@ static void str2json(CMStringA &str)
int CDbxSQLite::SetEventJson(MEVENT hDbEvent, const char *szSetting, DBVARIANT *dbv)
{
- if (hDbEvent == 0)
+ if (!hDbEvent || !dbv)
return 1;
CMStringA tmp(FORMAT, "$.%s", szSetting);
diff --git a/plugins/Dbx_sqlite/src/dbintf.h b/plugins/Dbx_sqlite/src/dbintf.h
index e14b5dbce3..15644ab959 100644
--- a/plugins/Dbx_sqlite/src/dbintf.h
+++ b/plugins/Dbx_sqlite/src/dbintf.h
@@ -82,7 +82,7 @@ class CDbxSQLite : public MDatabaseCommon, public MIDatabaseChecker, public MZer
void UninitEvents();
CQuery qEvAdd, qEvDel, qEvEdit1, qEvEdit2, qEvBlobSize, qEvGet, qEvGetFlags, qEvSetFlags, qEvGetContact, qEvGetContact2;
CQuery qEvFindFirst, qEvFindNext, qEvFindLast, qEvFindPrev, qEvFindUnread, qEvAddSrt, qEvDelSrt, qEvDelSrt2, qEvMetaSplit, qEvMetaMerge;
- CQuery qEvGetById, qEvUpdateId, qEvSetJson;
+ CQuery qEvGetById, qEvUpdateId, qEvSetJson, qEvSetJson2;
int AddEventSrt(MEVENT, MCONTACT, int64_t ts);
int DeleteEventMain(MEVENT);
int DeleteEventSrt(MCONTACT, int64_t ts);
@@ -119,6 +119,7 @@ public:
STDMETHODIMP_(BOOL) DeleteEvent(MEVENT hDbEvent) override;
STDMETHODIMP_(BOOL) EditEvent(MEVENT hDbEvent, const DBEVENTINFO *dbe) override;
STDMETHODIMP_(int) SetEventJson(MEVENT hDbEvent, const char *szSetting, DBVARIANT *dbv) override;
+ STDMETHODIMP_(int) SetEventJson(MEVENT hDbEvent, const char *pBlob) override;
STDMETHODIMP_(int) GetBlobSize(MEVENT hDbEvent) override;
STDMETHODIMP_(BOOL) GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbe) override;
STDMETHODIMP_(BOOL) MarkEventRead(MCONTACT contactID, MEVENT hDbEvent) override;
diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp
index fc7840492d..2d785301ac 100644
--- a/protocols/Telegram/src/server.cpp
+++ b/protocols/Telegram/src/server.cpp
@@ -1095,8 +1095,8 @@ void CTelegramProto::ProcessMessageReactions(TD::updateMessageInteractionInfo *p
json << reactions;
dbei.flushJson();
-
- db_event_edit(dbei.getEvent(), &dbei, true);
+
+ db_event_setJson(dbei.getEvent(), dbei.pBlob);
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/mir_app/src/MDatabaseCommon.cpp b/src/mir_app/src/MDatabaseCommon.cpp
index 2d4d774455..c59d832629 100644
--- a/src/mir_app/src/MDatabaseCommon.cpp
+++ b/src/mir_app/src/MDatabaseCommon.cpp
@@ -553,6 +553,11 @@ STDMETHODIMP_(int) MDatabaseCommon::SetEventJson(MEVENT, const char *, DBVARIANT
return 1;
}
+STDMETHODIMP_(int) MDatabaseCommon::SetEventJson(MEVENT, const char *)
+{
+ return 1;
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
// Resident settings
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def
index ef8f3858d5..d5916b76fa 100644
--- a/src/mir_app/src/mir_app.def
+++ b/src/mir_app/src/mir_app.def
@@ -1019,3 +1019,4 @@ Proto_CanDeleteHistory @1118 NONAME
?iHideTime@Clist@@3V?$CMOption@G@@A @1152 NONAME
?iAlpha@Clist@@3V?$CMOption@E@@A @1153 NONAME
?iAutoAlpha@Clist@@3V?$CMOption@E@@A @1154 NONAME
+?SetEventJson@MDatabaseCommon@@UAGHIPBD@Z @1155 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def
index f69bb6e58d..8682876159 100644
--- a/src/mir_app/src/mir_app64.def
+++ b/src/mir_app/src/mir_app64.def
@@ -1019,3 +1019,4 @@ Proto_CanDeleteHistory @1118 NONAME
?iHideTime@Clist@@3V?$CMOption@G@@A @1152 NONAME
?iAlpha@Clist@@3V?$CMOption@E@@A @1153 NONAME
?iAutoAlpha@Clist@@3V?$CMOption@E@@A @1154 NONAME
+?SetEventJson@MDatabaseCommon@@UEAAHIPEBD@Z @1155 NONAME
diff --git a/src/mir_core/src/db.cpp b/src/mir_core/src/db.cpp
index e2b67aa4b5..5a6811ab82 100644
--- a/src/mir_core/src/db.cpp
+++ b/src/mir_core/src/db.cpp
@@ -531,6 +531,14 @@ MIR_CORE_DLL(MEVENT) db_event_getById(const char *szModule, const char *szId)
return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->GetEventById(szModule, szId);
}
+MIR_CORE_DLL(int) db_event_setJson(MEVENT hDbEvent, const char *pBlob)
+{
+ if (g_pCurrDb == nullptr)
+ return 1;
+
+ return g_pCurrDb->SetEventJson(hDbEvent, pBlob);
+}
+
MIR_CORE_DLL(int) db_event_setJson(MEVENT hDbEvent, const char *szSetting, DBVARIANT *dbv)
{
if (g_pCurrDb == nullptr)
@@ -565,7 +573,7 @@ MIR_CORE_DLL(int) db_event_setJson(MEVENT hDbEvent, const char *szSetting, DBVAR
}
dbei.flushJson();
- return db_event_edit(hDbEvent, &dbei);
+ return g_pCurrDb->SetEventJson(hDbEvent, dbei.pBlob);
}
MIR_CORE_DLL(int) db_event_updateId(MEVENT hDbEvent, const char *szId)
diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def
index 4061511fb0..2c91438bee 100644
--- a/src/mir_core/src/mir_core.def
+++ b/src/mir_core/src/mir_core.def
@@ -1588,3 +1588,4 @@ _db_event_delivered@8 @1806 NONAME
??6MBinBuffer@@QAEAAV0@I@Z @1813 NONAME
??6MBinBuffer@@QAEAAV0@_K@Z @1814 NONAME
_Utils_IsoToUnixTime@4 @1815 NONAME
+?db_event_setJson@@YGHIPBD@Z @1816 NONAME
diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def
index 16e49f90b4..2f83d9c0b0 100644
--- a/src/mir_core/src/mir_core64.def
+++ b/src/mir_core/src/mir_core64.def
@@ -1588,3 +1588,4 @@ db_event_delivered @1806 NONAME
??6MBinBuffer@@QEAAAEAV0@I@Z @1813 NONAME
??6MBinBuffer@@QEAAAEAV0@_K@Z @1814 NONAME
Utils_IsoToUnixTime @1815 NONAME
+?db_event_setJson@@YAHIPEBD@Z @1816 NONAME