diff options
author | George Hazan <ghazan@miranda.im> | 2023-03-09 19:12:55 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2023-03-09 19:12:55 +0300 |
commit | 6c1480116ccabd92de7544179126478f4b243353 (patch) | |
tree | 92248c149ee27a0812f2d7dacd816b63ba6272af /protocols/Telegram | |
parent | 9417dafded645981c314e73884c2dcca6a6a27ed (diff) |
for #3395 (Telegram: single message deletion)
Diffstat (limited to 'protocols/Telegram')
-rw-r--r-- | protocols/Telegram/src/proto.cpp | 57 | ||||
-rw-r--r-- | protocols/Telegram/src/proto.h | 18 | ||||
-rw-r--r-- | protocols/Telegram/src/server.cpp | 12 |
3 files changed, 68 insertions, 19 deletions
diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp index dcf61279c1..3ad822dc15 100644 --- a/protocols/Telegram/src/proto.cpp +++ b/protocols/Telegram/src/proto.cpp @@ -171,28 +171,55 @@ void CTelegramProto::OnErase() DeleteDirectoryTreeW(GetProtoFolder(), false); } +void CTelegramProto::OnEventDeleted(MCONTACT hContact, MEVENT hDbEvent) +{ + if (!hContact) + return; + + ptrA userId(getStringA(hContact, DBKEY_ID)); + if (!userId) + return; + + DBEVENTINFO dbei = {}; + db_event_get(hDbEvent, &dbei); + if (dbei.szId) { + mir_cslock lck(m_csDeleteMsg); + if (m_deleteMsgContact) { + if (m_deleteMsgContact != hContact) + SendDeleteMsg(); + + m_impl.m_deleteMsg.Stop(); + } + + m_deleteMsgContact = hContact; + m_deleteIds.push_back(_atoi64(dbei.szId)); + m_impl.m_deleteMsg.Start(500); + } +} + void CTelegramProto::OnMarkRead(MCONTACT hContact, MEVENT hDbEvent) { if (!hContact) return; ptrA userId(getStringA(hContact, DBKEY_ID)); - if (userId) { - DBEVENTINFO dbei = {}; - db_event_get(hDbEvent, &dbei); - if (dbei.szId) { - mir_cslock lck(m_csMarkRead); - if (m_markContact) { - if (m_markContact != hContact) - SendMarkRead(); - - m_impl.m_markRead.Stop(); - } - - m_markContact = hContact; - m_markIds.push_back(_atoi64(dbei.szId)); - m_impl.m_markRead.Start(500); + if (!userId) + return; + + DBEVENTINFO dbei = {}; + db_event_get(hDbEvent, &dbei); + if (dbei.szId) { + mir_cslock lck(m_csMarkRead); + if (m_markContact) { + if (m_markContact != hContact) + SendMarkRead(); + + m_impl.m_markRead.Stop(); } + + m_markContact = hContact; + m_markIds.push_back(_atoi64(dbei.szId)); + m_impl.m_markRead.Start(500); } } diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index d0cdd764c2..c80477e2cb 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -124,11 +124,15 @@ class CTelegramProto : public PROTO<CTelegramProto> friend class CTelegramProto; CTelegramProto &m_proto; - CTimer m_keepAlive, m_markRead; + CTimer m_keepAlive, m_markRead, m_deleteMsg; void OnKeepAlive(CTimer *) { m_proto.SendKeepAlive(); } + void OnDeleteMsg(CTimer *) + { m_proto.SendDeleteMsg(); + } + void OnMarkRead(CTimer *) { m_proto.SendMarkRead(); } @@ -136,9 +140,11 @@ class CTelegramProto : public PROTO<CTelegramProto> CProtoImpl(CTelegramProto &pro) : m_proto(pro), m_markRead(Miranda_GetSystemWindow(), UINT_PTR(this)), - m_keepAlive(Miranda_GetSystemWindow(), UINT_PTR(this)+1) + m_keepAlive(Miranda_GetSystemWindow(), UINT_PTR(this)+1), + m_deleteMsg(Miranda_GetSystemWindow(), UINT_PTR(this)+2) { m_markRead.OnEvent = Callback(this, &CProtoImpl::OnMarkRead); + m_deleteMsg.OnEvent = Callback(this, &CProtoImpl::OnDeleteMsg); m_keepAlive.OnEvent = Callback(this, &CProtoImpl::OnKeepAlive); } } m_impl; @@ -154,6 +160,10 @@ class CTelegramProto : public PROTO<CTelegramProto> MCONTACT m_markContact = 0; TD::array<TD::int53> m_markIds; + mir_cs m_csDeleteMsg; + MCONTACT m_deleteMsgContact = 0; + TD::array<TD::int53> m_deleteIds; + bool m_bAuthorized, m_bTerminated, m_bUnregister = false, m_bSmileyAdd = false; int32_t m_iClientId, m_iMsgId; int64_t m_iQueryId; @@ -181,6 +191,7 @@ class CTelegramProto : public PROTO<CTelegramProto> void ProcessResponse(td::ClientManager::Response); void SendKeepAlive(void); + void SendDeleteMsg(void); void SendMarkRead(void); void SendQuery(TD::Function *pFunc, TG_QUERY_HANDLER pHandler = nullptr); void SendQuery(TD::Function *pFunc, TG_QUERY_HANDLER_FULL pHandler, void *pUserInfo); @@ -270,6 +281,7 @@ public: void OnBuildProtoMenu() override; void OnContactDeleted(MCONTACT hContact) override; MWindow OnCreateAccMgrUI(MWindow hwndParent) override; + void OnEventDeleted(MCONTACT, MEVENT) override; void OnMarkRead(MCONTACT, MEVENT) override; void OnModulesLoaded() override; void OnShutdown() override; @@ -304,4 +316,4 @@ public: void __cdecl ServerThread(void *); }; -typedef CProtoDlgBase<CTelegramProto> CTelegramDlgBase;
\ No newline at end of file +typedef CProtoDlgBase<CTelegramProto> CTelegramDlgBase; diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index 8611c6f625..0412b0ed0f 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -96,6 +96,16 @@ void CTelegramProto::SendKeepAlive() }
}
+void CTelegramProto::SendDeleteMsg()
+{
+ m_impl.m_deleteMsg.Stop();
+
+ mir_cslock lck(m_csDeleteMsg);
+ int64_t userId = _atoi64(getMStringA(m_deleteMsgContact, DBKEY_ID));
+ SendQuery(new TD::deleteMessages(userId, std::move(m_deleteIds), true));
+ m_markContact = 0;
+}
+
void CTelegramProto::SendMarkRead()
{
m_impl.m_markRead.Stop();
@@ -402,7 +412,7 @@ void CTelegramProto::ProcessDeleteMessage(TD::updateDeleteMessages *pObj) char id[100];
_i64toa(it, id, 10);
if (MEVENT hEvent = db_event_getById(m_szModuleName, id))
- db_event_delete(hEvent);
+ db_event_delete(hEvent, true);
}
}
|