diff options
author | George Hazan <ghazan@miranda.im> | 2022-10-30 13:16:07 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-10-30 13:16:07 +0300 |
commit | 96d5125d05d6ee41c567e8380608c2706d21656b (patch) | |
tree | 9b96a14b91ec5540e8c5d9f1c662151ca01e895f | |
parent | ecb2a3bb4c42ca47ba0ce8e405d5a47aa899b64c (diff) |
WhatsApp: extended message processing
-rw-r--r-- | protocols/WhatsApp/src/appsync.cpp | 13 | ||||
-rw-r--r-- | protocols/WhatsApp/src/message.cpp | 37 |
2 files changed, 35 insertions, 15 deletions
diff --git a/protocols/WhatsApp/src/appsync.cpp b/protocols/WhatsApp/src/appsync.cpp index fa204c00f3..f77fff2d4b 100644 --- a/protocols/WhatsApp/src/appsync.cpp +++ b/protocols/WhatsApp/src/appsync.cpp @@ -190,17 +190,22 @@ void WhatsAppProto::ParsePatch(WACollection *pColl, const Wa__SyncdRecord *rec, } proto::SyncActionData data(unpadBuffer16(decoded)); - - debugLogA("Applying patch for %s{%d}: %s", pColl->szName.get(), data->version, protobuf_c_text_to_string(data).c_str()); + if (!data) { + debugLogA("Unable to decode action data with id=%d", id); + return; + } + + JSONNode jsonRoot = JSONNode::parse((char *)data->index.data); if (bSet) { - JSONNode jsonRoot = JSONNode::parse((char*)data->index.data); ApplyPatch(jsonRoot, data->value); pColl->hash.add(macValue, 32); pColl->indexValueMap[index] = std::string((char*)macValue, 32); } else { + debugLogA("Removing data with index: %s", jsonRoot.write().c_str()); + auto &prevVal = pColl->indexValueMap.find(index); if (prevVal != pColl->indexValueMap.end()) { pColl->hash.sub(prevVal->second.c_str(), prevVal->second.size()); @@ -211,6 +216,8 @@ void WhatsAppProto::ParsePatch(WACollection *pColl, const Wa__SyncdRecord *rec, void WhatsAppProto::ApplyPatch(const JSONNode &index, const Wa__SyncActionValue *data) { + debugLogA("Applying patch for %s: %s", index.write().c_str(), protobuf_c_text_to_string(data).c_str()); + auto title = index.at((json_index_t)0).as_string(); if (title == "contact" && data->contactaction) { diff --git a/protocols/WhatsApp/src/message.cpp b/protocols/WhatsApp/src/message.cpp index 3ae999fcd2..84d863830a 100644 --- a/protocols/WhatsApp/src/message.cpp +++ b/protocols/WhatsApp/src/message.cpp @@ -196,7 +196,7 @@ void WhatsAppProto::ProcessMessage(WAMSG type, const Wa__WebMessageInfo &msg) auto *participant = key->participant; auto *chatId = key->remotejid; auto *msgId = key->id; - + WAUser *pUser = FindUser(chatId); if (pUser == nullptr) { if (type.bPrivateChat) @@ -208,17 +208,30 @@ void WhatsAppProto::ProcessMessage(WAMSG type, const Wa__WebMessageInfo &msg) if (!bFromMe && msg.pushname && pUser && !pUser->bIsGroupChat) setUString(pUser->hContact, "Nick", msg.pushname); - // try to extract some text - if (mir_strlen(body->conversation)) { - PROTORECVEVENT pre = {}; - pre.timestamp = timestamp; - pre.szMessage = body->conversation; - pre.szMsgId = msgId; - if (type.bOffline) - pre.flags |= PREF_CREATEREAD; - if (bFromMe) - pre.flags |= PREF_SENT; - ProtoChainRecvMsg(pUser->hContact, &pre); + // try to extract some text + if (pUser) { + CMStringA szMessageText; + if (auto *pExt = body->extendedtextmessage) { + if (pExt->contextinfo && pExt->contextinfo->quotedmessage) + szMessageText.AppendFormat("> %s\n\n", pExt->contextinfo->quotedmessage->conversation); + + if (pExt->text) + szMessageText.Append(pExt->text); + } + else if (mir_strlen(body->conversation)) + szMessageText = body->conversation; + + if (!szMessageText.IsEmpty()) { + PROTORECVEVENT pre = {}; + pre.timestamp = timestamp; + pre.szMessage = szMessageText.GetBuffer(); + pre.szMsgId = msgId; + if (type.bOffline) + pre.flags |= PREF_CREATEREAD; + if (bFromMe) + pre.flags |= PREF_SENT; + ProtoChainRecvMsg(pUser->hContact, &pre); + } } if (body->protocolmessage) { |