From bd33df2d4b9534d2241283f2b20d83f5b1811ebc Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 29 Jan 2015 21:36:42 +0000 Subject: media files detection git-svn-id: http://svn.miranda-ng.org/main/trunk@11954 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/WhatsApp/src/messages.cpp | 48 +++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 18 deletions(-) (limited to 'protocols/WhatsApp/src/messages.cpp') diff --git a/protocols/WhatsApp/src/messages.cpp b/protocols/WhatsApp/src/messages.cpp index e139af9512..36c4bcc1da 100644 --- a/protocols/WhatsApp/src/messages.cpp +++ b/protocols/WhatsApp/src/messages.cpp @@ -7,34 +7,46 @@ int WhatsAppProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT *pre) return Proto_RecvMessage(hContact, pre); } -void WhatsAppProto::onMessageForMe(FMessage* paramFMessage, bool paramBoolean) +void WhatsAppProto::onMessageForMe(FMessage *pMsg, bool paramBoolean) { - bool isChatRoom = !paramFMessage->remote_resource.empty(); - - std::string* msg; - switch (paramFMessage->media_wa_type) { - case FMessage::WA_TYPE_IMAGE: - case FMessage::WA_TYPE_AUDIO: - case FMessage::WA_TYPE_VIDEO: - msg = ¶mFMessage->media_url; - break; - default: - msg = ¶mFMessage->data; + bool isChatRoom = !pMsg->remote_resource.empty(); + + std::string msg; + if (!pMsg->media_url.empty()) { + msg = pMsg->media_url; + if (pMsg->bindata_len) { + TCHAR tszFilePath[MAX_PATH], tszFileName[MAX_PATH]; + GetTempPath(_countof(tszFilePath), tszFilePath); + mir_sntprintf(tszFileName, _countof(tszFileName), _T("%s\\%s.jpg"), tszFilePath, _A2T(pMsg->media_name.c_str())); + FILE *out = _tfopen(tszFileName, _T("wb")); + if (out != NULL) { + fwrite(pMsg->bindata, 1, pMsg->bindata_len, out); + fclose(out); + + std::string szFileName((const char*)_T2A(tszFileName)); + std::replace(szFileName.begin(), szFileName.end(), '\\', '/'); + std::replace(szFileName.begin(), szFileName.end(), ' ', '+'); + + msg.append("\nfile://"); + msg += szFileName; + } + } } + else msg = pMsg->data; if (isChatRoom) - msg->insert(0, std::string("[").append(paramFMessage->notifyname).append("]: ")); + msg.insert(0, std::string("[").append(pMsg->notifyname).append("]: ")); - MCONTACT hContact = this->AddToContactList(paramFMessage->key.remote_jid, 0, false, - isChatRoom ? NULL : paramFMessage->notifyname.c_str(), isChatRoom); + MCONTACT hContact = this->AddToContactList(pMsg->key.remote_jid, 0, false, + isChatRoom ? NULL : pMsg->notifyname.c_str(), isChatRoom); PROTORECVEVENT recv = { 0 }; recv.flags = PREF_UTF; - recv.szMessage = const_cast(msg->c_str()); - recv.timestamp = paramFMessage->timestamp; + recv.szMessage = const_cast(msg.c_str()); + recv.timestamp = pMsg->timestamp; ProtoChainRecvMsg(hContact, &recv); - m_pConnection->sendMessageReceived(paramFMessage); + m_pConnection->sendMessageReceived(pMsg); } int WhatsAppProto::SendMsg(MCONTACT hContact, int flags, const char *msg) -- cgit v1.2.3