diff options
Diffstat (limited to 'protocols/WhatsApp')
| -rw-r--r-- | protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp | 38 | ||||
| -rw-r--r-- | protocols/WhatsApp/src/messages.cpp | 45 | 
2 files changed, 56 insertions, 27 deletions
| diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp index 113d2c6bf3..c5ae37bb6b 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp @@ -303,7 +303,6 @@ 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 ¬ify = messageNode->getAttributeValue("notify");
  	const string &author = messageNode->getAttributeValue("author");
  	const string &typeAttribute = messageNode->getAttributeValue("type");
 @@ -348,7 +347,7 @@ void WAConnection::parseMessage(ProtocolTreeNode *messageNode) throw (WAExceptio  		FMessage fmessage(from, false, id);
  		fmessage.wants_receipt = false;
  		fmessage.timestamp = atoi(attribute_t.c_str());
 -		fmessage.notifyname = notify;
 +		fmessage.notifyname = messageNode->getAttributeValue("notify");
  		fmessage.data = body->getDataAsString();
  		fmessage.status = FMessage::STATUS_UNSENT;
  		if (fmessage.timestamp == 0) {
 @@ -363,13 +362,13 @@ void WAConnection::parseMessage(ProtocolTreeNode *messageNode) throw (WAExceptio  			return;
  		ProtocolTreeNode *media = messageNode->getChild("media");
 -		if (from.empty() || media == NULL || media->data == NULL || media->data->empty())
 +		if (media == NULL)
  			return;
  		FMessage fmessage(from, false, id);
  		fmessage.wants_receipt = false;
  		fmessage.timestamp = atoi(attribute_t.c_str());
 -		fmessage.notifyname = notify;
 +		fmessage.data = messageNode->getAttributeValue("caption");
  		fmessage.remote_resource = author;
  		fmessage.media_wa_type = FMessage::getMessage_WA_Type(media->getAttributeValue("type"));
  		fmessage.media_url = media->getAttributeValue("url");
 @@ -383,24 +382,41 @@ void WAConnection::parseMessage(ProtocolTreeNode *messageNode) throw (WAExceptio  			if (latitudeString.empty() || longitudeString.empty())
  				throw WAException("location message missing lat or long attribute", WAException::CORRUPT_STREAM_EX, 0);
 -			double latitude = atof(latitudeString.c_str());
 -			double longitude = atof(longitudeString.c_str());
 -			fmessage.latitude = latitude;
 -			fmessage.longitude = longitude;
 +			fmessage.latitude = atof(latitudeString.c_str());
 +			fmessage.longitude = atof(longitudeString.c_str());
  		}
 -
 -		if (fmessage.media_wa_type == FMessage::WA_TYPE_CONTACT) {
 +		else if (fmessage.media_wa_type == FMessage::WA_TYPE_CONTACT) {
  			ProtocolTreeNode *contactChildNode = media->getChild(0);
  			if (contactChildNode != NULL) {
  				fmessage.media_name = contactChildNode->getAttributeValue("name");
  				fmessage.data = contactChildNode->getDataAsString();
 +				size_t off = fmessage.data.find("TEL;");
 +				if (off != string::npos) {
 +					if ((off = fmessage.data.find(":", off)) != string::npos) {
 +						std::string number;
 +						for (off++;; off++) {
 +							char c = fmessage.data[off];
 +							if (isdigit(c))
 +								number += c;
 +							else if (c == '+' || c == ' ')
 +								continue;
 +							else
 +								break;
 +						}
 +						if (!number.empty())
 +							fmessage.remote_resource = number;
 +					}
 +				}
  			}
  		}
  		else {
 +			if (media->data == NULL || media->data->empty())
 +				return;
 +
  			const string &encoding = media->getAttributeValue("encoding");
  			if (encoding.empty() || encoding == "text")
  				fmessage.data = media->getDataAsString();
 -			else {
 +			else if (media->data->size() > 0) {
  				fmessage.bindata = (unsigned char*)malloc(fmessage.bindata_len = media->data->size());
  				memcpy(fmessage.bindata, media->data->data(), fmessage.bindata_len);
  			}
 diff --git a/protocols/WhatsApp/src/messages.cpp b/protocols/WhatsApp/src/messages.cpp index d5b1325f5f..f1ad83d252 100644 --- a/protocols/WhatsApp/src/messages.cpp +++ b/protocols/WhatsApp/src/messages.cpp @@ -9,25 +9,38 @@ int WhatsAppProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT *pre)  void WhatsAppProto::onMessageForMe(FMessage *pMsg, bool paramBoolean)
  {
 -	bool isChatRoom = !pMsg->remote_resource.empty();
 -
 -	std::string msg;
 -	if (!pMsg->media_url.empty())
 -		msg = pMsg->media_url;
 -	else
 -		msg = pMsg->data;
 +	// someone sent us a contact. launch contact addition dialog
 +	if (pMsg->media_wa_type == FMessage::WA_TYPE_CONTACT) {
 +		MCONTACT hContact = AddToContactList(pMsg->remote_resource, 0, false, pMsg->media_name.c_str());
 +
 +		ADDCONTACTSTRUCT acs = { 0 };
 +		acs.handleType = HANDLE_CONTACT;
 +		acs.hContact = hContact;
 +		acs.szProto = m_szModuleName;
 +		CallServiceSync(MS_ADDCONTACT_SHOW, 0, (LPARAM)&acs);
 +	}
 +	else {
 +		bool isChatRoom = !pMsg->remote_resource.empty();
 +
 +		std::string msg(pMsg->data);
 +		if (!pMsg->media_url.empty()) {
 +			if (!msg.empty())
 +				msg.append("\n");
 +			msg += pMsg->media_url;
 +		}
 -	if (isChatRoom)
 -		msg.insert(0, std::string("[").append(pMsg->notifyname).append("]: "));
 +		if (isChatRoom)
 +			msg.insert(0, std::string("[").append(pMsg->notifyname).append("]: "));
 -	MCONTACT hContact = this->AddToContactList(pMsg->key.remote_jid, 0, false,
 -		isChatRoom ? NULL : pMsg->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<char*>(msg.c_str());
 -	recv.timestamp = pMsg->timestamp;
 -	ProtoChainRecvMsg(hContact, &recv);
 +		PROTORECVEVENT recv = { 0 };
 +		recv.flags = PREF_UTF;
 +		recv.szMessage = const_cast<char*>(msg.c_str());
 +		recv.timestamp = pMsg->timestamp;
 +		ProtoChainRecvMsg(hContact, &recv);
 +	}
  	m_pConnection->sendMessageReceived(pMsg);
  }
 | 
