From d63357b81e3cd3b9a54146d98222113d7a73cb59 Mon Sep 17 00:00:00 2001 From: sss Date: Mon, 2 Dec 2024 17:13:45 +0300 Subject: jabber: working on xmppmsg --- protocols/JabberG/src/jabber_archive.cpp | 35 ++++++++------------------------ protocols/JabberG/src/jabber_omemo.cpp | 13 ++++++------ protocols/JabberG/src/jabber_proto.h | 4 ++-- protocols/JabberG/src/jabber_thread.cpp | 10 ++++----- 4 files changed, 22 insertions(+), 40 deletions(-) (limited to 'protocols') diff --git a/protocols/JabberG/src/jabber_archive.cpp b/protocols/JabberG/src/jabber_archive.cpp index d0c6065db4..8da5128406 100644 --- a/protocols/JabberG/src/jabber_archive.cpp +++ b/protocols/JabberG/src/jabber_archive.cpp @@ -102,41 +102,24 @@ void CJabberProto::OnIqResultGetCollection(const TiXmlElement *iqNode, CJabberIq time_t tmLast = getDword(hContact, "LastCollection", 0); for (auto *itemNode : TiXmlEnum(chatNode)) { - int from; XmppMsg msg(itemNode, this); - //TODO: integrate following logic into XmppMessage and remove it here const char *itemName = itemNode->Name(); if (!mir_strcmp(itemName, "to")) - from = DBEF_SENT; - else if (!mir_strcmp(itemName, "from")) - from = 0; - else + msg.dbei.flags |= DBEF_SENT; + else if (mir_strcmp(itemName, "from")) continue; - const TiXmlElement *body = XmlFirstChild(itemNode, "body"); - if (!body) - continue; - - const char *tszBody = body->GetText(); const char *tszSecs = XmlGetAttr(itemNode, "secs"); - if (!tszBody || !tszSecs) - continue; + msg.msgTime = tmStart + atol(tszSecs); + + msg.process(); + - DBEVENTINFO dbei = {}; - dbei.eventType = EVENTTYPE_MESSAGE; - dbei.szModule = m_szModuleName; - dbei.cbBlob = (uint32_t)mir_strlen(tszBody) + 1; - dbei.flags = DBEF_READ + DBEF_UTF + from; - dbei.pBlob = (char *)tszBody; - dbei.timestamp = tmStart + atol(tszSecs); - if (!DB::IsDuplicateEvent(hContact, dbei)) - db_event_add(hContact, &dbei); - - tmStart = dbei.timestamp; - if (dbei.timestamp > tmLast) - tmLast = dbei.timestamp; + tmStart = msg.dbei.timestamp; + if (msg.dbei.timestamp > tmLast) + tmLast = msg.dbei.timestamp; } if (tmLast != 0) diff --git a/protocols/JabberG/src/jabber_omemo.cpp b/protocols/JabberG/src/jabber_omemo.cpp index 39b6b7d8dd..b28f32ccb0 100644 --- a/protocols/JabberG/src/jabber_omemo.cpp +++ b/protocols/JabberG/src/jabber_omemo.cpp @@ -1255,7 +1255,7 @@ void CJabberProto::OmemoHandleMessageQueue() uint32_t JabberGetLastContactMessageTime(MCONTACT hContact); -bool CJabberProto::OmemoHandleMessage(const TiXmlElement *node, const char *jid, time_t msgTime, bool isCarbon) +bool CJabberProto::OmemoHandleMessage(XmppMsg *msg, const TiXmlElement *node, const char *jid, time_t msgTime, bool isCarbon) { auto *header_node = XmlFirstChild(node, "header"); if (!header_node) { @@ -1418,14 +1418,13 @@ bool CJabberProto::OmemoHandleMessage(const TiXmlElement *node, const char *jid, db_event_add(hContact, &dbei); } else { - DB::EventInfo dbei; - dbei.timestamp = (uint32_t)msgTime; - dbei.pBlob = result.GetBuffer(); + msg->msgTime = msgTime; + msg->szMessage = result; + if (trusted) - dbei.flags = DBEF_STRONG; + msg->dbei.flags = DBEF_STRONG; if (isCarbon) - dbei.flags = DBEF_SENT; - ProtoChainRecvMsg(hContact, dbei); + msg->dbei.flags = DBEF_SENT; } return true; diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index a373f04df6..83d13b8797 100644 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -100,7 +100,7 @@ struct CJabberProto : public PROTO, public IJabberInterface void process(); void handle_mam(); void handle_carbon(); - void handle_omemo(); + bool handle_omemo(); void handle_chatstates(); void add_to_db(); @@ -762,7 +762,7 @@ struct CJabberProto : public PROTO, public IJabberInterface //---- jabber_omemo.cpp -------------------------------------------------------------- - bool OmemoHandleMessage(const TiXmlElement *node, const char *jid, time_t msgTime, bool isCarbon); + bool OmemoHandleMessage(XmppMsg *msg, const TiXmlElement *node, const char *jid, time_t msgTime, bool isCarbon); void OmemoPutMessageToOutgoingQueue(MCONTACT hContact, const char *pszSrc); void OmemoHandleMessageQueue(); bool OmemoHandleDeviceList(const char *from, const TiXmlElement *node); diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index 86f7e12bd4..b43afa84c0 100644 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -1031,9 +1031,8 @@ time_t CJabberProto::XmppMsg::extract_timestamp() } void CJabberProto::XmppMsg::handle_mam() { - dbei.flags |= DBEF_READ; - if (auto* mamResult = XmlGetChildByTag(node, "result", "xmlns", JABBER_FEAT_MAM)) { + dbei.flags |= DBEF_READ; szMamMsgId = XmlGetAttr(mamResult, "id"); if (szMamMsgId) m_proto->setString("LastMamId", szMamMsgId); @@ -1122,14 +1121,15 @@ void CJabberProto::XmppMsg::handle_carbon() } } -void CJabberProto::XmppMsg::handle_omemo() +bool CJabberProto::XmppMsg::handle_omemo() { if (m_proto->m_bUseOMEMO) { if (auto* encNode = XmlGetChildByTag(node, "encrypted", "xmlns", JABBER_FEAT_OMEMO)) { - m_proto->OmemoHandleMessage(encNode, from, msgTime, bWasSent); - return; //we do not want any additional processing + m_proto->OmemoHandleMessage(this, encNode, from, msgTime, bWasSent); + return true; } } + return false; } void CJabberProto::XmppMsg::handle_chatstates() -- cgit v1.2.3