diff options
author | George Hazan <ghazan@miranda.im> | 2021-04-25 20:22:00 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2021-04-25 20:22:00 +0300 |
commit | 6e2c04c2c7ea221afb58e71f6e99f2d0ed1c7781 (patch) | |
tree | db5fb61a368684b9656087096bb4ebc14251ffa4 /protocols/WhatsAppWeb/src | |
parent | 7ae04023cd92e37c3d3a7d8752dc5e76818ca8d7 (diff) |
suddenly: major crutch to handle WhatsApp groupchats history
Diffstat (limited to 'protocols/WhatsAppWeb/src')
-rw-r--r-- | protocols/WhatsAppWeb/src/chats.cpp | 16 | ||||
-rw-r--r-- | protocols/WhatsAppWeb/src/proto.h | 10 | ||||
-rw-r--r-- | protocols/WhatsAppWeb/src/server.cpp | 29 |
3 files changed, 46 insertions, 9 deletions
diff --git a/protocols/WhatsAppWeb/src/chats.cpp b/protocols/WhatsAppWeb/src/chats.cpp index f674dc3f5c..402fc019ee 100644 --- a/protocols/WhatsAppWeb/src/chats.cpp +++ b/protocols/WhatsAppWeb/src/chats.cpp @@ -68,6 +68,22 @@ void WhatsAppProto::OnGetChatInfo(const JSONNode &root, void *param) Chat_Event(&gce); } + if (pChatUser->arHistory.getCount()) { + for (auto &it : pChatUser->arHistory) { + CMStringW jid(it->jid), text(Utf2T(it->text)); + + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; + gce.pszID.w = pChatUser->si->ptszID; + gce.dwFlags = GCEF_ADDTOLOG; + gce.pszUID.w = jid; + gce.pszText.w = text; + gce.time = it->timestamp; + gce.bIsMe = (it->jid == m_szJid); + Chat_Event(&gce); + } + pChatUser->arHistory.destroy(); + } + CMStringW wszSubject(root["subject"].as_mstring()); if (!wszSubject.IsEmpty()) { time_t iSubjectTime(root["subjectTime"].as_int()); diff --git a/protocols/WhatsAppWeb/src/proto.h b/protocols/WhatsAppWeb/src/proto.h index 878d664c54..0437d4ed36 100644 --- a/protocols/WhatsAppWeb/src/proto.h +++ b/protocols/WhatsAppWeb/src/proto.h @@ -71,11 +71,18 @@ struct WARequest void *pUserInfo; }; +struct WAHistoryMessage +{ + CMStringA jid, text; + DWORD timestamp; +}; + struct WAUser { WAUser(MCONTACT _1, const char *_2) : hContact(_1), - szId(mir_strdup(_2)) + szId(mir_strdup(_2)), + arHistory(1) { } @@ -90,6 +97,7 @@ struct WAUser bool bInited = false; SESSION_INFO *si = 0; DWORD m_time1 = 0, m_time2 = 0; + OBJLIST<WAHistoryMessage> arHistory; }; struct WAOwnMessage diff --git a/protocols/WhatsAppWeb/src/server.cpp b/protocols/WhatsAppWeb/src/server.cpp index c771d72220..ff6b0c2740 100644 --- a/protocols/WhatsAppWeb/src/server.cpp +++ b/protocols/WhatsAppWeb/src/server.cpp @@ -577,14 +577,27 @@ void WhatsAppProto::ProcessAdd(const CMStringA &type, const WANode *root) CMStringA szText(szMsgText); szText.Replace("%", "%%"); - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; - gce.pszID.a = jid; - gce.dwFlags = GCEF_ADDTOLOG | GCEF_UTF8; - gce.pszUID.a = payLoad.participant().c_str(); - gce.pszText.a = szText; - gce.time = dwTimestamp; - gce.bIsMe = true; - Chat_Event(&gce); + CMStringA szUserJid(payLoad.participant().c_str()); + if (!szUserJid.Replace("@s.whatsapp.net", "@c.us")) + szUserJid.Replace("@g.whatsapp.net", "@g.us"); + + if (pUser->bInited) { + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; + gce.pszID.a = jid; + gce.dwFlags = GCEF_ADDTOLOG | GCEF_UTF8; + gce.pszUID.a = szUserJid; + gce.pszText.a = szText; + gce.time = dwTimestamp; + gce.bIsMe = (jid == m_szJid); + Chat_Event(&gce); + } + else { + auto *pMsg = new WAHistoryMessage; + pMsg->jid = jid; + pMsg->text = szText; + pMsg->timestamp = dwTimestamp; + pUser->arHistory.insert(pMsg); + } } else { PROTORECVEVENT pre = { 0 }; |