From 412d378dadabf1f5e297183ed1e82110cea6edd3 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Tue, 8 Sep 2015 15:05:07 +0000 Subject: Tox: added offline check on message sending git-svn-id: http://svn.miranda-ng.org/main/trunk@15306 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_messages.cpp | 29 +++++++++++++++++++++++++---- protocols/Tox/src/tox_network.cpp | 2 +- 2 files changed, 26 insertions(+), 5 deletions(-) (limited to 'protocols/Tox/src') diff --git a/protocols/Tox/src/tox_messages.cpp b/protocols/Tox/src/tox_messages.cpp index 79aaf06710..e2ff4534b2 100644 --- a/protocols/Tox/src/tox_messages.cpp +++ b/protocols/Tox/src/tox_messages.cpp @@ -54,10 +54,30 @@ int CToxProto::OnReceiveMessage(MCONTACT hContact, PROTORECVEVENT *pre) // outcoming message flow int CToxProto::OnSendMessage(MCONTACT hContact, const char *szMessage) { + if (!IsOnline()) + { + ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, NULL, (LPARAM)Translate("You cannot send when you are offline.")); + return 0; + } + int32_t friendNumber = GetToxFriendNumber(hContact); if (friendNumber == UINT32_MAX) return 0; + TOX_ERR_FRIEND_QUERY queryError; + TOX_CONNECTION connection = tox_friend_get_connection_status(tox, friendNumber, &queryError); + if (queryError == TOX_ERR_FRIEND_QUERY_OK) + { + debugLogA(__FUNCTION__": failed to get connection status for %d (%d)", friendNumber, queryError); + return 0; + } + + if (connection == TOX_CONNECTION_NONE) + { + ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, NULL, (LPARAM)Translate("You cannot send when contact is offline.")); + return 0; + } + size_t msgLen = mir_strlen(szMessage); uint8_t *msg = (uint8_t*)szMessage; TOX_MESSAGE_TYPE type = TOX_MESSAGE_TYPE_NORMAL; @@ -66,11 +86,12 @@ int CToxProto::OnSendMessage(MCONTACT hContact, const char *szMessage) msg += 4; msgLen -= 4; type = TOX_MESSAGE_TYPE_ACTION; } - TOX_ERR_FRIEND_SEND_MESSAGE error; - int messageId = tox_friend_send_message(tox, friendNumber, type, msg, msgLen, &error); - if (error != TOX_ERR_FRIEND_SEND_MESSAGE_OK) + + TOX_ERR_FRIEND_SEND_MESSAGE sendError; + int messageId = tox_friend_send_message(tox, friendNumber, type, msg, msgLen, &sendError); + if (sendError != TOX_ERR_FRIEND_SEND_MESSAGE_OK) { - debugLogA(__FUNCTION__": failed to send message (%d)", error); + debugLogA(__FUNCTION__": failed to send message for %d (%d)", friendNumber, sendError); return 0; } diff --git a/protocols/Tox/src/tox_network.cpp b/protocols/Tox/src/tox_network.cpp index 84db80e7c3..8db001a5a5 100644 --- a/protocols/Tox/src/tox_network.cpp +++ b/protocols/Tox/src/tox_network.cpp @@ -2,7 +2,7 @@ bool CToxProto::IsOnline() { - return isConnected && m_iStatus > ID_STATUS_OFFLINE; + return isConnected && m_iStatus >= ID_STATUS_ONLINE; } void CToxProto::BootstrapNode(const char *address, int port, const char *hexKey) -- cgit v1.2.3