summaryrefslogtreecommitdiff
path: root/protocols/WhatsApp/src/messages.cpp
diff options
context:
space:
mode:
authorKirill Volinsky <mataes2007@gmail.com>2013-06-08 14:51:53 +0000
committerKirill Volinsky <mataes2007@gmail.com>2013-06-08 14:51:53 +0000
commit48f4b68ffcb66611a4294ed0fd0ac4e49dedb09d (patch)
treed286e97519019c4a8a6db120231d3df09dbf28a5 /protocols/WhatsApp/src/messages.cpp
parentd0932866332ca111c02d12cefc6373feef1a90bf (diff)
3 spaces changed to 1 tab
git-svn-id: http://svn.miranda-ng.org/main/trunk@4902 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/WhatsApp/src/messages.cpp')
-rw-r--r--protocols/WhatsApp/src/messages.cpp250
1 files changed, 125 insertions, 125 deletions
diff --git a/protocols/WhatsApp/src/messages.cpp b/protocols/WhatsApp/src/messages.cpp
index fff3d6caf5..c05e19de83 100644
--- a/protocols/WhatsApp/src/messages.cpp
+++ b/protocols/WhatsApp/src/messages.cpp
@@ -9,27 +9,27 @@ int WhatsAppProto::RecvMsg(HANDLE hContact, PROTORECVEVENT *pre)
void WhatsAppProto::onMessageForMe(FMessage* paramFMessage, 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 = &paramFMessage->media_url;
- break;
- default:
- msg = &paramFMessage->data;
- }
-
- if (isChatRoom)
- {
- msg->insert(0, std::string("[").append(paramFMessage->notifyname).append("]: "));
- }
-
- HANDLE hContact = this->AddToContactList(paramFMessage->key->remote_jid, 0, false,
- isChatRoom ? NULL : paramFMessage->notifyname.c_str(), isChatRoom);
+ 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 = &paramFMessage->media_url;
+ break;
+ default:
+ msg = &paramFMessage->data;
+ }
+
+ if (isChatRoom)
+ {
+ msg->insert(0, std::string("[").append(paramFMessage->notifyname).append("]: "));
+ }
+
+ HANDLE hContact = this->AddToContactList(paramFMessage->key->remote_jid, 0, false,
+ isChatRoom ? NULL : paramFMessage->notifyname.c_str(), isChatRoom);
PROTORECVEVENT recv = {0};
recv.flags = PREF_UTF;
@@ -37,75 +37,75 @@ void WhatsAppProto::onMessageForMe(FMessage* paramFMessage, bool paramBoolean)
recv.timestamp = paramFMessage->timestamp; //time(NULL);
ProtoChainRecvMsg(hContact, &recv);
- this->connection->sendMessageReceived(paramFMessage);
+ this->connection->sendMessageReceived(paramFMessage);
}
int WhatsAppProto::SendMsg(HANDLE hContact, int flags, const char *msg)
{
- LOG("");
+ LOG("");
int msgId = ++(this->msgId);
- ForkThread( &WhatsAppProto::SendMsgWorker, this, new send_direct(hContact, msg, (HANDLE) msgId, flags & IS_CHAT));
- return this->msgIdHeader + msgId;
+ ForkThread( &WhatsAppProto::SendMsgWorker, this, new send_direct(hContact, msg, (HANDLE) msgId, flags & IS_CHAT));
+ return this->msgIdHeader + msgId;
}
void WhatsAppProto::SendMsgWorker(void* p)
{
- LOG("");
- if (p == NULL)
- return;
-
- DBVARIANT dbv;
- send_direct *data = static_cast<send_direct*>(p);
-
- if (db_get_b(data->hContact, m_szModuleName, "SimpleChatRoom", 0) > 0 &&
- db_get_b(data->hContact, m_szModuleName, "IsGroupMember", 0) == 0)
- {
- LOG("not a group member");
- ProtoBroadcastAck(m_szModuleName,data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED,
- (HANDLE) (this->msgIdHeader + this->msgId), (LPARAM) "You cannot send messages to groups if you are not a member.");
- }
- else if (!db_get_s(data->hContact, m_szModuleName,"ID", &dbv, DBVT_ASCIIZ) &&
- this->connection != NULL)
- {
- try
- {
- db_set_dw(data->hContact, m_szModuleName, WHATSAPP_KEY_LAST_MSG_STATE, 2);
- db_set_dw(data->hContact, m_szModuleName, WHATSAPP_KEY_LAST_MSG_ID_HEADER, this->msgIdHeader);
- db_set_dw(data->hContact, m_szModuleName, WHATSAPP_KEY_LAST_MSG_ID, this->msgId);
-
- std::stringstream ss;
- ss << this->msgIdHeader << "-" << this->msgId;
- Key* key = new Key(Key(dbv.pszVal, true, ss.str())); // deleted by FMessage
- FMessage fmsg(key);
- fmsg.data = data->msg;
- fmsg.timestamp = time(NULL);
-
- db_free(&dbv);
-
- this->connection->sendMessage(&fmsg);
- }
- catch (exception &e)
- {
- LOG("exception: %s", e.what());
- ProtoBroadcastAck(m_szModuleName,data->hContact,ACKTYPE_MESSAGE,ACKRESULT_FAILED,
- (HANDLE) (this->msgIdHeader + this->msgId), (LPARAM) e.what());
- }
- catch (...)
- {
- LOG("unknown exception");
- ProtoBroadcastAck(m_szModuleName,data->hContact,ACKTYPE_MESSAGE,ACKRESULT_FAILED,
- (HANDLE) (this->msgIdHeader + this->msgId), (LPARAM) "Failed sending message");
- }
- }
- else
- {
- LOG("No connection");
- ProtoBroadcastAck(m_szModuleName,data->hContact,ACKTYPE_MESSAGE,ACKRESULT_FAILED,
- (HANDLE) (this->msgIdHeader + this->msgId), (LPARAM) "You cannot send messages when you are offline.");
- }
-
- delete data;
+ LOG("");
+ if (p == NULL)
+ return;
+
+ DBVARIANT dbv;
+ send_direct *data = static_cast<send_direct*>(p);
+
+ if (db_get_b(data->hContact, m_szModuleName, "SimpleChatRoom", 0) > 0 &&
+ db_get_b(data->hContact, m_szModuleName, "IsGroupMember", 0) == 0)
+ {
+ LOG("not a group member");
+ ProtoBroadcastAck(m_szModuleName,data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED,
+ (HANDLE) (this->msgIdHeader + this->msgId), (LPARAM) "You cannot send messages to groups if you are not a member.");
+ }
+ else if (!db_get_s(data->hContact, m_szModuleName,"ID", &dbv, DBVT_ASCIIZ) &&
+ this->connection != NULL)
+ {
+ try
+ {
+ db_set_dw(data->hContact, m_szModuleName, WHATSAPP_KEY_LAST_MSG_STATE, 2);
+ db_set_dw(data->hContact, m_szModuleName, WHATSAPP_KEY_LAST_MSG_ID_HEADER, this->msgIdHeader);
+ db_set_dw(data->hContact, m_szModuleName, WHATSAPP_KEY_LAST_MSG_ID, this->msgId);
+
+ std::stringstream ss;
+ ss << this->msgIdHeader << "-" << this->msgId;
+ Key* key = new Key(Key(dbv.pszVal, true, ss.str())); // deleted by FMessage
+ FMessage fmsg(key);
+ fmsg.data = data->msg;
+ fmsg.timestamp = time(NULL);
+
+ db_free(&dbv);
+
+ this->connection->sendMessage(&fmsg);
+ }
+ catch (exception &e)
+ {
+ LOG("exception: %s", e.what());
+ ProtoBroadcastAck(m_szModuleName,data->hContact,ACKTYPE_MESSAGE,ACKRESULT_FAILED,
+ (HANDLE) (this->msgIdHeader + this->msgId), (LPARAM) e.what());
+ }
+ catch (...)
+ {
+ LOG("unknown exception");
+ ProtoBroadcastAck(m_szModuleName,data->hContact,ACKTYPE_MESSAGE,ACKRESULT_FAILED,
+ (HANDLE) (this->msgIdHeader + this->msgId), (LPARAM) "Failed sending message");
+ }
+ }
+ else
+ {
+ LOG("No connection");
+ ProtoBroadcastAck(m_szModuleName,data->hContact,ACKTYPE_MESSAGE,ACKRESULT_FAILED,
+ (HANDLE) (this->msgIdHeader + this->msgId), (LPARAM) "You cannot send messages when you are offline.");
+ }
+
+ delete data;
}
void WhatsAppProto::RecvMsgWorker(void *p)
@@ -113,21 +113,21 @@ void WhatsAppProto::RecvMsgWorker(void *p)
if (p == NULL)
return;
- //WAConnection.cpp l1225 - message will be deleted. We cannot send the ack inside a thread!
+ //WAConnection.cpp l1225 - message will be deleted. We cannot send the ack inside a thread!
//FMessage *fmsg = static_cast<FMessage*>(p);
- //this->connection->sendMessageReceived(fmsg);
+ //this->connection->sendMessageReceived(fmsg);
//delete fmsg;
}
void WhatsAppProto::onIsTyping(const std::string& paramString, bool paramBoolean)
{
- HANDLE hContact = this->AddToContactList(paramString, 0, false);
- if (hContact != NULL)
- {
- CallService(MS_PROTO_CONTACTISTYPING, (WPARAM) hContact, (LPARAM)
- paramBoolean ? PROTOTYPE_CONTACTTYPING_INFINITE : PROTOTYPE_CONTACTTYPING_OFF);
- }
+ HANDLE hContact = this->AddToContactList(paramString, 0, false);
+ if (hContact != NULL)
+ {
+ CallService(MS_PROTO_CONTACTISTYPING, (WPARAM) hContact, (LPARAM)
+ paramBoolean ? PROTOTYPE_CONTACTTYPING_INFINITE : PROTOTYPE_CONTACTTYPING_OFF);
+ }
}
@@ -152,13 +152,13 @@ void WhatsAppProto::SendTypingWorker(void* p)
DBVARIANT dbv;
if ( !db_get_s(typing->hContact,m_szModuleName,WHATSAPP_KEY_ID,&dbv, DBVT_ASCIIZ) &&
- this->isOnline())
+ this->isOnline())
{
- if (typing->status == PROTOTYPE_SELFTYPING_ON) {
- this->connection->sendComposing(dbv.pszVal);
- } else {
- this->connection->sendPaused(dbv.pszVal);
- }
+ if (typing->status == PROTOTYPE_SELFTYPING_ON) {
+ this->connection->sendComposing(dbv.pszVal);
+ } else {
+ this->connection->sendPaused(dbv.pszVal);
+ }
}
delete typing;
@@ -166,35 +166,35 @@ void WhatsAppProto::SendTypingWorker(void* p)
void WhatsAppProto::onMessageStatusUpdate(FMessage* fmsg)
{
- LOG("");
-
- HANDLE hContact = this->ContactIDToHContact(fmsg->key->remote_jid);
- if (hContact == 0)
- return;
-
- int state = 5 - fmsg->status;
- if (state != 0 && state != 1)
- return;
-
- int header;
- int id;
- size_t delimPos = fmsg->key->id.find("-");
-
- std::stringstream ss;
- ss << fmsg->key->id.substr(0, delimPos);
- ss >> header;
-
- ss.clear();
- ss << fmsg->key->id.substr(delimPos + 1);
- ss >> id;
-
- if (state == 1)
- ProtoBroadcastAck(m_szModuleName, hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE) (header + id),0);
-
- if (db_get_dw(hContact, m_szModuleName, WHATSAPP_KEY_LAST_MSG_ID_HEADER, 0) == header &&
- db_get_dw(hContact, m_szModuleName, WHATSAPP_KEY_LAST_MSG_ID, -1) == id)
- {
- db_set_dw(hContact, m_szModuleName, WHATSAPP_KEY_LAST_MSG_STATE, state);
- this->UpdateStatusMsg(hContact);
- }
+ LOG("");
+
+ HANDLE hContact = this->ContactIDToHContact(fmsg->key->remote_jid);
+ if (hContact == 0)
+ return;
+
+ int state = 5 - fmsg->status;
+ if (state != 0 && state != 1)
+ return;
+
+ int header;
+ int id;
+ size_t delimPos = fmsg->key->id.find("-");
+
+ std::stringstream ss;
+ ss << fmsg->key->id.substr(0, delimPos);
+ ss >> header;
+
+ ss.clear();
+ ss << fmsg->key->id.substr(delimPos + 1);
+ ss >> id;
+
+ if (state == 1)
+ ProtoBroadcastAck(m_szModuleName, hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE) (header + id),0);
+
+ if (db_get_dw(hContact, m_szModuleName, WHATSAPP_KEY_LAST_MSG_ID_HEADER, 0) == header &&
+ db_get_dw(hContact, m_szModuleName, WHATSAPP_KEY_LAST_MSG_ID, -1) == id)
+ {
+ db_set_dw(hContact, m_szModuleName, WHATSAPP_KEY_LAST_MSG_STATE, state);
+ this->UpdateStatusMsg(hContact);
+ }
} \ No newline at end of file