From 04b8a61c89ef27e03ce3d9057bb98998c769a8a3 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 10 Jan 2024 20:11:38 +0300 Subject: =?UTF-8?q?fixes=20#4107=20(ICQ:=20=D0=BE=D1=87=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D0=BD=D0=BE=D0=B5=20=D0=BD=D0=B5=D0=BE=D0=BF=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=84=D1=84?= =?UTF-8?q?=D0=BB=D0=B0=D0=B9=D0=BD=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=20?= =?UTF-8?q?=D0=B2=20=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D0=B5=20=D0=BA=D0=B0?= =?UTF-8?q?=D1=80=D1=82=D0=B8=D0=BD=D0=BA=D0=BE=D0=B9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/ICQ-WIM/src/proto.h | 1 + protocols/ICQ-WIM/src/server.cpp | 69 ++++++++++++++++++++++++++++------------ 2 files changed, 50 insertions(+), 20 deletions(-) (limited to 'protocols') diff --git a/protocols/ICQ-WIM/src/proto.h b/protocols/ICQ-WIM/src/proto.h index dfb75d78a3..7de752df5b 100644 --- a/protocols/ICQ-WIM/src/proto.h +++ b/protocols/ICQ-WIM/src/proto.h @@ -243,6 +243,7 @@ class CIcqProto : public PROTO void Json2string(MCONTACT, const JSONNode&, const char *szJson, const char *szSetting, bool bIsPartial); MCONTACT ParseBuddyInfo(const JSONNode &buddy, MCONTACT hContact = INVALID_CONTACT_ID, bool bIsPartial = false); void ParseMessage(MCONTACT hContact, __int64 &lastMsgId, const JSONNode &msg, bool bCreateRead, bool bLocalTime); + void ParseMessagePart(MCONTACT hContact, const JSONNode &msg, MEVENT hOldEvent, IcqFileInfo *&pFileInfo); IcqFileInfo* RetrieveFileInfo(MCONTACT hContact, const CMStringW &wszUrl); int StatusFromPresence(const JSONNode &presence, MCONTACT hContact); void ProcessPatchVersion(MCONTACT hContact, __int64 currPatch); diff --git a/protocols/ICQ-WIM/src/server.cpp b/protocols/ICQ-WIM/src/server.cpp index 67361d82b7..ba6a41728b 100644 --- a/protocols/ICQ-WIM/src/server.cpp +++ b/protocols/ICQ-WIM/src/server.cpp @@ -451,7 +451,7 @@ MCONTACT CIcqProto::ParseBuddyInfo(const JSONNode &buddy, MCONTACT hContact, boo void CIcqProto::ParseMessage(MCONTACT hContact, __int64 &lastMsgId, const JSONNode &it, bool bCreateRead, bool bLocalTime) { - CMStringA szMsgId(it["msgId"].as_mstring()), szSender; + CMStringA szMsgId(it["msgId"].as_mstring()), szSender, szReply; __int64 msgId = _atoi64(szMsgId); if (msgId > lastMsgId) lastMsgId = msgId; @@ -533,33 +533,33 @@ void CIcqProto::ParseMessage(MCONTACT hContact, __int64 &lastMsgId, const JSONNo // check for embedded file IcqFileInfo *pFileInfo = nullptr; + const JSONNode *pForward = nullptr, *pQuote = nullptr; for (auto &jt : it["parts"]) { - if (auto &content = jt["captionedContent"]) { - CMStringW wszUrl(content["url"].as_mstring()); - if (wszUrl.IsEmpty()) - continue; - - if (hOldEvent && fileText2url(wszText)) - return; + auto szType = jt["mediaType"].as_string(); + if (szType == "forward") + pForward = &jt; + else if (szType == "quote") + pQuote = &jt; + else if (szType == "text") + ParseMessagePart(hContact, jt, hOldEvent, pFileInfo); + } - if (!CheckFile(hContact, wszUrl, pFileInfo)) - continue; + if (pForward) { + int idx = wszText.Find(L"\n\n"); + if (idx != -1) + wszText.Truncate(idx + 2); - if (jt["mediaType"].as_string() == "forward") { - int idx = wszText.Find(L"\n\n"); - if (idx != -1) - wszText.Truncate(idx + 2); + if (!pFileInfo) { + ParseMessagePart(hContact, *pForward, hOldEvent, pFileInfo); + if (pFileInfo) pFileInfo->wszDescr = wszText; - } - - CMStringW wszDescr(content["caption"].as_mstring()); - if (!wszDescr.IsEmpty()) - pFileInfo->wszDescr = wszDescr; - break; } } + if (pQuote) + szReply = pQuote->at("msgId").as_mstring(); + // message text might be a separate file link as well if (pFileInfo == nullptr && fileText2url(wszText)) { if (hOldEvent) @@ -602,6 +602,8 @@ void CIcqProto::ParseMessage(MCONTACT hContact, __int64 &lastMsgId, const JSONNo pre.dwFlags |= PRFF_READ; if (bIsOutgoing) pre.dwFlags |= PRFF_SENT; + if (!szReply.IsEmpty()) + pre.szReplyId = szReply; if (isChatRoom(hContact)) pre.szUserId = szSender; ProtoChainRecvFile(hContact, &pre); @@ -633,6 +635,8 @@ void CIcqProto::ParseMessage(MCONTACT hContact, __int64 &lastMsgId, const JSONNo dbei.szId = szMsgId; if (isChatRoom(hContact)) dbei.szUserId = szSender; + if (!szReply.IsEmpty()) + dbei.szReplyId = szReply; db_event_edit(hOldEvent, &dbei, true); } else { @@ -646,10 +650,35 @@ void CIcqProto::ParseMessage(MCONTACT hContact, __int64 &lastMsgId, const JSONNo pre.szMsgId = szMsgId; if (isChatRoom(hContact)) pre.szUserId = szSender; + if (!szReply.IsEmpty()) + pre.szReplyId = szReply; ProtoChainRecvMsg(hContact, &pre); } } +void CIcqProto::ParseMessagePart(MCONTACT hContact, const JSONNode &part, MEVENT hOldEvent, IcqFileInfo *&pFileInfo) +{ + if (pFileInfo != nullptr) + return; + + if (auto &content = part["captionedContent"]) { + CMStringW wszUrl(content["url"].as_mstring()); + if (wszUrl.IsEmpty()) + return; + + CMStringW wszText(part["text"].as_mstring()); + if (hOldEvent && fileText2url(wszText)) + return; + + if (!CheckFile(hContact, wszUrl, pFileInfo)) + return; + + CMStringW wszDescr(content["caption"].as_mstring()); + if (!wszDescr.IsEmpty()) + pFileInfo->wszDescr = wszDescr; + } +} + bool CIcqProto::RefreshRobustToken(AsyncHttpRequest *pOrigReq) { if (!m_szRToken.IsEmpty()) -- cgit v1.2.3