diff options
-rw-r--r-- | plugins/Dbx_sqlite/src/dbevents.cpp | 15 | ||||
-rw-r--r-- | protocols/Telegram/src/mt_proto.cpp | 25 | ||||
-rw-r--r-- | protocols/Telegram/src/mt_proto.h | 1 |
3 files changed, 38 insertions, 3 deletions
diff --git a/plugins/Dbx_sqlite/src/dbevents.cpp b/plugins/Dbx_sqlite/src/dbevents.cpp index fa3691a47e..bf8959c977 100644 --- a/plugins/Dbx_sqlite/src/dbevents.cpp +++ b/plugins/Dbx_sqlite/src/dbevents.cpp @@ -268,6 +268,8 @@ int CDbxSQLite::GetBlobSize(MEVENT hDbEvent) return res; } +static char g_szId[100]; + BOOL CDbxSQLite::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei) { if (hDbEvent == 0) @@ -282,7 +284,7 @@ BOOL CDbxSQLite::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei) } mir_cslock lock(m_csDbAccess); - sqlite3_stmt *stmt = InitQuery("SELECT module, timestamp, type, flags, length(data), data FROM events WHERE id = ? LIMIT 1;", qEvGet); + sqlite3_stmt *stmt = InitQuery("SELECT module, timestamp, type, flags, server_id, length(data), data FROM events WHERE id = ? LIMIT 1;", qEvGet); sqlite3_bind_int64(stmt, 1, hDbEvent); int rc = sqlite3_step(stmt); logError(rc, __FILE__, __LINE__); @@ -299,8 +301,15 @@ BOOL CDbxSQLite::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei) dbei->timestamp = sqlite3_column_int64(stmt, 1); dbei->eventType = sqlite3_column_int(stmt, 2); dbei->flags = sqlite3_column_int64(stmt, 3); + + char *pszId = (char *)sqlite3_column_text(stmt, 4); + if (mir_strlen(pszId)) { + mir_strncpy(g_szId, pszId, sizeof(g_szId)); + dbei->szId = g_szId; + } + else dbei->szId = nullptr; - int32_t cbBlob = sqlite3_column_int64(stmt, 4); + int32_t cbBlob = sqlite3_column_int64(stmt, 5); size_t bytesToCopy = cbBlob; if (dbei->cbBlob == -1) dbei->pBlob = (uint8_t*)mir_calloc(cbBlob + 2); @@ -309,7 +318,7 @@ BOOL CDbxSQLite::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei) dbei->cbBlob = cbBlob; if (bytesToCopy && dbei->pBlob) { - uint8_t *data = (uint8_t *)sqlite3_column_blob(stmt, 5); + uint8_t *data = (uint8_t *)sqlite3_column_blob(stmt, 6); if (dbei->flags & DBEF_ENCRYPTED) { dbei->flags &= ~DBEF_ENCRYPTED; diff --git a/protocols/Telegram/src/mt_proto.cpp b/protocols/Telegram/src/mt_proto.cpp index a99c91eb31..d00f84c434 100644 --- a/protocols/Telegram/src/mt_proto.cpp +++ b/protocols/Telegram/src/mt_proto.cpp @@ -32,6 +32,7 @@ CMTProto::CMTProto(const char* protoName, const wchar_t* userName) : CreateProtoService(PS_CREATEACCMGRUI, &CMTProto::SvcCreateAccMgrUI); HookProtoEvent(ME_OPT_INITIALISE, &CMTProto::OnOptionsInit); + HookProtoEvent(ME_DB_EVENT_MARKED_READ, &CMTProto::OnDbMarkedRead); // default contacts group if (m_wszDefaultGroup == NULL) @@ -87,6 +88,30 @@ void CMTProto::OnErase() DeleteDirectoryTreeW(GetProtoFolder(), false); } +int CMTProto::OnDbMarkedRead(WPARAM hContact, LPARAM hDbEvent) +{ + if (!hContact) + return 0; + + // filter out only events of my protocol + const char *szProto = Proto_GetBaseAccountName(hContact); + if (mir_strcmp(szProto, m_szModuleName)) + return 0; + + ptrA userId(getStringA(hContact, DBKEY_ID)); + if (userId) { + DBEVENTINFO dbei = {}; + db_event_get(hDbEvent, &dbei); + if (dbei.szId) { + TD::array<TD::int53> ids; + ids.push_back(_atoi64(dbei.szId)); + SendQuery(new TD::viewMessages(_atoi64(userId), 0, std::move(ids), true)); + } + } + + return 0; +} + INT_PTR CMTProto::GetCaps(int type, MCONTACT) { switch (type) { diff --git a/protocols/Telegram/src/mt_proto.h b/protocols/Telegram/src/mt_proto.h index 7aa85b722b..46439aee5f 100644 --- a/protocols/Telegram/src/mt_proto.h +++ b/protocols/Telegram/src/mt_proto.h @@ -173,6 +173,7 @@ public: // Events //////////////////////////////////////////////////////////////////////////// int __cdecl OnOptionsInit(WPARAM, LPARAM); + int __cdecl OnDbMarkedRead(WPARAM, LPARAM); // Options /////////////////////////////////////////////////////////////////////////// |