diff options
author | George Hazan <george.hazan@gmail.com> | 2025-06-06 15:18:35 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2025-06-06 15:36:07 +0300 |
commit | 59c69952e5a14de5e6a4e9d567aaaf0ce7685d86 (patch) | |
tree | ecb4f1a27401356fa604bac6edcf49b4cfdb43cd /plugins/Dbx_sqlite/src | |
parent | d9a702e80233b1fd7e6d9476793bef89b9181b04 (diff) |
Telegram protocol not to use db_event_edit to update reactions, because it exports a message each time
Diffstat (limited to 'plugins/Dbx_sqlite/src')
-rw-r--r-- | plugins/Dbx_sqlite/src/dbevents.cpp | 47 | ||||
-rw-r--r-- | plugins/Dbx_sqlite/src/dbintf.h | 3 |
2 files changed, 48 insertions, 2 deletions
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;
|