diff options
author | George Hazan <george.hazan@gmail.com> | 2015-02-07 20:46:03 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-02-07 20:46:03 +0000 |
commit | 65ef9d3aaa306361f039679fcf73cdfbf10ec6b4 (patch) | |
tree | 2ac626cdf3f99326850f9ede059a4c478b28d59f /protocols/WhatsApp/src | |
parent | be396370409163efe1e1d8868100cf1a2020d068 (diff) |
fix for sending media messages to group chats
git-svn-id: http://svn.miranda-ng.org/main/trunk@12046 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/WhatsApp/src')
-rw-r--r-- | protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp | 33 | ||||
-rw-r--r-- | protocols/WhatsApp/src/chat.cpp | 25 |
2 files changed, 32 insertions, 26 deletions
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<ProtocolTreeNode*> 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)
diff --git a/protocols/WhatsApp/src/chat.cpp b/protocols/WhatsApp/src/chat.cpp index 1f855f9b55..0f574b2c93 100644 --- a/protocols/WhatsApp/src/chat.cpp +++ b/protocols/WhatsApp/src/chat.cpp @@ -319,17 +319,24 @@ void WhatsAppProto::onGroupInfo(const std::string &jid, const std::string &owner CallServiceSync(MS_GC_EVENT, SESSION_INITDONE, (LPARAM)&gce);
}
-void WhatsAppProto::onGroupMessage(const FMessage &msg)
+void WhatsAppProto::onGroupMessage(const FMessage &pMsg)
{
- WAChatInfo *pInfo = SafeGetChat(msg.key.remote_jid);
+ WAChatInfo *pInfo = SafeGetChat(pMsg.key.remote_jid);
if (pInfo == NULL) {
- pInfo = InitChat(msg.key.remote_jid, "");
+ pInfo = InitChat(pMsg.key.remote_jid, "");
pInfo->bActive = true;
}
- ptrT tszText(str2t(msg.data));
- ptrT tszUID(str2t(msg.remote_resource));
- ptrT tszNick(GetChatUserNick(msg.remote_resource));
+ std::string msg(pMsg.data);
+ if (!pMsg.media_url.empty()) {
+ if (!msg.empty())
+ msg.append("\n");
+ msg += pMsg.media_url;
+ }
+
+ ptrT tszText(str2t(msg));
+ ptrT tszUID(str2t(pMsg.remote_resource));
+ ptrT tszNick(GetChatUserNick(pMsg.remote_resource));
GCDEST gcd = { m_szModuleName, pInfo->tszJid, GC_EVENT_MESSAGE };
@@ -337,13 +344,13 @@ void WhatsAppProto::onGroupMessage(const FMessage &msg) gce.dwFlags = GCEF_ADDTOLOG;
gce.ptszUID = tszUID;
gce.ptszNick = tszNick;
- gce.time = msg.timestamp;
+ gce.time = pMsg.timestamp;
gce.ptszText = tszText;
- gce.bIsMe = m_szJid == msg.remote_resource;
+ gce.bIsMe = m_szJid == pMsg.remote_resource;
CallServiceSync(MS_GC_EVENT, NULL, (LPARAM)&gce);
if (isOnline())
- m_pConnection->sendMessageReceived(msg);
+ m_pConnection->sendMessageReceived(pMsg);
}
void WhatsAppProto::onGroupNewSubject(const std::string &gjid, const std::string &author, const std::string &newSubject, int ts)
|