From dd6ac172c4f814fa4b5ace6caca80d00d7e01ac8 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 20 Feb 2020 21:23:22 +0300 Subject: bunch of useless threads replaced with a call of ProtoBroadcastAsync --- protocols/MSN/src/msn_proto.cpp | 59 +++++++---------------------------------- protocols/MSN/src/msn_proto.h | 2 -- protocols/MSN/src/msn_svcs.cpp | 13 +++------ 3 files changed, 13 insertions(+), 61 deletions(-) (limited to 'protocols/MSN/src') diff --git a/protocols/MSN/src/msn_proto.cpp b/protocols/MSN/src/msn_proto.cpp index 57647a9733..0f22c2e977 100644 --- a/protocols/MSN/src/msn_proto.cpp +++ b/protocols/MSN/src/msn_proto.cpp @@ -704,54 +704,19 @@ int CMsnProto::RecvContacts(MCONTACT hContact, PROTORECVEVENT* pre) return 0; } -///////////////////////////////////////////////////////////////////////////////////////// - -struct TFakeAckParams -{ - inline TFakeAckParams(MCONTACT p2, long p3, const char* p4, CMsnProto *p5, int p6 = ACKTYPE_MESSAGE) : - hContact(p2), - id(p3), - msg(p4), - proto(p5), - type(p6) - {} - - MCONTACT hContact; - int type; - long id; - const char* msg; - CMsnProto *proto; -}; - -void CMsnProto::MsnFakeAck(void* arg) -{ - TFakeAckParams* tParam = (TFakeAckParams*)arg; - - Sleep(150); - tParam->proto->ProtoBroadcastAck(tParam->hContact, tParam->type, - tParam->msg ? ACKRESULT_FAILED : ACKRESULT_SUCCESS, - (HANDLE)tParam->id, LPARAM(tParam->msg)); - - delete tParam; -} - ///////////////////////////////////////////////////////////////////////////////////////// // MsnSendMessage - sends the message to a server int CMsnProto::SendMsg(MCONTACT hContact, int flags, const char* pszSrc) { - const char *errMsg = nullptr; - if (!msnLoggedIn) { - errMsg = Translate("Protocol is offline"); - ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, 999999, errMsg, this)); + ProtoBroadcastAsync(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)999999, (LPARAM)Translate("Protocol is offline")); return 999999; } char tEmail[MSN_MAX_EMAIL_LEN]; if (MSN_IsMeByContact(hContact, tEmail)) { - errMsg = Translate("You cannot send message to yourself"); - ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, 999999, errMsg, this)); + ProtoBroadcastAsync(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)999999, (LPARAM)Translate("You cannot send message to yourself")); return 999999; } @@ -767,43 +732,39 @@ int CMsnProto::SendMsg(MCONTACT hContact, int flags, const char* pszSrc) switch (netId) { case NETID_MOB: if (mir_strlen(msg) > 133) { - errMsg = Translate("Message is too long: SMS page limited to 133 UTF8 chars"); seq = 999997; + ProtoBroadcastAsync(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)seq, (LPARAM)Translate("Message is too long: SMS page limited to 133 UTF8 chars")); } else { - errMsg = nullptr; seq = msnNsThread->sendMessage('1', tEmail, netId, msg, rtlFlag); + ProtoBroadcastAsync(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)seq); } - ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this)); break; case NETID_YAHOO: if (mir_strlen(msg) > 1202) { seq = 999996; - errMsg = Translate("Message is too long: MSN messages are limited by 1202 UTF8 chars"); - ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this)); + ProtoBroadcastAsync(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)seq, (LPARAM)Translate("Message is too long: MSN messages are limited by 1202 UTF8 chars")); } else { seq = msnNsThread->sendMessage('1', tEmail, netId, msg, rtlFlag); - ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, nullptr, this)); + ProtoBroadcastAsync(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)seq); } break; default: if (mir_strlen(msg) > 1202) { seq = 999996; - errMsg = Translate("Message is too long: MSN messages are limited by 1202 UTF8 chars"); - ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this)); + ProtoBroadcastAsync(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)seq, (LPARAM)Translate("Message is too long: MSN messages are limited by 1202 UTF8 chars")); } else { if (netId != NETID_LCS) { seq = msnNsThread->sendMessage('1', tEmail, netId, msg, rtlFlag | MSG_OFFLINE); - ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, nullptr, this)); + ProtoBroadcastAsync(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)seq); } else { seq = 999993; - errMsg = Translate("Offline messaging is not allowed for LCS contacts"); - ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this)); + ProtoBroadcastAsync(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)seq, (LPARAM)Translate("Offline messaging is not allowed for LCS contacts")); } } break; @@ -835,7 +796,7 @@ int CMsnProto::SendContacts(MCONTACT hContact, int, int nContacts, MCONTACT *hCo } msg.Append(""); seq = msnNsThread->sendMessage('1', tEmail, netId, msg, MSG_CONTACT); - ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, nullptr, this, ACKTYPE_CONTACTS)); + ProtoBroadcastAsync(hContact, ACKTYPE_CONTACTS, ACKRESULT_SUCCESS, (HANDLE)seq); return seq; } diff --git a/protocols/MSN/src/msn_proto.h b/protocols/MSN/src/msn_proto.h index 347757ab75..0d0fa760a1 100644 --- a/protocols/MSN/src/msn_proto.h +++ b/protocols/MSN/src/msn_proto.h @@ -246,8 +246,6 @@ struct CMsnProto : public PROTO void __cdecl MsnFileAckThread(void* arg); void __cdecl MsnSearchAckThread(void* arg); - void __cdecl sttFakeAvatarAck(void* arg); - void __cdecl MsnFakeAck(void* arg); void __cdecl MsnGetAwayMsgThread(void* arg); diff --git a/protocols/MSN/src/msn_svcs.cpp b/protocols/MSN/src/msn_svcs.cpp index 8d9ef1105c..9c20fd7c50 100644 --- a/protocols/MSN/src/msn_svcs.cpp +++ b/protocols/MSN/src/msn_svcs.cpp @@ -55,12 +55,6 @@ INT_PTR CMsnProto::GetAvatar(WPARAM wParam, LPARAM lParam) ///////////////////////////////////////////////////////////////////////////////////////// // MsnGetAvatarInfo - retrieve the avatar info -void CMsnProto::sttFakeAvatarAck(void* arg) -{ - Sleep(100); - ProtoBroadcastAck(((PROTO_AVATAR_INFORMATION*)arg)->hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, arg); -} - INT_PTR CMsnProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam) { PROTO_AVATAR_INFORMATION *pai = (PROTO_AVATAR_INFORMATION*)lParam; @@ -69,7 +63,8 @@ INT_PTR CMsnProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam) if (pai->hContact) { cont = Lists_Get(pai->hContact); - if (cont == nullptr) return GAIR_NOAVATAR; + if (cont == nullptr) + return GAIR_NOAVATAR; /* if ((cont->cap1 & 0xf0000000) == 0) @@ -125,9 +120,7 @@ INT_PTR CMsnProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam) WORD wStatus = getWord(pai->hContact, "Status", ID_STATUS_OFFLINE); if (wStatus == ID_STATUS_OFFLINE) { delSetting(pai->hContact, "AvatarHash"); - PROTO_AVATAR_INFORMATION *fakeAI = new PROTO_AVATAR_INFORMATION; - *fakeAI = *pai; - ForkThread(&CMsnProto::sttFakeAvatarAck, fakeAI); + ProtoBroadcastAck(pai->hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, pai); } else if (!getString(pai->hContact, "AvatarUrl", &dbv)) { pushAvatarRequest(pai->hContact, dbv.pszVal); -- cgit v1.2.3