From ca6bffd6d1a5d38d2c5f151a2e831d517e4ccbc2 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 24 Dec 2023 17:03:50 +0300 Subject: fixes #2282 (ICQ: add message deletion support) --- protocols/ICQ-WIM/src/proto.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ protocols/ICQ-WIM/src/proto.h | 21 +++++++++++++++++---- 2 files changed, 57 insertions(+), 4 deletions(-) (limited to 'protocols') diff --git a/protocols/ICQ-WIM/src/proto.cpp b/protocols/ICQ-WIM/src/proto.cpp index b6f27ec26a..3b00ee14c5 100644 --- a/protocols/ICQ-WIM/src/proto.cpp +++ b/protocols/ICQ-WIM/src/proto.cpp @@ -45,6 +45,7 @@ CIcqProto::CIcqProto(const char *aProtoName, const wchar_t *aUserName) : m_arOwnIds(1, PtrKeySortT), m_arCache(20, &CompareCache), m_arGroups(10, NumericKeySortT), + m_arDeleteQueue(10), m_arMarkReadQueue(10, NumericKeySortT), m_evRequestsQueue(CreateEvent(nullptr, FALSE, FALSE, nullptr)), m_szOwnId(this, DB_KEY_ID), @@ -201,6 +202,44 @@ void CIcqProto::OnEventEdited(MCONTACT, MEVENT, const DBEVENTINFO &) } +///////////////////////////////////////////////////////////////////////////////////////// +// batch events deletion from the server + +void CIcqProto::BatchDeleteMsg() +{ + auto *pReq = new AsyncRapiRequest(this, "delMsgBatch"); + + JSONNode ids(JSON_ARRAY); ids.set_name("msgIds"); + + mir_cslock lck(m_csDeleteQueue); + for (auto &it : m_arDeleteQueue) { + ids.push_back(JSONNode("", _atoi64(it))); + mir_free(it); + } + + pReq->params << WCHAR_PARAM("sn", GetUserId(m_hDeleteContact)) << BOOL_PARAM("shared", true) << ids; + Push(pReq); + + m_arDeleteQueue.destroy(); + m_hDeleteContact = INVALID_CONTACT_ID; +} + +void CIcqProto::OnEventDeleted(MCONTACT hContact, MEVENT hEvent) +{ + if (m_hDeleteContact != INVALID_CONTACT_ID) + if (m_hDeleteContact != hContact) + BatchDeleteMsg(); + + DB::EventInfo dbei(hEvent, false); + if (!dbei || !dbei.szId) + return; + + mir_cslock lck(m_csDeleteQueue); + m_hDeleteContact = hContact; + m_arDeleteQueue.insert(mir_strdup(dbei.szId)); + m_impl.m_delete.Start(100); +} + ///////////////////////////////////////////////////////////////////////////////////////// void CIcqProto::OnFileRecv(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq) @@ -338,6 +377,7 @@ INT_PTR CIcqProto::SvcGotoInbox(WPARAM, LPARAM) } ///////////////////////////////////////////////////////////////////////////////////////// +// mark events read at the server void CIcqProto::SendMarkRead() { diff --git a/protocols/ICQ-WIM/src/proto.h b/protocols/ICQ-WIM/src/proto.h index b236397541..b6462bbbda 100644 --- a/protocols/ICQ-WIM/src/proto.h +++ b/protocols/ICQ-WIM/src/proto.h @@ -175,7 +175,7 @@ class CIcqProto : public PROTO friend class CIcqProto; CIcqProto &m_proto; - CTimer m_heartBeat, m_markRead; + CTimer m_heartBeat, m_markRead, m_delete; void OnHeartBeat(CTimer *) { m_proto.CheckStatus(); @@ -186,11 +186,18 @@ class CIcqProto : public PROTO pTimer->Stop(); } + void OnDelete(CTimer *pTimer) { + m_proto.BatchDeleteMsg(); + pTimer->Stop(); + } + CIcqProtoImpl(CIcqProto &pro) : m_proto(pro), - m_markRead(Miranda_GetSystemWindow(), UINT_PTR(this)), - m_heartBeat(Miranda_GetSystemWindow(), UINT_PTR(this) + 1) + m_delete(Miranda_GetSystemWindow(), UINT_PTR(this)), + m_markRead(Miranda_GetSystemWindow(), UINT_PTR(this) + 1), + m_heartBeat(Miranda_GetSystemWindow(), UINT_PTR(this) + 2) { + m_delete.OnEvent = Callback(this, &CIcqProtoImpl::OnDelete); m_markRead.OnEvent = Callback(this, &CIcqProtoImpl::OnMarkRead); m_heartBeat.OnEvent = Callback(this, &CIcqProtoImpl::OnHeartBeat); } @@ -207,7 +214,7 @@ class CIcqProto : public PROTO bool m_bOnline, m_bTerminated, m_bFirstBos, m_isMra, m_bError462; int m_iTimeShift; - + MCONTACT CheckOwnMessage(const CMStringA &reqId, const CMStringA &msgId, bool bRemove); void CheckPassword(void); void ConnectionFailed(int iReason, int iErrorCode = 0); @@ -248,6 +255,11 @@ class CIcqProto : public PROTO LIST m_arMarkReadQueue; void SendMarkRead(); + mir_cs m_csDeleteQueue; + LIST m_arDeleteQueue; + MCONTACT m_hDeleteContact = INVALID_CONTACT_ID; + void BatchDeleteMsg(); + __int64 getId(MCONTACT hContact, const char *szSetting); void setId(MCONTACT hContact, const char *szSetting, __int64 iValue); @@ -432,6 +444,7 @@ class CIcqProto : public PROTO void OnContactAdded(MCONTACT) override; bool OnContactDeleted(MCONTACT) override; MWindow OnCreateAccMgrUI(MWindow) override; + void OnEventDeleted(MCONTACT, MEVENT) override; void OnEventEdited(MCONTACT, MEVENT, const DBEVENTINFO &dbei) override; void OnMarkRead(MCONTACT, MEVENT) override; void OnModulesLoaded() override; -- cgit v1.2.3