diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-09-08 15:05:07 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-09-08 15:05:07 +0000 |
commit | 412d378dadabf1f5e297183ed1e82110cea6edd3 (patch) | |
tree | ef1a6c858925ef92e3afdd066f0b8db492f91b87 /protocols | |
parent | 4f5b0e5458a2f305a7f4f3908ae2a40e851ceb49 (diff) |
Tox: added offline check on message sending
git-svn-id: http://svn.miranda-ng.org/main/trunk@15306 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Tox/src/tox_messages.cpp | 29 | ||||
-rw-r--r-- | protocols/Tox/src/tox_network.cpp | 2 |
2 files changed, 26 insertions, 5 deletions
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)
|