Skip to content

Commit

Permalink
fixes #4141 (ICQ: при удалении своего сообщения нужно сразу же запраш…
Browse files Browse the repository at this point in the history
…ивать новые события у сервера)
  • Loading branch information
georgehazan committed Feb 5, 2024
1 parent 89a1de0 commit 92937e4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
6 changes: 6 additions & 0 deletions protocols/ICQ-WIM/src/poll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,13 @@ void CIcqProto::ProcessHistData(const JSONNode &ev)
setId(hContact, DB_KEY_LASTMSGID, lastMsgId);
}

if (pUser && pUser->m_bSkipPatch) {
pUser->m_bSkipPatch = false;
goto LBL_SkipPatch;
}

ProcessPatchVersion(hContact, _wtoi64(ev["patchVersion"].as_mstring()));
LBL_SkipPatch:

__int64 srvLastId = _wtoi64(ev["lastMsgId"].as_mstring());

Expand Down
18 changes: 15 additions & 3 deletions protocols/ICQ-WIM/src/proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,19 @@ void CIcqProto::OnEventEdited(MCONTACT, MEVENT, const DBEVENTINFO &)
/////////////////////////////////////////////////////////////////////////////////////////
// batch events deletion from the server

void CIcqProto::BatchDeleteMsg()
void CIcqProto::OnBatchDeleteMsg(MHttpResponse *pReply, AsyncHttpRequest *pReq)
{
auto *pReq = new AsyncRapiRequest(this, "delMsgBatch");
RobustReply root(pReply);
if (root.error() != 20000)
return;

if (auto *pUser = FindUser(GetUserId(pReq->hContact)))
pUser->m_bSkipPatch = true;
RetrievePatches(pReq->hContact);
}

void CIcqProto::BatchDeleteMsg()
{
JSONNode ids(JSON_ARRAY); ids.set_name("msgIds");

mir_cslock lck(m_csDeleteQueue);
Expand All @@ -221,6 +230,8 @@ void CIcqProto::BatchDeleteMsg()
mir_free(it);
}

auto *pReq = new AsyncRapiRequest(this, "delMsgBatch", &CIcqProto::OnBatchDeleteMsg);
pReq->hContact = m_hDeleteContact;
pReq->params << WCHAR_PARAM("sn", GetUserId(m_hDeleteContact)) << BOOL_PARAM("silent", true) << BOOL_PARAM("shared", m_bRemoveForAll) << ids;
Push(pReq);

Expand All @@ -230,7 +241,8 @@ void CIcqProto::BatchDeleteMsg()

void CIcqProto::OnEventDeleted(MCONTACT hContact, MEVENT hEvent, int flags)
{
if (!(flags & CDF_FROM_SERVER))
// the command arrived from the server, don't send it back then
if (flags & CDF_FROM_SERVER)
return;

if (m_hDeleteContact != INVALID_CONTACT_ID)
Expand Down
4 changes: 3 additions & 1 deletion protocols/ICQ-WIM/src/proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct IcqUser : public MZeroedObject

CMStringW m_aimid;
MCONTACT m_hContact;
bool m_bInList, m_bGotCaps, m_bWasOnline;
bool m_bInList, m_bGotCaps, m_bWasOnline, m_bSkipPatch;
__int64 m_iProcessedMsgId;
int m_iApparentMode;
time_t m_timer1, m_timer2;
Expand Down Expand Up @@ -245,6 +245,7 @@ class CIcqProto : public PROTO<CIcqProto>
void ParseMessage(MCONTACT hContact, __int64 &lastMsgId, const JSONNode &msg, bool bCreateRead, bool bLocalTime);
void ParseMessagePart(MCONTACT hContact, const JSONNode &msg, IcqFileInfo *&pFileInfo);
IcqFileInfo* RetrieveFileInfo(MCONTACT hContact, const CMStringW &wszUrl);
void RetrievePatches(MCONTACT hContact);
int StatusFromPresence(const JSONNode &presence, MCONTACT hContact);
void ProcessPatchVersion(MCONTACT hContact, __int64 currPatch);
void ProcessStatus(IcqUser *pUser, int iStatus);
Expand All @@ -266,6 +267,7 @@ class CIcqProto : public PROTO<CIcqProto>

void OnAddBuddy(MHttpResponse *pReply, AsyncHttpRequest *pReq);
void OnAddClient(MHttpResponse *pReply, AsyncHttpRequest *pReq);
void OnBatchDeleteMsg(MHttpResponse *pReply, AsyncHttpRequest *pReq);
void OnCheckMraAuth(MHttpResponse *pReply, AsyncHttpRequest *pReq);
void OnCheckMraAuthFinal(MHttpResponse *pReply, AsyncHttpRequest *pReq);
void OnCheckMrimLogin(MHttpResponse *pReply, AsyncHttpRequest *pReq);
Expand Down
32 changes: 29 additions & 3 deletions protocols/ICQ-WIM/src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,15 +822,26 @@ void CIcqProto::OnGetPatches(MHttpResponse *pReply, AsyncHttpRequest *pReq)
for (auto &it : results["patch"]) {
std::string type = it["type"].as_string();
__int64 msgId = _wtoi64(it["msgId"].as_mstring());
if (type == "update")
if (type == "update" || type == "modify")
events[msgId] = true;
else
events[msgId] = false;
}

for (auto &it : events) {
if (it.second)
RetrieveHistoryChunk(pReq->hContact, it.first, it.first-1, 1);
if (it.second) {
bool bFound = false;

for (auto &msg: results["messages"])
if (_wtoi64(msg["msgId"].as_mstring()) == it.first) {
bFound = true;
__int64 lastMsgId;
ParseMessage(pReq->hContact, lastMsgId, msg, true, false);
}

if (!bFound)
RetrieveHistoryChunk(pReq->hContact, it.first, it.first - 1, 1);
}
else {
char msgId[100];
_i64toa(it.first, msgId, 10);
Expand Down Expand Up @@ -858,6 +869,21 @@ void CIcqProto::ProcessPatchVersion(MCONTACT hContact, __int64 currPatch)
Push(pReq);
}

void CIcqProto::RetrievePatches(MCONTACT hContact)
{
__int64 oldPatch(getId(hContact, DB_KEY_PATCHVER));
if (!oldPatch)
oldPatch = 1;

auto *pReq = new AsyncRapiRequest(this, "getHistory", &CIcqProto::OnGetPatches);
#ifndef _DEBUG
pReq->flags |= NLHRF_NODUMPSEND;
#endif
pReq->hContact = hContact;
pReq->params << WCHAR_PARAM("sn", GetUserId(hContact)) << INT_PARAM("fromMsgId", -1) << INT_PARAM("count", -1) << SINT64_PARAM("patchVersion", oldPatch);
Push(pReq);
}

/////////////////////////////////////////////////////////////////////////////////////////

void CIcqProto::OnGetUserHistory(MHttpResponse *pReply, AsyncHttpRequest *pReq)
Expand Down

0 comments on commit 92937e4

Please sign in to comment.