From 48f4b68ffcb66611a4294ed0fd0ac4e49dedb09d Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Sat, 8 Jun 2013 14:51:53 +0000 Subject: 3 spaces changed to 1 tab git-svn-id: http://svn.miranda-ng.org/main/trunk@4902 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/WhatsApp/src/messages.cpp | 250 ++++++++++++++++++------------------ 1 file changed, 125 insertions(+), 125 deletions(-) (limited to 'protocols/WhatsApp/src/messages.cpp') 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 = ¶mFMessage->media_url; - break; - default: - msg = ¶mFMessage->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 = ¶mFMessage->media_url; + break; + default: + msg = ¶mFMessage->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(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(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(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 -- cgit v1.2.3