From 65ef9d3aaa306361f039679fcf73cdfbf10ec6b4 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 7 Feb 2015 20:46:03 +0000 Subject: fix for sending media messages to group chats git-svn-id: http://svn.miranda-ng.org/main/trunk@12046 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp | 33 +++++++++++----------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp') diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp index e1e983cad0..60e585e801 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp @@ -382,12 +382,12 @@ void WAConnection::parseMessage(ProtocolTreeNode *messageNode) throw (WAExceptio const string &id = messageNode->getAttributeValue("id"); const string &attribute_t = messageNode->getAttributeValue("t"); const string &from = messageNode->getAttributeValue("from"); - const string &author = messageNode->getAttributeValue("author"); const string &typeAttribute = messageNode->getAttributeValue("type"); if (typeAttribute.empty()) return; + const string &participant = messageNode->getAttributeValue("participant"); if (typeAttribute == "error") { int errorCode = 0; std::vector errorNodes(messageNode->getAllChildren("error")); @@ -401,16 +401,21 @@ void WAConnection::parseMessage(ProtocolTreeNode *messageNode) throw (WAExceptio if (m_pEventHandler != NULL) m_pEventHandler->onMessageError(message, errorCode); + return; } - else if (typeAttribute == "text") { + + if (from.empty() || id.empty()) + return; + FMessage fmessage(from, false, id); + + if (typeAttribute == "text") { ProtocolTreeNode *body = messageNode->getChild("body"); - if (from.empty() || body == NULL || body->data == NULL || body->data->empty()) + if (body == NULL || body->data == NULL || body->data->empty()) return; - FMessage fmessage(from, false, id); fmessage.wants_receipt = false; fmessage.timestamp = atoi(attribute_t.c_str()); - fmessage.remote_resource = messageNode->getAttributeValue("participant"); + fmessage.remote_resource = participant; fmessage.notifyname = messageNode->getAttributeValue("notify"); fmessage.data = body->getDataAsString(); fmessage.status = FMessage::STATUS_UNSENT; @@ -418,27 +423,16 @@ void WAConnection::parseMessage(ProtocolTreeNode *messageNode) throw (WAExceptio fmessage.timestamp = time(NULL); fmessage.offline = false; } - - if (fmessage.remote_resource.empty()) { - if (m_pEventHandler != NULL) - m_pEventHandler->onMessageForMe(fmessage); - } - else if (m_pGroupEventHandler != NULL) - m_pGroupEventHandler->onGroupMessage(fmessage); } else if (typeAttribute == "media") { - if (from.empty() || id.empty()) - return; - ProtocolTreeNode *media = messageNode->getChild("media"); if (media == NULL) return; - FMessage fmessage(from, false, id); fmessage.wants_receipt = false; fmessage.timestamp = atoi(attribute_t.c_str()); fmessage.notifyname = messageNode->getAttributeValue("notify"); - fmessage.remote_resource = author; + fmessage.remote_resource = messageNode->getAttributeValue("participant"); fmessage.media_wa_type = FMessage::getMessage_WA_Type(media->getAttributeValue("type")); fmessage.media_url = media->getAttributeValue("url"); fmessage.media_name = media->getAttributeValue("file"); @@ -488,10 +482,15 @@ void WAConnection::parseMessage(ProtocolTreeNode *messageNode) throw (WAExceptio else fmessage.data = media->getAttributeValue("caption"); } + } + else return; + if (fmessage.remote_resource.empty()) { if (m_pEventHandler != NULL) m_pEventHandler->onMessageForMe(fmessage); } + else if (m_pGroupEventHandler != NULL) + m_pGroupEventHandler->onGroupMessage(fmessage); } void WAConnection::parseNotification(ProtocolTreeNode *node) throw(WAException) -- cgit v1.2.3