diff options
author | George Hazan <ghazan@miranda.im> | 2023-01-11 12:05:57 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2023-01-11 12:05:57 +0300 |
commit | 80879265e20ec0abd7384c20b670d9385b2e8f6a (patch) | |
tree | 4b1016695f49a351306d72ce0803ed0dca55333b /protocols/Telegram | |
parent | 9ab83c6bb239d88e54ae1ce7a8af49432543443a (diff) |
Telegram: mark read sending optimization
Diffstat (limited to 'protocols/Telegram')
-rw-r--r-- | protocols/Telegram/src/mt_proto.cpp | 14 | ||||
-rw-r--r-- | protocols/Telegram/src/mt_proto.h | 18 | ||||
-rw-r--r-- | protocols/Telegram/src/server.cpp | 12 |
3 files changed, 37 insertions, 7 deletions
diff --git a/protocols/Telegram/src/mt_proto.cpp b/protocols/Telegram/src/mt_proto.cpp index 87e7f5c7d7..a58c3ded1d 100644 --- a/protocols/Telegram/src/mt_proto.cpp +++ b/protocols/Telegram/src/mt_proto.cpp @@ -110,9 +110,17 @@ int CMTProto::OnDbMarkedRead(WPARAM hContact, LPARAM hDbEvent) 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)); + 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/mt_proto.h b/protocols/Telegram/src/mt_proto.h index 99a1160b97..8bc5cc3c66 100644 --- a/protocols/Telegram/src/mt_proto.h +++ b/protocols/Telegram/src/mt_proto.h @@ -80,16 +80,21 @@ class CMTProto : public PROTO<CMTProto> friend class CMTProto; CMTProto &m_proto; - CTimer m_keepAlive; + CTimer m_keepAlive, m_markRead; void OnKeepAlive(CTimer *) - { - m_proto.SendKeepAlive(); + { m_proto.SendKeepAlive(); + } + + void OnMarkRead(CTimer *) + { m_proto.SendMarkRead(); } CProtoImpl(CMTProto &pro) : m_proto(pro), - m_keepAlive(Miranda_GetSystemWindow(), UINT_PTR(this)) + m_markRead(Miranda_GetSystemWindow(), UINT_PTR(this)), + m_keepAlive(Miranda_GetSystemWindow(), UINT_PTR(this)+1) { + m_markRead.OnEvent = Callback(this, &CProtoImpl::OnMarkRead); m_keepAlive.OnEvent = Callback(this, &CProtoImpl::OnKeepAlive); } } m_impl; @@ -101,6 +106,10 @@ class CMTProto : public PROTO<CMTProto> std::unique_ptr<td::ClientManager> m_pClientMmanager; TD::object_ptr<TD::AuthorizationState> pAuthState; + mir_cs m_csMarkRead; + MCONTACT m_markContact = 0; + TD::array<TD::int53> m_markIds; + bool m_bAuthorized, m_bTerminated, m_bUnregister = false; int32_t m_iClientId, m_iMsgId; uint64_t m_iQueryId; @@ -123,6 +132,7 @@ class CMTProto : public PROTO<CMTProto> void ProcessResponse(td::ClientManager::Response); void SendKeepAlive(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); int SendTextMessage(uint64_t chatId, const char *pszMessage); diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index fbb6c53f3d..24ad055fff 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -88,6 +88,16 @@ void CMTProto::SendKeepAlive() } } +void CMTProto::SendMarkRead() +{ + m_impl.m_markRead.Stop(); + + mir_cslock lck(m_csMarkRead); + uint64_t userId = _atoi64(getMStringA(m_markContact, DBKEY_ID)); + SendQuery(new TD::viewMessages(userId, 0, std::move(m_markIds), true)); + m_markContact = 0; +} + /////////////////////////////////////////////////////////////////////////////// void CMTProto::ProcessResponse(td::ClientManager::Response response) @@ -146,6 +156,8 @@ void CMTProto::ProcessResponse(td::ClientManager::Response response) } } +///////////////////////////////////////////////////////////////////////////////////////// + void CMTProto::OnSendMessage(td::ClientManager::Response &response, void *pUserInfo) { if (!response.object) |